@@ -14,7 +14,8 @@ import * as openpgp from 'openpgp'
1414import os from 'node:os'
1515import CONET_Guardian_NodeInfo_ABI from './CONET_Guardian_NodeInfo_ABI.json'
1616import { runUpdater } from './updateProcess'
17-
17+ import { app as electronApp } from 'electron'
18+ import fs from 'node:fs'
1819
1920const ver = '0.1.4'
2021
@@ -215,7 +216,7 @@ type filterRule = {
215216 IP : string [ ]
216217}
217218
218- const appsPath : string = join ( __dirname )
219+
219220export class Daemon {
220221 private logsPool : proxyLogs [ ] = [ ]
221222
@@ -253,9 +254,28 @@ export class Daemon {
253254 }
254255
255256 private initialize = ( ) => {
256- const staticFolder = join ( appsPath , 'workers' )
257- //const launcherFolder = join ( this.appsPath, '../launcher' )
258- //console.dir ({ staticFolder: staticFolder, launcherFolder: launcherFolder })
257+ // --- 关键逻辑开始 ---
258+
259+ // 1. 定义默认路径(只读的应用包内部)
260+ const defaultPath = join ( __dirname , 'workers' )
261+
262+ // 2. 定义更新路径(可写的 userData 目录内部)
263+ const userDataPath = electronApp . getPath ( 'userData' ) ;
264+ const updatedPath = join ( userDataPath , 'workers' ) ;
265+
266+ // 3. 检查更新路径是否存在,然后决定使用哪个路径
267+ // 如果 updatedPath 存在,就用它;否则,回退到 defaultPath。
268+ const staticFolder = fs . existsSync ( updatedPath ) ? updatedPath : defaultPath ;
269+
270+ // 确保我们选择的目录确实存在(主要针对首次启动时 defaultPath 的情况)
271+ if ( ! fs . existsSync ( staticFolder ) ) {
272+ // 如果连默认目录都不存在,可能需要从别处复制或创建
273+ logger ( Colors . red ( `CRITICAL ERROR: Static folder not found at ${ staticFolder } ` ) ) ;
274+ // 在这种情况下,可以考虑从一个备用位置将默认 `workers` 内容复制到 `updatedPath`
275+ // fs.cpSync(join(__dirname, 'initial_workers'), updatedPath, { recursive: true });
276+ }
277+
278+ // --- 关键逻辑结束 ---
259279
260280 const app = express ( )
261281 const cors = require ( 'cors' )
@@ -530,17 +550,17 @@ export class Daemon {
530550 this . loginListening . write ( JSON . stringify ( cmd ) + '\r\n\r\n' )
531551 } )
532552
533-
534-
535553 app . all ( '/' , ( req : any , res : any ) => {
536554 logger ( Colors . red ( `Local web server got unknow request URL Error! [${ splitIpAddr ( req . ip ) } ] => ${ req . method } url =[${ req . url } ]` ) )
537555 return res . status ( 404 ) . end ( return404 ( ) )
538556 } )
539557
540558 this . localserver = app . listen ( this . PORT , ( ) => {
541- return console . table ( [
542- { 'CONET Local Web Server' : `http://localhost:${ this . PORT } , local-path = [${ staticFolder } ]` } ,
543- ] )
559+ // 在日志中打印出当前正在使用的路径,这对于调试至关重要!
560+ return console . table ( [
561+ { 'CONET Local Web Server' : `http://localhost:${ this . PORT } ` } ,
562+ { 'Serving files from' : staticFolder }
563+ ] )
544564 } )
545565 }
546566}
0 commit comments