mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-25 00:14:07 +01:00
This commit is contained in:
parent
a99cb898c4
commit
910a600d5d
12 changed files with 400 additions and 388 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import {Constants} from "../constants";
|
||||
/// #if !BROWSER
|
||||
import {app, shell} from "electron";
|
||||
import {app, ipcRenderer, shell} from "electron";
|
||||
import {dialog} from "@electron/remote";
|
||||
/// #endif
|
||||
import {isBrowser} from "../util/functions";
|
||||
|
|
@ -242,8 +242,9 @@ export const about = {
|
|||
fetchPost("/api/system/setWorkspaceDir", {
|
||||
path: workspace
|
||||
}, () => {
|
||||
exportLayout(false, () => {
|
||||
exitSiYuan();
|
||||
ipcRenderer.send(Constants.SIYUAN_OPEN_WORKSPACE, {
|
||||
workspace,
|
||||
lang: window.siyuan.config.appearance.lang
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -274,7 +274,6 @@ export const appearance = {
|
|||
}
|
||||
/// #if !BROWSER
|
||||
ipcRenderer.send(Constants.SIYUAN_CONFIG_THEME, data.modeOS ? "system" : (data.mode === 1 ? "dark" : "light"));
|
||||
ipcRenderer.send(Constants.SIYUAN_CONFIG_CLOSE, data.closeButtonBehavior);
|
||||
/// #endif
|
||||
if (needLoadAsset) {
|
||||
loadAssets(data);
|
||||
|
|
|
|||
|
|
@ -2,8 +2,11 @@ import {hotKey2Electron, isCtrl, isMac, updateHotkeyTip} from "../protyle/util/c
|
|||
import {Constants} from "../constants";
|
||||
import {showMessage} from "../dialog/message";
|
||||
import {fetchPost} from "../util/fetch";
|
||||
import {ipcRenderer} from "electron";
|
||||
import {exportLayout} from "../layout/util";
|
||||
/// #if !BROWSER
|
||||
import {getCurrentWindow} from "@electron/remote";
|
||||
import {ipcRenderer} from "electron";
|
||||
/// #endif
|
||||
import {confirmDialog} from "../dialog/confirmDialog";
|
||||
|
||||
export const keymap = {
|
||||
|
|
@ -132,7 +135,11 @@ export const keymap = {
|
|||
data
|
||||
}, () => {
|
||||
/// #if !BROWSER
|
||||
ipcRenderer.send(Constants.SIYUAN_HOTKEY, hotKey2Electron(window.siyuan.config.keymap.general.toggleWin.custom));
|
||||
ipcRenderer.send(Constants.SIYUAN_HOTKEY, {
|
||||
languages: window.siyuan.languages["_trayMenu"],
|
||||
id: getCurrentWindow().id,
|
||||
hotkey: hotKey2Electron(window.siyuan.config.keymap.general.toggleWin.custom)
|
||||
});
|
||||
/// #endif
|
||||
});
|
||||
},
|
||||
|
|
@ -219,7 +226,11 @@ export const keymap = {
|
|||
}, () => {
|
||||
window.location.reload();
|
||||
/// #if !BROWSER
|
||||
ipcRenderer.send(Constants.SIYUAN_HOTKEY, hotKey2Electron(window.siyuan.config.keymap.general.toggleWin.custom));
|
||||
ipcRenderer.send(Constants.SIYUAN_HOTKEY, {
|
||||
languages: window.siyuan.languages["_trayMenu"],
|
||||
id: getCurrentWindow().id,
|
||||
hotkey: hotKey2Electron(window.siyuan.config.keymap.general.toggleWin.custom)
|
||||
});
|
||||
/// #endif
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@ export abstract class Constants {
|
|||
public static readonly SIYUAN_DROP_EDITOR: string = "application/siyuan-editor";
|
||||
|
||||
// 渲染进程调主进程
|
||||
public static readonly SIYUAN_SHOW: string = "siyuan-show";
|
||||
public static readonly SIYUAN_CONFIG_THEME: string = "siyuan-config-theme";
|
||||
public static readonly SIYUAN_CONFIG_CLOSE: string = "siyuan-config-close";
|
||||
public static readonly SIYUAN_CONFIG_TRAY: string = "siyuan-config-tray";
|
||||
public static readonly SIYUAN_CONFIG_CLOSETRAY: string = "siyuan-config-closetray";
|
||||
public static readonly SIYUAN_OPEN_WORKSPACE: string = "siyuan-open-workspace";
|
||||
public static readonly SIYUAN_QUIT: string = "siyuan-quit";
|
||||
public static readonly SIYUAN_HOTKEY: string = "siyuan-hotkey";
|
||||
public static readonly SIYUAN_INIT: string = "siyuan-init";
|
||||
|
|
|
|||
|
|
@ -93,7 +93,6 @@ export const exitSiYuan = () => {
|
|||
buttonElement.addEventListener("click", () => {
|
||||
fetchPost("/api/system/exit", {force: true}, () => {
|
||||
/// #if !BROWSER
|
||||
ipcRenderer.send(Constants.SIYUAN_CONFIG_CLOSETRAY);
|
||||
ipcRenderer.send(Constants.SIYUAN_QUIT);
|
||||
/// #else
|
||||
if (["ios", "android"].includes(window.siyuan.config.system.container) && (window.webkit?.messageHandlers || window.JSAndroid)) {
|
||||
|
|
@ -118,7 +117,6 @@ export const exitSiYuan = () => {
|
|||
}, 2000);
|
||||
// 然后等待一段时间后再退出,避免界面主进程退出以后内核子进程被杀死
|
||||
setTimeout(() => {
|
||||
ipcRenderer.send(Constants.SIYUAN_CONFIG_CLOSETRAY);
|
||||
ipcRenderer.send(Constants.SIYUAN_QUIT);
|
||||
}, 4000);
|
||||
/// #endif
|
||||
|
|
@ -129,14 +127,12 @@ export const exitSiYuan = () => {
|
|||
execInstallPkg: 1 // 0:默认检查新版本,1:不执行新版本安装,2:执行新版本安装
|
||||
}, () => {
|
||||
/// #if !BROWSER
|
||||
ipcRenderer.send(Constants.SIYUAN_CONFIG_CLOSETRAY);
|
||||
ipcRenderer.send(Constants.SIYUAN_QUIT);
|
||||
/// #endif
|
||||
});
|
||||
});
|
||||
} else { // 正常退出
|
||||
/// #if !BROWSER
|
||||
ipcRenderer.send(Constants.SIYUAN_CONFIG_CLOSETRAY);
|
||||
ipcRenderer.send(Constants.SIYUAN_QUIT);
|
||||
/// #else
|
||||
if (["ios", "android"].includes(window.siyuan.config.system.container) && (window.webkit?.messageHandlers || window.JSAndroid)) {
|
||||
|
|
|
|||
|
|
@ -416,11 +416,12 @@ const renderPDF = (id: string) => {
|
|||
});
|
||||
actionElement.querySelector('.b3-button--cancel').addEventListener('click', () => {
|
||||
const {ipcRenderer} = require("electron");
|
||||
ipcRenderer.send("${Constants.SIYUAN_EXPORT_CLOSE}")
|
||||
ipcRenderer.send("${Constants.SIYUAN_EXPORT_CLOSE}", getCurrentWindow().id)
|
||||
});
|
||||
actionElement.querySelector('.b3-button--text').addEventListener('click', () => {
|
||||
const {ipcRenderer} = require("electron");
|
||||
ipcRenderer.send("${Constants.SIYUAN_EXPORT_PDF}", {
|
||||
id: getCurrentWindow().id,
|
||||
pdfOptions:{
|
||||
printBackground: true,
|
||||
landscape: actionElement.querySelector("#landscape").checked,
|
||||
|
|
|
|||
|
|
@ -235,7 +235,6 @@ export const setMode = (modeElementValue: number) => {
|
|||
window.siyuan.config.appearance = response.data;
|
||||
/// #if !BROWSER
|
||||
ipcRenderer.send(Constants.SIYUAN_CONFIG_THEME, response.data.modeOS ? "system" : (response.data.mode === 1 ? "dark" : "light"));
|
||||
ipcRenderer.send(Constants.SIYUAN_CONFIG_CLOSE, response.data.closeButtonBehavior);
|
||||
/// #endif
|
||||
loadAssets(response.data);
|
||||
document.querySelector("#barMode use").setAttribute("xlink:href", `#icon${window.siyuan.config.appearance.modeOS ? "Mode" : (window.siyuan.config.appearance.mode === 0 ? "Light" : "Dark")}`);
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@ export const fetchPost = (url: string, data?: any, cb?: (response: IWebSocketDat
|
|||
if (url === "/api/system/exit" || url === "/api/system/setWorkspaceDir" || (
|
||||
["/api/system/setUILayout"].includes(url) && data.exit // 内核中断,点关闭处理
|
||||
)) {
|
||||
ipcRenderer.send(Constants.SIYUAN_CONFIG_CLOSETRAY);
|
||||
ipcRenderer.send(Constants.SIYUAN_QUIT);
|
||||
}
|
||||
/// #endif
|
||||
|
|
|
|||
|
|
@ -126,14 +126,25 @@ export const onGetConfig = (isStart: boolean) => {
|
|||
data: window.siyuan.config.keymap
|
||||
}, () => {
|
||||
/// #if !BROWSER
|
||||
ipcRenderer.send(Constants.SIYUAN_HOTKEY, hotKey2Electron(window.siyuan.config.keymap.general.toggleWin.custom));
|
||||
ipcRenderer.send(Constants.SIYUAN_HOTKEY, {
|
||||
languages: window.siyuan.languages["_trayMenu"],
|
||||
id: getCurrentWindow().id,
|
||||
hotkey: hotKey2Electron(window.siyuan.config.keymap.general.toggleWin.custom)
|
||||
});
|
||||
/// #endif
|
||||
});
|
||||
}
|
||||
/// #if !BROWSER
|
||||
ipcRenderer.send(Constants.SIYUAN_CONFIG_CLOSE, window.siyuan.config.appearance.closeButtonBehavior);
|
||||
ipcRenderer.send(Constants.SIYUAN_INIT, window.siyuan.languages);
|
||||
ipcRenderer.send(Constants.SIYUAN_HOTKEY, hotKey2Electron(window.siyuan.config.keymap.general.toggleWin.custom));
|
||||
ipcRenderer.send(Constants.SIYUAN_INIT, {
|
||||
languages: window.siyuan.languages["_trayMenu"],
|
||||
workspaceDir: window.siyuan.config.system.workspaceDir,
|
||||
id: getCurrentWindow().id,
|
||||
});
|
||||
ipcRenderer.send(Constants.SIYUAN_HOTKEY, {
|
||||
languages: window.siyuan.languages["_trayMenu"],
|
||||
id: getCurrentWindow().id,
|
||||
hotkey: hotKey2Electron(window.siyuan.config.keymap.general.toggleWin.custom)
|
||||
});
|
||||
/// #endif
|
||||
if (!window.siyuan.config.uiLayout || (window.siyuan.config.uiLayout && !window.siyuan.config.uiLayout.left)) {
|
||||
window.siyuan.config.uiLayout = Constants.SIYUAN_EMPTY_LAYOUT;
|
||||
|
|
@ -332,7 +343,7 @@ const winOnClose = (currentWindow: Electron.BrowserWindow, close = false) => {
|
|||
if (window.siyuan.config.appearance.closeButtonBehavior === 1 && !close) {
|
||||
// 最小化
|
||||
if ("windows" === window.siyuan.config.system.os) {
|
||||
ipcRenderer.send(Constants.SIYUAN_CONFIG_TRAY);
|
||||
ipcRenderer.send(Constants.SIYUAN_CONFIG_TRAY, getCurrentWindow().id);
|
||||
} else {
|
||||
if (currentWindow.isFullScreen()) {
|
||||
currentWindow.once("leave-full-screen", () => currentWindow.hide());
|
||||
|
|
@ -359,10 +370,16 @@ const initWindow = () => {
|
|||
if (!/^siyuan:\/\/blocks\/\d{14}-\w{7}/.test(url)) {
|
||||
return;
|
||||
}
|
||||
openFileById({
|
||||
id: url.substr(16, 22),
|
||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||
zoomIn: getSearch("focus", url) === "1"
|
||||
const id = url.substr(16, 22);
|
||||
fetchPost("/api/block/checkBlockExist", {id}, existResponse => {
|
||||
if (existResponse.data) {
|
||||
openFileById({
|
||||
id,
|
||||
action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
||||
zoomIn: getSearch("focus", url) === "1"
|
||||
});
|
||||
ipcRenderer.send(Constants.SIYUAN_SHOW, getCurrentWindow().id);
|
||||
}
|
||||
});
|
||||
});
|
||||
ipcRenderer.on(Constants.SIYUAN_SAVE_CLOSE, (event, close) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue