Skip to content

Commit 8e460cf

Browse files
authored
Add vscode theme generation (#31)
1 parent 8f533c2 commit 8e460cf

5 files changed

Lines changed: 1397 additions & 3 deletions

File tree

src/components/SettingsSidebar.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const SettingsSidebar = GObject.registerClass(
5252
this._includeNeovim = true;
5353
this._includeVencord = false;
5454
this._includeZed = false;
55+
this._includeVscode = false;
5556
this._includeGtk = false;
5657
this._lightMode = false;
5758
this._selectedNeovimConfig = null;
@@ -638,6 +639,27 @@ export const SettingsSidebar = GObject.registerClass(
638639

639640
expanderRow.add_row(zedRow);
640641

642+
const vscodeRow = new Adw.ActionRow({
643+
title: 'Include VSCode Theme',
644+
subtitle:
645+
'Copy vscode.json to ~/.vscode/extensions/theme-aether/themes/',
646+
});
647+
648+
this._vscodeSwitch = new Gtk.Switch({
649+
active: this._includeVscode,
650+
valign: Gtk.Align.CENTER,
651+
});
652+
653+
this._vscodeSwitch.connect('notify::active', sw => {
654+
this._includeVscode = sw.get_active();
655+
this.emit('settings-changed', this.getSettings());
656+
});
657+
658+
vscodeRow.add_suffix(this._vscodeSwitch);
659+
vscodeRow.set_activatable_widget(this._vscodeSwitch);
660+
661+
expanderRow.add_row(vscodeRow);
662+
641663
return expanderRow;
642664
}
643665

@@ -790,6 +812,7 @@ export const SettingsSidebar = GObject.registerClass(
790812
includeNeovim: this._includeNeovim,
791813
includeVencord: this._includeVencord,
792814
includeZed: this._includeZed,
815+
includeVscode: this._includeVscode,
793816
includeGtk: this._includeGtk,
794817
lightMode: this._lightMode,
795818
selectedNeovimConfig: this._selectedNeovimConfig,
@@ -809,6 +832,7 @@ export const SettingsSidebar = GObject.registerClass(
809832
this._includeNeovim = settings.includeNeovim ?? true;
810833
this._includeVencord = settings.includeVencord ?? false;
811834
this._includeZed = settings.includeZed ?? false;
835+
this._includeVscode = settings.includeVscode ?? false;
812836
this._includeGtk = settings.includeGtk ?? false;
813837
this._enableAppOverrides = settings.enableAppOverrides ?? false;
814838
console.log('Loaded settings from', this._settingsPath);
@@ -826,6 +850,7 @@ export const SettingsSidebar = GObject.registerClass(
826850
includeNeovim: this._includeNeovim,
827851
includeVencord: this._includeVencord,
828852
includeZed: this._includeZed,
853+
includeVscode: this._includeVscode,
829854
includeGtk: this._includeGtk,
830855
enableAppOverrides: this._enableAppOverrides,
831856
};

src/utils/ConfigWriter.js

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class ConfigWriter {
5858
this._copyWallpaper(wallpaperPath);
5959
}
6060

61-
const variables = this._buildVariables(colorRoles);
61+
const variables = this._buildVariables(colorRoles, lightMode);
6262
this._processTemplates(variables, settings, appOverrides);
6363
this._applyAetherThemeOverride(variables);
6464

@@ -77,6 +77,11 @@ export class ConfigWriter {
7777
this._copyZedTheme();
7878
}
7979

80+
// Copy VSCode theme if enabled
81+
if (settings.includeVscode === true) {
82+
this._copyVscodeTheme(variables);
83+
}
84+
8085
this._handleLightModeMarker(this.themeDir, lightMode);
8186
this._applyOmarchyTheme();
8287

@@ -107,14 +112,17 @@ export class ConfigWriter {
107112
return destPath;
108113
}
109114

110-
_buildVariables(colorRoles) {
115+
_buildVariables(colorRoles, lightMode = false) {
111116
const variables = {};
112117

113118
// Use default colors as fallback
114119
Object.keys(DEFAULT_COLORS).forEach(key => {
115120
variables[key] = colorRoles[key] || DEFAULT_COLORS[key];
116121
});
117122

123+
// Add theme type for VSCode and other templates
124+
variables.theme_type = lightMode ? 'light' : 'dark';
125+
118126
return variables;
119127
}
120128

@@ -156,6 +164,25 @@ export class ConfigWriter {
156164
fileName,
157165
]);
158166

167+
// Handle vscode.empty.json - use when VSCode is disabled
168+
if (fileName === 'vscode.empty.json') {
169+
if (settings.includeVscode === false) {
170+
// Write empty vscode.json when disabled
171+
const vscodeOutputPath = GLib.build_filenamev([
172+
this.themeDir,
173+
'vscode.json',
174+
]);
175+
this._processTemplate(
176+
templatePath,
177+
vscodeOutputPath,
178+
variables,
179+
'vscode.empty.json',
180+
appOverrides
181+
);
182+
}
183+
return;
184+
}
185+
159186
// If this is neovim.lua and a custom config is selected, write it directly
160187
if (
161188
fileName === 'neovim.lua' &&
@@ -305,7 +332,7 @@ export class ConfigWriter {
305332
console.log(`Copied wallpaper to: ${destPath}`);
306333
}
307334

308-
const variables = this._buildVariables(colorRoles);
335+
const variables = this._buildVariables(colorRoles, lightMode);
309336
this._processTemplatesToDirectory(
310337
variables,
311338
exportPath,
@@ -362,6 +389,25 @@ export class ConfigWriter {
362389

363390
const outputPath = GLib.build_filenamev([exportPath, fileName]);
364391

392+
// Handle vscode.empty.json - use when VSCode is disabled
393+
if (fileName === 'vscode.empty.json') {
394+
if (settings.includeVscode === false) {
395+
// Write empty vscode.json when disabled
396+
const vscodeOutputPath = GLib.build_filenamev([
397+
exportPath,
398+
'vscode.json',
399+
]);
400+
this._processTemplate(
401+
templatePath,
402+
vscodeOutputPath,
403+
variables,
404+
'vscode.empty.json',
405+
appOverrides
406+
);
407+
}
408+
return;
409+
}
410+
365411
// If this is neovim.lua and a custom config is selected, write it directly
366412
if (
367413
fileName === 'neovim.lua' &&
@@ -565,6 +611,66 @@ export class ConfigWriter {
565611
}
566612
}
567613

614+
_copyVscodeTheme(variables) {
615+
try {
616+
const homeDir = GLib.get_home_dir();
617+
const vscodeExtensionPath = GLib.build_filenamev([
618+
homeDir,
619+
'.vscode',
620+
'extensions',
621+
'theme-aether',
622+
]);
623+
624+
// Ensure the extension directory exists
625+
ensureDirectoryExists(vscodeExtensionPath);
626+
627+
// Process the entire vscode-extension folder from templates
628+
const vscodeTemplateDir = GLib.build_filenamev([
629+
this.templatesDir,
630+
'vscode-extension',
631+
]);
632+
633+
// Copy and process all files from vscode-extension template
634+
this._copyVscodeExtensionDirectory(
635+
vscodeTemplateDir,
636+
vscodeExtensionPath,
637+
variables
638+
);
639+
640+
console.log(
641+
`Installed VSCode extension to: ${vscodeExtensionPath}`
642+
);
643+
} catch (e) {
644+
console.error('Error copying VSCode theme:', e.message);
645+
}
646+
}
647+
648+
_copyVscodeExtensionDirectory(sourceDir, destDir, variables) {
649+
enumerateDirectory(sourceDir, (fileInfo, filePath, fileName) => {
650+
const fileType = fileInfo.get_file_type();
651+
652+
if (fileType === Gio.FileType.DIRECTORY) {
653+
// Recursively process subdirectories
654+
const subSourceDir = GLib.build_filenamev([
655+
sourceDir,
656+
fileName,
657+
]);
658+
const subDestDir = GLib.build_filenamev([destDir, fileName]);
659+
ensureDirectoryExists(subDestDir);
660+
this._copyVscodeExtensionDirectory(
661+
subSourceDir,
662+
subDestDir,
663+
variables
664+
);
665+
} else if (fileType === Gio.FileType.REGULAR) {
666+
// Process and copy file
667+
const destPath = GLib.build_filenamev([destDir, fileName]);
668+
this._processTemplate(filePath, destPath, variables, fileName);
669+
console.log(`Processed VSCode extension file: ${fileName}`);
670+
}
671+
});
672+
}
673+
568674
_copyGtkFile(sourcePath, destPath, label) {
569675
try {
570676
// Remove existing file if it exists
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "theme-aether",
3+
"displayName": "Aether Theme",
4+
"description": "Aether color theme generated from wallpaper",
5+
"version": "1.0.0",
6+
"engines": {
7+
"vscode": "^1.70.0"
8+
},
9+
"categories": ["Themes"],
10+
"contributes": {
11+
"themes": [
12+
{
13+
"label": "Aether",
14+
"uiTheme": "vs-{theme_type}",
15+
"path": "./themes/aether-color-theme.json"
16+
}
17+
]
18+
}
19+
}

0 commit comments

Comments
 (0)