mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
This commit is contained in:
parent
7a68c8ad1b
commit
f06a2e62a5
11 changed files with 175 additions and 71 deletions
|
|
@ -172,7 +172,11 @@ export const initWindow = () => {
|
|||
focusByRange(getSelection().getRangeAt(0));
|
||||
}
|
||||
}
|
||||
exportLayout(false);
|
||||
exportLayout({
|
||||
reload: false,
|
||||
onlyData: false,
|
||||
errorExit: false
|
||||
});
|
||||
window.siyuan.altIsPressed = false;
|
||||
window.siyuan.ctrlIsPressed = false;
|
||||
window.siyuan.shiftIsPressed = false;
|
||||
|
|
@ -184,7 +188,9 @@ export const initWindow = () => {
|
|||
};
|
||||
|
||||
const winOnClose = (currentWindow: Electron.BrowserWindow, close = false) => {
|
||||
exportLayout(false, () => {
|
||||
exportLayout({
|
||||
reload: false,
|
||||
cb() {
|
||||
if (window.siyuan.config.appearance.closeButtonBehavior === 1 && !close) {
|
||||
// 最小化
|
||||
if ("windows" === window.siyuan.config.system.os) {
|
||||
|
|
@ -203,7 +209,10 @@ export const initWindow = () => {
|
|||
} else {
|
||||
exitSiYuan();
|
||||
}
|
||||
}, false, true);
|
||||
},
|
||||
onlyData: false,
|
||||
errorExit: true
|
||||
});
|
||||
};
|
||||
|
||||
const winOnMaxRestore = () => {
|
||||
|
|
@ -469,10 +478,18 @@ ${response.data.replace("%pages", "<span class=totalPages></span>").replace("%pa
|
|||
document.querySelector(".toolbar").classList.add("toolbar--browser");
|
||||
}
|
||||
window.addEventListener("beforeunload", () => {
|
||||
exportLayout(false);
|
||||
exportLayout({
|
||||
reload: false,
|
||||
onlyData: false,
|
||||
errorExit: false
|
||||
});
|
||||
}, false);
|
||||
window.addEventListener("pagehide", () => {
|
||||
exportLayout(false);
|
||||
exportLayout({
|
||||
reload: false,
|
||||
onlyData: false,
|
||||
errorExit: false
|
||||
});
|
||||
}, false);
|
||||
/// #endif
|
||||
};
|
||||
|
|
|
|||
|
|
@ -323,23 +323,33 @@ export const about = {
|
|||
const networkServeElement = about.element.querySelector("#networkServe") as HTMLInputElement;
|
||||
networkServeElement.addEventListener("change", () => {
|
||||
fetchPost("/api/system/setNetworkServe", {networkServe: networkServeElement.checked}, () => {
|
||||
exportLayout(false, () => {
|
||||
exitSiYuan();
|
||||
}, false, true);
|
||||
exportLayout({
|
||||
reload: false,
|
||||
onlyData: false,
|
||||
errorExit: true,
|
||||
cb: exitSiYuan
|
||||
});
|
||||
});
|
||||
});
|
||||
const googleAnalyticsElement = about.element.querySelector("#googleAnalytics") as HTMLInputElement;
|
||||
googleAnalyticsElement.addEventListener("change", () => {
|
||||
fetchPost("/api/system/setGoogleAnalytics", {googleAnalytics: googleAnalyticsElement.checked}, () => {
|
||||
exportLayout(true);
|
||||
exportLayout({
|
||||
reload: true,
|
||||
onlyData: false,
|
||||
errorExit: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
const uploadErrLogElement = about.element.querySelector("#uploadErrLog") as HTMLInputElement;
|
||||
uploadErrLogElement.addEventListener("change", () => {
|
||||
fetchPost("/api/system/setUploadErrLog", {uploadErrLog: uploadErrLogElement.checked}, () => {
|
||||
exportLayout(false, () => {
|
||||
exitSiYuan();
|
||||
}, false, true);
|
||||
exportLayout({
|
||||
reload: false,
|
||||
onlyData: false,
|
||||
errorExit: true,
|
||||
cb: exitSiYuan
|
||||
});
|
||||
});
|
||||
});
|
||||
const downloadInstallPkgElement = about.element.querySelector("#downloadInstallPkg") as HTMLInputElement;
|
||||
|
|
|
|||
|
|
@ -177,14 +177,22 @@ export const appearance = {
|
|||
window.siyuan.config.appearance.themeLight !== response.data.themeLight ||
|
||||
window.siyuan.config.appearance.themeDark !== response.data.themeDark
|
||||
)) {
|
||||
exportLayout(true);
|
||||
exportLayout({
|
||||
reload: true,
|
||||
onlyData: false,
|
||||
errorExit: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
const OSTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
||||
if (response.data.modeOS && (
|
||||
(response.data.mode === 1 && OSTheme === "light") || (response.data.mode === 0 && OSTheme === "dark")
|
||||
)) {
|
||||
exportLayout(true);
|
||||
exportLayout({
|
||||
reload: true,
|
||||
onlyData: false,
|
||||
errorExit: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -215,7 +223,11 @@ export const appearance = {
|
|||
shell.openPath(path.join(window.siyuan.config.system.dataDir, "emojis"));
|
||||
});
|
||||
appearance.element.querySelector("#appearanceRefresh").addEventListener("click", () => {
|
||||
exportLayout(true);
|
||||
exportLayout({
|
||||
reload: true,
|
||||
onlyData: false,
|
||||
errorExit: false,
|
||||
});
|
||||
});
|
||||
/// #endif
|
||||
appearance.element.querySelectorAll("select").forEach(item => {
|
||||
|
|
@ -231,7 +243,11 @@ export const appearance = {
|
|||
},
|
||||
onSetappearance(data: IAppearance) {
|
||||
if (data.lang !== window.siyuan.config.appearance.lang || data.nativeEmoji !== window.siyuan.config.appearance.nativeEmoji) {
|
||||
exportLayout(true);
|
||||
exportLayout({
|
||||
reload: true,
|
||||
onlyData: false,
|
||||
errorExit: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
window.siyuan.config.appearance = data;
|
||||
|
|
|
|||
|
|
@ -482,7 +482,11 @@ export const bazaar = {
|
|||
mode: dataObj.themeMode === "dark" ? 1 : 0,
|
||||
}, response => {
|
||||
if (window.siyuan.config.appearance.themeJS && bazaarType === "themes") {
|
||||
exportLayout(true);
|
||||
exportLayout({
|
||||
reload: true,
|
||||
onlyData: false,
|
||||
errorExit: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
bazaar._genMyHTML(bazaarType, app);
|
||||
|
|
@ -525,7 +529,11 @@ export const bazaar = {
|
|||
(window.siyuan.config.appearance.mode === 1 && window.siyuan.config.appearance.themeDark === dataObj.name)
|
||||
)) {
|
||||
if (window.siyuan.config.appearance.themeJS) {
|
||||
exportLayout(true);
|
||||
exportLayout({
|
||||
reload: true,
|
||||
onlyData: false,
|
||||
errorExit: false,
|
||||
});
|
||||
} else {
|
||||
const linkElement = (document.getElementById("themeDefaultStyle") as HTMLLinkElement);
|
||||
linkElement.href = linkElement.href + "1";
|
||||
|
|
@ -563,7 +571,11 @@ export const bazaar = {
|
|||
bazaar._onBazaar(response, bazaarType, ["themes", "icons"].includes(bazaarType));
|
||||
// TODO destroy plugin
|
||||
if (bazaarType === "plugins") {
|
||||
exportLayout(true);
|
||||
exportLayout({
|
||||
reload: true,
|
||||
onlyData: false,
|
||||
errorExit: false,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -596,7 +608,11 @@ export const bazaar = {
|
|||
(mode === 1 && window.siyuan.config.appearance.themeDark !== packageName) ||
|
||||
(mode === 0 && window.siyuan.config.appearance.themeLight !== packageName)) &&
|
||||
window.siyuan.config.appearance.themeJS) {
|
||||
exportLayout(true);
|
||||
exportLayout({
|
||||
reload: true,
|
||||
onlyData: false,
|
||||
errorExit: false,
|
||||
});
|
||||
} else {
|
||||
this._genMyHTML("themes", app);
|
||||
fetchPost("/api/bazaar/getBazaarTheme", {}, response => {
|
||||
|
|
@ -628,7 +644,11 @@ export const bazaar = {
|
|||
enabled: (target as HTMLInputElement).checked
|
||||
}, () => {
|
||||
// TODO destroy plugin
|
||||
exportLayout(true);
|
||||
exportLayout({
|
||||
reload: true,
|
||||
onlyData: false,
|
||||
errorExit: false,
|
||||
});
|
||||
});
|
||||
}
|
||||
event.stopPropagation();
|
||||
|
|
|
|||
|
|
@ -196,7 +196,11 @@ export const keymap = {
|
|||
},
|
||||
bindEvent() {
|
||||
keymap.element.querySelector("#keymapRefreshBtn").addEventListener("click", () => {
|
||||
exportLayout(true);
|
||||
exportLayout({
|
||||
reload: true,
|
||||
onlyData: false,
|
||||
errorExit: false,
|
||||
});
|
||||
});
|
||||
const searchElement = keymap.element.querySelector("#keymapInput") as HTMLInputElement;
|
||||
const searchKeymapElement = keymap.element.querySelector("#searchByKey") as HTMLInputElement;
|
||||
|
|
|
|||
|
|
@ -245,9 +245,12 @@ export const transactionError = () => {
|
|||
/// #if MOBILE
|
||||
exitSiYuan();
|
||||
/// #else
|
||||
exportLayout(false, () => {
|
||||
exitSiYuan();
|
||||
}, false, true);
|
||||
exportLayout({
|
||||
reload: false,
|
||||
onlyData: false,
|
||||
errorExit: true,
|
||||
cb: exitSiYuan
|
||||
});
|
||||
/// #endif
|
||||
});
|
||||
btnsElement[1].addEventListener("click", () => {
|
||||
|
|
|
|||
|
|
@ -187,20 +187,26 @@ export const resetLayout = () => {
|
|||
});
|
||||
};
|
||||
|
||||
export const exportLayout = (reload: boolean, cb?: () => void, onlyData = false, errorExit = false) => {
|
||||
export const exportLayout = (options: {
|
||||
reload: boolean,
|
||||
cb?: () => void,
|
||||
onlyData: boolean,
|
||||
errorExit: boolean,
|
||||
dropEditScroll?: boolean
|
||||
}) => {
|
||||
if (isWindow()) {
|
||||
const layoutJSON: any = {
|
||||
layout: {},
|
||||
};
|
||||
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);
|
||||
if (onlyData) {
|
||||
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout, !!options.dropEditScroll);
|
||||
if (options.onlyData) {
|
||||
return layoutJSON;
|
||||
}
|
||||
sessionStorage.setItem("layout", JSON.stringify(layoutJSON));
|
||||
if (reload) {
|
||||
if (options.reload) {
|
||||
window.location.reload();
|
||||
} else if (cb) {
|
||||
cb();
|
||||
} else if (options.cb) {
|
||||
options.cb();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -215,18 +221,18 @@ export const exportLayout = (reload: boolean, cb?: () => void, onlyData = false,
|
|||
left: dockToJSON(window.siyuan.layout.leftDock),
|
||||
right: dockToJSON(window.siyuan.layout.rightDock),
|
||||
};
|
||||
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);
|
||||
if (onlyData) {
|
||||
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout, !!options.dropEditScroll);
|
||||
if (options.onlyData) {
|
||||
return layoutJSON;
|
||||
}
|
||||
fetchPost("/api/system/setUILayout", {
|
||||
layout: layoutJSON,
|
||||
errorExit // 后台不接受该参数,用于请求发生错误时退出程序
|
||||
errorExit: options.errorExit // 后台不接受该参数,用于请求发生错误时退出程序
|
||||
}, () => {
|
||||
if (reload) {
|
||||
if (options.reload) {
|
||||
window.location.reload();
|
||||
} else if (cb) {
|
||||
cb();
|
||||
} else if (options.cb) {
|
||||
options.cb();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
@ -404,7 +410,7 @@ export const JSONToLayout = (app: App, isStart: boolean) => {
|
|||
}
|
||||
};
|
||||
|
||||
export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any) => {
|
||||
export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any, dropEditScroll = false) => {
|
||||
if (layout instanceof Layout) {
|
||||
json.direction = layout.direction;
|
||||
if (layout.parent) {
|
||||
|
|
@ -453,7 +459,9 @@ export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any) => {
|
|||
json.mode = layout.editor.protyle.preview.element.classList.contains("fn__none") ? "wysiwyg" : "preview";
|
||||
json.action = layout.editor.protyle.block.showAll ? Constants.CB_GET_ALL : "";
|
||||
json.instance = "Editor";
|
||||
if (!dropEditScroll) {
|
||||
json.scrollAttr = saveScroll(layout.editor.protyle, true);
|
||||
}
|
||||
} else if (layout instanceof Asset) {
|
||||
json.path = layout.path;
|
||||
if (layout.pdfObject) {
|
||||
|
|
@ -517,13 +525,13 @@ export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any) => {
|
|||
layout.children.forEach((item: Layout | Wnd | Tab) => {
|
||||
const itemJSON = {};
|
||||
json.children.push(itemJSON);
|
||||
layoutToJSON(item, itemJSON);
|
||||
layoutToJSON(item, itemJSON, dropEditScroll);
|
||||
});
|
||||
}
|
||||
} else if (layout instanceof Tab) {
|
||||
if (layout.model) {
|
||||
json.children = {};
|
||||
layoutToJSON(layout.model, json.children);
|
||||
layoutToJSON(layout.model, json.children, dropEditScroll);
|
||||
} else if (layout.headElement) {
|
||||
// 当前页签没有激活时编辑器没有初始化
|
||||
json.children = JSON.parse(layout.headElement.getAttribute("data-initdata") || "{}");
|
||||
|
|
|
|||
|
|
@ -137,7 +137,11 @@ export const workspaceMenu = (app:App, rect: DOMRect) => {
|
|||
if (item.name === value) {
|
||||
saveDialog.destroy();
|
||||
confirmDialog(window.siyuan.languages.save, window.siyuan.languages.exportTplTip, () => {
|
||||
item.layout = exportLayout(false, undefined, true);
|
||||
item.layout = exportLayout({
|
||||
reload: false,
|
||||
onlyData: true,
|
||||
errorExit: false,
|
||||
});
|
||||
setStorageVal(Constants.LOCAL_LAYOUTS, window.siyuan.storage[Constants.LOCAL_LAYOUTS]);
|
||||
});
|
||||
return true;
|
||||
|
|
@ -148,7 +152,11 @@ export const workspaceMenu = (app:App, rect: DOMRect) => {
|
|||
}
|
||||
window.siyuan.storage[Constants.LOCAL_LAYOUTS].push({
|
||||
name: value,
|
||||
layout: exportLayout(false, undefined, true)
|
||||
layout: exportLayout({
|
||||
reload: false,
|
||||
onlyData: true,
|
||||
errorExit: false,
|
||||
})
|
||||
});
|
||||
setStorageVal(Constants.LOCAL_LAYOUTS, window.siyuan.storage[Constants.LOCAL_LAYOUTS]);
|
||||
saveDialog.destroy();
|
||||
|
|
|
|||
|
|
@ -145,7 +145,11 @@ export const initAssets = () => {
|
|||
}, response => {
|
||||
if (window.siyuan.config.appearance.themeJS) {
|
||||
/// #if !MOBILE
|
||||
exportLayout(true);
|
||||
exportLayout({
|
||||
reload: true,
|
||||
onlyData: false,
|
||||
errorExit: false,
|
||||
});
|
||||
/// #else
|
||||
window.location.reload();
|
||||
/// #endif
|
||||
|
|
@ -261,14 +265,22 @@ export const setMode = (modeElementValue: number) => {
|
|||
window.siyuan.config.appearance.themeLight !== response.data.themeLight ||
|
||||
window.siyuan.config.appearance.themeDark !== response.data.themeDark
|
||||
)) {
|
||||
exportLayout(true);
|
||||
exportLayout({
|
||||
reload: true,
|
||||
onlyData: false,
|
||||
errorExit: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
const OSTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
||||
if (response.data.modeOS && (
|
||||
(response.data.mode === 1 && OSTheme === "light") || (response.data.mode === 0 && OSTheme === "dark")
|
||||
)) {
|
||||
exportLayout(true);
|
||||
exportLayout({
|
||||
reload: true,
|
||||
onlyData: false,
|
||||
errorExit: false,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,11 +23,12 @@ export const processMessage = (response: IWebSocketData) => {
|
|||
/// #if MOBILE
|
||||
window.location.reload();
|
||||
/// #else
|
||||
if (response.data?.dropCurrentLayout) {
|
||||
window.location.reload();
|
||||
} else {
|
||||
exportLayout(true);
|
||||
}
|
||||
exportLayout({
|
||||
reload: true,
|
||||
onlyData: false,
|
||||
errorExit: false,
|
||||
dropEditScroll: response.data?.resetScroll,
|
||||
});
|
||||
/// #endif
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,11 +15,16 @@ export const onWindowsMsg = (ipcData: IWebSocketData) => {
|
|||
closeTab(ipcData);
|
||||
break;
|
||||
case "lockscreen":
|
||||
exportLayout(false, () => {
|
||||
exportLayout({
|
||||
reload: false,
|
||||
onlyData: false,
|
||||
errorExit: false,
|
||||
cb() {
|
||||
fetchPost("/api/system/logoutAuth", {}, () => {
|
||||
redirectToCheckAuth();
|
||||
});
|
||||
}, false, false);
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue