-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
84 lines (67 loc) · 2.31 KB
/
extension.js
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
const vscode = require('vscode');
/**
* @param {vscode.ExtensionContext} context
*/
async function activate(context) {
const iconThemes = vscode.extensions.all.flatMap(extension => {
const contributes = extension.packageJSON.contributes;
return contributes && contributes.iconThemes
? contributes.iconThemes.map(iconTheme => iconTheme.id)
: [];
});
// Check if user has configured the icon themes
const configuration = vscode.workspace.getConfiguration();
const darkIconTheme = configuration.get('icontheme.darkIconTheme');
const lightIconTheme = configuration.get('icontheme.lightIconTheme');
if (darkIconTheme === "" || lightIconTheme === "") {
// Send a message to the user with a link to the settings.json file
const selection = await vscode.window.showInformationMessage(
'Please configure the icon themes to have them dynamically changed.',
'Configure now',
'Later'
);
if (selection === 'Later') {
return;
}
// Open popup with list of icon themes
const selectedDarkIconTheme = await vscode.window.showQuickPick(iconThemes, {
placeHolder: 'Select dark icon theme'
});
if (!selectedDarkIconTheme) {
return;
}
const selectedLightIconTheme = await vscode.window.showQuickPick(iconThemes, {
placeHolder: 'Select light icon theme'
});
if (!selectedLightIconTheme) {
return;
}
await configuration.update(
'icontheme.darkIconTheme',
selectedDarkIconTheme,
vscode.ConfigurationTarget.Global
);
await configuration.update(
'icontheme.lightIconTheme',
selectedLightIconTheme,
vscode.ConfigurationTarget.Global
);
vscode.window.showInformationMessage('Icon themes configured successfully.');
}
vscode.window.onDidChangeActiveColorTheme(() => {
setIconTheme();
});
setIconTheme();
}
// This method is called when your extension is deactivated
function deactivate() {}
function setIconTheme() {
const config = vscode.workspace.getConfiguration();
const isDark = vscode.window.activeColorTheme.kind === vscode.ColorThemeKind.Dark;
const iconThemeName = isDark ? config.get("icontheme.darkIconTheme") : config.get("icontheme.lightIconTheme");
if(iconThemeName !== "null") vscode.workspace.getConfiguration().update('workbench.iconTheme', iconThemeName, vscode.ConfigurationTarget.Global);
}
module.exports = {
activate,
deactivate
}