mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-29 04:48:48 +01:00
This commit is contained in:
parent
da24409e96
commit
bf2d71fe78
1 changed files with 20 additions and 9 deletions
|
|
@ -1,10 +1,9 @@
|
|||
import {Constants} from "../constants";
|
||||
/// #if !MOBILE
|
||||
import {Tab} from "./Tab";
|
||||
import {exportLayout} from "./util";
|
||||
/// #endif
|
||||
import {processMessage} from "../util/processMessage";
|
||||
import {kernelError} from "../dialog/processSystem";
|
||||
import {kernelError, reloadSync} from "../dialog/processSystem";
|
||||
|
||||
export class Model {
|
||||
public ws: WebSocket;
|
||||
|
|
@ -17,13 +16,23 @@ export class Model {
|
|||
|
||||
/// #endif
|
||||
|
||||
constructor(options: { id: string, type?: TWS, callback?: () => void, msgCallback?: (data: IWebSocketData) => void }) {
|
||||
constructor(options: {
|
||||
id: string,
|
||||
type?: TWS,
|
||||
callback?: () => void,
|
||||
msgCallback?: (data: IWebSocketData) => void
|
||||
}) {
|
||||
if (options.msgCallback) {
|
||||
this.connect(options);
|
||||
}
|
||||
}
|
||||
|
||||
private connect(options: { id: string, type?: TWS, callback?: () => void, msgCallback?: (data: IWebSocketData) => void }) {
|
||||
private connect(options: {
|
||||
id: string,
|
||||
type?: TWS,
|
||||
callback?: () => void,
|
||||
msgCallback?: (data: IWebSocketData) => void
|
||||
}) {
|
||||
const websocketURL = `${window.location.protocol === "https:" ? "wss" : "ws"}://${window.location.host}/ws`;
|
||||
const ws = new WebSocket(`${websocketURL}?app=${Constants.SIYUAN_APPID}&id=${options.id}${options.type ? "&type=" + options.type : ""}`);
|
||||
ws.onopen = () => {
|
||||
|
|
@ -33,11 +42,13 @@ export class Model {
|
|||
const logElement = document.getElementById("errorLog");
|
||||
if (logElement) {
|
||||
// 内核中断后无法 catch fetch 请求错误,重连会导致无法执行 transactionsTimeout
|
||||
/// #if MOBILE
|
||||
window.location.reload();
|
||||
/// #else
|
||||
exportLayout(true);
|
||||
/// #endif
|
||||
reloadSync({upsertRootIDs: [], removeRootIDs: []});
|
||||
window.siyuan.dialogs.find(item =>{
|
||||
if (item.element.id === "errorLog") {
|
||||
item.destroy();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
ws.onmessage = (event) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue