mirror of
https://github.com/koodo-reader/koodo-reader.git
synced 2026-04-28 19:08:22 -04:00
fix bug
This commit is contained in:
46
main.js
46
main.js
@@ -1,6 +1,7 @@
|
||||
const {
|
||||
app,
|
||||
BrowserWindow,
|
||||
BrowserView,
|
||||
Menu,
|
||||
ipcMain,
|
||||
dialog,
|
||||
@@ -16,6 +17,7 @@ const configDir = app.getPath("userData");
|
||||
const { ra } = require("./edge-tts");
|
||||
const dirPath = path.join(configDir, "uploads");
|
||||
let mainWin;
|
||||
let mainView
|
||||
const singleInstance = app.requestSingleInstanceLock();
|
||||
var filePath = null;
|
||||
if (process.platform != "darwin" && process.argv.length >= 2) {
|
||||
@@ -69,12 +71,12 @@ const createMainWin = () => {
|
||||
mainWin = null;
|
||||
});
|
||||
ipcMain.handle("open-book", (event, config) => {
|
||||
let { url, isMergeWord, isFullscreen, isPreventSleep } = config;
|
||||
let { url, isMergeWord, isAutoFullscreen, isPreventSleep } = config;
|
||||
options.webPreferences.nodeIntegrationInSubFrames = true;
|
||||
store.set({
|
||||
url,
|
||||
isMergeWord: isMergeWord ? isMergeWord : "no",
|
||||
isFullscreen: isFullscreen ? isFullscreen : "no",
|
||||
isAutoFullscreen: isAutoFullscreen ? isAutoFullscreen : "no",
|
||||
isPreventSleep: isPreventSleep ? isPreventSleep : "no",
|
||||
});
|
||||
let id;
|
||||
@@ -83,7 +85,7 @@ const createMainWin = () => {
|
||||
console.log(powerSaveBlocker.isStarted(id));
|
||||
}
|
||||
|
||||
if (isFullscreen === "yes") {
|
||||
if (isAutoFullscreen === "yes") {
|
||||
readerWindow = new BrowserWindow(options);
|
||||
readerWindow.loadURL(url);
|
||||
readerWindow.maximize();
|
||||
@@ -480,6 +482,44 @@ const createMainWin = () => {
|
||||
createMainWin();
|
||||
}
|
||||
});
|
||||
ipcMain.handle("new-tab", (event, config) => {
|
||||
if (mainWin) {
|
||||
mainView = new BrowserView(options)
|
||||
mainWin.setBrowserView(mainView)
|
||||
let [width, height] = mainWin.getSize()
|
||||
mainView.setBounds({ x: 0, y: 0, width: width, height: height })
|
||||
console.log(config.url);
|
||||
mainView.webContents.loadURL(config.url)
|
||||
}
|
||||
});
|
||||
ipcMain.handle("reload-tab", (event, config) => {
|
||||
if (mainWin && mainView) {
|
||||
mainView.webContents.reload()
|
||||
}
|
||||
});
|
||||
ipcMain.handle("adjust-tab-size", (event, config) => {
|
||||
if (mainWin && mainView) {
|
||||
let [width, height] = mainWin.getSize()
|
||||
mainView.setBounds({ x: 0, y: 0, width: width, height: height })
|
||||
}
|
||||
});
|
||||
ipcMain.handle("exit-tab", (event, message) => {
|
||||
if (mainWin && mainView) {
|
||||
mainWin.setBrowserView(null)
|
||||
}
|
||||
});
|
||||
ipcMain.handle("enter-tab-fullscreen", () => {
|
||||
if (mainWin && mainView) {
|
||||
mainWin.setFullScreen(true);
|
||||
console.log("enter full");
|
||||
}
|
||||
});
|
||||
ipcMain.handle("exit-tab-fullscreen", () => {
|
||||
if (mainWin && mainView) {
|
||||
mainWin.setFullScreen(false);
|
||||
console.log("exit full");
|
||||
}
|
||||
});
|
||||
ipcMain.handle("enter-fullscreen", () => {
|
||||
if (readerWindow) {
|
||||
readerWindow.setFullScreen(true);
|
||||
|
||||
2
public/lib/kookit/kookit.min.js
vendored
2
public/lib/kookit/kookit.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -81,9 +81,9 @@ class ImageViewer extends React.Component<ImageViewerProps, ImageViewerStates> {
|
||||
this.setState({ zoomIndex: this.state.zoomIndex + 1 }, () => {
|
||||
if (this.state.imageRatio === "horizontal") {
|
||||
image.style.width = `${60 + this.state.zoomIndex * 10}vw`;
|
||||
image.style.marginTop = `${10 * this.state.zoomIndex}vh`;
|
||||
} else {
|
||||
image.style.height = `${100 + 10 * this.state.zoomIndex}vh`;
|
||||
image.style.marginTop = `${10 * this.state.zoomIndex}vh`;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -84,7 +84,7 @@ export const settingList = [
|
||||
propName: "isLemmatizeWord",
|
||||
},
|
||||
{
|
||||
isElectron: false,
|
||||
isElectron: true,
|
||||
title: "Open books in the main window",
|
||||
desc: "Book won't be opened in a separate window but directly opened in the main window",
|
||||
propName: "isOpenInMain",
|
||||
|
||||
@@ -61,11 +61,7 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
|
||||
this.props.handleRenderBookFunc(this.handleRenderBook);
|
||||
|
||||
window.addEventListener("resize", () => {
|
||||
if (StorageUtil.getReaderConfig("isFullscreen") === "yes") {
|
||||
this.handleRenderBook();
|
||||
} else {
|
||||
BookUtil.reloadBooks();
|
||||
}
|
||||
BookUtil.reloadBooks();
|
||||
});
|
||||
}
|
||||
handlePageWidth = () => {
|
||||
@@ -318,7 +314,10 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
|
||||
this.setState({ rect });
|
||||
});
|
||||
doc.addEventListener("contextmenu", (event) => {
|
||||
event.preventDefault();
|
||||
if (document.location.href.indexOf("localhost") === -1) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
if (!this.state.isDisablePopup && !this.state.isTouch) return;
|
||||
|
||||
if (!doc!.getSelection() || doc!.getSelection()!.rangeCount === 0) return;
|
||||
|
||||
@@ -12,6 +12,7 @@ import toast from "react-hot-toast";
|
||||
import { HtmlMouseEvent } from "../../../utils/serviceUtils/mouseEvent";
|
||||
import storageUtil from "../../../utils/serviceUtils/storageUtil";
|
||||
import BingTTSUtil from "../../../utils/serviceUtils/bingTTSUtil";
|
||||
import { isElectron } from "react-device-detect";
|
||||
declare var document: any;
|
||||
declare var window: any;
|
||||
class OperationPanel extends React.Component<
|
||||
@@ -78,9 +79,12 @@ class OperationPanel extends React.Component<
|
||||
this.props.handleHtmlBook(null);
|
||||
}
|
||||
setTimeout(() => {
|
||||
if (StorageUtil.getReaderConfig("isOpenInMain") === "yes") {
|
||||
this.props.history.push("/manager/home");
|
||||
document.title = "Koodo Reader";
|
||||
if (isElectron) {
|
||||
if (StorageUtil.getReaderConfig("isOpenInMain") === "yes") {
|
||||
window.require("electron").ipcRenderer.invoke("exit-tab", "ping");
|
||||
} else {
|
||||
window.close();
|
||||
}
|
||||
} else {
|
||||
window.close();
|
||||
}
|
||||
@@ -88,21 +92,53 @@ class OperationPanel extends React.Component<
|
||||
}
|
||||
//控制进入全屏
|
||||
handleFullScreen() {
|
||||
let de: any = document.documentElement;
|
||||
if (de.requestFullscreen) {
|
||||
de.requestFullscreen();
|
||||
if (isElectron) {
|
||||
if (StorageUtil.getReaderConfig("isOpenInMain") === "yes") {
|
||||
window
|
||||
.require("electron")
|
||||
.ipcRenderer.invoke("enter-tab-fullscreen", "ping");
|
||||
} else {
|
||||
window
|
||||
.require("electron")
|
||||
.ipcRenderer.invoke("enter-fullscreen", "ping");
|
||||
}
|
||||
} else {
|
||||
let de: any = document.documentElement;
|
||||
if (de.requestFullscreen) {
|
||||
de.requestFullscreen();
|
||||
}
|
||||
}
|
||||
|
||||
StorageUtil.setReaderConfig("isFullscreen", "yes");
|
||||
if (StorageUtil.getReaderConfig("isOpenInMain") === "yes" && isElectron) {
|
||||
window.require("electron").ipcRenderer.invoke("adjust-tab-size", "ping");
|
||||
}
|
||||
}
|
||||
// 退出全屏模式
|
||||
handleExitFullScreen() {
|
||||
//解决使用esc退出全屏,再退出阅读时发生的bug
|
||||
if (!document.fullscreenElement) return;
|
||||
if (isElectron) {
|
||||
if (StorageUtil.getReaderConfig("isOpenInMain") === "yes") {
|
||||
window
|
||||
.require("electron")
|
||||
.ipcRenderer.invoke("exit-tab-fullscreen", "ping");
|
||||
} else {
|
||||
window
|
||||
.require("electron")
|
||||
.ipcRenderer.invoke("exit-fullscreen", "ping");
|
||||
}
|
||||
} else {
|
||||
//解决使用esc退出全屏,再退出阅读时发生的bug
|
||||
if (!document.fullscreenElement) return;
|
||||
|
||||
if (document.exitFullscreen) {
|
||||
document.exitFullscreen();
|
||||
if (document.exitFullscreen) {
|
||||
document.exitFullscreen();
|
||||
}
|
||||
}
|
||||
|
||||
StorageUtil.setReaderConfig("isFullscreen", "no");
|
||||
if (StorageUtil.getReaderConfig("isOpenInMain") === "yes" && isElectron) {
|
||||
window.require("electron").ipcRenderer.invoke("adjust-tab-size", "ping");
|
||||
}
|
||||
}
|
||||
handleAddBookmark = () => {
|
||||
let bookKey = this.props.currentBook.key;
|
||||
|
||||
@@ -25,6 +25,7 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
|
||||
rect: null,
|
||||
loading: true,
|
||||
isDisablePopup: StorageUtil.getReaderConfig("isDisablePopup") === "yes",
|
||||
isTouch: StorageUtil.getReaderConfig("isTouch") === "yes",
|
||||
};
|
||||
}
|
||||
UNSAFE_componentWillMount() {
|
||||
@@ -83,10 +84,14 @@ class Viewer extends React.Component<ViewerProps, ViewerState> {
|
||||
// iWin.getSelection() && showHighlight(getHightlightCoords());
|
||||
});
|
||||
doc.addEventListener("contextmenu", (event) => {
|
||||
if (!this.state.isDisablePopup) return;
|
||||
if (document.location.href.indexOf("localhost") === -1) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
if (!this.state.isDisablePopup && !this.state.isTouch) return;
|
||||
if (!doc!.getSelection() || doc!.getSelection().rangeCount === 0)
|
||||
return;
|
||||
event.preventDefault();
|
||||
|
||||
var rect = doc!.getSelection()!.getRangeAt(0).getBoundingClientRect();
|
||||
this.setState({
|
||||
rect,
|
||||
|
||||
@@ -23,6 +23,7 @@ export interface ViewerState {
|
||||
title: string;
|
||||
cfiRange: any;
|
||||
contents: any;
|
||||
isTouch: boolean;
|
||||
rect: any;
|
||||
loading: boolean;
|
||||
isDisablePopup: boolean;
|
||||
|
||||
@@ -161,27 +161,29 @@ class BookUtil {
|
||||
toast.error(t("Book not exist"));
|
||||
return;
|
||||
}
|
||||
if (StorageUtil.getReaderConfig("isOpenInMain") === "yes") {
|
||||
history.push(
|
||||
BookUtil.getBookUrl(book) + `?title=${book.name}&file=${book.key}`
|
||||
);
|
||||
return;
|
||||
}
|
||||
let ref = book.format.toLowerCase();
|
||||
|
||||
if (isElectron) {
|
||||
const { ipcRenderer } = window.require("electron");
|
||||
ipcRenderer.invoke("open-book", {
|
||||
url: `${window.location.href.split("#")[0]}#/${ref}/${book.key}?title=${
|
||||
book.name
|
||||
}&file=${book.key}`,
|
||||
isMergeWord:
|
||||
book.format === "PDF"
|
||||
? "no"
|
||||
: StorageUtil.getReaderConfig("isMergeWord"),
|
||||
isFullscreen: StorageUtil.getReaderConfig("isAutoFullscreen"),
|
||||
isPreventSleep: StorageUtil.getReaderConfig("isPreventSleep"),
|
||||
});
|
||||
if (StorageUtil.getReaderConfig("isOpenInMain") === "yes") {
|
||||
window.require("electron").ipcRenderer.invoke("new-tab", {
|
||||
url: `${window.location.href.split("#")[0]}#/${ref}/${
|
||||
book.key
|
||||
}?title=${book.name}&file=${book.key}`,
|
||||
});
|
||||
} else {
|
||||
const { ipcRenderer } = window.require("electron");
|
||||
ipcRenderer.invoke("open-book", {
|
||||
url: `${window.location.href.split("#")[0]}#/${ref}/${
|
||||
book.key
|
||||
}?title=${book.name}&file=${book.key}`,
|
||||
isMergeWord:
|
||||
book.format === "PDF"
|
||||
? "no"
|
||||
: StorageUtil.getReaderConfig("isMergeWord"),
|
||||
isAutoFullscreen: StorageUtil.getReaderConfig("isAutoFullscreen"),
|
||||
isPreventSleep: StorageUtil.getReaderConfig("isPreventSleep"),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
window.open(
|
||||
`${window.location.href.split("#")[0]}#/${ref}/${book.key}?title=${
|
||||
@@ -226,12 +228,15 @@ class BookUtil {
|
||||
static reloadBooks() {
|
||||
if (isElectron) {
|
||||
if (StorageUtil.getReaderConfig("isOpenInMain") === "yes") {
|
||||
window.require("electron").ipcRenderer.invoke("reload-main", "ping");
|
||||
window.require("electron").ipcRenderer.invoke("reload-tab", "ping");
|
||||
} else {
|
||||
window.require("electron").ipcRenderer.invoke("reload-reader", "ping");
|
||||
}
|
||||
} else {
|
||||
window.location.reload();
|
||||
if (StorageUtil.getReaderConfig("isFullscreen") === "yes") {
|
||||
} else {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
}
|
||||
static getRendtion = (
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { openExternalUrl } from "../serviceUtils/urlUtil";
|
||||
|
||||
export const handleLinkJump = async (event: any, rendition: any = {}) => {
|
||||
console.log("gdfdgfdg");
|
||||
let href;
|
||||
if (event.target) {
|
||||
href =
|
||||
@@ -17,7 +16,6 @@ export const handleLinkJump = async (event: any, rendition: any = {}) => {
|
||||
event.target.parentNode.getAttribute("src")))) ||
|
||||
"";
|
||||
}
|
||||
console.log(href, "sfsdf");
|
||||
if (href && href.indexOf("#") > -1) {
|
||||
let pageArea = document.getElementById("page-area");
|
||||
if (!pageArea) return;
|
||||
@@ -27,7 +25,6 @@ export const handleLinkJump = async (event: any, rendition: any = {}) => {
|
||||
if (!doc) {
|
||||
return;
|
||||
}
|
||||
console.log(href, "href");
|
||||
if (href.indexOf("#") !== 0) {
|
||||
let chapterInfo = rendition.resolveChapter(href.split("#")[0]);
|
||||
await rendition.goToChapter(
|
||||
@@ -37,7 +34,6 @@ export const handleLinkJump = async (event: any, rendition: any = {}) => {
|
||||
);
|
||||
}
|
||||
let id = href.split("#").reverse()[0];
|
||||
console.log(doc.body.querySelector("#" + id));
|
||||
await rendition.goToNode(doc.body.querySelector("#" + id) || doc.body);
|
||||
} else if (href && rendition.resolveChapter(href)) {
|
||||
let chapterInfo = rendition.resolveChapter(href);
|
||||
|
||||
Reference in New Issue
Block a user