@@ -27,7 +27,8 @@ export default class Main {
2727 static myCapacitorApp = createCapacitorElectronApp ( ) ;
2828 static winChildren : Array < Electron . BrowserWindow > = [ ] ;
2929 static processChildren : Array < ChildProcess > = [ ] ;
30- static crud = new CRUD ( ) ;
30+ static booksDir = join ( app . getPath ( 'appData' ) , 'gbr_books' ) ;
31+ static crud = new CRUD ( Main . booksDir ) ;
3132
3233 // This method will be called when Electron has finished
3334 // initialization and is ready to create browser windows.
@@ -63,8 +64,7 @@ export default class Main {
6364
6465 Main . myCapacitorApp . init ( ) ;
6566
66- const booksDir = join ( app . getPath ( 'appData' ) , 'gbr_books' ) ;
67- const serverProcess : ChildProcess = fork ( join ( __dirname , 'server.js' ) , [ '-d' , booksDir ] ) ;
67+ const serverProcess : ChildProcess = fork ( join ( __dirname , 'server.js' ) , [ '-d' , Main . booksDir ] ) ;
6868 Main . processChildren . push ( serverProcess ) ;
6969
7070 const mainWindow = Main . myCapacitorApp . getMainWindow ( ) ;
@@ -88,17 +88,17 @@ export default class Main {
8888 } ) ;
8989
9090 ipcMain . on ( 'open-book' , ( event , book : Book ) => {
91- const _book = new BookBackend ( booksDir , book , mainWindow , loadingWin )
91+ const _book = new BookBackend ( Main . crud , Main . booksDir , book , mainWindow , loadingWin )
9292 _book . open ( w => Main . winChildren . push ( w ) ) ;
9393 } ) ;
9494
9595 ipcMain . on ( 'open-book-with-path' , ( event , msg : IBookWithPath ) => {
96- const book = new BookBackend ( booksDir , msg . book , mainWindow , loadingWin , msg . path )
96+ const book = new BookBackend ( Main . crud , Main . booksDir , msg . book , mainWindow , loadingWin , msg . path )
9797 book . open ( w => Main . winChildren . push ( w ) ) ;
9898 } ) ;
9999
100100 ipcMain . on ( 'download-book' , ( event , book : Book ) => {
101- const _book = new BookBackend ( booksDir , book , mainWindow , loadingWin ) ;
101+ const _book = new BookBackend ( Main . crud , Main . booksDir , book , mainWindow , loadingWin ) ;
102102 _book . download ( cp => Main . processChildren . push ( cp ) ) ;
103103 } ) ;
104104
@@ -121,7 +121,7 @@ export default class Main {
121121
122122 if ( query . table === 'Book' ) {
123123 const book = query . item as Book ;
124- const bookDir = join ( booksDir , book . website . uri , book . writer . name , book . name ) ;
124+ const bookDir = join ( Main . booksDir , book . website . uri , book . writer . name , book . name ) ;
125125 await remove ( bookDir )
126126 . then ( ( ) => res . message . push ( ',已成功从文件系统移除' ) )
127127 . catch ( ( e : Error ) => res . message . push ( e . message ) ) ;
0 commit comments