Skip to content

Commit 6e65291

Browse files
committed
Refactor header component to handle reading finish event and visibility change
- Added ipcRenderer listener for "reading-finished" event to trigger handleFinishReading method. - Consolidated logic in visibilitychange event to call handleFinishReading instead of duplicating fetch calls. - Moved fetch logic into handleFinishReading method for better code organization and reusability.
1 parent ec27a79 commit 6e65291

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

main.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ const createMainWin = () => {
173173
x: parseInt(store.get("mainWinX")),
174174
y: parseInt(store.get("mainWinY")),
175175
});
176-
console.log(isMainWindVisible, 'isMainWindVisible')
177176
if (!isMainWindVisible) {
178177
delete options.x
179178
delete options.y
@@ -375,8 +374,7 @@ const createMainWin = () => {
375374
if (isPreventSleep && !readerWindow.isDestroyed()) {
376375
id && powerSaveBlocker.stop(id);
377376
}
378-
// readerWindow && readerWindow.destroy();
379-
// readerWindow = null;
377+
mainWin.webContents.send('reading-finished', {});
380378
});
381379

382380

@@ -873,8 +871,7 @@ const createMainWin = () => {
873871
if (store.get("isPreventSleep") && !readerWindow.isDestroyed()) {
874872
id && powerSaveBlocker.stop(id);
875873
}
876-
// readerWindow && readerWindow.destroy();
877-
// readerWindow = null;
874+
mainWin.webContents.send('reading-finished', {});
878875
});
879876
}
880877
event.returnvalue = false;

src/assets/lib/kookit-extra-browser.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/assets/lib/kookit.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/containers/header/component.tsx

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ class Header extends React.Component<HeaderProps, HeaderState> {
102102
) {
103103
this.setState({ isDataChange: true });
104104
}
105+
ipcRenderer.on("reading-finished", async (event: any, config: any) => {
106+
this.handleFinishReading();
107+
});
105108
} else {
106109
upgradeConfig();
107110
const status = await LocalFileManager.getPermissionStatus();
@@ -126,22 +129,10 @@ class Header extends React.Component<HeaderProps, HeaderState> {
126129
this.setState({ width: document.body.clientWidth });
127130
});
128131
this.props.handleCloudSyncFunc(this.handleCloudSync);
129-
document.addEventListener("visibilitychange", async () => {
132+
document.addEventListener("visibilitychange", async (event) => {
133+
console.log(event, "visibilitychange");
130134
if (document.visibilityState === "visible") {
131-
this.props.handleFetchBooks();
132-
this.props.handleFetchBookmarks();
133-
this.props.handleFetchNotes();
134-
if (ConfigService.getItem("isFinshReading") === "yes") {
135-
ConfigService.setItem("isFinshReading", "no");
136-
if (
137-
ConfigService.getReaderConfig("isDisableAutoSync") !== "yes" &&
138-
ConfigService.getItem("defaultSyncOption")
139-
) {
140-
await this.props.handleFetchUserInfo();
141-
this.setState({ isSync: true });
142-
this.handleCloudSync();
143-
}
144-
}
135+
this.handleFinishReading();
145136
}
146137
});
147138
}
@@ -178,6 +169,22 @@ class Header extends React.Component<HeaderProps, HeaderState> {
178169
}
179170
}
180171
}
172+
handleFinishReading = async () => {
173+
this.props.handleFetchBooks();
174+
this.props.handleFetchBookmarks();
175+
this.props.handleFetchNotes();
176+
if (ConfigService.getItem("isFinshReading") === "yes") {
177+
ConfigService.setItem("isFinshReading", "no");
178+
if (
179+
ConfigService.getReaderConfig("isDisableAutoSync") !== "yes" &&
180+
ConfigService.getItem("defaultSyncOption")
181+
) {
182+
await this.props.handleFetchUserInfo();
183+
this.setState({ isSync: true });
184+
this.handleCloudSync();
185+
}
186+
}
187+
};
181188
handleFinishUpgrade = () => {
182189
setTimeout(() => {
183190
this.props.history.push("/manager/home");

0 commit comments

Comments
 (0)