Former-commit-id: ae48186e9b939b1d67ff4562c2cea376673fa8d4
This commit is contained in:
troyeguo
2021-11-30 18:35:55 +08:00
parent 5d1a7dad7e
commit 8011c66d33
7 changed files with 777 additions and 599 deletions

12
main.js
View File

@@ -130,15 +130,19 @@ app.on("ready", () => {
ipcMain.on("user-data", (event, arg) => {
event.returnValue = dirPath;
});
ipcMain.on("close-reader", (event, arg) => {
ipcMain.handle("hide-reader", (event, arg) => {
if (readerWindow && readerWindow.isFocused()) {
readerWindow.destroy();
readerWindow.minimize();
event.returnvalue = true;
} else if (mainWin && mainWin.isFocused()) {
mainWin.minimize();
event.returnvalue = true;
} else {
event.returnvalue = false;
}
event.returnvalue = false;
});
ipcMain.on("switch-moyu", (event, arg) => {
let id;
console.log(readerWindow);
if (store.get("isPreventSleep") === "yes") {
id = powerSaveBlocker.start("prevent-display-sleep");
console.log(powerSaveBlocker.isStarted(id));

View File

File diff suppressed because it is too large Load Diff

View File

@@ -249,7 +249,6 @@ class PopupMenu extends React.Component<PopupMenuProps, PopupMenuStates> {
"line-2",
"line-3",
];
highlightersByChapter &&
highlightersByChapter.forEach((item: any) => {
this.key = item.key;
@@ -344,6 +343,7 @@ class PopupMenu extends React.Component<PopupMenuProps, PopupMenuStates> {
}
render() {
if (this.props.menuMode === "highlight") {
// this.getHighlighter();
this.handleHighlight();
}
const PopupProps = {

View File

@@ -121,6 +121,9 @@ class OperationPanel extends React.Component<
window.speechSynthesis.cancel();
ReadingTime.setTime(this.props.currentBook.key, this.props.time);
this.handleExitFullScreen();
if (this.props.htmlBook) {
this.props.handleHtmlBook(null);
}
}
//控制进入全屏
handleFullScreen() {

View File

@@ -6,6 +6,7 @@ import {
handleShowBookmark,
handleSearch,
handleReadingState,
handleHtmlBook,
} from "../../../store/actions";
import { stateType } from "../../../store";
import { withTranslation } from "react-i18next";
@@ -18,6 +19,7 @@ const mapStateToProps = (state: stateType) => {
bookmarks: state.reader.bookmarks,
notes: state.reader.notes,
books: state.manager.books,
htmlBook: state.reader.htmlBook,
locations: state.progressPanel.locations,
flattenChapters: state.reader.flattenChapters,
};
@@ -29,6 +31,7 @@ const actionCreator = {
handleOpenMenu,
handleShowBookmark,
handleSearch,
handleHtmlBook,
};
export default connect(
mapStateToProps,

View File

@@ -1,5 +1,6 @@
import BookModel from "../../../model/Book";
import NoteModel from "../../../model/Note";
import HtmlBookModel from "../../../model/HtmlBook";
import BookmarkModel from "../../../model/Bookmark";
import { RouteComponentProps } from "react-router";
@@ -9,6 +10,7 @@ export interface OperationPanelProps extends RouteComponentProps<any> {
bookmarks: BookmarkModel[];
notes: NoteModel[];
books: BookModel[];
htmlBook: HtmlBookModel;
flattenChapters: any;
locations: any;
rendition: any;
@@ -20,6 +22,7 @@ export interface OperationPanelProps extends RouteComponentProps<any> {
handleOpenMenu: (isOpenMenu: boolean) => void;
handleShowBookmark: (isShowBookmark: boolean) => void;
t: (title: string) => string;
handleHtmlBook: (htmlBook: HtmlBookModel | null) => void;
}
export interface OperationPanelState {

View File

@@ -17,7 +17,8 @@ export const getSelection = () => {
return text;
};
let lock = false; //prevent from clicking too fast
const arrowKeys = (rendition: any, keyCode: number) => {
const arrowKeys = (rendition: any, keyCode: number, event: any) => {
event.preventDefault();
if (document.querySelector(".editor-box")) {
return;
}
@@ -57,7 +58,7 @@ const arrowKeys = (rendition: any, keyCode: number) => {
}
if (keyCode === 9) {
if (isElectron) {
window.require("electron").ipcRenderer.sendSync("close-reader", "ping");
window.require("electron").ipcRenderer.invoke("hide-reader", "ping");
}
lock = true;
setTimeout(function () {
@@ -114,7 +115,7 @@ const bindEvent = (
readerMode: string = ""
) => {
doc.addEventListener("keydown", (event) => {
arrowKeys(rendition, event.keyCode);
arrowKeys(rendition, event.keyCode, event);
//使用Key判断是否是htmlBook
if (key) {
let postion = rendition.getPosition();
@@ -184,7 +185,7 @@ export const EpubMouseEvent = (rendition: any) => {
}
// navigate with mousewheel
window.addEventListener("keydown", (event) => {
arrowKeys(rendition, event.keyCode);
arrowKeys(rendition, event.keyCode, event);
});
bindEvent(rendition, doc);
});
@@ -203,7 +204,7 @@ export const HtmlMouseEvent = (
}
// navigate with mousewheel
window.addEventListener("keydown", (event) => {
arrowKeys(rendition, event.keyCode);
arrowKeys(rendition, event.keyCode, event);
if (key) {
let postion = rendition.getPosition();
RecordLocation.recordScrollHeight(