Skip to content

Commit

Permalink
Fixes #2602
Browse files Browse the repository at this point in the history
  • Loading branch information
danielweck committed Nov 5, 2024
1 parent 9d2e3e8 commit b0e18c8
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 40 deletions.
3 changes: 2 additions & 1 deletion src/main/redux/middleware/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export const reduxSyncMiddleware: Middleware
const a = ActionSerializer.serialize(action as ActionWithSender);
// debug(a);
try {
if (!win.isDestroyed() && !win.webContents.isDestroyed())
win.webContents.send(syncIpc.CHANNEL, {
type: syncIpc.EventType.MainAction,
payload: {
Expand Down Expand Up @@ -177,7 +178,7 @@ export const reduxSyncMiddleware: Middleware
// }

// try {
// appWindow.browserWindow.webContents.send(syncIpc.CHANNEL, {
// !appWindow.isDestroyed() && !appWindow.webContents.isDestroyed() && appWindow.browserWindow.webContents.send(syncIpc.CHANNEL, {
// type: syncIpc.EventType.MainAction,
// payload: {
// action: actionSerializer.serialize(action),
Expand Down
2 changes: 2 additions & 0 deletions src/main/redux/sagas/annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ function* importAnnotationSet(action: annotationActions.importAnnotationSet.TAct
const annotationToUpdateOld = annotations.find(({ uuid }) => uuid === annotationToUpdate.uuid);
const a = ActionSerializer.serialize(readerActions.annotation.update.build(annotationToUpdateOld, annotationToUpdate));
try {
if (!readerWin.isDestroyed() && !readerWin.webContents.isDestroyed())
readerWin.webContents.send(syncIpc.CHANNEL, {
type: syncIpc.EventType.MainAction,
payload: {
Expand All @@ -359,6 +360,7 @@ function* importAnnotationSet(action: annotationActions.importAnnotationSet.TAct
for (const annotationParsedReadyToBeImported of annotationsParsedNoConflictArray) {
const a = ActionSerializer.serialize(readerActions.annotation.push.build(annotationParsedReadyToBeImported));
try {
if (!readerWin.isDestroyed() && !readerWin.webContents.isDestroyed())
readerWin.webContents.send(syncIpc.CHANNEL, {
type: syncIpc.EventType.MainAction,
payload: {
Expand Down
2 changes: 1 addition & 1 deletion src/main/redux/sagas/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function* init() {
debug("getAllReaderWindowFromDi ERROR?", e);
}
browserWindows.forEach((win) => {
if (win.webContents) {
if (!win.isDestroyed() && !win.webContents.isDestroyed()) {
console.log("webContents.send - accessibility-support-changed: ", accessibilitySupportEnabled, win.id);
try {
win.webContents.send("accessibility-support-changed", accessibilitySupportEnabled);
Expand Down
2 changes: 1 addition & 1 deletion src/main/redux/sagas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export function* rootSaga() {
yield put(appActions.initSuccess.build());

// wait library window fully opened before to throw events
yield take(winActions.library.openSucess.build);
yield take(winActions.library.openSucess.ID);

if (!process.windowsStore && _APP_NAME === "Thorium" && _PACK_NAME === "EDRLab.ThoriumReader") {
yield call(checkAppVersionUpdate);
Expand Down
56 changes: 29 additions & 27 deletions src/main/redux/sagas/win/browserWindow/createLibraryWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,28 @@ export function* createLibraryWindow(_action: winActions.library.openRequest.TAc
contextMenuSetup(wc, wc.id);
}

if (IS_DEV) {
yield put(winActions.session.registerLibrary.build(libWindow, windowBound));

const readers = yield* selectTyped(
(state: RootState) => state.win.session.reader,
);
const readersArray = ObjectValues(readers);
if (readersArray.length === 1) {
libWindow.hide();
}

let rendererBaseUrl = _RENDERER_LIBRARY_BASE_URL;
if (rendererBaseUrl === "file://") {
// dist/prod mode (without WebPack HMR Hot Module Reload HTTP server)
rendererBaseUrl += path.normalize(path.join(__dirname, "index_library.html"));
} else {
// dev/debug mode (with WebPack HMR Hot Module Reload HTTP server)
rendererBaseUrl += "index_library.html";
}
rendererBaseUrl = rendererBaseUrl.replace(/\\/g, "/");

if (true) { // IS_DEV

libWindow.webContents.on("did-finish-load", () => {
// see app.whenReady() in src/main/redux/sagas/app.ts
// // app.whenReady().then(() => {
Expand All @@ -92,49 +113,30 @@ export function* createLibraryWindow(_action: winActions.library.openRequest.TAc
// because webpack-dev-server automaticaly refresh the window.
const store = diMainGet("store");
const identifier = store.getState().win.session.library.identifier;
// const identifier = yield* selectTyped((state: RootState) => state.win.session.library.identifier);
store.dispatch(winActions.library.openSucess.build(libWindow, identifier));

});

if (_VSCODE_LAUNCH !== "true" && OPEN_DEV_TOOLS) {
setTimeout(() => {
if (!libWindow.isDestroyed()) {
if (!libWindow.isDestroyed() && !libWindow.webContents.isDestroyed()) {
debug("opening dev tools (library) ...");
libWindow.webContents.openDevTools({ activate: true, mode: "detach" });
}
}, 2000);
}
}

yield put(winActions.session.registerLibrary.build(libWindow, windowBound));

const readers = yield* selectTyped(
(state: RootState) => state.win.session.reader,
);
const readersArray = ObjectValues(readers);
if (readersArray.length === 1) {
libWindow.hide();
}

let rendererBaseUrl = _RENDERER_LIBRARY_BASE_URL;
if (rendererBaseUrl === "file://") {
// dist/prod mode (without WebPack HMR Hot Module Reload HTTP server)
rendererBaseUrl += path.normalize(path.join(__dirname, "index_library.html"));
} else {
// dev/debug mode (with WebPack HMR Hot Module Reload HTTP server)
rendererBaseUrl += "index_library.html";
}
rendererBaseUrl = rendererBaseUrl.replace(/\\/g, "/");

yield* callTyped(() => libWindow.loadURL(rendererBaseUrl));
// the promise will resolve when the page has finished loading (see did-finish-load)
// and rejects if the page fails to load (see did-fail-load).

if (!IS_DEV) {
// see 'did-finish-load' otherwise
const identifier = yield* selectTyped((state: RootState) => state.win.session.library.identifier);
yield put(winActions.library.openSucess.build(libWindow, identifier));
}
// if (!IS_DEV) {
// // see 'did-finish-load' otherwise
// const identifier = yield* selectTyped((state: RootState) => state.win.session.library.identifier);
// yield put(winActions.library.openSucess.build(libWindow, identifier));
// }

setMenu(libWindow, false);

Expand Down
23 changes: 14 additions & 9 deletions src/main/redux/sagas/win/browserWindow/createReaderWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,7 @@ export function* createReaderWindow(action: winActions.reader.openRequest.TActio

readerUrl = readerUrl.replace(/\\/g, "/");

yield* callTyped(() => readerWindow.webContents.loadURL(readerUrl, { extraHeaders: "pragma: no-cache\n" }));

// TODO shouldn't the call to reader.openSucess be fenced with if (!IS_DEV) {}, just like in createlibraryWindow??
// (otherwise called a second time in did-finish-load event handler below)
yield* putTyped(winActions.reader.openSucess.build(readerWindow, registerReaderAction.payload.identifier));

if (IS_DEV) {
if (true) { // IS_DEV

readerWindow.webContents.on("did-finish-load", () => {
// see app.whenReady() in src/main/redux/sagas/app.ts
Expand All @@ -130,12 +124,23 @@ export function* createReaderWindow(action: winActions.reader.openRequest.TActio
const store = diMainGet("store");

store.dispatch(winActions.reader.openSucess.build(readerWindow, registerReaderAction.payload.identifier));

});
}

yield* callTyped(() => readerWindow.webContents.loadURL(readerUrl, { extraHeaders: "pragma: no-cache\n" }));

// // TODO shouldn't the call to reader.openSucess be fenced with if (!IS_DEV) {}, just like in createlibraryWindow??
// // (otherwise called a second time in did-finish-load event handler below)
// if (!IS_DEV) {
// // see 'did-finish-load' otherwise
// yield* putTyped(winActions.reader.openSucess.build(readerWindow, registerReaderAction.payload.identifier));
// }

if (IS_DEV) {

if (_VSCODE_LAUNCH !== "true" && OPEN_DEV_TOOLS) {
setTimeout(() => {
if (!readerWindow.isDestroyed()) {
if (!readerWindow.isDestroyed() && !readerWindow.webContents.isDestroyed()) {
debug("opening dev tools (reader) ...");
readerWindow.webContents.openDevTools({ activate: true, mode: "detach" });
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/redux/sagas/win/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function* appActivate() {
yield put(winActions.library.openRequest.build());

// wait
yield take(winActions.library.openSucess.build);
yield take(winActions.library.openSucess.ID);
}

}
Expand Down

0 comments on commit b0e18c8

Please sign in to comment.