Skip to content

Commit a01fd90

Browse files
committed
Refactor NavList component to streamline click handling and improve user interaction
- Consolidated click event handlers for bookmarks and chapter titles in NavList component. - Added cursor pointer style to bookmark page list item title for better UX. - Updated Background component to handle changes in reader mode state. - Added console log for bookLocation in OperationPanel for debugging purposes. - Integrated IPC call to clear all data in clearAllData utility function.
1 parent cd4a873 commit a01fd90

File tree

7 files changed

+39
-11
lines changed

7 files changed

+39
-11
lines changed

main.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,17 @@ const isWindowPartiallyVisible = (bounds) => {
167167
return false;
168168
}
169169
const createMainWin = () => {
170-
170+
const isMainWindVisible = isWindowPartiallyVisible({
171+
width: parseInt(store.get("mainWinWidth") || 1050) / mainWinDisplayScale,
172+
height: parseInt(store.get("mainWinHeight") || 660) / mainWinDisplayScale,
173+
x: parseInt(store.get("mainWinX")),
174+
y: parseInt(store.get("mainWinY")),
175+
});
176+
console.log(isMainWindVisible, 'isMainWindVisible')
177+
if (!isMainWindVisible) {
178+
delete options.x
179+
delete options.y
180+
}
171181
mainWin = new BrowserWindow(options);
172182
if (store.get("isAlwaysOnTop") === "yes") {
173183
mainWin.setAlwaysOnTop(true);
@@ -353,13 +363,13 @@ const createMainWin = () => {
353363
let bounds = readerWindow.getBounds();
354364
const currentDisplay = screen.getDisplayMatching(bounds);
355365
const primaryDisplay = screen.getPrimaryDisplay();
356-
console.log(currentDisplay, primaryDisplay)
366+
console.log(currentDisplay, primaryDisplay, bounds)
357367
if (bounds.width > 0 && bounds.height > 0) {
358368
store.set({
359369
windowWidth: bounds.width,
360370
windowHeight: bounds.height,
361-
windowX: readerWindow.isMaximized() ? 0 : bounds.x,
362-
windowY: readerWindow.isMaximized() ? 0 : bounds.y,
371+
windowX: readerWindow.isMaximized() && currentDisplay.id === primaryDisplay.id ? 0 : bounds.x,
372+
windowY: readerWindow.isMaximized() && currentDisplay.id === primaryDisplay.id ? 0 : (bounds.y < 0 ? 0 : bounds.y),
363373
windowDisplayScale: currentDisplay.scaleFactor / primaryDisplay.scaleFactor,
364374
});
365375
}
@@ -755,6 +765,9 @@ const createMainWin = () => {
755765
googlePickerView = null;
756766
}
757767
});
768+
ipcMain.handle('clear-all-data', (event, config) => {
769+
store.clear();
770+
});
758771
ipcMain.handle("new-tab", (event, config) => {
759772
if (mainWin) {
760773
mainView = new WebContentsView(options)
@@ -848,12 +861,15 @@ const createMainWin = () => {
848861
readerWindow.on("close", (event) => {
849862
if (!readerWindow.isDestroyed()) {
850863
let bounds = readerWindow.getBounds();
864+
const currentDisplay = screen.getDisplayMatching(bounds);
865+
const primaryDisplay = screen.getPrimaryDisplay();
866+
console.log(currentDisplay, primaryDisplay, bounds)
851867
if (bounds.width > 0 && bounds.height > 0) {
852868
store.set({
853869
windowWidth: bounds.width,
854870
windowHeight: bounds.height,
855-
windowX: readerWindow.isMaximized() ? 0 : bounds.x,
856-
windowY: readerWindow.isMaximized() ? 0 : bounds.y,
871+
windowX: readerWindow.isMaximized() && currentDisplay.id === primaryDisplay.id ? 0 : bounds.x,
872+
windowY: readerWindow.isMaximized() && currentDisplay.id === primaryDisplay.id ? 0 : (bounds.y < 0 ? 0 : bounds.y),
857873
});
858874
}
859875
}

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/lists/navList/component.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ class NavList extends React.Component<NavListProps, NavListState> {
117117
width: "100%",
118118
maxHeight: "198px",
119119
}}
120+
onClick={async () => {
121+
await this.handleJump(item.cfi);
122+
}}
120123
>
121124
<p
122125
className="book-bookmark-digest"
@@ -125,9 +128,6 @@ class NavList extends React.Component<NavListProps, NavListState> {
125128
? this.convertColorCode(classes[item.color])
126129
: {}
127130
}
128-
onClick={async () => {
129-
await this.handleJump(item.cfi);
130-
}}
131131
>
132132
{this.props.currentTab === "bookmarks"
133133
? item.label
@@ -140,7 +140,12 @@ class NavList extends React.Component<NavListProps, NavListState> {
140140
</div>
141141
</div>
142142

143-
<div className="bookmark-page-list-item-title">
143+
<div
144+
className="bookmark-page-list-item-title"
145+
onClick={async () => {
146+
await this.handleJump(item.cfi);
147+
}}
148+
>
144149
<Trans>{item.chapter}</Trans>
145150
</div>
146151
<div className="book-bookmark-progress">

src/containers/lists/navList/navList.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,5 @@
7171
text-overflow: ellipsis;
7272
float: left;
7373
margin-left: 5px;
74+
cursor: pointer;
7475
}

src/containers/pageWidget/component.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class Background extends React.Component<BackgroundProps, BackgroundState> {
2424
this.handleLocation();
2525
});
2626
}
27+
if (nextProps.readerMode !== this.props.readerMode) {
28+
this.setState({ isSingle: nextProps.readerMode !== "double" });
29+
}
2730
}
2831
handleLocation = () => {
2932
let position = this.props.htmlBook.rendition.getPosition();

src/containers/panels/operationPanel/component.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class OperationPanel extends React.Component<
9999
let text = bookLocation.text;
100100
let chapter = bookLocation.chapterTitle;
101101
let percentage = bookLocation.percentage;
102+
console.log(bookLocation, "bookLocation");
102103

103104
let cfi = JSON.stringify(bookLocation);
104105
if (!text) {

src/utils/common.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,8 @@ export const clearAllData = async () => {
826826
if (fs.existsSync(storageLocation)) {
827827
fs.rmSync(storageLocation, { recursive: true, force: true });
828828
}
829+
const { ipcRenderer } = window.require("electron");
830+
ipcRenderer.invoke("clear-all-data", {});
829831
}
830832
await localforage.clear();
831833
};

0 commit comments

Comments
 (0)