🎨 Auto-close browser page when publish service is closed https://github.com/siyuan-note/siyuan/issues/16587#issuecomment-3698421929 (#16804)

This commit is contained in:
Jeffrey Chen 2026-01-10 19:47:30 +08:00 committed by GitHub
parent 1aaabefe05
commit 840fd99bbb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 97 additions and 3 deletions

View file

@ -5,6 +5,7 @@ import {hideMessage, showMessage} from "../dialog/message";
import {setStorageVal} from "../protyle/util/compatibility";
import {Constants} from "../constants";
import {fetchPost} from "./fetch";
import {isBrowser} from "./functions";
export const processMessage = (response: IWebSocketData) => {
if ("msg" === response.cmd) {
@ -61,6 +62,10 @@ export const processMessage = (response: IWebSocketData) => {
}
return false;
}
if ("closepublishpage" === response.cmd) {
handlePublishServiceClosed(response.msg);
return false;
}
// 小于 0 为提示:-2 提示;-1 报错,大于 0 的错误需处理,等于 0 的为正常操作
if (response.code < 0) {
@ -70,3 +75,22 @@ export const processMessage = (response: IWebSocketData) => {
return response;
};
export const handlePublishServiceClosed = (msg: string) => {
if (isBrowser()) {
sessionStorage.setItem("siyuanPublishServiceClosed", msg || "");
window.location.reload();
}
};
export const checkPublishServiceClosed = (): boolean => {
if (isBrowser()) {
const publishServiceClosedMsg = sessionStorage.getItem("siyuanPublishServiceClosed");
if (publishServiceClosedMsg) {
sessionStorage.removeItem("siyuanPublishServiceClosed");
document.body.innerHTML = `<div style="display:flex;align-items:center;justify-content:center;height:100vh">${publishServiceClosedMsg}</div>`;
return true;
}
}
return false;
};