Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/redux/sagas/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,11 @@ export function* init() {
});
}

function* closeProcess() {
export function* closeProcess() {

if (closeProcessLock.isLock) {
return ;
}
closeProcessLock.lock();

const reduxState = yield* selectTyped((store: RootState) => store);
Expand Down
42 changes: 37 additions & 5 deletions src/main/redux/sagas/win/session/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import debug_ from "debug";
import { takeSpawnLeading } from "readium-desktop/common/redux/sagas/takeSpawnLeading";
import { error } from "readium-desktop/main/tools/error";
import { winActions } from "readium-desktop/main/redux/actions";
import { eventChannel, Task, buffers } from "redux-saga";
import { eventChannel, Task, buffers, END } from "redux-saga";
// eslint-disable-next-line local-rules/typed-redux-saga-use-typed-effects
import { cancel, debounce, fork, put, take } from "redux-saga/effects";
import { closeProcessLock } from "readium-desktop/main/di";
import { closeProcessLock, diMainGet } from "readium-desktop/main/di";
import { closeProcess } from "../../app";
import { app } from "electron";

// Logger
const filename_ = "readium-desktop:main:redux:sagas:win:session:library";
Expand All @@ -27,14 +29,44 @@ function* libraryClosureManagement(action: winActions.session.registerLibrary.TA
const channel = eventChannel<boolean>(
(emit) => {

const handler = (event: Electron.Event) => {
const closeHandler = () => {
emit(true);
emit(END);
};
library.once("close", closeHandler);

// Windows11 shutdown/reboot only firing this closing request event
const queryHandler = (event: Electron.Event) => {
// delay the system shutdown
event.preventDefault();
debug("WINDOWS11 query-session-end event", event);
diMainGet("saga-middleware").run(closeProcess)
.toPromise()
.then(() => {
if (!library.isDestroyed()) {
library.destroy();
}
}).then(() => {
app.exit(0);
}).catch(() => {
// nothing
});

};
library.once("query-session-end", queryHandler);

const endHandler = (event: Electron.Event) => {
debug("WINDOWS11 session-end event", event);
if (!library.isDestroyed()) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without force-closing the library windows, a system breakpoint error dialog is raised, blocking the shutdown process until the user confirms it by "OK"

library.destroy();
}
emit(true);
emit(END);
};
library.on("close", handler);
library.once("session-end", endHandler);

return () => {
library.removeListener("close", handler);
library.removeAllListeners();
};
},
buffers.none(),
Expand Down
19 changes: 17 additions & 2 deletions src/main/redux/sagas/win/session/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import debug_ from "debug";
import { takeSpawnEvery } from "readium-desktop/common/redux/sagas/takeSpawnEvery";
import { error } from "readium-desktop/main/tools/error";
import { winActions } from "readium-desktop/main/redux/actions";
import { eventChannel, Task, buffers } from "redux-saga";
import { eventChannel, Task, buffers, END } from "redux-saga";
// eslint-disable-next-line local-rules/typed-redux-saga-use-typed-effects
import { cancel, debounce, fork, put, take, call } from "redux-saga/effects";
import { diMainGet } from "readium-desktop/main/di";
Expand All @@ -29,11 +29,26 @@ function* readerClosureManagement(action: winActions.session.registerReader.TAct
const channel = eventChannel<boolean>(
(emit) => {

const handler = () => emit(true);
const handler = (event: Electron.Event) => {
debug(event);
emit(true);
emit(END);
};
const handlerWin = (/*event: Electron.Event*/) => {
if (!readerWindow.isDestroyed()) {
readerWindow.destroy();
}
emit(true);
emit(END);
};
readerWindow.on("close", handler);
readerWindow.on("query-session-end", handlerWin);
readerWindow.on("session-end", handlerWin);

return () => {
readerWindow.removeListener("close", handler);
readerWindow.removeListener("query-session-end", handlerWin);
readerWindow.removeListener("session-end", handlerWin);
};
},
buffers.none(),
Expand Down
Loading