mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-03-10 14:42:33 +01:00
🎨 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:
parent
1aaabefe05
commit
840fd99bbb
7 changed files with 97 additions and 3 deletions
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue