forked from Binaryify/OneDark-Pro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.ts
89 lines (86 loc) · 2.46 KB
/
extension.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { join } from 'path'
import { TextEncoder } from 'util'
import {
commands as Commands,
ConfigurationTarget,
Uri,
workspace,
} from 'vscode'
import { ChangelogWebview } from './webviews/Changelog'
import { updateCSS, updateTheme } from './utils'
/**
* This method is called when the extension is activated.
* It initializes the core functionality of the extension.
*/
export async function activate() {
const flagPath = Uri.file(join(__dirname, '../temp', 'flag.txt'))
let flag
try {
// await workspace.fs.writeFile(flagPath, new TextEncoder().encode('true'))
try {
if (await workspace.fs.stat(flagPath)) {
flag = true
}
} catch (error) {}
if (!flag) {
await workspace.fs.writeFile(flagPath, new TextEncoder().encode('true'))
const configArr = [
{ defaultVal: false, type: 'bold' },
{ defaultVal: true, type: 'italic' },
{ defaultVal: false, type: 'vivid' },
]
const configuration = workspace.getConfiguration('oneDarkPro')
let isDefaultConfig = configArr.every((item) => {
return configuration.get<boolean>(item.type) === item.defaultVal
})
let colorConfig = configuration.get<object>(`color`)
let colorFlagStr = ''
for (let key in colorConfig) {
colorFlagStr += colorConfig[key]
}
if (colorFlagStr != '') {
isDefaultConfig = false
}
if (!isDefaultConfig) {
updateTheme()
}
if (!configuration.get<boolean>('markdownStyle')) {
updateCSS()
}
}
} catch (err) {
console.log(err)
// do nothing
}
// Observe changes in the config
workspace.onDidChangeConfiguration((event) => {
if (event.affectsConfiguration('oneDarkPro')) {
updateTheme()
updateCSS()
}
})
Commands.registerCommand('oneDarkPro.showChangelog', () => {
new ChangelogWebview().show()
})
const settingArr = ['Vivid', 'Italic', 'Bold']
settingArr.forEach((settingItem) => {
Commands.registerCommand(`oneDarkPro.set${settingItem}`, () => {
workspace
.getConfiguration()
.update(
`oneDarkPro.${settingItem.toLowerCase()}`,
true,
ConfigurationTarget.Global
)
})
Commands.registerCommand(`oneDarkPro.cancel${settingItem}`, () => {
workspace
.getConfiguration()
.update(
`oneDarkPro.${settingItem.toLowerCase()}`,
false,
ConfigurationTarget.Global
)
})
})
}