mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-21 14:34:06 +01:00
This commit is contained in:
parent
93bed6e29f
commit
f3390e37ad
4 changed files with 23 additions and 33 deletions
|
|
@ -848,6 +848,13 @@ app.whenReady().then(() => {
|
|||
const menu = Menu.buildFromTemplate(template);
|
||||
menu.popup({window: BrowserWindow.fromWebContents(event.sender)});
|
||||
});
|
||||
ipcMain.on("siyuan-confirm-dialog", (event, options) => {
|
||||
event.returnValue = dialog.showMessageBoxSync(BrowserWindow.fromWebContents(event.sender) || BrowserWindow.getFocusedWindow(), options);
|
||||
});
|
||||
ipcMain.on("siyuan-alert-dialog", (event, options) => {
|
||||
dialog.showMessageBoxSync(BrowserWindow.fromWebContents(event.sender) || BrowserWindow.getFocusedWindow(), options);
|
||||
event.returnValue = undefined;
|
||||
});
|
||||
ipcMain.on("siyuan-first-quit", () => {
|
||||
app.exit();
|
||||
});
|
||||
|
|
@ -948,15 +955,6 @@ app.whenReady().then(() => {
|
|||
event.sender.send("siyuan-event", "leave-full-screen");
|
||||
});
|
||||
});
|
||||
ipcMain.on("siyuan-confirm-dialog", (event, options) => {
|
||||
const window = BrowserWindow.fromWebContents(event.sender);
|
||||
event.returnValue = dialog.showMessageBoxSync(window || BrowserWindow.getFocusedWindow(), options);
|
||||
});
|
||||
ipcMain.on("siyuan-alert-dialog", (event, options) => {
|
||||
const window = BrowserWindow.fromWebContents(event.sender);
|
||||
dialog.showMessageBoxSync(window || BrowserWindow.getFocusedWindow(), options);
|
||||
event.returnValue = undefined;
|
||||
});
|
||||
ipcMain.on("siyuan-cmd", (event, data) => {
|
||||
let cmd = data;
|
||||
let webContentsId = event.sender.id;
|
||||
|
|
|
|||
|
|
@ -55,6 +55,8 @@ export abstract class Constants {
|
|||
public static readonly SIYUAN_EXPORT_NEWWINDOW: string = "siyuan-export-newwindow";
|
||||
|
||||
public static readonly SIYUAN_CONTEXT_MENU: string = "siyuan-context-menu";
|
||||
public static readonly SIYUAN_CONFIRM_DIALOG: string = "siyuan-confirm-dialog";
|
||||
public static readonly SIYUAN_ALERT_DIALOG: string = "siyuan-alert-dialog";
|
||||
|
||||
public static readonly SIYUAN_SHOW_WINDOW: string = "siyuan-show-window";
|
||||
|
||||
|
|
|
|||
|
|
@ -579,32 +579,24 @@ export const setStorageVal = (key: string, val: any, cb?: () => void) => {
|
|||
export const initNativeDialogOverride = () => {
|
||||
const originalAlert = window.alert;
|
||||
const originalConfirm = window.confirm;
|
||||
|
||||
|
||||
window.alert = function (message: string) {
|
||||
try {
|
||||
ipcRenderer.sendSync("siyuan-alert-dialog", {
|
||||
title: window.siyuan?.languages?.siyuanNote || "SiYuan",
|
||||
ipcRenderer.sendSync(Constants.SIYUAN_ALERT_DIALOG, {
|
||||
title: window.siyuan.languages.siyuanNote,
|
||||
message,
|
||||
buttons: [window.siyuan?.languages?.confirm || "OK"],
|
||||
buttons: [window.siyuan.languages.confirm],
|
||||
noLink: true,
|
||||
});
|
||||
|
||||
return undefined;
|
||||
} catch (error) {
|
||||
console.error("SiYuan alert error:", error);
|
||||
try {
|
||||
const result = originalAlert.call(this, message);
|
||||
return result;
|
||||
} catch (e) {
|
||||
console.error("Original alert error:", e);
|
||||
return undefined;
|
||||
}
|
||||
return originalAlert.call(this, message);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
window.confirm = function (message: string): boolean {
|
||||
try {
|
||||
const buttonIndex = ipcRenderer.sendSync("siyuan-confirm-dialog", {
|
||||
const buttonIndex = ipcRenderer.sendSync(Constants.SIYUAN_CONFIRM_DIALOG, {
|
||||
title: window.siyuan?.languages?.siyuanNote || "SiYuan",
|
||||
message,
|
||||
buttons: [window.siyuan?.languages?.cancel || "Cancel", window.siyuan?.languages?.confirm || "OK"],
|
||||
|
|
@ -612,17 +604,9 @@ export const initNativeDialogOverride = () => {
|
|||
defaultId: 1,
|
||||
noLink: true,
|
||||
});
|
||||
|
||||
return buttonIndex === 1;
|
||||
} catch (error) {
|
||||
console.error("SiYuan confirm error:", error);
|
||||
try {
|
||||
const result = originalConfirm.call(this, message);
|
||||
return result;
|
||||
} catch (e) {
|
||||
console.error("Original confirm error:", e);
|
||||
return false;
|
||||
}
|
||||
return originalConfirm.call(this, message);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,6 +14,9 @@ import {afterLoadPlugin} from "../plugin/loader";
|
|||
import {Tab} from "../layout/Tab";
|
||||
import {initWindowEvent} from "../boot/globalEvent/event";
|
||||
import {getAllEditor} from "../layout/getAll";
|
||||
/// #if !BROWSER
|
||||
import {initNativeDialogOverride} from "../protyle/util/compatibility";
|
||||
/// #endif
|
||||
|
||||
export const init = (app: App) => {
|
||||
webFrame.setZoomFactor(window.siyuan.storage[Constants.LOCAL_ZOOM]);
|
||||
|
|
@ -52,6 +55,9 @@ export const init = (app: App) => {
|
|||
});
|
||||
initStatus(true);
|
||||
initWindow(app);
|
||||
/// #if !BROWSER
|
||||
initNativeDialogOverride();
|
||||
/// #endif
|
||||
appearance.onSetAppearance(window.siyuan.config.appearance);
|
||||
initAssets();
|
||||
setInlineStyle();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue