Skip to content

Commit 0bb98eb

Browse files
committed
Initial commit
1 parent a69b67c commit 0bb98eb

File tree

6 files changed

+2334
-41
lines changed

6 files changed

+2334
-41
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# wallbash README
1+
# wallbash
22

3-
This is the README for your extension "wallbash". After writing up a brief description, we recommend including the following sections.
3+
VSCode extension for Wallbash.
44

55
## Features
66

@@ -65,7 +65,7 @@ You can author your README using Visual Studio Code. Here are some useful editor
6565

6666
## For more information
6767

68-
* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
68+
* [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown)
6969
* [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/)
7070

7171
**Enjoy!**

hyde.png

174 KB
Loading

package-lock.json

+3-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+43-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,56 @@
11
{
22
"name": "wallbash",
3-
"displayName": "wallbash",
3+
"displayName": "Wallbash",
44
"description": "VSCode dynamic theme using wallbash",
55
"version": "0.0.1",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/HyDE-Project/vscode-wallbash",
9+
"issues": "https://github.com/HyDE-Project/vscode-wallbash/issues",
10+
"pulls": "https://github.com/HyDE-Project/vscode-wallbash/pulls"
11+
12+
},
13+
"license": "GPL",
614
"engines": {
715
"vscode": "^1.95.0"
816
},
917
"categories": [
10-
"Other"
18+
"Themes"
19+
],
20+
"keywords": [
21+
"theme",
22+
"wallbash",
23+
"dynamic",
24+
"hyde",
25+
"hyprland"
1126
],
12-
"activationEvents": [],
27+
"icon": "hyde.png",
28+
"activationEvents": [ "wallbash.update" ] ,
1329
"main": "./out/extension.js",
1430
"contributes": {
1531
"commands": [
1632
{
17-
"command": "wallbash.helloWorld",
18-
"title": "Hello World"
33+
"command": "wallbash.update",
34+
"title": "Reload Wallbash Colors",
35+
"category": "Color Update"
36+
}
37+
],
38+
"configuration": {
39+
"title": "Wallbash",
40+
"properties": {
41+
"wallbash.autoUpdate": {
42+
"type": "boolean",
43+
"default": true,
44+
"description": "Update automatically the theme when the wallbash color palette changes"
45+
}
46+
}
47+
},
48+
"themes": [
49+
{
50+
"label": "Wallbash",
51+
"uiTheme": "vs-dark",
52+
"path": "./themes/wallbash.json",
53+
"_watch": true
1954
}
2055
]
2156
},
@@ -37,5 +72,8 @@
3772
"typescript": "^5.6.3",
3873
"@vscode/test-cli": "^0.0.10",
3974
"@vscode/test-electron": "^2.4.1"
75+
},
76+
"dependencies": {
77+
"chokidar": "^3.5.2"
4078
}
4179
}

src/extension.ts

+80-18
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,88 @@
1-
// The module 'vscode' contains the VS Code extensibility API
2-
// Import the module and reference it with the alias vscode in your code below
1+
import * as chokidar from 'chokidar';
2+
import * as fs from 'fs';
3+
import * as os from 'os';
4+
import * as path from 'path';
35
import * as vscode from 'vscode';
46

5-
// This method is called when your extension is activated
6-
// Your extension is activated the very first time the command is executed
7+
const walCachePath = path.join(
8+
os.homedir(), '.cache', 'hyde', 'landing', 'vscode-wallbash.json');
9+
const targetPath = path.join(__dirname, '..', 'themes', 'wallbash.json');
10+
let autoUpdateWatcher: chokidar.FSWatcher|null = null;
11+
12+
713
export function activate(context: vscode.ExtensionContext) {
14+
console.log('Initializing!\n');
15+
console.log('walCachePath: \n', walCachePath);
16+
console.log('targetPath: \n', targetPath);
17+
18+
19+
// The command has been defined in the package.json file
20+
// Now provide the implementation of the command with registerCommand
21+
// The commandId parameter must match the command field in package.json
22+
let disposable =
23+
vscode.commands.registerCommand('wallbash.update', populateColorThemes);
24+
context.subscriptions.push(disposable);
25+
26+
// Start the auto update if enabled
27+
if (vscode.workspace.getConfiguration().get('wallbash.autoUpdate')) {
28+
/*
29+
* Update theme at startup
30+
* Needed for when wal palette updates while vscode isn't running.
31+
* The timeout is required to overcome a limitation of vscode which
32+
* breaks the theme auto-update if updated too early at startup.
33+
*/
34+
setTimeout(populateColorThemes, 10000);
35+
36+
autoUpdateWatcher = autoUpdate();
37+
}
838

9-
// Use the console to output diagnostic information (console.log) and errors (console.error)
10-
// This line of code will only be executed once when your extension is activated
11-
console.log('Congratulations, your extension "wallbash" is now active!');
39+
// Toggle the auto update in real time when changing the extension
40+
// configuration
41+
vscode.workspace.onDidChangeConfiguration(event => {
42+
if (event.affectsConfiguration('wallbash.autoUpdate')) {
43+
if (vscode.workspace.getConfiguration().get('wallbash.autoUpdate')) {
44+
if (autoUpdateWatcher === null) {
45+
autoUpdateWatcher = autoUpdate();
46+
}
47+
} else if (autoUpdateWatcher !== null) {
48+
autoUpdateWatcher.close();
49+
autoUpdateWatcher = null;
50+
}
51+
}
52+
});
53+
}
54+
55+
export function deactivate() {
56+
// Close the watcher if active
57+
if (autoUpdateWatcher !== null) {
58+
autoUpdateWatcher.close();
59+
}
60+
}
61+
62+
/**
63+
* Populates the color themes from the wal color palette
64+
*/
65+
function populateColorThemes() {
66+
// Basically will copy from cache to targetPath
67+
fs.copyFile(walCachePath, targetPath, (err) => {
68+
if (err) {
69+
vscode.window.showErrorMessage(
70+
`Failed to copy the color palette: ${err}`);
71+
} else {
72+
vscode.window.showInformationMessage(
73+
'Successfully updated the color palette');
74+
}
75+
});
1276

13-
// The command has been defined in the package.json file
14-
// Now provide the implementation of the command with registerCommand
15-
// The commandId parameter must match the command field in package.json
16-
const disposable = vscode.commands.registerCommand('wallbash.helloWorld', () => {
17-
// The code you place here will be executed every time your command is executed
18-
// Display a message box to the user
19-
vscode.window.showInformationMessage('Hello World from wallbash!');
20-
});
2177

22-
context.subscriptions.push(disposable);
2378
}
2479

25-
// This method is called when your extension is deactivated
26-
export function deactivate() {}
80+
81+
/**
82+
* Automatically updates the theme when the color palette changes
83+
* @returns The watcher for the color palette
84+
*/
85+
function autoUpdate(): chokidar.FSWatcher {
86+
// Watch for changes in the color palette of wal
87+
return chokidar.watch(walCachePath).on('change', populateColorThemes);
88+
}

0 commit comments

Comments
 (0)