Vanessa 2024-09-27 00:21:31 +08:00
parent 459b700e26
commit c33e9429cd
8 changed files with 38 additions and 25 deletions

View file

@ -119,11 +119,11 @@ export const initBar = (app: App) => {
event.stopPropagation(); event.stopPropagation();
break; break;
} else if (targetId === "barExit") { } else if (targetId === "barExit") {
event.stopPropagation();
exportLayout({ exportLayout({
errorExit: true, errorExit: true,
cb: exitSiYuan, cb: exitSiYuan,
}); });
event.stopPropagation();
break; break;
} else if (targetId === "barMode") { } else if (targetId === "barMode") {
if (!window.siyuan.menus.menu.element.classList.contains("fn__none") && if (!window.siyuan.menus.menu.element.classList.contains("fn__none") &&

View file

@ -225,18 +225,19 @@ export const saveLayout = () => {
} }
}; };
export const exportLayout = (options: { export const exportLayout = async (options: {
cb: () => void, cb: () => void,
errorExit: boolean errorExit: boolean
}) => { }) => {
const editors = getAllModels().editor
for (let i = 0; i < editors.length; i++) {
await saveScroll(editors[i].editor.protyle);
}
if (isWindow()) { if (isWindow()) {
const layoutJSON: any = { const layoutJSON: any = {
layout: {}, layout: {},
}; };
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout); layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);
getAllModels().editor.forEach(item => {
saveScroll(item.editor.protyle);
});
sessionStorage.setItem("layout", JSON.stringify(layoutJSON)); sessionStorage.setItem("layout", JSON.stringify(layoutJSON));
options.cb(); options.cb();
return; return;
@ -253,10 +254,6 @@ export const exportLayout = (options: {
right: dockToJSON(window.siyuan.layout.rightDock), right: dockToJSON(window.siyuan.layout.rightDock),
}; };
layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout); layoutToJSON(window.siyuan.layout.layout, layoutJSON.layout);
getAllModels().editor.forEach(item => {
saveScroll(item.editor.protyle);
});
if (window.siyuan.config.readonly) { if (window.siyuan.config.readonly) {
options.cb(); options.cb();
} else { } else {

View file

@ -170,9 +170,9 @@ export const initRightMenu = (app: App) => {
event.stopPropagation(); event.stopPropagation();
break; break;
} else if (target.id === "menuSafeQuit") { } else if (target.id === "menuSafeQuit") {
exitSiYuan();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
exitSiYuan();
break; break;
} else if (target.id === "menuAbout") { } else if (target.id === "menuAbout") {
initAbout(); initAbout();

View file

@ -39,8 +39,13 @@ export const saveScroll = (protyle: IProtyle, getObject = false) => {
if (getObject) { if (getObject) {
return attr; return attr;
} }
window.siyuan.storage[Constants.LOCAL_FILEPOSITION][protyle.block.rootID] = attr; window.siyuan.storage[Constants.LOCAL_FILEPOSITION][protyle.block.rootID] = attr;
setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]); return new Promise(resolve => {
setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION], () => {
resolve(true);
});
})
}; };
export const getDocByScroll = (options: { export const getDocByScroll = (options: {

View file

@ -300,7 +300,6 @@ export const setStorageVal = (key: string, val: any, cb?: () => void) => {
if (window.siyuan.config.readonly) { if (window.siyuan.config.readonly) {
return; return;
} }
fetchPost("/api/storage/setLocalStorageVal", { fetchPost("/api/storage/setLocalStorageVal", {
app: Constants.SIYUAN_APPID, app: Constants.SIYUAN_APPID,
key, key,

View file

@ -54,7 +54,7 @@ export const reloadProtyle = (protyle: IProtyle, focus: boolean, updateReadonly?
getDocByScroll({ getDocByScroll({
protyle, protyle,
focus, focus,
scrollAttr: saveScroll(protyle, true), scrollAttr: saveScroll(protyle, true) as IScrollAttr,
updateReadonly updateReadonly
}); });
} }

View file

@ -48,7 +48,7 @@ const focusStack = async (app: App, stack: IBackStack) => {
title: info.data.rootTitle, title: info.data.rootTitle,
docIcon: info.data.rootIcon, docIcon: info.data.rootIcon,
callback(tab) { callback(tab) {
const scrollAttr = saveScroll(stack.protyle, true); const scrollAttr = saveScroll(stack.protyle, true) as IScrollAttr;
scrollAttr.rootId = stack.protyle.block.rootID; scrollAttr.rootId = stack.protyle.block.rootID;
scrollAttr.focusId = stack.id; scrollAttr.focusId = stack.id;
scrollAttr.focusStart = stack.position.start; scrollAttr.focusStart = stack.position.start;

View file

@ -24,18 +24,30 @@ export const processMessage = (response: IWebSocketData) => {
if ("reloadui" === response.cmd) { if ("reloadui" === response.cmd) {
if (response.data?.resetScroll) { if (response.data?.resetScroll) {
window.siyuan.storage[Constants.LOCAL_FILEPOSITION] = {}; window.siyuan.storage[Constants.LOCAL_FILEPOSITION] = {};
setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]); setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION], () => {
} /// #if MOBILE
/// #if MOBILE
window.location.reload();
/// #else
exportLayout({
cb() {
window.location.reload(); window.location.reload();
}, /// #else
errorExit: false, exportLayout({
}); cb() {
/// #endif window.location.reload();
},
errorExit: false,
});
/// #endif
});
} else {
/// #if MOBILE
window.location.reload();
/// #else
exportLayout({
cb() {
window.location.reload();
},
errorExit: false,
});
/// #endif
}
return false; return false;
} }