Skip to content

Commit 4615c7a

Browse files
committed
Add uninstall hook to alert on incomplete uninstalls
Update vsce file ignore list
1 parent dd7ac00 commit 4615c7a

File tree

7 files changed

+129
-16
lines changed

7 files changed

+129
-16
lines changed

.vscodeignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
firstload.lock
1+
firstload.lock
2+
build
3+
images/*
4+
!images/logo.png

changelog.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 1.1.46
2+
3+
* Reduced package size by excluding unnecessary files
4+
* Added an alert when uninstalling without performing the "Disable Vibrancy" action
5+
16
# 1.1.45
27

38
* Windows on ARM is now supported (resolves [#9](https://github.com/illixion/vscode-vibrancy-continued/issues/9))
@@ -205,7 +210,7 @@
205210

206211
# 1.1.1
207212

208-
Add Noir et blanc theme (by [pryter](https://github.com/pryter))
213+
* Add Noir et blanc theme (by [pryter](https://github.com/pryter))
209214

210215
# 1.1.0
211216

@@ -221,6 +226,7 @@ Add Noir et blanc theme (by [pryter](https://github.com/pryter))
221226
# 1.0.14
222227

223228
* fix: not work with Customize UI
229+
224230
# 1.0.13
225231

226232
* fix: not working in vscode 1.53.0-insider

extension/index.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var fs = require('mz/fs');
33
var fsExtra = require('fs-extra');
44
var path = require('path');
55
var { pathToFileURL } = require('url')
6+
var os = require('os');
67

78
/**
89
* @type {(info: string) => string}
@@ -12,7 +13,7 @@ const localize = require('./i18n');
1213
/**
1314
* @type {'unknown' | 'win10' | 'macos'}
1415
*/
15-
const os = require('./platform');
16+
const osType = require('./platform');
1617

1718
var themeStylePaths = {
1819
'Default Dark': '../themes/Default Dark.css',
@@ -317,7 +318,7 @@ function activate(context) {
317318
const imports = await generateImports(config);
318319

319320
const injectData = {
320-
os: os,
321+
os: osType,
321322
config: config,
322323
theme: themeConfig,
323324
themeCSS: themeCSS,
@@ -568,11 +569,37 @@ function activate(context) {
568569
}
569570
}
570571

572+
async function getActiveFlagPath() {
573+
const envPaths = (await import('env-paths')).default;
574+
575+
const paths = envPaths('vscode-vibrancy');
576+
const activeFlagPath = path.join(paths.config, 'active');
577+
578+
// Ensure the directory exists recursively
579+
await fs.mkdir(paths.config, { recursive: true }).catch(() =>
580+
console.warn(`Failed to create directory: ${paths.config}`)
581+
);
582+
583+
return activeFlagPath;
584+
}
585+
586+
// This function will create or remove the active flag file
587+
async function setActiveFlag(state) {
588+
const activeFlagPath = await getActiveFlagPath();
589+
590+
if (state) {
591+
await fs.writeFile(activeFlagPath, '');
592+
} else {
593+
await fs.unlink(activeFlagPath).catch(() => { });
594+
}
595+
}
596+
597+
571598
// #### main commands ######################################################
572599

573600
async function Install() {
574601

575-
if (os === 'unknown') {
602+
if (osType === 'unknown') {
576603
vscode.window.showInformationMessage(localize('messages.unsupported'));
577604
throw new Error('unsupported');
578605
}
@@ -587,14 +614,15 @@ function activate(context) {
587614
await fs.stat(JSFile);
588615
await fs.stat(HTMLFile);
589616

590-
if (os === 'win10') {
617+
if (osType === 'win10') {
591618
await installRuntimeWin();
592619
} else {
593620
await installRuntime();
594621
}
595622
await installJS();
596623
await installHTML();
597624
await changeTerminalSettings();
625+
await setActiveFlag(true);
598626
} catch (error) {
599627
if (error && (error.code === 'EPERM' || error.code === 'EACCES')) {
600628
vscode.window.showInformationMessage(localize('messages.admin') + error);
@@ -614,6 +642,7 @@ function activate(context) {
614642
// uninstall old version
615643
await fs.stat(HTMLFile);
616644
await uninstallHTML();
645+
await setActiveFlag(false);
617646
} finally {
618647

619648
}

extension/uninstallHook.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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');
6+
const path = require('path');
7+
8+
(async () => {
9+
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);
15+
}
16+
17+
function showWarning(message) {
18+
// Escape quotes for macOS/Linux
19+
const escapedMessageUnix = message.replace(/"/g, '\\"');
20+
21+
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+
});
37+
} else if (process.platform === 'darwin') {
38+
// Use AppleScript to show a message box
39+
exec(`osascript -e 'display alert "Warning" message "${escapedMessageUnix}" as critical'`);
40+
} else {
41+
// Use Zenity to show a message box, assumes Linux
42+
exec(`zenity --warning --title="Warning" --text="${escapedMessageUnix}"`);
43+
}
44+
}
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 command palette action \"Disable Vibrancy\" first.\n\nCheck Vibrancy Continued description for more information.");
48+
}
49+
})();

extension/uninstallHookAlert.vbs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Dim message
2+
message = "Uninstalling Vibrancy Continued without disabling it first will NOT remove the effect! Please reinstall the extension and disable it using the command palette action ""Disable Vibrancy"" first." & vbCrLf & vbCrLf & "Check Vibrancy Continued description for more information."
3+
MsgBox message, 48, "Warning"

package-lock.json

Lines changed: 30 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,11 @@
196196
}
197197
},
198198
"scripts": {
199-
"build-win10": "node-gyp rebuild"
199+
"build-win10": "node-gyp rebuild",
200+
"vscode:uninstall": "node ./extension/uninstallHook.js"
200201
},
201202
"dependencies": {
203+
"env-paths": "^3.0.0",
202204
"fs-extra": "^10.1.0",
203205
"mz": "^2.7.0"
204206
},

0 commit comments

Comments
 (0)