bug修复
This commit is contained in:
+21
-1
@@ -351,9 +351,29 @@ ipcMain.on('myreader:allow-close', (event) => {
|
||||
win.close()
|
||||
})
|
||||
|
||||
let pendingOpenPaths: string[] = []
|
||||
|
||||
app.whenReady().then(() => {
|
||||
Menu.setApplicationMenu(buildMenu())
|
||||
createWindow()
|
||||
|
||||
const args = process.argv.slice(1)
|
||||
for (const arg of args) {
|
||||
if (existsSync(arg) && isMarkdownFile(arg)) {
|
||||
pendingOpenPaths.push(arg)
|
||||
}
|
||||
}
|
||||
|
||||
const win = createWindow()
|
||||
|
||||
win.webContents.on('dom-ready', () => {
|
||||
if (pendingOpenPaths.length > 0) {
|
||||
setTimeout(() => {
|
||||
win.webContents.send('myreader:open-files', pendingOpenPaths)
|
||||
pendingOpenPaths = []
|
||||
}, 500)
|
||||
}
|
||||
})
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow()
|
||||
|
||||
@@ -25,6 +25,7 @@ export interface MyReaderApi {
|
||||
allowClose: () => void
|
||||
onRequestClose: (handler: () => void) => () => void
|
||||
onMenuAction: (handler: (action: string) => void) => () => void
|
||||
onOpenFiles: (handler: (paths: string[]) => void) => () => void
|
||||
}
|
||||
|
||||
const api: MyReaderApi = {
|
||||
@@ -64,6 +65,15 @@ const api: MyReaderApi = {
|
||||
return () => {
|
||||
ipcRenderer.removeListener('myreader:menu', listener)
|
||||
}
|
||||
},
|
||||
onOpenFiles: (handler: (paths: string[]) => void) => {
|
||||
const listener = (_e: unknown, paths: string[]): void => {
|
||||
handler(paths)
|
||||
}
|
||||
ipcRenderer.on('myreader:open-files', listener)
|
||||
return () => {
|
||||
ipcRenderer.removeListener('myreader:open-files', listener)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user