Commit 7f539ad pompurin404
committed
1 parent f1916c1 commit 7f539ad Copy full SHA for 7f539ad
File tree 3 files changed +34
-1
lines changed
3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import yaml from 'yaml'
8
8
import fs from 'fs'
9
9
import { dialog } from 'electron'
10
10
import { addProfileUpdater } from '../core/profileUpdater'
11
+ import { pauseWebsockets } from '../core/mihomoApi'
11
12
12
13
let profileConfig : IProfileConfig // profile.yaml
13
14
@@ -27,7 +28,9 @@ export async function changeCurrentProfile(id: string): Promise<void> {
27
28
const oldId = getProfileConfig ( ) . current
28
29
profileConfig . current = id
29
30
try {
31
+ const recover = pauseWebsockets ( )
30
32
await startCore ( )
33
+ recover ( )
31
34
} catch ( e ) {
32
35
profileConfig . current = oldId
33
36
} finally {
@@ -177,7 +180,9 @@ export function getProfileStr(id: string): string {
177
180
export async function setProfileStr ( id : string , content : string ) : Promise < void > {
178
181
fs . writeFileSync ( profilePath ( id ) , content , 'utf-8' )
179
182
if ( id === getProfileConfig ( ) . current ) {
183
+ const recover = pauseWebsockets ( )
180
184
await startCore ( )
185
+ recover ( )
181
186
}
182
187
}
183
188
Original file line number Diff line number Diff line change @@ -340,3 +340,26 @@ const mihomoConnections = (): void => {
340
340
}
341
341
}
342
342
}
343
+
344
+ export const pauseWebsockets = ( ) => {
345
+ const recoverList : ( ( ) => void ) [ ] = [ ]
346
+ if ( mihomoTrafficWs ) {
347
+ stopMihomoTraffic ( )
348
+ recoverList . push ( startMihomoTraffic )
349
+ }
350
+ if ( mihomoMemoryWs ) {
351
+ stopMihomoMemory ( )
352
+ recoverList . push ( startMihomoMemory )
353
+ }
354
+ if ( mihomoLogsWs ) {
355
+ stopMihomoLogs ( )
356
+ recoverList . push ( startMihomoLogs )
357
+ }
358
+ if ( mihomoConnectionsWs ) {
359
+ stopMihomoConnections ( )
360
+ recoverList . push ( startMihomoConnections )
361
+ }
362
+ return ( ) : void => {
363
+ recoverList . forEach ( ( recover ) => recover ( ) )
364
+ }
365
+ }
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import {
14
14
mihomoUpgradeGeo ,
15
15
mihomoVersion ,
16
16
patchMihomoConfig ,
17
+ pauseWebsockets ,
17
18
startMihomoConnections ,
18
19
startMihomoLogs ,
19
20
stopMihomoConnections ,
@@ -79,7 +80,11 @@ export function registerIpcMainHandlers(): void {
79
80
ipcMain . handle ( 'changeCurrentProfile' , ( _e , id ) => changeCurrentProfile ( id ) )
80
81
ipcMain . handle ( 'addProfileItem' , ( _e , item ) => addProfileItem ( item ) )
81
82
ipcMain . handle ( 'removeProfileItem' , ( _e , id ) => removeProfileItem ( id ) )
82
- ipcMain . handle ( 'restartCore' , startCore )
83
+ ipcMain . handle ( 'restartCore' , async ( ) => {
84
+ const recover = pauseWebsockets ( )
85
+ await startCore ( )
86
+ recover ( )
87
+ } )
83
88
ipcMain . handle ( 'triggerSysProxy' , ( _e , enable ) => triggerSysProxy ( enable ) )
84
89
ipcMain . handle ( 'isEncryptionAvailable' , isEncryptionAvailable )
85
90
ipcMain . handle ( 'encryptString' , ( _e , str ) => safeStorage . encryptString ( str ) )
You can’t perform that action at this time.
0 commit comments