@@ -8,12 +8,13 @@ import { commands, window } from 'vscode'
8
8
import { config } from './config'
9
9
import * as Meta from './generated/meta'
10
10
import { log } from './logger'
11
+ import { baseDir } from './path'
11
12
import { restartApp } from './restart'
12
13
13
14
export const fileProtocol = 'file://'
14
15
export const httpsProtocol = 'https://'
15
16
16
- const lockFile = path . join ( os . tmpdir ( ) , `__${ Meta . name } __.lock` )
17
+ const lockFile = path . join ( baseDir , `__${ Meta . name } __.lock` )
17
18
18
19
let last = hasElectronWindowOptions ( )
19
20
function hasElectronWindowOptions ( ) : string {
@@ -49,44 +50,56 @@ export async function runAndRestart(message: string, fullRestart: boolean, actio
49
50
return
50
51
}
51
52
}
53
+ let success = true
52
54
try {
53
55
writeFileSync ( lockFile , String ( Date . now ( ) ) )
54
- let success = true
55
56
try {
56
57
logWindowOptionsChanged ( fullRestart )
57
58
await action ( )
58
59
} catch ( error ) {
59
60
logError ( 'Fail to execute action' , error )
60
61
success = false
62
+ } finally {
63
+ fs . rmSync ( lockFile )
61
64
}
62
- if ( success ) {
63
- let shouldProceed = false
64
- if ( config . reloadWithoutPrompting ) {
65
- shouldProceed = true
66
- } else {
67
- const item = await showMessage (
68
- message ,
69
- fullRestart ? 'Restart APP' : 'Reload Window' ,
70
- 'Cancel' ,
71
- )
72
- shouldProceed = item === 'Reload Window' || item === 'Restart APP'
65
+ } catch ( err ) {
66
+ if ( err instanceof Error ) {
67
+ const base = 'This extension need to modify VSCode\'s source code but'
68
+ if ( 'code' in err && err . code === 'EROFS' ) {
69
+ logError ( `${ base } it runs on read-only filesystem. Maybe you need to choose another way to install VSCode` , err )
70
+ return
71
+ } else if ( err . message . includes ( 'RangeError: Maximum call stack size exceeded' ) ) {
72
+ logError ( `${ base } current user is not allowed. Please comfirm that you have the permission to write files in ${ baseDir } ` , err )
73
+ return
73
74
}
74
- if ( shouldProceed ) {
75
- if ( fullRestart ) {
76
- try {
77
- await restartApp ( )
78
- } catch ( error ) {
79
- logError ( 'Fail to restart VSCode' , error )
80
- }
81
- } else {
82
- commands . executeCommand ( 'workbench.action.reloadWindow' )
75
+ }
76
+ logError ( 'Unknown error in npm:atomically' , err )
77
+ return
78
+ }
79
+
80
+ if ( success ) {
81
+ let shouldProceed = false
82
+ if ( config . reloadWithoutPrompting ) {
83
+ shouldProceed = true
84
+ } else {
85
+ const item = await showMessage (
86
+ message ,
87
+ fullRestart ? 'Restart APP' : 'Reload Window' ,
88
+ 'Cancel' ,
89
+ )
90
+ shouldProceed = item === 'Reload Window' || item === 'Restart APP'
91
+ }
92
+ if ( shouldProceed ) {
93
+ if ( fullRestart ) {
94
+ try {
95
+ await restartApp ( )
96
+ } catch ( error ) {
97
+ logError ( 'Fail to restart VSCode' , error )
83
98
}
99
+ } else {
100
+ commands . executeCommand ( 'workbench.action.reloadWindow' )
84
101
}
85
102
}
86
- } catch ( e ) {
87
- logError ( `npm:atomically error, maybe you need to enhance VSCode's permissions?` , e )
88
- } finally {
89
- fs . rmSync ( lockFile )
90
103
}
91
104
}
92
105
0 commit comments