diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts index f28aeea7b..1c374064d 100644 --- a/app/src/boot/globalEvent/keydown.ts +++ b/app/src/boot/globalEvent/keydown.ts @@ -1265,7 +1265,7 @@ export const windowKeyDown = (app: App, event: KeyboardEvent) => { return; } if (!isTabWindow && matchHotKey(window.siyuan.config.keymap.general.dailyNote.custom, event)) { - newDailyNote(); + newDailyNote(app); event.stopPropagation(); event.preventDefault(); return; diff --git a/app/src/index.ts b/app/src/index.ts index 81905ee57..04892f017 100644 --- a/app/src/index.ts +++ b/app/src/index.ts @@ -135,9 +135,6 @@ export class App { (document.getElementById("themeDefaultStyle") as HTMLLinkElement).href = data.data.theme; } break; - case "createdailynote": - openFileById({app: this, id: data.data.id, action: [Constants.CB_GET_FOCUS]}); - break; case "openFileById": openFileById({app: this, id: data.data.id, action: [Constants.CB_GET_FOCUS]}); break; diff --git a/app/src/menus/workspace.ts b/app/src/menus/workspace.ts index c03ab6172..8f6f6d5fd 100644 --- a/app/src/menus/workspace.ts +++ b/app/src/menus/workspace.ts @@ -4,7 +4,7 @@ import {ipcRenderer} from "electron"; /// #endif import {openHistory} from "../history/history"; import {getOpenNotebookCount, originalPath, pathPosix, showFileInFolder} from "../util/pathName"; -import {mountHelp, newDailyNote} from "../util/mount"; +import {fetchNewDailyNote, mountHelp, newDailyNote} from "../util/mount"; import {fetchPost} from "../util/fetch"; import {Constants} from "../constants"; import {isInAndroid, isInIOS, setStorageVal, writeText} from "../protyle/util/compatibility"; @@ -324,7 +324,7 @@ export const workspaceMenu = (app: App, rect: DOMRect) => { icon: "iconCalendar", accelerator: window.siyuan.config.keymap.general.dailyNote.custom, click: () => { - newDailyNote(); + newDailyNote(app); } }).element); } else { @@ -336,10 +336,7 @@ export const workspaceMenu = (app: App, rect: DOMRect) => { iconHTML: unicode2Emoji(item.icon || Constants.SIYUAN_IMAGE_NOTE, "b3-menu__icon", true), accelerator: window.siyuan.storage[Constants.LOCAL_DAILYNOTEID] === item.id ? window.siyuan.config.keymap.general.dailyNote.custom : "", click: () => { - fetchPost("/api/filetree/createDailyNote", { - notebook: item.id, - app: Constants.SIYUAN_APPID, - }); + fetchNewDailyNote(app, item.id); window.siyuan.storage[Constants.LOCAL_DAILYNOTEID] = item.id; setStorageVal(Constants.LOCAL_DAILYNOTEID, window.siyuan.storage[Constants.LOCAL_DAILYNOTEID]); } diff --git a/app/src/mobile/menu/index.ts b/app/src/mobile/menu/index.ts index d4f0f1f5c..61a637578 100644 --- a/app/src/mobile/menu/index.ts +++ b/app/src/mobile/menu/index.ts @@ -161,7 +161,7 @@ export const initRightMenu = (app: App) => { event.stopPropagation(); break; } else if (target.id === "menuNewDaily") { - newDailyNote(); + newDailyNote(app); closePanel(); event.preventDefault(); event.stopPropagation(); diff --git a/app/src/mobile/util/onMessage.ts b/app/src/mobile/util/onMessage.ts index bda2ee437..0ff780166 100644 --- a/app/src/mobile/util/onMessage.ts +++ b/app/src/mobile/util/onMessage.ts @@ -21,9 +21,6 @@ export const onMessage = (app: App, data: IWebSocketData) => { document.getElementById("toolbarSync").classList.add("fn__none"); } break; - case "createdailynote": - openMobileFileById(app, data.data.id); - break; case "openFileById": openMobileFileById(app, data.data.id, [Constants.CB_GET_FOCUS]); break; diff --git a/app/src/util/mount.ts b/app/src/util/mount.ts index 429ebe8d3..f8c82414f 100644 --- a/app/src/util/mount.ts +++ b/app/src/util/mount.ts @@ -6,8 +6,24 @@ import {Dialog} from "../dialog"; import {getOpenNotebookCount} from "./pathName"; import {validateName} from "../editor/rename"; import {setStorageVal} from "../protyle/util/compatibility"; +import {openFileById} from "../editor/util"; +import {openMobileFileById} from "../mobile/editor"; +import {App} from "../index"; -export const newDailyNote = () => { +export const fetchNewDailyNote = (app: App, notebook: string) => { + fetchPost("/api/filetree/createDailyNote", { + notebook, + app: Constants.SIYUAN_APPID, + }, (response) => { + /// #if MOBILE + openMobileFileById(app, response.data.id); + /// #else + openFileById({app, id: response.data.id, action: [Constants.CB_GET_FOCUS]}); + /// #endif + }); +}; + +export const newDailyNote = (app: App) => { const exit = window.siyuan.dialogs.find(item => { if (item.element.getAttribute("data-key") === window.siyuan.config.keymap.general.dailyNote.custom) { item.destroy(); @@ -29,10 +45,7 @@ export const newDailyNote = () => { notebookId = item.id; } }); - fetchPost("/api/filetree/createDailyNote", { - notebook: notebookId, - app: Constants.SIYUAN_APPID, - }); + fetchNewDailyNote(app, notebookId); return; } const localNotebookId = window.siyuan.storage[Constants.LOCAL_DAILYNOTEID]; @@ -42,10 +55,7 @@ export const newDailyNote = () => { } }); if (localNotebookId && localNotebookIsOpen && !isMobile()) { - fetchPost("/api/filetree/createDailyNote", { - notebook: localNotebookId, - app: Constants.SIYUAN_APPID, - }); + fetchNewDailyNote(app, localNotebookId); } else { let optionsHTML = ""; window.siyuan.notebooks.forEach(item => { @@ -75,10 +85,7 @@ export const newDailyNote = () => { const notebook = selectElement.value; window.siyuan.storage[Constants.LOCAL_DAILYNOTEID] = notebook; setStorageVal(Constants.LOCAL_DAILYNOTEID, window.siyuan.storage[Constants.LOCAL_DAILYNOTEID]); - fetchPost("/api/filetree/createDailyNote", { - notebook, - app: Constants.SIYUAN_APPID, - }); + fetchNewDailyNote(app, notebook); dialog.destroy(); }); } diff --git a/app/src/window/index.ts b/app/src/window/index.ts index 7c5228bac..45ce18446 100644 --- a/app/src/window/index.ts +++ b/app/src/window/index.ts @@ -117,9 +117,6 @@ class App { (document.getElementById("themeDefaultStyle") as HTMLLinkElement).href = data.data.theme; } break; - case "createdailynote": - openFileById({app: this, id: data.data.id, action: [Constants.CB_GET_FOCUS]}); - break; case "openFileById": openFileById({app: this, id: data.data.id, action: [Constants.CB_GET_FOCUS]}); break;