@@ -2,6 +2,116 @@ const { spawn, exec } = require('child_process');
2
2
const fs = require ( 'fs' ) . promises ; // Use fs.promises for Promise-based APIs
3
3
const fsSync = require ( 'fs' ) ; // Import standard fs for synchronous methods
4
4
const path = require ( 'path' ) ;
5
+ const os = require ( 'os' ) ;
6
+
7
+ function getVSCodeSettingsPath ( ) {
8
+ const platform = os . platform ( ) ;
9
+ const home = os . homedir ( ) ;
10
+
11
+ if ( platform === 'win32' ) {
12
+ return path . join ( process . env . APPDATA , 'Code' , 'User' , 'settings.json' ) ;
13
+ } else if ( platform === 'darwin' ) {
14
+ return path . join ( home , 'Library' , 'Application Support' , 'Code' , 'User' , 'settings.json' ) ;
15
+ } else {
16
+ // Assume Linux
17
+ return path . join ( home , '.config' , 'Code' , 'User' , 'settings.json' ) ;
18
+ }
19
+ }
20
+
21
+ // Function to restore previous settings
22
+ // Because VSCode uses JSONC, we need to be careful with comments
23
+ // and formatting. We will use regex to find and replace the specific settings.
24
+ function restorePreviousSettings ( previousCustomizations ) {
25
+ const settingsPath = getVSCodeSettingsPath ( ) ;
26
+
27
+ if ( ! fsSync . existsSync ( settingsPath ) ) {
28
+ console . error ( 'VSCode settings.json not found!' ) ;
29
+ return ;
30
+ }
31
+
32
+ let settingsContent = '' ;
33
+ try {
34
+ settingsContent = fsSync . readFileSync ( settingsPath , 'utf-8' ) ;
35
+ } catch ( err ) {
36
+ console . error ( 'Failed to read settings.json:' , err ) ;
37
+ return ;
38
+ }
39
+
40
+ // Remove transparent terminal background
41
+ settingsContent = settingsContent . replace (
42
+ / " t e r m i n a l \. b a c k g r o u n d " \s * : \s * " # 0 0 0 0 0 0 0 0 " , ? \s * / g,
43
+ ''
44
+ ) ;
45
+
46
+ // Restore saved customizations
47
+ if ( previousCustomizations ?. saved ) {
48
+ if ( previousCustomizations . terminalBackground !== null ) {
49
+ if (
50
+ previousCustomizations . terminalBackground === '#00000000'
51
+ ) {
52
+ settingsContent = settingsContent . replace (
53
+ / " t e r m i n a l \. b a c k g r o u n d " \s * : \s * " .* ?" , ? \s * / g,
54
+ ''
55
+ ) ;
56
+ } else {
57
+ settingsContent = settingsContent . replace (
58
+ / " t e r m i n a l \. b a c k g r o u n d " \s * : \s * " .* ?" , ? \s * / g,
59
+ `"terminal.background": "${ previousCustomizations . terminalBackground } ",`
60
+ ) ;
61
+ }
62
+ }
63
+
64
+ if ( previousCustomizations . systemColorTheme !== null ) {
65
+ settingsContent = settingsContent . replace (
66
+ / " w i n d o w \. s y s t e m C o l o r T h e m e " \s * : \s * " .* ?" , ? \s * / g,
67
+ previousCustomizations . systemColorTheme === null
68
+ ? ''
69
+ : `"window.systemColorTheme": "${ previousCustomizations . systemColorTheme } ",`
70
+ ) ;
71
+ } else {
72
+ settingsContent = settingsContent . replace (
73
+ / " w i n d o w \. s y s t e m C o l o r T h e m e " \s * : \s * " .* ?" , ? \s * / g,
74
+ ''
75
+ ) ;
76
+ }
77
+
78
+ if ( previousCustomizations . autoDetectColorScheme !== null ) {
79
+ settingsContent = settingsContent . replace (
80
+ / " w i n d o w \. a u t o D e t e c t C o l o r S c h e m e " \s * : \s * ( t r u e | f a l s e ) , ? \s * / g,
81
+ previousCustomizations . autoDetectColorScheme === null
82
+ ? ''
83
+ : `"window.autoDetectColorScheme": ${ previousCustomizations . autoDetectColorScheme } ,`
84
+ ) ;
85
+ } else {
86
+ settingsContent = settingsContent . replace (
87
+ / " w i n d o w \. a u t o D e t e c t C o l o r S c h e m e " \s * : \s * ( t r u e | f a l s e ) , ? \s * / g,
88
+ ''
89
+ ) ;
90
+ }
91
+
92
+ if ( previousCustomizations . gpuAcceleration !== null ) {
93
+ settingsContent = settingsContent . replace (
94
+ / " t e r m i n a l \. i n t e g r a t e d \. g p u A c c e l e r a t i o n " \s * : \s * " .* ?" , ? \s * / g,
95
+ previousCustomizations . gpuAcceleration === null
96
+ ? ''
97
+ : `"terminal.integrated.gpuAcceleration": "${ previousCustomizations . gpuAcceleration } ",`
98
+ ) ;
99
+ } else {
100
+ settingsContent = settingsContent . replace (
101
+ / " t e r m i n a l \. i n t e g r a t e d \. g p u A c c e l e r a t i o n " \s * : \s * " .* ?" , ? \s * / g,
102
+ ''
103
+ ) ;
104
+ }
105
+ }
106
+
107
+ // Write updated settings back to disk
108
+ try {
109
+ fsSync . writeFileSync ( settingsPath , settingsContent . trim ( ) + '\n' , 'utf-8' ) ;
110
+ console . log ( 'VSCode settings.json successfully reverted.' ) ;
111
+ } catch ( err ) {
112
+ console . error ( 'Failed to write settings.json:' , err ) ;
113
+ }
114
+ }
5
115
6
116
( async ( ) => {
7
117
const envPaths = ( await import ( 'env-paths' ) ) . default ;
@@ -58,10 +168,11 @@ const path = require('path');
58
168
59
169
const config = loadConfig ( ) ;
60
170
if ( config ) {
61
- const { workbenchHtmlPath, jsPath, electronJsPath } = config ;
171
+ const { workbenchHtmlPath, jsPath, electronJsPath, previousCustomizations } = config ;
62
172
63
173
await uninstallJS ( jsPath , electronJsPath ) ;
64
174
await uninstallHTML ( workbenchHtmlPath ) ;
175
+ restorePreviousSettings ( previousCustomizations ) ;
65
176
66
177
showNotification ( "Vibrancy Continued has been removed. Please restart VSCode to apply changes." ) ;
67
178
}
0 commit comments