diff --git a/README.md b/README.md
index 894d9dc..56b81cf 100644
--- a/README.md
+++ b/README.md
@@ -33,7 +33,9 @@ To rollback or uninstall the plugin, please open command panel and run `Custom U
See [details](https://github.com/shalldie/vscode-background?tab=readme-ov-file#warns)
-### No Effect?
+### FAQ
+
+#### No Effect?
If you are using Windows or Linux, make sure you have closed all the VSCode windows and then restart.
@@ -41,6 +43,16 @@ If you are using MacOS, press Command + Q first, then restart VSCode.
There are [guide](https://github.com/subframe7536/vscode-custom-ui-style/issues/1#issuecomment-2423660217) and [video](https://github.com/subframe7536/vscode-custom-ui-style/issues/2#issuecomment-2432225106) (MacOS) of the process.
+#### RangeError: Maximum call stack size exceeded
+
+Due to system permission restrictions, you will receive `RangeError: Maximum call stack size exceeded` prompt when you reload the configuration. You need to fully close (press Command + Q) VSCode first, then run:
+
+```sh
+sudo chown -R $(whoami) "/Applications/Visual Studio Code.app"
+```
+
+See #6
+
## Configurations
diff --git a/src/utils.ts b/src/utils.ts
index a4b55d8..0ae4936 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -1,5 +1,5 @@
import type { AnyFunction } from '@subframe7536/type-utils'
-import { existsSync, rmSync } from 'node:fs'
+import fs from 'node:fs'
import path from 'node:path'
import { readFileSync, writeFileSync } from 'atomically'
import { useLogger } from 'reactive-vscode'
@@ -13,31 +13,43 @@ const lockFile = path.join(baseDir, `__${name}__.lock`)
export async function runAndRestart(message: string, action: () => Promise) {
let count = 5
- const check = () => existsSync(lockFile)
+ const check = () => fs.existsSync(lockFile)
while (check() && count--) {
+ log.warn('Lock file detected, waiting...')
await new Promise(resolve => setTimeout(resolve, 1000))
}
if (!count) {
// If exists and expire time exceed 10 minutes, just remove it
if (check() && Number(readFileSync(lockFile, 'utf-8')) - Date.now() > 6e5) {
- rmSync(lockFile)
+ log.warn('Lock file timeout, remove and continue')
+ fs.rmSync(lockFile)
} else {
+ log.error('File locked:', lockFile)
await showMessage('File locked, cancel operation')
return
}
}
try {
writeFileSync(lockFile, String(Date.now()))
- await action()
- const item = await showMessage(message, 'Reload Window', 'Cancel')
- if (item === 'Reload Window') {
- commands.executeCommand('workbench.action.reloadWindow')
+ let success = true
+ try {
+ await action()
+ } catch (error) {
+ log.error(`Fail to execute action,`, error)
+ showMessage(`Fail to execute action: ${error}`)
+ success = false
+ }
+ if (success) {
+ const item = await showMessage(message, 'Reload Window', 'Cancel')
+ if (item === 'Reload Window') {
+ commands.executeCommand('workbench.action.reloadWindow')
+ }
}
} catch (e) {
- log.error(e)
- showMessage(`Fail to execute action, ${e}`)
+ log.error(`npm:atomically error,`, e)
+ showMessage(`npm:atomically error: ${e}, maybe you need to enhance VSCode's permissions?`)
} finally {
- rmSync(lockFile)
+ fs.rmSync(lockFile)
}
}
@@ -45,7 +57,11 @@ export async function showMessage(
content: string,
...buttons: T
): Promise {
- return await window.showInformationMessage(content, ...buttons)
+ try {
+ return await window.showInformationMessage(content, ...buttons)
+ } catch (error) {
+ log.error('VSCode error:', error)
+ }
}
export function escapeQuote(str: string) {