-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
60 lines (50 loc) · 1.77 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
const vscode = require("vscode");
const fs = require("fs");
const path = require("path");
function activate(context) {
const styleFilePath = path.join(
context.extensionPath,
"styles",
"custom-style.css"
).replace(/\\/g, '/');
const appDir = path.dirname(require.main.filename);
const base = path.join(appDir, "vs", "code");
const htmlFile = path.join(base, "electron-sandbox", "workbench", "workbench.html");
async function patchHtmlFile(enable) {
// Read the current content of the HTML file
let html = await fs.promises.readFile(htmlFile, "utf-8");
// Clear any existing custom styles
html = html.replace(
/<!-- !! VSCODE-CUSTOM-CSS-START !! -->[\s\S]*?<!-- !! VSCODE-CUSTOM-CSS-END !! -->/,
""
);
if (enable) {
// If enabling, add our custom styles
const styleContent = await fs.promises.readFile(styleFilePath, "utf-8");
html = html.replace(
/<\/head>/,
`<!-- !! VSCODE-CUSTOM-CSS-START !! -->
<style>${styleContent}</style>
<!-- !! VSCODE-CUSTOM-CSS-END !! -->
</head>`
);
}
// Write the modified HTML back to the file
await fs.promises.writeFile(htmlFile, html, "utf-8");
// Reload VS Code window
vscode.commands.executeCommand('workbench.action.reloadWindow');
}
context.subscriptions.push(
vscode.commands.registerCommand("synthwave--2077.disable", async () => {
await patchHtmlFile(false);
vscode.window.showInformationMessage("There's no spoon");
})
);
context.subscriptions.push(
vscode.commands.registerCommand("synthwave--2077.enable", async () => {
await patchHtmlFile(true);
vscode.window.showInformationMessage("Wake up Samurai, we have a city to burn");
})
);
}
exports.activate = activate;