2022-05-26 15:18:53 +08:00
|
|
|
|
import {addScript, addScriptSync} from "../protyle/util/addScript";
|
|
|
|
|
|
import {Constants} from "../constants";
|
|
|
|
|
|
import {onMessage} from "./util/onMessage";
|
|
|
|
|
|
import {genUUID} from "../util/genID";
|
|
|
|
|
|
import {hasClosestByAttribute} from "../protyle/util/hasClosest";
|
|
|
|
|
|
import {Model} from "../layout/Model";
|
|
|
|
|
|
import "../assets/scss/mobile.scss";
|
|
|
|
|
|
import {Menus} from "../menus";
|
2023-04-19 11:27:32 +08:00
|
|
|
|
import {addBaseURL, getIdFromSYProtocol, isSYProtocol, setNoteBook} from "../util/pathName";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {handleTouchEnd, handleTouchMove, handleTouchStart} from "./util/touch";
|
|
|
|
|
|
import {fetchGet, fetchPost} from "../util/fetch";
|
|
|
|
|
|
import {initFramework} from "./util/initFramework";
|
2022-10-30 09:37:46 +08:00
|
|
|
|
import {addGA, initAssets, loadAssets} from "../util/assets";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
import {bootSync} from "../dialog/processSystem";
|
2022-06-06 21:18:25 +08:00
|
|
|
|
import {initMessage} from "../dialog/message";
|
2022-08-23 11:55:40 +08:00
|
|
|
|
import {goBack} from "./util/MobileBackFoward";
|
2023-04-10 19:01:20 +08:00
|
|
|
|
import {hideKeyboardToolbar, showKeyboardToolbar} from "./util/keyboardToolbar";
|
2023-01-01 15:18:32 +08:00
|
|
|
|
import {getLocalStorage} from "../protyle/util/compatibility";
|
2023-01-22 17:34:16 +08:00
|
|
|
|
import {openMobileFileById} from "./editor";
|
2023-04-19 11:27:32 +08:00
|
|
|
|
import {getSearch} from "../util/functions";
|
2023-03-30 18:12:09 +08:00
|
|
|
|
import {initRightMenu} from "./menu";
|
2023-04-06 22:25:50 +08:00
|
|
|
|
import {openChangelog} from "../boot/openChangelog";
|
2023-04-19 15:43:24 +08:00
|
|
|
|
import {registerServiceWorker} from "../util/serviceWorker";
|
2023-05-26 17:03:35 +08:00
|
|
|
|
import {afterLoadPlugin, loadPlugins} from "../plugin/loader";
|
2023-07-04 12:24:02 +08:00
|
|
|
|
import {saveScroll} from "../protyle/scroll/saveScroll";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
|
|
|
|
|
class App {
|
2023-05-07 17:31:50 +08:00
|
|
|
|
public plugins: import("../plugin").Plugin[] = [];
|
|
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
|
constructor() {
|
2023-04-19 15:43:24 +08:00
|
|
|
|
if (!window.webkit?.messageHandlers && !window.JSAndroid) {
|
|
|
|
|
|
registerServiceWorker(`${Constants.SERVICE_WORKER_PATH}?v=${Constants.SIYUAN_VERSION}`);
|
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
addScriptSync(`${Constants.PROTYLE_CDN}/js/lute/lute.min.js?v=${Constants.SIYUAN_VERSION}`, "protyleLuteScript");
|
|
|
|
|
|
addScript(`${Constants.PROTYLE_CDN}/js/protyle-html.js?v=${Constants.SIYUAN_VERSION}`, "protyleWcHtmlScript");
|
|
|
|
|
|
addBaseURL();
|
|
|
|
|
|
window.siyuan = {
|
2023-09-02 11:13:47 +08:00
|
|
|
|
zIndex: 10,
|
2023-05-21 21:08:50 +08:00
|
|
|
|
notebooks: [],
|
2022-05-26 15:18:53 +08:00
|
|
|
|
transactions: [],
|
|
|
|
|
|
reqIds: {},
|
|
|
|
|
|
backStack: [],
|
|
|
|
|
|
dialogs: [],
|
|
|
|
|
|
blockPanels: [],
|
2023-01-19 20:31:14 +08:00
|
|
|
|
mobile: {},
|
2022-05-26 15:18:53 +08:00
|
|
|
|
ws: new Model({
|
2023-05-18 19:27:21 +08:00
|
|
|
|
app: this,
|
2022-05-26 15:18:53 +08:00
|
|
|
|
id: genUUID(),
|
|
|
|
|
|
type: "main",
|
2023-05-18 19:27:21 +08:00
|
|
|
|
msgCallback: (data) => {
|
2023-05-07 17:31:50 +08:00
|
|
|
|
this.plugins.forEach((plugin) => {
|
|
|
|
|
|
plugin.eventBus.emit("ws-main", data);
|
|
|
|
|
|
});
|
2023-05-18 19:27:21 +08:00
|
|
|
|
onMessage(this, data);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
};
|
|
|
|
|
|
// 不能使用 touchstart,否则会被 event.stopImmediatePropagation() 阻塞
|
|
|
|
|
|
window.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => {
|
|
|
|
|
|
if (!window.siyuan.menus.menu.element.contains(event.target) && !hasClosestByAttribute(event.target, "data-menu", "true")) {
|
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2023-07-04 12:24:02 +08:00
|
|
|
|
window.addEventListener("beforeunload", () => {
|
|
|
|
|
|
saveScroll(window.siyuan.mobile.editor.protyle);
|
|
|
|
|
|
}, false);
|
|
|
|
|
|
window.addEventListener("pagehide", () => {
|
|
|
|
|
|
saveScroll(window.siyuan.mobile.editor.protyle);
|
|
|
|
|
|
}, false);
|
2023-05-24 11:05:56 +08:00
|
|
|
|
fetchPost("/api/system/getConf", {}, async (confResponse) => {
|
2022-07-15 10:41:05 +08:00
|
|
|
|
confResponse.data.conf.keymap = Constants.SIYUAN_KEYMAP;
|
|
|
|
|
|
window.siyuan.config = confResponse.data.conf;
|
2023-05-24 11:05:56 +08:00
|
|
|
|
await loadPlugins(this);
|
2023-01-04 15:37:37 +08:00
|
|
|
|
getLocalStorage(() => {
|
|
|
|
|
|
fetchGet(`/appearance/langs/${window.siyuan.config.appearance.lang}.json?v=${Constants.SIYUAN_VERSION}`, (lauguages) => {
|
|
|
|
|
|
window.siyuan.languages = lauguages;
|
2023-05-18 19:27:21 +08:00
|
|
|
|
window.siyuan.menus = new Menus(this);
|
2023-01-04 15:37:37 +08:00
|
|
|
|
document.title = window.siyuan.languages.siyuanNote;
|
|
|
|
|
|
bootSync();
|
|
|
|
|
|
loadAssets(confResponse.data.conf.appearance);
|
|
|
|
|
|
initMessage();
|
|
|
|
|
|
initAssets();
|
2023-01-19 11:49:31 +08:00
|
|
|
|
fetchPost("/api/setting/getCloudUser", {}, userResponse => {
|
|
|
|
|
|
window.siyuan.user = userResponse.data;
|
|
|
|
|
|
fetchPost("/api/system/getEmojiConf", {}, emojiResponse => {
|
|
|
|
|
|
window.siyuan.emojis = emojiResponse.data as IEmoji[];
|
2023-05-21 21:08:50 +08:00
|
|
|
|
setNoteBook(() => {
|
|
|
|
|
|
initFramework(this);
|
|
|
|
|
|
initRightMenu(this);
|
|
|
|
|
|
openChangelog();
|
2023-05-26 17:03:35 +08:00
|
|
|
|
this.plugins.forEach(item => {
|
|
|
|
|
|
afterLoadPlugin(item);
|
|
|
|
|
|
});
|
2023-05-21 21:08:50 +08:00
|
|
|
|
});
|
2023-01-19 11:49:31 +08:00
|
|
|
|
});
|
2023-01-04 15:37:37 +08:00
|
|
|
|
});
|
|
|
|
|
|
addGA();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
|
|
|
|
|
});
|
2023-03-30 18:12:09 +08:00
|
|
|
|
document.addEventListener("touchstart", handleTouchStart, false);
|
|
|
|
|
|
document.addEventListener("touchmove", handleTouchMove, false);
|
2023-05-18 19:27:21 +08:00
|
|
|
|
document.addEventListener("touchend", (event) => {
|
2023-06-01 20:50:49 +08:00
|
|
|
|
handleTouchEnd(event);
|
2023-05-18 19:27:21 +08:00
|
|
|
|
}, false);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-05-07 17:31:50 +08:00
|
|
|
|
const siyuanApp = new App();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
2023-06-03 11:52:28 +08:00
|
|
|
|
// https://github.com/siyuan-note/siyuan/issues/8441
|
|
|
|
|
|
window.reconnectWebSocket = () => {
|
2023-06-03 12:01:31 +08:00
|
|
|
|
window.siyuan.ws.send("ping", {});
|
|
|
|
|
|
window.siyuan.mobile.files.send("ping", {});
|
|
|
|
|
|
window.siyuan.mobile.editor.protyle.ws.send("ping", {});
|
|
|
|
|
|
window.siyuan.mobile.popEditor.protyle.ws.send("ping", {});
|
2023-06-03 11:52:28 +08:00
|
|
|
|
};
|
2023-06-01 20:50:49 +08:00
|
|
|
|
window.goBack = goBack;
|
2023-04-10 12:00:51 +08:00
|
|
|
|
window.showKeyboardToolbar = (height) => {
|
|
|
|
|
|
document.getElementById("keyboardToolbar").setAttribute("data-keyboardheight", (height ? height : window.innerHeight / 2 - 42).toString());
|
2023-04-10 19:01:20 +08:00
|
|
|
|
showKeyboardToolbar();
|
2023-04-10 12:00:51 +08:00
|
|
|
|
};
|
2022-10-06 17:30:43 +08:00
|
|
|
|
window.hideKeyboardToolbar = hideKeyboardToolbar;
|
2023-01-22 17:34:16 +08:00
|
|
|
|
window.openFileByURL = (openURL) => {
|
2023-04-19 11:27:32 +08:00
|
|
|
|
if (openURL && isSYProtocol(openURL)) {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
openMobileFileById(siyuanApp, getIdFromSYProtocol(openURL),
|
2023-01-22 17:34:16 +08:00
|
|
|
|
getSearch("focus", openURL) === "1" ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT]);
|
2023-01-24 20:33:13 +08:00
|
|
|
|
return true;
|
2023-01-22 17:34:16 +08:00
|
|
|
|
}
|
2023-01-24 20:33:13 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
};
|