Skip to content

Commit

Permalink
fix: more error logs and add FAQ #6
Browse files Browse the repository at this point in the history
  • Loading branch information
subframe7536 committed Nov 2, 2024
1 parent 9f03bca commit e9cc12e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,26 @@ 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.

If you are using MacOS, press <kbd>Command + Q</kbd> 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 <kbd>Command + Q</kbd>) VSCode first, then run:

```sh
sudo chown -R $(whoami) "/Applications/Visual Studio Code.app"
```

See #6

## Configurations

<!-- configs -->
Expand Down
38 changes: 27 additions & 11 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -13,39 +13,55 @@ const lockFile = path.join(baseDir, `__${name}__.lock`)

export async function runAndRestart(message: string, action: () => Promise<any>) {
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)
}
}

export async function showMessage<T extends string[]>(
content: string,
...buttons: T
): Promise<T[number] | undefined> {
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) {
Expand Down

0 comments on commit e9cc12e

Please sign in to comment.