Skip to content

Commit 0a89c9a

Browse files
committed
Enhance uninstall process, reduce package size, fix VSC 1.85.2 error
1 parent 4ff7b41 commit 0a89c9a

File tree

5 files changed

+126
-75
lines changed

5 files changed

+126
-75
lines changed

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 1.1.50
2+
3+
* Vibrancy will now attempt to automatically remove itself when uninstalled without running "Disable Vibrancy"
4+
* This doesn't cover VSCode config changes for now
5+
* Reduced package size from 70 MB to 764 KB by not bundling node-gyp
6+
* Fixed a regression that caused activation errors on VSCode 1.85.2
7+
18
# 1.1.49
29

310
* Updated uninstall hook message

extension/index.js

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ function activate(context) {
485485
const themeConfigPath = path.resolve(__dirname, themeConfigPaths[vibrancyTheme]);
486486
const themeConfig = require(themeConfigPath);
487487
const enableAutoTheme = vscode.workspace.getConfiguration().get("vscode_vibrancy.enableAutoTheme");
488-
488+
489489
// Get the current settings
490490
const terminalColorConfig = vscode.workspace.getConfiguration().inspect("workbench.colorCustomizations");
491491
const gpuAccelerationConfig = vscode.workspace.getConfiguration().inspect("terminal.integrated.gpuAcceleration");
@@ -495,15 +495,15 @@ function activate(context) {
495495

496496
// Fetch previous values from global state
497497
let previousCustomizations = context.globalState.get('customizations') || {};
498-
498+
499499
// Get current values
500500
const currentColorCustomizations = terminalColorConfig?.globalValue || {};
501501
const currentBackground = currentColorCustomizations?.["terminal.background"];
502502
const currentGpuAcceleration = gpuAccelerationConfig?.globalValue;
503503
const currentApplyToAllProfiles = applyToAllProfilesConfig?.globalValue;
504504
const currentSystemColorTheme = systemColorTheme?.globalValue;
505505
const currentAutoDetectColorScheme = autoDetectColorScheme?.globalValue;
506-
506+
507507
// Store original values if not already saved
508508
if (!previousCustomizations.saved) {
509509
previousCustomizations = {
@@ -515,16 +515,15 @@ function activate(context) {
515515
autoDetectColorScheme: currentAutoDetectColorScheme,
516516
};
517517
}
518-
518+
519519
try {
520-
// Remove "workbench.colorCustomizations" from applyToAllProfiles if it's there to fix an issue this caused with profiles
521-
if (!previousCustomizations.removedFromApplyToAllProfiles && currentApplyToAllProfiles.includes("workbench.colorCustomizations")) {
520+
// Remove "workbench.colorCustomizations" from applyToAllProfiles if it's there
521+
if (!previousCustomizations.removedFromApplyToAllProfiles && currentApplyToAllProfiles?.includes("workbench.colorCustomizations")) {
522522
const updatedApplyToAllProfiles = currentApplyToAllProfiles.filter(setting => setting !== "workbench.colorCustomizations");
523523
await vscode.workspace.getConfiguration().update("workbench.settings.applyToAllProfiles", updatedApplyToAllProfiles, vscode.ConfigurationTarget.Global);
524524

525525
// Notify user of the change
526526
vscode.window.showInformationMessage(localize('messages.applyToAllProfiles'));
527-
528527
}
529528
// Ensure this fix is only applied once
530529
previousCustomizations.removedFromApplyToAllProfiles = true;
@@ -537,23 +536,38 @@ function activate(context) {
537536
"terminal.background": "#00000000"
538537
};
539538
}
540-
539+
541540
await vscode.workspace.getConfiguration().update("workbench.colorCustomizations", newColorCustomization, vscode.ConfigurationTarget.Global);
542541
await vscode.workspace.getConfiguration().update("terminal.integrated.gpuAcceleration", "off", vscode.ConfigurationTarget.Global);
543-
542+
543+
// Handle auto theme settings
544544
if (enableAutoTheme) {
545-
// Allow VSCode to auto-detect the color theme
546-
vscode.workspace.getConfiguration().update("window.systemColorTheme", undefined, vscode.ConfigurationTarget.Global);
547-
vscode.workspace.getConfiguration().update("window.autoDetectColorScheme", true, vscode.ConfigurationTarget.Global);
545+
try {
546+
await vscode.workspace.getConfiguration().update("window.autoDetectColorScheme", true, vscode.ConfigurationTarget.Global);
547+
} catch (error) {
548+
console.warn("window.autoDetectColorScheme is not supported in this version of VSCode.");
549+
}
550+
try {
551+
await vscode.workspace.getConfiguration().update("window.systemColorTheme", undefined, vscode.ConfigurationTarget.Global);
552+
} catch (error) {
553+
console.warn("window.systemColorTheme is not supported in this version of VSCode.");
554+
}
548555
} else {
549-
// Sync VSCode color theme with Vibrancy theme
550-
vscode.workspace.getConfiguration().update("window.systemColorTheme", themeConfig.systemColorTheme, vscode.ConfigurationTarget.Global);
551-
vscode.workspace.getConfiguration().update("window.autoDetectColorScheme", false, vscode.ConfigurationTarget.Global);
556+
try {
557+
await vscode.workspace.getConfiguration().update("window.systemColorTheme", themeConfig.systemColorTheme, vscode.ConfigurationTarget.Global);
558+
} catch (error) {
559+
console.warn("window.systemColorTheme is not supported in this version of VSCode.");
560+
}
561+
try {
562+
await vscode.workspace.getConfiguration().update("window.autoDetectColorScheme", false, vscode.ConfigurationTarget.Global);
563+
} catch (error) {
564+
console.warn("window.autoDetectColorScheme is not supported in this version of VSCode.");
565+
}
552566
}
553567
} catch (error) {
554568
console.error("Error updating settings:", error);
555569
}
556-
570+
557571
// Save user customizations
558572
await context.globalState.update('customizations', previousCustomizations);
559573
}
@@ -586,9 +600,17 @@ function activate(context) {
586600
await vscode.workspace.getConfiguration().update("workbench.colorCustomizations", restoredColorCustomizations, vscode.ConfigurationTarget.Global);
587601
}
588602

603+
try {
604+
await vscode.workspace.getConfiguration().update("window.systemColorTheme", previousCustomizations.systemColorTheme, vscode.ConfigurationTarget.Global);
605+
} catch (error) {
606+
console.warn("window.systemColorTheme is not supported in this version of VSCode.");
607+
}
608+
try {
609+
await vscode.workspace.getConfiguration().update("window.autoDetectColorScheme", previousCustomizations.autoDetectColorScheme, vscode.ConfigurationTarget.Global);
610+
} catch (error) {
611+
console.warn("window.autoDetectColorScheme is not supported in this version of VSCode.");
612+
}
589613
await vscode.workspace.getConfiguration().update("terminal.integrated.gpuAcceleration", previousCustomizations.gpuAcceleration, vscode.ConfigurationTarget.Global);
590-
await vscode.workspace.getConfiguration().update("window.systemColorTheme", previousCustomizations.systemColorTheme, vscode.ConfigurationTarget.Global);
591-
await vscode.workspace.getConfiguration().update("window.autoDetectColorScheme", previousCustomizations.autoDetectColorScheme, vscode.ConfigurationTarget.Global);
592614

593615
// Preserve the removedFromApplyToAllProfiles flag
594616
const removedFromApplyToAllProfiles = previousCustomizations.removedFromApplyToAllProfiles;
@@ -601,30 +623,33 @@ function activate(context) {
601623
}
602624
}
603625

604-
async function getActiveFlagPath() {
626+
async function getLocalConfigPath() {
605627
const envPaths = (await import('env-paths')).default;
606-
607-
const paths = envPaths('vscode-vibrancy');
608-
const activeFlagPath = path.join(paths.config, 'active');
628+
const paths = envPaths('vscode-vibrancy-continued');
629+
const configFilePath = path.join(paths.config, 'config.json');
609630

610631
// Ensure the directory exists recursively
611632
await fs.mkdir(paths.config, { recursive: true }).catch(() =>
612633
console.warn(`Failed to create directory: ${paths.config}`)
613634
);
614635

615-
return activeFlagPath;
616-
}
636+
return configFilePath;
637+
}
617638

618-
// This function will create or remove the active flag file
619-
async function setActiveFlag(state) {
620-
const activeFlagPath = await getActiveFlagPath();
639+
async function setLocalConfig(state, paths) {
640+
const configFilePath = await getLocalConfigPath();
621641

622642
if (state) {
623-
await fs.writeFile(activeFlagPath, '');
643+
const configData = {
644+
workbenchHtmlPath: paths.workbenchHtmlPath,
645+
jsPath: paths.jsPath,
646+
electronJsPath: paths.electronJsPath
647+
};
648+
await fs.writeFile(configFilePath, JSON.stringify(configData, null, 2), 'utf-8');
624649
} else {
625-
await fs.unlink(activeFlagPath).catch(() => { });
650+
await fs.unlink(configFilePath).catch(() => { });
626651
}
627-
}
652+
}
628653

629654

630655
// #### main commands ######################################################
@@ -656,7 +681,11 @@ function activate(context) {
656681
await changeVSCodeSettings();
657682
await checkColorTheme();
658683
await checkElectronDeprecatedType();
659-
await setActiveFlag(true);
684+
await setLocalConfig(true, {
685+
workbenchHtmlPath: HTMLFile,
686+
jsPath: JSFile,
687+
electronJsPath: ElectronJSFile
688+
});
660689
} catch (error) {
661690
if (error && (error.code === 'EPERM' || error.code === 'EACCES')) {
662691
vscode.window.showInformationMessage(localize('messages.admin') + error);
@@ -678,7 +707,7 @@ function activate(context) {
678707
// uninstall old version
679708
await fs.stat(HTMLFile);
680709
await uninstallHTML();
681-
await setActiveFlag(false);
710+
await setLocalConfig(false);
682711
} finally {
683712

684713
}

extension/uninstallHook.js

Lines changed: 57 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,68 @@
1-
// This script will alert the user on uninstalling Vibrancy without prior cleanup
2-
// TODO: investigate if we can perform all cleanup steps here including VSCode settings update
3-
4-
const { exec } = require('child_process');
5-
const fs = require('fs');
1+
const { spawn, exec } = require('child_process');
2+
const fs = require('fs').promises; // Use fs.promises for Promise-based APIs
3+
const fsSync = require('fs'); // Import standard fs for synchronous methods
64
const path = require('path');
75

86
(async () => {
97
const envPaths = (await import('env-paths')).default;
10-
const paths = envPaths('vscode-vibrancy');
11-
const activeFlagPath = path.join(paths.config, 'active');
12-
13-
function isActive() {
14-
return fs.existsSync(activeFlagPath);
8+
const paths = envPaths('vscode-vibrancy-continued');
9+
const configFilePath = path.join(paths.config, 'config.json');
10+
11+
function loadConfig() {
12+
if (fsSync.existsSync(configFilePath)) {
13+
return JSON.parse(fsSync.readFileSync(configFilePath, 'utf-8'));
14+
}
15+
return null;
16+
}
17+
18+
async function uninstallJS(jsFilePath, electronJsFilePath) {
19+
const JS = await fs.readFile(jsFilePath, 'utf-8');
20+
const needClean = /\n\/\* !! VSCODE-VIBRANCY-START !! \*\/[\s\S]*?\/\* !! VSCODE-VIBRANCY-END !! \*\//.test(JS);
21+
if (needClean) {
22+
const newJS = JS.replace(/\n\/\* !! VSCODE-VIBRANCY-START !! \*\/[\s\S]*?\/\* !! VSCODE-VIBRANCY-END !! \*\//, '');
23+
await fs.writeFile(jsFilePath, newJS, 'utf-8');
24+
}
25+
26+
const ElectronJS = await fs.readFile(electronJsFilePath, 'utf-8');
27+
const newElectronJS = ElectronJS
28+
.replace(/frame:false,transparent:true,experimentalDarkMode/g, 'experimentalDarkMode')
29+
.replace(/visualEffectState:"active",experimentalDarkMode/g, 'experimentalDarkMode');
30+
await fs.writeFile(electronJsFilePath, newElectronJS, 'utf-8');
1531
}
16-
17-
function showWarning(message) {
18-
// Escape quotes for macOS/Linux
19-
const escapedMessageUnix = message.replace(/"/g, '\\"');
20-
32+
33+
async function uninstallHTML(htmlFilePath) {
34+
const HTML = await fs.readFile(htmlFilePath, 'utf-8');
35+
const needClean = /trusted-types VscodeVibrancy/.test(HTML);
36+
if (needClean) {
37+
const newHTML = HTML.replace(/trusted-types VscodeVibrancy(\r\n|\r|\n)/, "trusted-types$1");
38+
await fs.writeFile(htmlFilePath, newHTML, 'utf-8');
39+
}
40+
}
41+
42+
function showNotification(message) {
43+
const escapedMessage = message.replace(/'/g, "\\'").replace(/"/g, '\\"');
44+
2145
if (process.platform === 'win32') {
22-
// Use VBScript to generate the alert
23-
// PowerShell wasn't used as VSCode terminates the nodejs process, which then closes the alert
24-
const vbsPath = path.join(__dirname, 'uninstallHookAlert.vbs');
25-
26-
exec(`cscript //nologo "${vbsPath}"`, (err, stdout, stderr) => {
27-
if (err) {
28-
console.error('Error executing VBScript:', err);
29-
return;
30-
}
31-
if (stderr) {
32-
console.error('VBScript error:', stderr);
33-
return;
34-
}
35-
console.log('VBScript executed successfully:', stdout);
36-
});
46+
const js = `javascript:var sh=new ActiveXObject('WScript.Shell'); sh.Popup('${escapedMessage}', 0, 'Alert', 64); close()`;
47+
const child = spawn('mshta', [js], {
48+
detached: true,
49+
stdio: 'ignore'
50+
});
51+
child.unref();
3752
} else if (process.platform === 'darwin') {
38-
// Use AppleScript to show a message box
39-
exec(`osascript -e 'display alert "Warning" message "${escapedMessageUnix}" as critical'`);
53+
exec(`osascript -e 'display alert "Notification" message "${escapedMessage}" as critical'`);
4054
} else {
41-
// Use Zenity to show a message box, assumes Linux
42-
exec(`zenity --warning --title="Warning" --text="${escapedMessageUnix}"`);
55+
exec(`zenity --info --title="Notification" --text="${escapedMessage}"`);
4356
}
4457
}
45-
46-
if (isActive()) {
47-
showWarning("Uninstalling Vibrancy Continued without disabling it first will NOT remove the effect! Please reinstall the extension and disable it using the ⌘+Shift+P action \"Disable Vibrancy\", then uninstall.\n\nCheck Vibrancy Continued description for more information.");
58+
59+
const config = loadConfig();
60+
if (config) {
61+
const { workbenchHtmlPath, jsPath, electronJsPath } = config;
62+
63+
await uninstallJS(jsPath, electronJsPath);
64+
await uninstallHTML(workbenchHtmlPath);
65+
66+
showNotification("Vibrancy Continued has been removed. Please restart VSCode to apply changes.");
4867
}
49-
})();
68+
})();

extension/uninstallHookAlert.vbs

Lines changed: 0 additions & 3 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@
205205
"mz": "^2.7.0"
206206
},
207207
"devDependencies": {
208-
"node-addon-api": "^5.0.0",
209-
"node-gyp": "^9.1.0"
208+
"node-addon-api": "^5.0.0"
210209
}
211210
}

0 commit comments

Comments
 (0)