@@ -94,7 +94,7 @@ const createEventChannel = (server: ServerRecord, serverRuntime?: ServerRuntime)
9494 } ;
9595 Dialog . tipError ( data . msg || msgMap [ data . type ] ) ;
9696 setTimeout ( ( ) => {
97- window . $mapi . user . open ( ) . then ( ) ;
97+ $mapi . user . open ( ) . then ( ) ;
9898 } , 2000 ) ;
9999 break ;
100100 }
@@ -153,7 +153,7 @@ const updateRunningServerCount = async () => {
153153 const count = serverStoreInstance . records . filter ( r => {
154154 return r . type === EnumServerType . LOCAL_DIR && r . status === EnumServerStatus . RUNNING && ! r . autoStart ;
155155 } ) . length ;
156- await window . $mapi . server . runningServerCount ( count ) ;
156+ await $mapi . server . runningServerCount ( count ) ;
157157} ;
158158
159159export const serverStore = defineStore ( "server" , {
@@ -167,7 +167,7 @@ export const serverStore = defineStore("server", {
167167 // await serverCloudStore.waitReady()
168168 } ,
169169 async init ( ) {
170- await window . $mapi . storage . get ( "server" , "records" , [ ] ) . then ( records => {
170+ await $mapi . storage . get ( "server" , "records" , [ ] ) . then ( records => {
171171 records . forEach ( ( record : ServerRecord ) => {
172172 record . status = createServerStatus ( record ) ;
173173 record . runtime = getServerRuntimeComputedValue ( record ) ;
@@ -189,12 +189,12 @@ export const serverStore = defineStore("server", {
189189 this . isReady = true ;
190190 } ,
191191 async refresh ( ) {
192- const dirs = await window . $mapi . file . list ( "model" , {
192+ const dirs = await $mapi . file . list ( "model" , {
193193 isDataPath : true ,
194194 } ) ;
195195 const localRecords : ServerRecord [ ] = [ ] ;
196196 for ( let dir of dirs ) {
197- const config = await window . $mapi . file . read ( `model/${ dir . name } /config.json` , {
197+ const config = await $mapi . file . read ( `model/${ dir . name } /config.json` , {
198198 isDataPath : true ,
199199 } ) ;
200200 let json ;
@@ -295,18 +295,18 @@ export const serverStore = defineStore("server", {
295295 } .log`;
296296 serverRuntime . eventChannelName = createEventChannel ( server ) ;
297297 const serverInfo = await this . serverInfo ( server ) ;
298- await window . $mapi . server . start ( serverInfo ) ;
298+ await $mapi . server . start ( serverInfo ) ;
299299 let pingTimeout = 60 * 5 * 1000 ;
300300 let pingStart = TimeUtil . timestampMS ( ) ;
301301 const pingCheck = ( ) => {
302302 const now = TimeUtil . timestampMS ( ) ;
303303 if ( now - pingStart > pingTimeout ) {
304304 // console.log('ping.timeout')
305305 serverRuntime . status = EnumServerStatus . ERROR ;
306- window . $mapi . server . stop ( serverInfo ) ;
306+ $mapi . server . stop ( serverInfo ) ;
307307 return ;
308308 }
309- window . $mapi . server
309+ $mapi . server
310310 . ping ( serverInfo )
311311 . then ( success => {
312312 if ( success ) {
@@ -332,7 +332,7 @@ export const serverStore = defineStore("server", {
332332 serverRuntime . status = EnumServerStatus . STOPPING ;
333333 const serverInfo = await this . serverInfo ( server ) ;
334334 serverInfo . logFile = serverRuntime . logFile ;
335- await window . $mapi . server . stop ( serverInfo ) ;
335+ await $mapi . server . stop ( serverInfo ) ;
336336 } ,
337337 async cancel ( server : ServerRecord ) {
338338 const record = this . findRecord ( server ) ;
@@ -343,7 +343,7 @@ export const serverStore = defineStore("server", {
343343 const serverRuntime = getOrCreateServerRuntime ( server ) ;
344344 const serverInfo = await this . serverInfo ( server ) ;
345345 serverInfo . logFile = serverRuntime . logFile ;
346- await window . $mapi . server . cancel ( serverInfo ) ;
346+ await $mapi . server . cancel ( serverInfo ) ;
347347 } ,
348348 async updateSetting ( key : string , setting : any ) {
349349 const record = this . records . find ( record => record . key === key ) ;
@@ -369,8 +369,10 @@ export const serverStore = defineStore("server", {
369369 throw new Error ( "StatusError" ) ;
370370 }
371371 }
372+ const serverInfo = await this . serverInfo ( server ) ;
373+ $mapi . server . deletes ( serverInfo ) . then ( ) ;
372374 if ( record . type === EnumServerType . LOCAL ) {
373- await window . $mapi . file . deletes ( record . localPath as string , {
375+ await $mapi . file . deletes ( record . localPath as string , {
374376 isDataPath : true ,
375377 } ) ;
376378 }
@@ -394,7 +396,7 @@ export const serverStore = defineStore("server", {
394396 record . status = undefined ;
395397 record . runtime = undefined ;
396398 } ) ;
397- await window . $mapi . storage . set ( "server" , "records" , savedRecords ) ;
399+ await $mapi . storage . set ( "server" , "records" , savedRecords ) ;
398400 } ,
399401 async getByKey ( key : string ) : Promise < ServerRecord | undefined > {
400402 // if (key.startsWith('Cloud')) {
@@ -424,7 +426,7 @@ export const serverStore = defineStore("server", {
424426 option ?: ServerCallFunctionOption
425427 ) : Promise < ServerCallFunctionResult > {
426428 await this . callStart ( serverInfo ) ;
427- const res = await window . $mapi . server . callFunctionWithException ( serverInfo , method , data , option ) ;
429+ const res = await $mapi . server . callFunctionWithException ( serverInfo , method , data , option ) ;
428430 await this . callEnd ( serverInfo ) ;
429431 return res ;
430432 } ,
@@ -459,7 +461,7 @@ export const serverStore = defineStore("server", {
459461 config : JSON . parse ( JSON . stringify ( server ) ) ,
460462 } ;
461463 if ( server . type === EnumServerType . LOCAL ) {
462- result . localPath = await window . $mapi . file . fullPath ( server . localPath as string ) ;
464+ result . localPath = await $mapi . file . fullPath ( server . localPath as string ) ;
463465 } else if ( server . type === EnumServerType . LOCAL_DIR ) {
464466 result . localPath = server . localPath as string ;
465467 } else if ( server . type === EnumServerType . CLOUD ) {
0 commit comments