@@ -65,6 +65,9 @@ export const useCoreBranch = (isAlpha = false) => {
65
65
66
66
const grantable = computed ( ( ) => localVersion . value && envStore . env . os !== 'windows' )
67
67
68
+ const CoreFilePath = `${ CoreWorkingDirectory } /${ getKernelFileName ( isAlpha ) } `
69
+ const CoreBakFilePath = `${ CoreFilePath } .bak`
70
+
68
71
const downloadCore = async ( ) => {
69
72
downloading . value = true
70
73
try {
@@ -102,24 +105,19 @@ export const useCoreBranch = (isAlpha = false) => {
102
105
update ( t ( 'common.downloading' ) + ( ( progress / total ) * 100 ) . toFixed ( 2 ) + '%' )
103
106
} ,
104
107
{ CancelId : downloadCancelId } ,
105
- ) . catch ( ( err ) => {
106
- destroy ( )
107
- throw err
108
- } )
108
+ ) . finally ( destroy )
109
109
110
110
const stableFileName = getKernelFileName ( )
111
- const alphaFileName = getKernelFileName ( true )
112
- const kernelFilePath = CoreWorkingDirectory + '/' + ( isAlpha ? alphaFileName : stableFileName )
113
111
114
- await ignoredError ( Movefile , kernelFilePath , kernelFilePath + '.bak' )
112
+ await ignoredError ( Movefile , CoreFilePath , CoreBakFilePath )
115
113
116
114
if ( assetName . endsWith ( '.zip' ) ) {
117
115
await UnzipZIPFile ( downloadCacheFile , 'data/.cache' )
118
- const tmpPath = `data/.cache/` + assetName . replace ( '.zip' , '' )
119
- await Movefile ( tmpPath + '/' + stableFileName , kernelFilePath )
116
+ const tmpPath = `data/.cache/${ assetName . replace ( '.zip' , '' ) } `
117
+ await Movefile ( ` ${ tmpPath } / ${ stableFileName } ` , CoreFilePath )
120
118
await Removefile ( tmpPath )
121
119
} else {
122
- const extractDir = ' data/.cache/' + ( isAlpha ? 'latest' : 'stable' )
120
+ const extractDir = ` data/.cache/${ isAlpha ? 'latest' : 'stable' } `
123
121
await Makedir ( extractDir )
124
122
await Exec ( 'tar' , [
125
123
'xzvf' ,
@@ -129,17 +127,16 @@ export const useCoreBranch = (isAlpha = false) => {
129
127
'--strip-components' ,
130
128
'1' ,
131
129
] )
132
- await Movefile ( extractDir + '/' + stableFileName , kernelFilePath )
130
+ await Movefile ( ` ${ extractDir } / ${ stableFileName } ` , CoreFilePath )
133
131
await Removefile ( extractDir )
134
132
}
135
133
136
134
await Removefile ( downloadCacheFile )
137
135
138
- if ( ! kernelFilePath . endsWith ( '.exe' ) ) {
139
- await ignoredError ( Exec , 'chmod' , [ '+x' , await AbsolutePath ( kernelFilePath ) ] )
136
+ if ( ! CoreFilePath . endsWith ( '.exe' ) ) {
137
+ await ignoredError ( Exec , 'chmod' , [ '+x' , await AbsolutePath ( CoreFilePath ) ] )
140
138
}
141
139
142
- destroy ( )
143
140
refreshLocalVersion ( )
144
141
downloadCompleted . value = true
145
142
message . success ( 'common.success' )
@@ -154,9 +151,7 @@ export const useCoreBranch = (isAlpha = false) => {
154
151
const getLocalVersion = async ( showTips = false ) => {
155
152
localVersionLoading . value = true
156
153
try {
157
- const fileName = getKernelFileName ( isAlpha )
158
- const kernelFilePath = CoreWorkingDirectory + '/' + fileName
159
- const res = await Exec ( kernelFilePath , [ 'version' ] )
154
+ const res = await Exec ( CoreFilePath , [ 'version' ] )
160
155
versionDetail . value = res . trim ( )
161
156
return res . match ( / v e r s i o n ( \S + ) / ) ?. [ 1 ] || ''
162
157
} catch ( error : any ) {
@@ -206,20 +201,14 @@ export const useCoreBranch = (isAlpha = false) => {
206
201
}
207
202
208
203
const grantCorePermission = async ( ) => {
209
- const fileName = getKernelFileName ( isAlpha )
210
- const kernelFilePath = CoreWorkingDirectory + '/' + fileName
211
- await GrantTUNPermission ( kernelFilePath )
204
+ await GrantTUNPermission ( CoreFilePath )
212
205
message . success ( 'common.success' )
213
206
}
214
207
215
208
const rollbackCore = async ( ) => {
216
209
await confirm ( 'common.warning' , 'settings.kernel.rollback' )
217
210
218
- const doRollback = async ( ) => {
219
- const file = getKernelFileName ( isAlpha )
220
- await Movefile ( `${ CoreWorkingDirectory } /${ file } .bak` , `${ CoreWorkingDirectory } /${ file } ` )
221
- refreshLocalVersion ( )
222
- }
211
+ const doRollback = ( ) => Movefile ( CoreBakFilePath , CoreFilePath )
223
212
224
213
const { running, branch } = appSettings . app . kernel
225
214
const isCurrentRunning = running && ( branch === 'alpha' ) === isAlpha
@@ -228,6 +217,7 @@ export const useCoreBranch = (isAlpha = false) => {
228
217
} else {
229
218
await doRollback ( )
230
219
}
220
+ refreshLocalVersion ( )
231
221
message . success ( 'common.success' )
232
222
}
233
223
@@ -243,8 +233,7 @@ export const useCoreBranch = (isAlpha = false) => {
243
233
watch (
244
234
[ localVersion , downloadCompleted ] ,
245
235
debounce ( async ( ) => {
246
- const bak = CoreWorkingDirectory + '/' + getKernelFileName ( isAlpha ) + '.bak'
247
- rollbackable . value = await FileExists ( bak )
236
+ rollbackable . value = await FileExists ( CoreBakFilePath )
248
237
} , 500 ) ,
249
238
)
250
239
0 commit comments