diff --git a/package-lock.json b/package-lock.json index d2b64714b..55900dea8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -124,7 +124,7 @@ "css-hot-loader": "^1.4.4", "css-loader": "^7.1.2", "devtron": "^1.4.0", - "electron": "^33.1.0", + "electron": "^33.2.0", "electron-builder": "^25.1.8", "electron-devtools-installer": "^3.2.0", "eslint": "^8.57.1", @@ -12240,9 +12240,9 @@ } }, "node_modules/electron": { - "version": "33.1.0", - "resolved": "https://registry.npmjs.org/electron/-/electron-33.1.0.tgz", - "integrity": "sha512-7KiY6MtRo1fVFLPGyHS7Inh8yZfrbUTy43nNwUgMD2CBk729BgSwOC2WhmcptNJVlzHJpVxSWkiVi2hp9mH/bw==", + "version": "33.2.0", + "resolved": "https://registry.npmjs.org/electron/-/electron-33.2.0.tgz", + "integrity": "sha512-PVw1ICAQDPsnnsmpNFX/b1i/49h67pbSPxuIENd9K9WpGO1tsRaQt+K2bmXqTuoMJsbzIc75Ce8zqtuwBPqawA==", "dev": true, "hasInstallScript": true, "license": "MIT", diff --git a/package.json b/package.json index 9a979b8fc..845e94931 100644 --- a/package.json +++ b/package.json @@ -378,7 +378,7 @@ "css-hot-loader": "^1.4.4", "css-loader": "^7.1.2", "devtron": "^1.4.0", - "electron": "^33.1.0", + "electron": "^33.2.0", "electron-builder": "^25.1.8", "electron-devtools-installer": "^3.2.0", "eslint": "^8.57.1", diff --git a/src/main/cli/lock.ts b/src/main/cli/lock.ts index 696902dbc..52ad4d667 100644 --- a/src/main/cli/lock.ts +++ b/src/main/cli/lock.ts @@ -87,7 +87,7 @@ export function lockInstance() { // https://github.com/edrlab/thorium-reader/pull/1573#issuecomment-1003042325 try { const libraryAppWindow = getLibraryWindowFromDi(); - if (libraryAppWindow) { + if (libraryAppWindow && !libraryAppWindow.isDestroyed() && !libraryAppWindow.webContents.isDestroyed()) { if (libraryAppWindow.isMinimized()) { libraryAppWindow.restore(); } diff --git a/src/main/redux/middleware/sync.ts b/src/main/redux/middleware/sync.ts index f6b1eae1e..60163f433 100644 --- a/src/main/redux/middleware/sync.ts +++ b/src/main/redux/middleware/sync.ts @@ -114,7 +114,9 @@ export const reduxSyncMiddleware: Middleware if (libId) { try { const libWin = getLibraryWindowFromDi(); - browserWin.set(libId, libWin); + if (libWin && !libWin.isDestroyed() && !libWin.webContents.isDestroyed()) { + browserWin.set(libId, libWin); + } } catch (_err) { // ignore // library window may be not initialized in first @@ -126,6 +128,7 @@ export const reduxSyncMiddleware: Middleware if (readers[key]) { try { const readerWin = getReaderWindowFromDi(readers[key].identifier); + if (!readerWin.isDestroyed() && !readerWin.webContents.isDestroyed()) browserWin.set(readers[key].identifier, readerWin); } catch (_err) { // ignore diff --git a/src/main/redux/sagas/annotation.ts b/src/main/redux/sagas/annotation.ts index 59c53576d..c90d7b922 100644 --- a/src/main/redux/sagas/annotation.ts +++ b/src/main/redux/sagas/annotation.ts @@ -49,7 +49,8 @@ function* importAnnotationSet(action: annotationActions.importAnnotationSet.TAct const currentTimestamp = (new Date()).getTime(); const win = winId ? getReaderWindowFromDi(winId) : getLibraryWindowFromDi(); - if (!win) { + + if (!win || win.isDestroyed() || win.webContents.isDestroyed()) { debug("ERROR!! No Browser window !!! exit"); return ; } diff --git a/src/main/redux/sagas/api/publication/export.ts b/src/main/redux/sagas/api/publication/export.ts index 7f8ceeb4e..d6154648b 100644 --- a/src/main/redux/sagas/api/publication/export.ts +++ b/src/main/redux/sagas/api/publication/export.ts @@ -13,6 +13,10 @@ import { diMainGet, getLibraryWindowFromDi } from "readium-desktop/main/di"; export function* exportPublication(publicationView: PublicationView) { const libraryAppWindow = yield* callTyped(() => getLibraryWindowFromDi()); + if (!libraryAppWindow || libraryAppWindow.isDestroyed() || libraryAppWindow.webContents.isDestroyed()) { + return; + } + const publicationStorage = diMainGet("publication-storage"); const defaultFilename = publicationStorage.getPublicationFilename(publicationView); diff --git a/src/main/redux/sagas/app.ts b/src/main/redux/sagas/app.ts index 0b53ab496..f0c55c448 100644 --- a/src/main/redux/sagas/app.ts +++ b/src/main/redux/sagas/app.ts @@ -71,7 +71,7 @@ export function* init() { const browserWindows = []; try { const libraryWin = getLibraryWindowFromDi(); - if (libraryWin) { + if (libraryWin && !libraryWin.isDestroyed() && !libraryWin.webContents.isDestroyed()) { browserWindows.push(libraryWin); } } catch (e) { @@ -80,7 +80,11 @@ export function* init() { try { const readerWins = getAllReaderWindowFromDi(); if (readerWins?.length) { - browserWindows.push(...readerWins); + for (const readerWin of readerWins) { + if (readerWin && !readerWin.isDestroyed() && !readerWin.webContents.isDestroyed()) { + browserWindows.push(readerWin); + } + } } } catch (e) { debug("getAllReaderWindowFromDi ERROR?", e); @@ -331,7 +335,6 @@ export function exit() { shouldExit = true; const libraryWin = getLibraryWindowFromDi(); - if (process.platform === "darwin") { if (libraryWin.isDestroyed()) { if (closeProcessLock.isLock) { @@ -345,7 +348,9 @@ export function exit() { } } + if (libraryWin && !libraryWin.isDestroyed() && !libraryWin.webContents.isDestroyed()) { libraryWin.close(); + } }; yield takeSpawnEveryChannel( diff --git a/src/main/redux/sagas/auth.ts b/src/main/redux/sagas/auth.ts index 19771ce41..328630fab 100644 --- a/src/main/redux/sagas/auth.ts +++ b/src/main/redux/sagas/auth.ts @@ -696,7 +696,7 @@ function opdsAuthDocConverter(doc: OPDSAuthenticationDoc, baseUrl: string): IOPD function createOpdsAuthenticationModalWin(url: string): BrowserWindow | undefined { const libWin = tryCatchSync(() => getLibraryWindowFromDi(), filename_); - if (!libWin) { + if (!libWin || libWin.isDestroyed() || libWin.webContents.isDestroyed()) { debug("no lib win !!"); return undefined; } diff --git a/src/main/redux/sagas/reader.ts b/src/main/redux/sagas/reader.ts index 78bb0b8a5..24963c1d2 100644 --- a/src/main/redux/sagas/reader.ts +++ b/src/main/redux/sagas/reader.ts @@ -45,7 +45,8 @@ function* readerFullscreenRequest(action: readerActions.fullScreenRequest.TActio if (sender.identifier && sender.type === SenderType.Renderer) { const readerWin = yield* callTyped(() => getReaderWindowFromDi(sender.identifier)); - if (readerWin) { + + if (readerWin && !readerWin.isDestroyed() && !readerWin.webContents.isDestroyed()) { readerWin.setFullScreen(action.payload.full); } } @@ -54,7 +55,7 @@ function* readerFullscreenRequest(action: readerActions.fullScreenRequest.TActio function* readerDetachRequest(action: readerActions.detachModeRequest.TAction) { const libWin = yield* callTyped(() => getLibraryWindowFromDi()); - if (libWin && !libWin.isDestroyed()) { + if (libWin && !libWin.isDestroyed() && !libWin.webContents.isDestroyed()) { // try-catch to do not trigger an error message when the winbound is not handle by the os let libBound: Electron.Rectangle; @@ -80,8 +81,7 @@ function* readerDetachRequest(action: readerActions.detachModeRequest.TAction) { if (readerWinId && action.sender?.type === SenderType.Renderer) { const readerWin = getReaderWindowFromDi(readerWinId); - - if (readerWin) { + if (readerWin && !readerWin.isDestroyed() && !readerWin.webContents.isDestroyed()) { // this should never occur, but let's do it for certainty if (readerWin.isMinimized()) { @@ -230,7 +230,10 @@ function* readerOpenRequest(action: readerActions.openRequest.TAction) { const mode = yield* selectTyped((state: RootState) => state.mode); if (mode === ReaderMode.Attached) { try { - getLibraryWindowFromDi().hide(); + const libWin = getLibraryWindowFromDi(); + if (libWin && !libWin.isDestroyed() && !libWin.webContents.isDestroyed()) { + libWin.hide(); + } } catch (_err) { debug("library can't be loaded from di"); } @@ -262,7 +265,7 @@ function* readerCLoseRequestFromIdentifier(action: readerActions.closeRequest.TA yield call(readerCloseRequest, action.sender.identifier); const libWin = yield* callTyped(() => getLibraryWindowFromDi()); - if (libWin && !libWin.isDestroyed()) { + if (libWin && !libWin.isDestroyed() && !libWin.webContents.isDestroyed()) { const winBound = yield* selectTyped( (state: RootState) => state.win.session.library.windowBound, @@ -313,7 +316,7 @@ function* readerCloseRequest(identifier?: string) { } const readerWindow = getReaderWindowFromDi(identifier); - if (readerWindow) { + if (readerWindow && !readerWindow.isDestroyed() && !readerWindow.webContents.isDestroyed()) { readerWindow.close(); } diff --git a/src/main/redux/sagas/win/library.ts b/src/main/redux/sagas/win/library.ts index 337079412..512cf2c58 100644 --- a/src/main/redux/sagas/win/library.ts +++ b/src/main/redux/sagas/win/library.ts @@ -51,7 +51,7 @@ export function* appActivate() { const libWin = yield* callTyped(() => getLibraryWindowFromDi()); - if (!libWin?.isDestroyed()) { + if (libWin && !libWin.isDestroyed() && !libWin.webContents.isDestroyed()) { if (libWin.isMinimized()) { libWin.restore(); @@ -65,11 +65,12 @@ export function* appActivate() { const readers = yield* selectTyped((state: RootState) => state.win.session.reader); const readersArray = ObjectKeys(readers); const readerWin = getReaderWindowFromDi(readersArray[0]); - - if (readerWin.isMinimized()) { - readerWin.restore(); + if (readerWin && !readerWin.isDestroyed() && !readerWin.webContents.isDestroyed()) { + if (readerWin.isMinimized()) { + readerWin.restore(); + } + readerWin.show(); } - readerWin.show(); } return ; @@ -189,7 +190,7 @@ function* winClose(_action: winActions.library.closed.TAction) { debug("library -> winClose"); - const library = getLibraryWindowFromDi(); + const libraryWin = getLibraryWindowFromDi(); let sessionSaving = false; // window.close() // not saved session by default { @@ -242,7 +243,7 @@ function* winClose(_action: winActions.library.closed.TAction) { } try { const readerWin = yield* callTyped(() => getReaderWindowFromDi(reader.identifier)); - + if (readerWin && !readerWin.isDestroyed() && !readerWin.webContents.isDestroyed()) if (sessionSaving) { // force quit the reader windows to keep session in next startup debug("destroy reader", index); @@ -264,9 +265,8 @@ function* winClose(_action: winActions.library.closed.TAction) { } if (sessionSaving) { - - // closed the library and thorium - library.destroy(); + if (libraryWin && !libraryWin.isDestroyed() && !libraryWin.webContents.isDestroyed()) + libraryWin.destroy(); } else { yield spawn(function* () { @@ -280,7 +280,8 @@ function* winClose(_action: winActions.library.closed.TAction) { } while (readersArray.length); - library.destroy(); + if (libraryWin && !libraryWin.isDestroyed() && !libraryWin.webContents.isDestroyed()) + libraryWin.destroy(); }); } diff --git a/src/main/redux/sagas/win/reader.ts b/src/main/redux/sagas/win/reader.ts index 6ecbea965..c088bcbae 100644 --- a/src/main/redux/sagas/win/reader.ts +++ b/src/main/redux/sagas/win/reader.ts @@ -120,7 +120,7 @@ function* winClose(action: winActions.reader.closed.TAction) { const readersArray = ObjectValues(readers); try { - const libraryWindow = yield* callTyped(() => getLibraryWindowFromDi()); + const libraryWin = yield* callTyped(() => getLibraryWindowFromDi()); debug("Nb of readers:", readersArray.length); debug("readers: ", readersArray); @@ -134,12 +134,14 @@ function* winClose(action: winActions.reader.closed.TAction) { } else { const readerWin = yield* callTyped(() => getReaderWindowFromDi(identifier)); - if (readerWin) { + if (readerWin && !readerWin.isDestroyed() && !readerWin.webContents.isDestroyed()) { try { const winBound = readerWin.getBounds(); debug("_______3 readerWin.getBounds()", winBound); normalizeRectangle(winBound); - libraryWindow.setBounds(winBound); + + if (libraryWin && !libraryWin.isDestroyed() && !libraryWin.webContents.isDestroyed()) + libraryWin.setBounds(winBound); } catch (e) { debug("error libraryWindow.setBounds(readerWin.getBounds())", e); } @@ -147,14 +149,14 @@ function* winClose(action: winActions.reader.closed.TAction) { } } - if (libraryWindow) { - if (libraryWindow.isMinimized()) { - libraryWindow.restore(); - } else if (!libraryWindow.isVisible()) { - libraryWindow.close(); + if (libraryWin && !libraryWin.isDestroyed() && !libraryWin.webContents.isDestroyed()) { + if (libraryWin.isMinimized()) { + libraryWin.restore(); + } else if (!libraryWin.isVisible()) { + libraryWin.close(); return; } - libraryWindow.show(); // focuses as well + libraryWin.show(); // focuses as well } } catch (_err) { diff --git a/src/main/tools/showLibrary.ts b/src/main/tools/showLibrary.ts index f347ba073..dc15c7b3d 100644 --- a/src/main/tools/showLibrary.ts +++ b/src/main/tools/showLibrary.ts @@ -11,7 +11,7 @@ import { getAppActivateEventChannel } from "../redux/sagas/getEventChannel"; export const showLibrary = () => { const library = getLibraryWindowFromDi(); - if (library.isDestroyed()) { + if (!library || library.isDestroyed() || library.webContents.isDestroyed()) { const appActivateChannel = getAppActivateEventChannel(); appActivateChannel.put(true);