2022-05-26 15:18:53 +08:00
|
|
|
|
import {Constants} from "../constants";
|
|
|
|
|
import {fetchPost} from "../util/fetch";
|
|
|
|
|
/// #if !MOBILE
|
2022-06-29 20:25:30 +08:00
|
|
|
|
import {exportLayout} from "../layout/util";
|
2024-09-07 12:08:50 +08:00
|
|
|
|
/// #endif
|
|
|
|
|
import {getAllEditor, getAllModels} from "../layout/getAll";
|
2024-09-06 23:17:10 +08:00
|
|
|
|
import {getDockByType} from "../layout/tabUtil";
|
|
|
|
|
import {Files} from "../layout/dock/Files";
|
2023-02-26 10:19:47 +08:00
|
|
|
|
/// #if !BROWSER
|
|
|
|
|
import {ipcRenderer} from "electron";
|
|
|
|
|
/// #endif
|
2022-09-09 10:10:38 +08:00
|
|
|
|
import {hideMessage, showMessage} from "./message";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {Dialog} from "./index";
|
2023-04-19 11:27:32 +08:00
|
|
|
|
import {isMobile} from "../util/functions";
|
2022-09-08 22:40:01 +08:00
|
|
|
|
import {confirmDialog} from "./confirmDialog";
|
2023-01-16 16:01:48 +08:00
|
|
|
|
import {escapeHtml} from "../util/escape";
|
2023-01-16 21:33:20 +08:00
|
|
|
|
import {getWorkspaceName} from "../util/noRelyPCFunction";
|
2023-01-24 12:13:57 +08:00
|
|
|
|
import {needSubscribe} from "../util/needSubscribe";
|
2023-05-01 15:40:12 +08:00
|
|
|
|
import {redirectToCheckAuth, setNoteBook} from "../util/pathName";
|
2023-04-25 18:53:41 +08:00
|
|
|
|
import {reloadProtyle} from "../protyle/util/reload";
|
2023-04-25 19:36:42 +08:00
|
|
|
|
import {Tab} from "../layout/Tab";
|
2023-04-27 10:14:58 +08:00
|
|
|
|
import {setEmpty} from "../mobile/util/setEmpty";
|
2023-10-29 19:49:36 +08:00
|
|
|
|
import {hideAllElements, hideElements} from "../protyle/ui/hideElements";
|
2023-05-18 19:27:21 +08:00
|
|
|
|
import {App} from "../index";
|
2023-07-04 13:40:47 +08:00
|
|
|
|
import {saveScroll} from "../protyle/scroll/saveScroll";
|
2024-11-23 09:48:08 +08:00
|
|
|
|
import {isInAndroid, isInHarmony, isInIOS, setStorageVal} from "../protyle/util/compatibility";
|
2023-12-03 22:17:07 +08:00
|
|
|
|
import {Plugin} from "../plugin";
|
2023-04-25 18:53:41 +08:00
|
|
|
|
|
2023-12-21 09:07:33 +08:00
|
|
|
|
const updateTitle = (rootID: string, tab: Tab, protyle?: IProtyle) => {
|
2023-04-25 19:36:42 +08:00
|
|
|
|
fetchPost("/api/block/getDocInfo", {
|
|
|
|
|
id: rootID
|
|
|
|
|
}, (response) => {
|
2023-04-25 19:38:31 +08:00
|
|
|
|
tab.updateTitle(response.data.name);
|
2023-12-21 09:07:33 +08:00
|
|
|
|
if (protyle && protyle.title) {
|
|
|
|
|
protyle.title.setTitle(response.data.name);
|
|
|
|
|
}
|
2023-04-25 19:38:31 +08:00
|
|
|
|
});
|
|
|
|
|
};
|
2023-04-27 10:14:58 +08:00
|
|
|
|
|
2024-06-24 21:46:20 +08:00
|
|
|
|
export const reloadSync = (
|
|
|
|
|
app: App,
|
|
|
|
|
data: { upsertRootIDs: string[], removeRootIDs: string[] },
|
|
|
|
|
hideMsg = true,
|
|
|
|
|
// 同步的时候需要更新只读状态 https://github.com/siyuan-note/siyuan/issues/11517
|
|
|
|
|
// 调整大纲的时候需要使用现有状态 https://github.com/siyuan-note/siyuan/issues/11808
|
2024-09-26 10:59:45 +08:00
|
|
|
|
updateReadonly = true,
|
|
|
|
|
onlyUpdateDoc = false
|
2024-06-24 21:46:20 +08:00
|
|
|
|
) => {
|
2024-04-17 11:13:12 +08:00
|
|
|
|
if (hideMsg) {
|
|
|
|
|
hideMessage();
|
|
|
|
|
}
|
|
|
|
|
/// #if MOBILE
|
2023-04-27 10:14:58 +08:00
|
|
|
|
if (window.siyuan.mobile.popEditor) {
|
|
|
|
|
if (data.removeRootIDs.includes(window.siyuan.mobile.popEditor.protyle.block.rootID)) {
|
|
|
|
|
hideElements(["dialog"]);
|
|
|
|
|
} else {
|
2024-06-24 21:46:20 +08:00
|
|
|
|
reloadProtyle(window.siyuan.mobile.popEditor.protyle, false, updateReadonly);
|
2023-04-27 10:14:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (window.siyuan.mobile.editor) {
|
|
|
|
|
if (data.removeRootIDs.includes(window.siyuan.mobile.editor.protyle.block.rootID)) {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
setEmpty(app);
|
2023-04-27 10:14:58 +08:00
|
|
|
|
} else {
|
2024-06-24 21:46:20 +08:00
|
|
|
|
reloadProtyle(window.siyuan.mobile.editor.protyle, false, updateReadonly);
|
2023-04-27 10:14:58 +08:00
|
|
|
|
fetchPost("/api/block/getDocInfo", {
|
|
|
|
|
id: window.siyuan.mobile.editor.protyle.block.rootID
|
|
|
|
|
}, (response) => {
|
2023-11-22 16:47:41 +08:00
|
|
|
|
setTitle(response.data.name);
|
2024-05-29 10:53:35 +08:00
|
|
|
|
window.siyuan.mobile.editor.protyle.title.setTitle(response.data.name);
|
2023-04-27 10:14:58 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-01 15:40:12 +08:00
|
|
|
|
setNoteBook(() => {
|
2024-10-23 15:47:36 +08:00
|
|
|
|
window.siyuan.mobile.docks.file.init(false);
|
2023-05-01 15:40:12 +08:00
|
|
|
|
});
|
2023-04-27 10:14:58 +08:00
|
|
|
|
/// #else
|
2023-04-25 19:38:31 +08:00
|
|
|
|
const allModels = getAllModels();
|
2023-04-25 18:53:41 +08:00
|
|
|
|
allModels.editor.forEach(item => {
|
|
|
|
|
if (data.upsertRootIDs.includes(item.editor.protyle.block.rootID)) {
|
2024-05-24 09:40:22 +08:00
|
|
|
|
fetchPost("/api/block/getDocInfo", {
|
|
|
|
|
id: item.editor.protyle.block.rootID,
|
|
|
|
|
}, (response) => {
|
|
|
|
|
item.editor.protyle.wysiwyg.renderCustom(response.data.ial);
|
2024-06-24 21:46:20 +08:00
|
|
|
|
reloadProtyle(item.editor.protyle, false, updateReadonly);
|
2024-05-24 09:40:22 +08:00
|
|
|
|
updateTitle(item.editor.protyle.block.rootID, item.parent, item.editor.protyle);
|
|
|
|
|
});
|
2023-04-25 18:53:41 +08:00
|
|
|
|
} else if (data.removeRootIDs.includes(item.editor.protyle.block.rootID)) {
|
2023-12-09 12:09:46 +08:00
|
|
|
|
item.parent.parent.removeTab(item.parent.id, false, false);
|
|
|
|
|
delete window.siyuan.storage[Constants.LOCAL_FILEPOSITION][item.editor.protyle.block.rootID];
|
|
|
|
|
setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]);
|
2023-04-25 18:53:41 +08:00
|
|
|
|
}
|
2023-04-25 19:38:31 +08:00
|
|
|
|
});
|
2023-04-25 18:53:41 +08:00
|
|
|
|
allModels.graph.forEach(item => {
|
2023-04-25 18:58:48 +08:00
|
|
|
|
if (item.type === "local" && data.removeRootIDs.includes(item.rootId)) {
|
2023-12-09 12:09:46 +08:00
|
|
|
|
item.parent.parent.removeTab(item.parent.id, false, false);
|
2023-04-25 19:36:42 +08:00
|
|
|
|
} else if (item.type !== "local" || data.upsertRootIDs.includes(item.rootId)) {
|
2023-04-25 18:58:48 +08:00
|
|
|
|
item.searchGraph(false);
|
2023-04-25 19:36:42 +08:00
|
|
|
|
if (item.type === "local") {
|
|
|
|
|
updateTitle(item.rootId, item.parent);
|
|
|
|
|
}
|
2023-04-25 18:58:48 +08:00
|
|
|
|
}
|
2023-04-25 19:38:31 +08:00
|
|
|
|
});
|
2023-04-25 18:53:41 +08:00
|
|
|
|
allModels.outline.forEach(item => {
|
|
|
|
|
if (item.type === "local" && data.removeRootIDs.includes(item.blockId)) {
|
2023-12-09 12:09:46 +08:00
|
|
|
|
item.parent.parent.removeTab(item.parent.id, false, false);
|
2023-04-25 19:36:42 +08:00
|
|
|
|
} else if (item.type !== "local" || data.upsertRootIDs.includes(item.blockId)) {
|
2023-04-25 18:53:41 +08:00
|
|
|
|
fetchPost("/api/outline/getDocOutline", {
|
|
|
|
|
id: item.blockId,
|
2024-09-18 11:34:41 +08:00
|
|
|
|
preview: item.isPreview
|
2023-04-25 18:53:41 +08:00
|
|
|
|
}, response => {
|
|
|
|
|
item.update(response);
|
|
|
|
|
});
|
2023-04-25 19:36:42 +08:00
|
|
|
|
if (item.type === "local") {
|
|
|
|
|
updateTitle(item.blockId, item.parent);
|
|
|
|
|
}
|
2023-04-25 18:53:41 +08:00
|
|
|
|
}
|
2023-04-25 19:38:31 +08:00
|
|
|
|
});
|
2023-04-25 18:53:41 +08:00
|
|
|
|
allModels.backlink.forEach(item => {
|
|
|
|
|
if (item.type === "local" && data.removeRootIDs.includes(item.rootId)) {
|
2023-12-09 12:09:46 +08:00
|
|
|
|
item.parent.parent.removeTab(item.parent.id, false, false);
|
2023-04-25 18:53:41 +08:00
|
|
|
|
} else {
|
|
|
|
|
item.refresh();
|
2023-04-25 19:36:42 +08:00
|
|
|
|
if (item.type === "local") {
|
|
|
|
|
updateTitle(item.rootId, item.parent);
|
|
|
|
|
}
|
2023-04-25 18:53:41 +08:00
|
|
|
|
}
|
2023-04-25 19:38:31 +08:00
|
|
|
|
});
|
2024-11-02 14:47:57 +08:00
|
|
|
|
if (!onlyUpdateDoc) {
|
2024-09-26 10:59:45 +08:00
|
|
|
|
allModels.files.forEach(item => {
|
|
|
|
|
setNoteBook(() => {
|
|
|
|
|
item.init(false);
|
|
|
|
|
});
|
2023-05-01 15:40:12 +08:00
|
|
|
|
});
|
2024-09-26 10:59:45 +08:00
|
|
|
|
}
|
2023-04-25 18:53:41 +08:00
|
|
|
|
allModels.bookmark.forEach(item => {
|
|
|
|
|
item.update();
|
2023-04-25 19:38:31 +08:00
|
|
|
|
});
|
2023-04-25 18:53:41 +08:00
|
|
|
|
allModels.tag.forEach(item => {
|
|
|
|
|
item.update();
|
2023-04-25 19:38:31 +08:00
|
|
|
|
});
|
2023-04-25 18:53:41 +08:00
|
|
|
|
// NOTE asset 无法获取推送地址,先不处理
|
|
|
|
|
allModels.search.forEach(item => {
|
2023-04-26 11:19:53 +08:00
|
|
|
|
item.parent.panelElement.querySelector("#searchInput").dispatchEvent(new CustomEvent("input"));
|
2023-04-25 19:38:31 +08:00
|
|
|
|
});
|
2023-04-28 12:02:08 +08:00
|
|
|
|
allModels.custom.forEach(item => {
|
|
|
|
|
if (item.update) {
|
|
|
|
|
item.update();
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-04-27 10:14:58 +08:00
|
|
|
|
/// #endif
|
2023-04-25 19:38:31 +08:00
|
|
|
|
};
|
2023-01-12 15:53:57 +08:00
|
|
|
|
|
2024-09-06 11:44:40 +08:00
|
|
|
|
export const setRefDynamicText = (data: {
|
|
|
|
|
"blockID": string,
|
|
|
|
|
"defBlockID": string,
|
|
|
|
|
"refText": string,
|
|
|
|
|
"rootID": string
|
2024-09-06 16:58:25 +08:00
|
|
|
|
}) => {
|
2025-03-16 11:56:12 +08:00
|
|
|
|
getAllEditor().forEach(editor => {
|
2024-09-19 17:31:37 +08:00
|
|
|
|
// 不能对比 rootId,否则嵌入块中的锚文本无法更新
|
2025-03-16 11:56:12 +08:00
|
|
|
|
editor.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${data.blockID}"] span[data-type~="block-ref"][data-subtype="d"][data-id="${data.defBlockID}"]`).forEach(item => {
|
2024-09-06 22:48:50 +08:00
|
|
|
|
item.innerHTML = data.refText;
|
|
|
|
|
});
|
2024-09-08 11:03:47 +08:00
|
|
|
|
});
|
|
|
|
|
};
|
2024-09-06 16:58:25 +08:00
|
|
|
|
|
|
|
|
|
export const setDefRefCount = (data: {
|
|
|
|
|
"blockID": string,
|
2024-09-06 22:48:50 +08:00
|
|
|
|
"refCount": number,
|
|
|
|
|
"rootRefCount": number,
|
2024-09-06 16:58:25 +08:00
|
|
|
|
"rootID": string
|
2024-09-06 11:44:40 +08:00
|
|
|
|
}) => {
|
2024-10-09 11:04:18 +08:00
|
|
|
|
getAllEditor().forEach(editor => {
|
2025-01-12 16:45:17 +08:00
|
|
|
|
if (editor.protyle.block.rootID === data.rootID && editor.protyle.title) {
|
2024-10-09 11:04:18 +08:00
|
|
|
|
const attrElement = editor.protyle.title.element.querySelector(".protyle-attr");
|
2024-09-26 23:33:28 +08:00
|
|
|
|
const countElement = attrElement.querySelector(".protyle-attr--refcount");
|
2024-09-06 23:17:10 +08:00
|
|
|
|
if (countElement) {
|
2024-12-09 23:17:13 +08:00
|
|
|
|
if (data.rootRefCount === 0) {
|
2024-09-08 11:03:47 +08:00
|
|
|
|
countElement.remove();
|
2024-09-06 23:17:10 +08:00
|
|
|
|
} else {
|
2024-12-09 23:17:13 +08:00
|
|
|
|
countElement.textContent = data.rootRefCount.toString();
|
2024-09-06 23:17:10 +08:00
|
|
|
|
}
|
2024-12-09 23:17:13 +08:00
|
|
|
|
} else if (data.rootRefCount > 0) {
|
2025-01-13 12:47:28 +08:00
|
|
|
|
attrElement.insertAdjacentHTML("beforeend", `<div class="protyle-attr--refcount popover__block">${data.rootRefCount}</div>`);
|
2024-09-06 23:17:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2025-01-12 11:32:31 +08:00
|
|
|
|
if (data.rootID === data.blockID) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-09-19 17:31:37 +08:00
|
|
|
|
// 不能对比 rootId,否则嵌入块中的锚文本无法更新
|
2024-10-09 11:04:18 +08:00
|
|
|
|
editor.protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${data.blockID}"]`).forEach(item => {
|
|
|
|
|
// 不能直接查询,否则列表中会获取到第一个列表项的 attr https://github.com/siyuan-note/siyuan/issues/12738
|
|
|
|
|
const countElement = item.lastElementChild.querySelector(".protyle-attr--refcount");
|
2024-09-06 22:48:50 +08:00
|
|
|
|
if (countElement) {
|
|
|
|
|
if (data.refCount === 0) {
|
2024-09-08 11:03:47 +08:00
|
|
|
|
countElement.remove();
|
2024-09-06 22:48:50 +08:00
|
|
|
|
} else {
|
|
|
|
|
countElement.textContent = data.refCount.toString();
|
|
|
|
|
}
|
|
|
|
|
} else if (data.refCount > 0) {
|
2024-10-09 11:04:18 +08:00
|
|
|
|
const attrElement = item.lastElementChild;
|
2024-09-06 22:48:50 +08:00
|
|
|
|
if (attrElement.childElementCount > 0) {
|
2024-09-08 11:03:47 +08:00
|
|
|
|
attrElement.lastElementChild.insertAdjacentHTML("afterend", `<div class="protyle-attr--refcount popover__block">${data.refCount}</div>`);
|
2024-09-06 22:48:50 +08:00
|
|
|
|
} else {
|
2024-09-08 11:03:47 +08:00
|
|
|
|
attrElement.innerHTML = `<div class="protyle-attr--refcount popover__block">${data.refCount}</div>${Constants.ZWSP}`;
|
2024-09-06 22:48:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-19 22:09:49 +08:00
|
|
|
|
if (data.refCount === 0) {
|
2024-09-19 22:12:39 +08:00
|
|
|
|
item.removeAttribute("refcount");
|
2024-09-19 22:09:49 +08:00
|
|
|
|
} else {
|
2024-09-19 22:12:39 +08:00
|
|
|
|
item.setAttribute("refcount", data.refCount.toString());
|
2024-09-19 22:09:49 +08:00
|
|
|
|
}
|
2024-09-06 22:48:50 +08:00
|
|
|
|
});
|
2024-09-08 11:03:47 +08:00
|
|
|
|
});
|
2024-09-06 23:17:10 +08:00
|
|
|
|
|
2024-09-06 23:24:07 +08:00
|
|
|
|
let liElement;
|
2024-09-06 23:17:10 +08:00
|
|
|
|
/// #if MOBILE
|
2024-10-23 15:47:36 +08:00
|
|
|
|
liElement = window.siyuan.mobile.docks.file.element.querySelector(`li[data-node-id="${data.rootID}"]`);
|
2024-09-06 23:17:10 +08:00
|
|
|
|
/// #else
|
2024-09-08 11:03:47 +08:00
|
|
|
|
liElement = (getDockByType("file").data.file as Files).element.querySelector(`li[data-node-id="${data.rootID}"]`);
|
2024-09-06 23:24:07 +08:00
|
|
|
|
/// #endif
|
2024-09-06 23:17:10 +08:00
|
|
|
|
if (liElement) {
|
2024-09-08 11:03:47 +08:00
|
|
|
|
const counterElement = liElement.querySelector(".counter");
|
2024-09-06 23:17:10 +08:00
|
|
|
|
if (counterElement) {
|
|
|
|
|
if (data.rootRefCount === 0) {
|
2024-09-08 11:03:47 +08:00
|
|
|
|
counterElement.remove();
|
2024-09-06 23:17:10 +08:00
|
|
|
|
} else {
|
2024-09-08 11:03:47 +08:00
|
|
|
|
counterElement.textContent = data.rootRefCount.toString();
|
2024-09-06 23:17:10 +08:00
|
|
|
|
}
|
|
|
|
|
} else if (data.rootRefCount > 0) {
|
2024-09-08 11:03:47 +08:00
|
|
|
|
liElement.insertAdjacentHTML("beforeend", `<span class="popover__block counter b3-tooltips b3-tooltips__nw" aria-label="${window.siyuan.languages.ref}">${data.rootRefCount}</span>`);
|
2024-09-06 23:17:10 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-08 11:03:47 +08:00
|
|
|
|
};
|
2024-09-06 11:44:40 +08:00
|
|
|
|
|
2023-12-28 19:36:42 +08:00
|
|
|
|
export const lockScreen = (app: App) => {
|
2023-03-10 10:00:03 +08:00
|
|
|
|
if (window.siyuan.config.readonly) {
|
2023-03-13 10:53:42 +08:00
|
|
|
|
return;
|
2023-03-10 10:00:03 +08:00
|
|
|
|
}
|
2023-12-28 19:36:42 +08:00
|
|
|
|
app.plugins.forEach(item => {
|
|
|
|
|
item.eventBus.emit("lock-screen");
|
|
|
|
|
});
|
2023-01-12 15:53:57 +08:00
|
|
|
|
/// #if BROWSER
|
2023-01-12 16:43:22 +08:00
|
|
|
|
fetchPost("/api/system/logoutAuth", {}, () => {
|
2023-04-18 19:07:58 +08:00
|
|
|
|
redirectToCheckAuth();
|
2023-01-12 16:43:22 +08:00
|
|
|
|
});
|
2023-01-12 15:53:57 +08:00
|
|
|
|
/// #else
|
2023-02-27 10:58:07 +08:00
|
|
|
|
ipcRenderer.send(Constants.SIYUAN_SEND_WINDOWS, {cmd: "lockscreen"});
|
2023-01-12 15:53:57 +08:00
|
|
|
|
/// #endif
|
2023-01-12 17:36:19 +08:00
|
|
|
|
};
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
|
|
|
|
export const kernelError = () => {
|
2023-04-22 19:07:57 +08:00
|
|
|
|
if (document.querySelector("#errorLog")) {
|
2023-04-21 21:58:57 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2025-03-05 00:02:14 +08:00
|
|
|
|
let title = `💔 ${window.siyuan.languages.kernelFault0} <small>v${Constants.SIYUAN_VERSION}</small>`;
|
|
|
|
|
let body = `<div>${window.siyuan.languages.kernelFault1}</div><div class="fn__hr"></div><div>${window.siyuan.languages.kernelFault2}</div>`;
|
2023-09-05 16:12:29 +08:00
|
|
|
|
if (isInIOS()) {
|
2025-03-05 00:02:14 +08:00
|
|
|
|
title = `🍵 ${window.siyuan.languages.pleaseWait} <small>v${Constants.SIYUAN_VERSION}</small>`;
|
|
|
|
|
body = `<div>${window.siyuan.languages.reconnectPrompt}</div><div class="fn__hr"></div><div class="fn__flex"><div class="fn__flex-1"></div><button class="b3-button">${window.siyuan.languages.retry}</button></div>`;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
2023-04-21 09:51:04 +08:00
|
|
|
|
const dialog = new Dialog({
|
|
|
|
|
disableClose: true,
|
2025-03-05 00:02:14 +08:00
|
|
|
|
title: title,
|
2023-04-21 09:51:04 +08:00
|
|
|
|
width: isMobile() ? "92vw" : "520px",
|
2023-04-22 19:07:57 +08:00
|
|
|
|
content: `<div class="b3-dialog__content">
|
2023-04-21 09:51:04 +08:00
|
|
|
|
<div class="ft__breakword">
|
2025-03-05 00:02:14 +08:00
|
|
|
|
${body}
|
2023-04-21 09:51:04 +08:00
|
|
|
|
</div>
|
|
|
|
|
</div>`
|
|
|
|
|
});
|
2023-04-22 19:22:53 +08:00
|
|
|
|
dialog.element.id = "errorLog";
|
2024-01-10 23:27:44 +08:00
|
|
|
|
dialog.element.setAttribute("data-key", Constants.DIALOG_KERNELFAULT);
|
2023-04-21 09:51:04 +08:00
|
|
|
|
const restartElement = dialog.element.querySelector(".b3-button");
|
|
|
|
|
if (restartElement) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
restartElement.addEventListener("click", () => {
|
2023-04-21 09:51:04 +08:00
|
|
|
|
dialog.destroy();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.webkit.messageHandlers.startKernelFast.postMessage("startKernelFast");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-09-27 00:22:20 +08:00
|
|
|
|
export const exitSiYuan = async () => {
|
2023-10-29 19:49:36 +08:00
|
|
|
|
hideAllElements(["util"]);
|
2023-07-04 13:40:47 +08:00
|
|
|
|
/// #if MOBILE
|
2023-11-22 16:18:32 +08:00
|
|
|
|
if (window.siyuan.mobile.editor) {
|
2024-09-27 00:22:20 +08:00
|
|
|
|
await saveScroll(window.siyuan.mobile.editor.protyle);
|
2023-11-22 16:18:32 +08:00
|
|
|
|
}
|
2023-07-04 13:40:47 +08:00
|
|
|
|
/// #endif
|
2022-05-26 15:18:53 +08:00
|
|
|
|
fetchPost("/api/system/exit", {force: false}, (response) => {
|
2022-09-08 09:55:29 +08:00
|
|
|
|
if (response.code === 1) { // 同步执行失败
|
2022-06-06 23:04:56 +08:00
|
|
|
|
const msgId = showMessage(response.msg, response.data.closeTimeout, "error");
|
|
|
|
|
const buttonElement = document.querySelector(`#message [data-id="${msgId}"] button`);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (buttonElement) {
|
|
|
|
|
buttonElement.addEventListener("click", () => {
|
|
|
|
|
fetchPost("/api/system/exit", {force: true}, () => {
|
|
|
|
|
/// #if !BROWSER
|
2023-03-19 11:57:22 +08:00
|
|
|
|
ipcRenderer.send(Constants.SIYUAN_QUIT, location.port);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
/// #else
|
2024-11-23 09:48:08 +08:00
|
|
|
|
if (isInIOS() || isInAndroid() || isInHarmony()) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.location.href = "siyuan://api/system/exit";
|
|
|
|
|
}
|
|
|
|
|
/// #endif
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-09-08 09:55:29 +08:00
|
|
|
|
} else if (response.code === 2) { // 提示新安装包
|
2022-09-09 10:10:38 +08:00
|
|
|
|
hideMessage();
|
2024-12-25 21:59:10 +08:00
|
|
|
|
|
|
|
|
|
if ("std" === window.siyuan.config.system.container) {
|
|
|
|
|
ipcRenderer.send(Constants.SIYUAN_SHOW_WINDOW);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-08 22:40:01 +08:00
|
|
|
|
confirmDialog(window.siyuan.languages.tip, response.msg, () => {
|
|
|
|
|
fetchPost("/api/system/exit", {
|
|
|
|
|
force: true,
|
|
|
|
|
execInstallPkg: 2 // 0:默认检查新版本,1:不执行新版本安装,2:执行新版本安装
|
|
|
|
|
}, () => {
|
|
|
|
|
/// #if !BROWSER
|
2022-11-11 10:09:36 +08:00
|
|
|
|
// 桌面端退出拉起更新安装时有时需要重启两次 https://github.com/siyuan-note/siyuan/issues/6544
|
|
|
|
|
// 这里先将主界面隐藏
|
|
|
|
|
setTimeout(() => {
|
2023-10-08 15:43:28 +08:00
|
|
|
|
ipcRenderer.send(Constants.SIYUAN_CMD, "hide");
|
2022-11-11 10:09:36 +08:00
|
|
|
|
}, 2000);
|
|
|
|
|
// 然后等待一段时间后再退出,避免界面主进程退出以后内核子进程被杀死
|
|
|
|
|
setTimeout(() => {
|
2023-03-19 11:57:22 +08:00
|
|
|
|
ipcRenderer.send(Constants.SIYUAN_QUIT, location.port);
|
2022-11-11 10:09:36 +08:00
|
|
|
|
}, 4000);
|
2022-09-08 22:40:01 +08:00
|
|
|
|
/// #endif
|
2022-09-08 09:55:29 +08:00
|
|
|
|
});
|
2022-09-08 22:40:01 +08:00
|
|
|
|
}, () => {
|
|
|
|
|
fetchPost("/api/system/exit", {
|
|
|
|
|
force: true,
|
|
|
|
|
execInstallPkg: 1 // 0:默认检查新版本,1:不执行新版本安装,2:执行新版本安装
|
|
|
|
|
}, () => {
|
|
|
|
|
/// #if !BROWSER
|
2023-03-19 11:57:22 +08:00
|
|
|
|
ipcRenderer.send(Constants.SIYUAN_QUIT, location.port);
|
2022-09-08 22:40:01 +08:00
|
|
|
|
/// #endif
|
|
|
|
|
});
|
2022-09-09 09:45:18 +08:00
|
|
|
|
});
|
2022-09-08 09:55:29 +08:00
|
|
|
|
} else { // 正常退出
|
2022-05-26 15:18:53 +08:00
|
|
|
|
/// #if !BROWSER
|
2023-03-19 11:57:22 +08:00
|
|
|
|
ipcRenderer.send(Constants.SIYUAN_QUIT, location.port);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
/// #else
|
2024-11-23 09:48:08 +08:00
|
|
|
|
if (isInIOS() || isInAndroid() || isInHarmony()) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
window.location.href = "siyuan://api/system/exit";
|
|
|
|
|
}
|
|
|
|
|
/// #endif
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2023-03-21 09:25:52 +08:00
|
|
|
|
export const transactionError = () => {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (document.getElementById("transactionError")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const dialog = new Dialog({
|
|
|
|
|
disableClose: true,
|
|
|
|
|
title: `${window.siyuan.languages.stateExcepted} v${Constants.SIYUAN_VERSION}`,
|
|
|
|
|
content: `<div class="b3-dialog__content" id="transactionError">${window.siyuan.languages.rebuildIndexTip}</div>
|
|
|
|
|
<div class="b3-dialog__action">
|
|
|
|
|
<button class="b3-button b3-button--text">${window.siyuan.languages._kernel[97]}</button>
|
|
|
|
|
<div class="fn__space"></div>
|
|
|
|
|
<button class="b3-button">${window.siyuan.languages.rebuildIndex}</button>
|
|
|
|
|
</div>`,
|
2023-04-20 10:05:24 +08:00
|
|
|
|
width: isMobile() ? "92vw" : "520px",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
2024-01-10 23:27:44 +08:00
|
|
|
|
dialog.element.setAttribute("data-key", Constants.DIALOG_STATEEXCEPTED);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
const btnsElement = dialog.element.querySelectorAll(".b3-button");
|
|
|
|
|
btnsElement[0].addEventListener("click", () => {
|
2022-06-29 20:25:30 +08:00
|
|
|
|
/// #if MOBILE
|
|
|
|
|
exitSiYuan();
|
|
|
|
|
/// #else
|
2023-05-11 12:22:53 +08:00
|
|
|
|
exportLayout({
|
|
|
|
|
errorExit: true,
|
|
|
|
|
cb: exitSiYuan
|
|
|
|
|
});
|
2022-06-29 20:25:30 +08:00
|
|
|
|
/// #endif
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
|
|
|
|
btnsElement[1].addEventListener("click", () => {
|
2024-06-21 22:22:24 +08:00
|
|
|
|
refreshFileTree();
|
2023-01-25 21:28:23 +08:00
|
|
|
|
dialog.destroy();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-24 21:46:20 +08:00
|
|
|
|
export const refreshFileTree = (cb?: () => void) => {
|
2024-06-21 22:22:24 +08:00
|
|
|
|
window.siyuan.storage[Constants.LOCAL_FILEPOSITION] = {};
|
|
|
|
|
setStorageVal(Constants.LOCAL_FILEPOSITION, window.siyuan.storage[Constants.LOCAL_FILEPOSITION]);
|
2025-08-25 16:17:52 +08:00
|
|
|
|
fetchPost("/api/system/rebuildDataIndex", {}, () => {
|
2024-06-21 22:22:24 +08:00
|
|
|
|
if (cb) {
|
2024-07-06 09:57:00 +08:00
|
|
|
|
cb();
|
2024-06-21 22:22:24 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2024-07-06 09:57:00 +08:00
|
|
|
|
};
|
2024-06-21 22:22:24 +08:00
|
|
|
|
|
2024-04-25 15:36:20 +08:00
|
|
|
|
let statusTimeout: number;
|
2022-06-25 20:40:07 +08:00
|
|
|
|
export const progressStatus = (data: IWebSocketData) => {
|
2023-01-20 11:24:11 +08:00
|
|
|
|
const statusElement = document.querySelector("#status") as HTMLElement;
|
|
|
|
|
if (!statusElement) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-04-26 09:17:50 +08:00
|
|
|
|
|
2022-08-28 12:41:49 +08:00
|
|
|
|
if (isMobile()) {
|
2023-03-01 18:58:39 +08:00
|
|
|
|
if (!document.querySelector("#keyboardToolbar").classList.contains("fn__none")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-04-25 15:36:20 +08:00
|
|
|
|
clearTimeout(statusTimeout);
|
2022-08-28 12:41:49 +08:00
|
|
|
|
statusElement.innerHTML = data.msg;
|
2023-03-01 18:58:39 +08:00
|
|
|
|
statusElement.style.bottom = "0";
|
2024-04-25 15:36:20 +08:00
|
|
|
|
statusTimeout = window.setTimeout(() => {
|
2024-04-17 11:13:12 +08:00
|
|
|
|
statusElement.style.bottom = "";
|
2024-11-21 11:04:30 +08:00
|
|
|
|
}, 12000);
|
2024-04-25 15:36:20 +08:00
|
|
|
|
} else {
|
|
|
|
|
const msgElement = statusElement.querySelector(".status__msg");
|
|
|
|
|
if (msgElement) {
|
2024-04-25 15:56:06 +08:00
|
|
|
|
clearTimeout(statusTimeout);
|
2024-04-25 15:36:20 +08:00
|
|
|
|
msgElement.innerHTML = data.msg;
|
|
|
|
|
statusTimeout = window.setTimeout(() => {
|
|
|
|
|
msgElement.innerHTML = "";
|
2024-11-21 11:04:30 +08:00
|
|
|
|
}, 12000);
|
2024-04-25 15:36:20 +08:00
|
|
|
|
}
|
2023-01-24 11:23:41 +08:00
|
|
|
|
}
|
2022-06-25 20:40:07 +08:00
|
|
|
|
};
|
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
|
export const progressLoading = (data: IWebSocketData) => {
|
|
|
|
|
let progressElement = document.getElementById("progress");
|
|
|
|
|
if (!progressElement) {
|
2023-09-02 11:13:47 +08:00
|
|
|
|
document.body.insertAdjacentHTML("beforeend", `<div id="progress" style="z-index: ${++window.siyuan.zIndex}"></div>`);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
progressElement = document.getElementById("progress");
|
|
|
|
|
}
|
|
|
|
|
// code 0: 有进度;1: 无进度;2: 关闭
|
|
|
|
|
if (data.code === 2) {
|
|
|
|
|
progressElement.remove();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (data.code === 0) {
|
2023-09-02 11:13:47 +08:00
|
|
|
|
progressElement.innerHTML = `<div class="b3-dialog__scrim" style="opacity: 1"></div>
|
2024-01-24 18:17:41 +08:00
|
|
|
|
<div class="b3-dialog__loading">
|
2022-05-26 15:18:53 +08:00
|
|
|
|
<div style="text-align: right">${data.data.current}/${data.data.total}</div>
|
2023-06-28 22:40:34 +08:00
|
|
|
|
<div style="margin: 8px 0;height: 8px;border-radius: var(--b3-border-radius);overflow: hidden;background-color:#fff;"><div style="width: ${data.data.current / data.data.total * 100}%;transition: var(--b3-transition);background-color: var(--b3-theme-primary);height: 8px;"></div></div>
|
2024-11-12 17:05:49 +08:00
|
|
|
|
<div class="ft__breakword">${data.msg}</div>
|
2022-05-26 15:18:53 +08:00
|
|
|
|
</div>`;
|
|
|
|
|
} else if (data.code === 1) {
|
|
|
|
|
if (progressElement.lastElementChild) {
|
|
|
|
|
progressElement.lastElementChild.lastElementChild.innerHTML = data.msg;
|
|
|
|
|
} else {
|
2023-09-02 11:13:47 +08:00
|
|
|
|
progressElement.innerHTML = `<div class="b3-dialog__scrim" style="opacity: 1"></div>
|
2024-01-24 18:17:41 +08:00
|
|
|
|
<div class="b3-dialog__loading">
|
2023-06-28 22:40:34 +08:00
|
|
|
|
<div style="margin: 8px 0;height: 8px;border-radius: var(--b3-border-radius);overflow: hidden;background-color:#fff;"><div style="background-color: var(--b3-theme-primary);height: 8px;background-image: linear-gradient(-45deg, rgba(255, 255, 255, 0.2) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0.2) 75%, transparent 75%, transparent);animation: stripMove 450ms linear infinite;background-size: 50px 50px;"></div></div>
|
2024-11-12 17:05:49 +08:00
|
|
|
|
<div class="ft__breakword">${data.msg}</div>
|
2022-05-26 15:18:53 +08:00
|
|
|
|
</div>`;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-20 19:37:42 +08:00
|
|
|
|
export const progressBackgroundTask = (tasks: { action: string }[]) => {
|
2023-01-24 20:31:35 +08:00
|
|
|
|
const backgroundTaskElement = document.querySelector(".status__backgroundtask");
|
|
|
|
|
if (!backgroundTaskElement) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (tasks.length === 0) {
|
|
|
|
|
backgroundTaskElement.classList.add("fn__none");
|
|
|
|
|
if (!window.siyuan.menus.menu.element.classList.contains("fn__none") &&
|
|
|
|
|
window.siyuan.menus.menu.element.getAttribute("data-name") === "statusBackgroundTask") {
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
backgroundTaskElement.classList.remove("fn__none");
|
|
|
|
|
backgroundTaskElement.setAttribute("data-tasks", JSON.stringify(tasks));
|
|
|
|
|
backgroundTaskElement.innerHTML = tasks[0].action + "<div><div></div></div>";
|
|
|
|
|
}
|
2023-01-24 20:33:13 +08:00
|
|
|
|
};
|
2023-01-24 20:31:35 +08:00
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
|
export const bootSync = () => {
|
|
|
|
|
fetchPost("/api/sync/getBootSync", {}, response => {
|
|
|
|
|
if (response.code === 1) {
|
|
|
|
|
const dialog = new Dialog({
|
2023-04-20 10:05:24 +08:00
|
|
|
|
width: isMobile() ? "92vw" : "50vw",
|
2022-05-26 15:18:53 +08:00
|
|
|
|
title: "🌩️ " + window.siyuan.languages.bootSyncFailed,
|
|
|
|
|
content: `<div class="b3-dialog__content">${response.msg}</div>
|
|
|
|
|
<div class="b3-dialog__action">
|
|
|
|
|
<button class="b3-button b3-button--cancel">${window.siyuan.languages.cancel}</button><div class="fn__space"></div>
|
|
|
|
|
<button class="b3-button b3-button--text">${window.siyuan.languages.syncNow}</button>
|
|
|
|
|
</div>`
|
|
|
|
|
});
|
2024-01-10 23:27:44 +08:00
|
|
|
|
dialog.element.setAttribute("data-key", Constants.DIALOG_BOOTSYNCFAILED);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
const btnsElement = dialog.element.querySelectorAll(".b3-button");
|
|
|
|
|
btnsElement[0].addEventListener("click", () => {
|
|
|
|
|
dialog.destroy();
|
|
|
|
|
});
|
|
|
|
|
btnsElement[1].addEventListener("click", () => {
|
|
|
|
|
if (btnsElement[1].getAttribute("disabled")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
btnsElement[1].setAttribute("disabled", "disabled");
|
|
|
|
|
fetchPost("/api/sync/performBootSync", {}, (syncResponse) => {
|
|
|
|
|
if (syncResponse.code === 0) {
|
|
|
|
|
dialog.destroy();
|
|
|
|
|
}
|
|
|
|
|
btnsElement[1].removeAttribute("disabled");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-16 22:54:07 +08:00
|
|
|
|
export const setTitle = (title: string) => {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
const dragElement = document.getElementById("drag");
|
2023-01-10 22:51:04 +08:00
|
|
|
|
const workspaceName = getWorkspaceName();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (title === window.siyuan.languages.siyuanNote) {
|
2023-10-18 22:53:44 +08:00
|
|
|
|
const versionTitle = `${workspaceName} - ${window.siyuan.languages.siyuanNote} v${Constants.SIYUAN_VERSION}`;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
document.title = versionTitle;
|
2023-01-16 21:33:20 +08:00
|
|
|
|
if (dragElement) {
|
|
|
|
|
dragElement.textContent = versionTitle;
|
|
|
|
|
dragElement.setAttribute("title", versionTitle);
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
2024-03-24 22:15:19 +08:00
|
|
|
|
title = title || window.siyuan.languages.untitled;
|
2023-01-16 16:01:48 +08:00
|
|
|
|
document.title = `${title} - ${workspaceName} - ${window.siyuan.languages.siyuanNote} v${Constants.SIYUAN_VERSION}`;
|
2023-01-16 21:33:20 +08:00
|
|
|
|
if (!dragElement) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-01-16 16:01:48 +08:00
|
|
|
|
dragElement.setAttribute("title", title);
|
2023-01-16 22:36:01 +08:00
|
|
|
|
dragElement.innerHTML = escapeHtml(title);
|
2023-01-12 21:53:27 +08:00
|
|
|
|
}
|
2023-01-16 00:00:53 +08:00
|
|
|
|
};
|
2023-01-12 21:53:27 +08:00
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
|
export const downloadProgress = (data: { id: string, percent: number }) => {
|
2023-03-13 15:16:26 +08:00
|
|
|
|
const bazzarSideElement = document.querySelector("#configBazaarReadme .item__side");
|
|
|
|
|
if (!bazzarSideElement) {
|
2022-05-26 15:18:53 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-03-13 15:16:26 +08:00
|
|
|
|
if (data.id !== JSON.parse(bazzarSideElement.getAttribute("data-obj")).repoURL) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const btnElement = bazzarSideElement.querySelector('[data-type="install"]') as HTMLElement;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (btnElement) {
|
|
|
|
|
if (data.percent >= 1) {
|
|
|
|
|
btnElement.parentElement.classList.add("fn__none");
|
2023-02-20 19:37:42 +08:00
|
|
|
|
btnElement.parentElement.nextElementSibling.classList.add("fn__none");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
|
|
|
|
btnElement.classList.add("b3-button--progress");
|
2023-02-20 19:37:42 +08:00
|
|
|
|
btnElement.parentElement.nextElementSibling.firstElementChild.classList.add("b3-button--progress");
|
2022-05-26 15:18:53 +08:00
|
|
|
|
btnElement.innerHTML = `<span style="width: ${data.percent * 100}%"></span>`;
|
2023-02-20 19:37:42 +08:00
|
|
|
|
btnElement.parentElement.nextElementSibling.firstElementChild.innerHTML = `<span style="width: ${data.percent * 100}%"></span>`;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
2023-01-24 11:18:02 +08:00
|
|
|
|
|
2023-12-03 22:17:07 +08:00
|
|
|
|
export const processSync = (data?: IWebSocketData, plugins?: Plugin[]) => {
|
2023-03-10 10:43:15 +08:00
|
|
|
|
/// #if MOBILE
|
|
|
|
|
const menuSyncUseElement = document.querySelector("#menuSyncNow use");
|
|
|
|
|
const barSyncUseElement = document.querySelector("#toolbarSync use");
|
|
|
|
|
if (!data) {
|
|
|
|
|
if (!window.siyuan.config.sync.enabled || (0 === window.siyuan.config.sync.provider && needSubscribe(""))) {
|
|
|
|
|
menuSyncUseElement?.setAttribute("xlink:href", "#iconCloudOff");
|
|
|
|
|
barSyncUseElement.setAttribute("xlink:href", "#iconCloudOff");
|
|
|
|
|
} else {
|
|
|
|
|
menuSyncUseElement?.setAttribute("xlink:href", "#iconCloudSucc");
|
|
|
|
|
barSyncUseElement.setAttribute("xlink:href", "#iconCloudSucc");
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
menuSyncUseElement?.parentElement.classList.remove("fn__rotate");
|
|
|
|
|
barSyncUseElement.parentElement.classList.remove("fn__rotate");
|
|
|
|
|
if (data.code === 0) { // syncing
|
|
|
|
|
menuSyncUseElement?.parentElement.classList.add("fn__rotate");
|
|
|
|
|
barSyncUseElement.parentElement.classList.add("fn__rotate");
|
|
|
|
|
menuSyncUseElement?.setAttribute("xlink:href", "#iconRefresh");
|
|
|
|
|
barSyncUseElement.setAttribute("xlink:href", "#iconRefresh");
|
|
|
|
|
} else if (data.code === 2) { // error
|
|
|
|
|
menuSyncUseElement?.setAttribute("xlink:href", "#iconCloudError");
|
|
|
|
|
barSyncUseElement.setAttribute("xlink:href", "#iconCloudError");
|
|
|
|
|
} else if (data.code === 1) { // success
|
|
|
|
|
menuSyncUseElement?.setAttribute("xlink:href", "#iconCloudSucc");
|
|
|
|
|
barSyncUseElement.setAttribute("xlink:href", "#iconCloudSucc");
|
|
|
|
|
}
|
|
|
|
|
/// #else
|
|
|
|
|
const iconElement = document.querySelector("#barSync");
|
2023-01-24 15:05:25 +08:00
|
|
|
|
if (!iconElement) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-01-24 20:33:13 +08:00
|
|
|
|
const useElement = iconElement.querySelector("use");
|
2023-01-24 12:13:57 +08:00
|
|
|
|
if (!data) {
|
2023-01-25 23:01:16 +08:00
|
|
|
|
iconElement.classList.remove("toolbar__item--active");
|
2023-01-24 12:13:57 +08:00
|
|
|
|
if (!window.siyuan.config.sync.enabled || (0 === window.siyuan.config.sync.provider && needSubscribe(""))) {
|
2023-01-24 20:33:13 +08:00
|
|
|
|
useElement.setAttribute("xlink:href", "#iconCloudOff");
|
2023-01-24 12:13:57 +08:00
|
|
|
|
} else {
|
2023-01-24 20:33:13 +08:00
|
|
|
|
useElement.setAttribute("xlink:href", "#iconCloudSucc");
|
2023-01-24 12:13:57 +08:00
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-01-27 14:33:03 +08:00
|
|
|
|
iconElement.firstElementChild.classList.remove("fn__rotate");
|
2023-01-24 11:18:02 +08:00
|
|
|
|
if (data.code === 0) { // syncing
|
|
|
|
|
iconElement.classList.add("toolbar__item--active");
|
2023-01-27 14:33:03 +08:00
|
|
|
|
iconElement.firstElementChild.classList.add("fn__rotate");
|
|
|
|
|
useElement.setAttribute("xlink:href", "#iconRefresh");
|
2023-01-24 11:18:02 +08:00
|
|
|
|
} else if (data.code === 2) { // error
|
2023-01-24 17:39:27 +08:00
|
|
|
|
iconElement.classList.remove("toolbar__item--active");
|
2023-01-24 20:33:13 +08:00
|
|
|
|
useElement.setAttribute("xlink:href", "#iconCloudError");
|
2023-01-24 11:18:02 +08:00
|
|
|
|
} else if (data.code === 1) { // success
|
|
|
|
|
iconElement.classList.remove("toolbar__item--active");
|
2023-01-24 20:33:13 +08:00
|
|
|
|
useElement.setAttribute("xlink:href", "#iconCloudSucc");
|
2023-01-24 11:18:02 +08:00
|
|
|
|
}
|
2023-03-10 10:43:15 +08:00
|
|
|
|
/// #endif
|
2023-12-03 22:17:07 +08:00
|
|
|
|
plugins.forEach((item) => {
|
|
|
|
|
if (data.code === 0) {
|
|
|
|
|
item.eventBus.emit("sync-start", data);
|
|
|
|
|
} else if (data.code === 1) {
|
|
|
|
|
item.eventBus.emit("sync-end", data);
|
|
|
|
|
} else if (data.code === 2) {
|
|
|
|
|
item.eventBus.emit("sync-fail", data);
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-01-24 20:33:13 +08:00
|
|
|
|
};
|