forked from vscode-icons/vscode-icons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add uninstall hook script (cleanUp) (vscode-icons#1537)
- Loading branch information
1 parent
7cb8fe2
commit 8ad15a4
Showing
5 changed files
with
413 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { readFile, writeFile, unlink } from 'fs'; | ||
import { constants } from '../constants'; | ||
import { vscodePath as getAppPath, parseJSON, pathUnixJoin } from '../utils'; | ||
|
||
export function getAppUserPath(dirPath: string): string { | ||
const isDev = /oss-dev/i.test(dirPath); | ||
const isOSS = !isDev && /oss/i.test(dirPath); | ||
const isInsiders = /insiders/i.test(dirPath); | ||
const vscodeAppName = isInsiders ? 'Code - Insiders' : isOSS ? 'Code - OSS' : isDev ? 'code-oss-dev' : 'Code'; | ||
return pathUnixJoin(getAppPath(), vscodeAppName, 'User'); | ||
} | ||
|
||
export function removeVSIconsSettings(settings: {}): void { | ||
Reflect.ownKeys(settings) | ||
.map(key => key.toString()) | ||
.filter(key => /^vsicons\..+/.test(key)) | ||
.forEach(key => delete settings[key]); | ||
} | ||
|
||
export function resetThemeSetting(settings: {}): void { | ||
if (settings[constants.vscode.iconThemeSetting] === constants.extensionName) { | ||
settings[constants.vscode.iconThemeSetting] = null; | ||
} | ||
} | ||
|
||
export function cleanUpVSCodeSettings(): void { | ||
const saveSettings = content => { | ||
const settings = JSON.stringify(content, null, 4); | ||
writeFile(settingsFilePath, settings, err => console.error(err)); | ||
}; | ||
const cleanUpSettings = (err, content) => { | ||
if (err) { | ||
console.error(err); | ||
return; | ||
} | ||
const settings = parseJSON(content); | ||
if (!settings) { return; } | ||
|
||
removeVSIconsSettings(settings); | ||
|
||
resetThemeSetting(settings); | ||
|
||
saveSettings(settings); | ||
}; | ||
const settingsFilePath = pathUnixJoin(getAppUserPath(__dirname), 'settings.json'); | ||
readFile(settingsFilePath, 'utf8', cleanUpSettings); | ||
} | ||
|
||
export function cleanUpVSIconsSettings(): void { | ||
unlink(pathUnixJoin(getAppUserPath(__dirname), 'vsicons.settings.json'), | ||
err => console.error(err)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { cleanUpVSCodeSettings, cleanUpVSIconsSettings } from './cleanUp'; | ||
|
||
cleanUpVSIconsSettings(); | ||
cleanUpVSCodeSettings(); |
Oops, something went wrong.