diff --git a/app/src/dialog/processSystem.ts b/app/src/dialog/processSystem.ts index 7500fb97f..ba9073a2f 100644 --- a/app/src/dialog/processSystem.ts +++ b/app/src/dialog/processSystem.ts @@ -10,8 +10,8 @@ import {Dialog} from "./index"; import {isMobile} from "../util/functions"; import {confirmDialog} from "./confirmDialog"; import {getCurrentWindow} from "@electron/remote"; -import {getWorkspaceName} from "../menus/workspace"; import {escapeHtml} from "../util/escape"; +import {getWorkspaceName} from "../util/noRelyPCFunction"; export const lockScreen = () => { /// #if BROWSER @@ -278,13 +278,18 @@ export const setTitle = (title: string, protyle?: IProtyle) => { if (title === window.siyuan.languages.siyuanNote) { const versionTitle = `${title} - ${workspaceName} - v${Constants.SIYUAN_VERSION}`; document.title = versionTitle; - dragElement.textContent = versionTitle; - dragElement.setAttribute("title", versionTitle); + if (dragElement) { + dragElement.textContent = versionTitle; + dragElement.setAttribute("title", versionTitle); + } } else { title = title || "Untitled"; document.title = `${title} - ${workspaceName} - ${window.siyuan.languages.siyuanNote} v${Constants.SIYUAN_VERSION}`; + if (!dragElement) { + return; + } dragElement.setAttribute("title", title); - title = escapeHtml(title) + title = escapeHtml(title); if (protyle && protyle.disabled) { title = `${title}`; } @@ -297,7 +302,6 @@ export const setTitle = (title: string, protyle?: IProtyle) => { export const updateTitle = (readonly?: boolean, zoomIn?: boolean, zoomInId?: string) => { const dragElement = document.getElementById("drag"); - const title = dragElement.textContent; if (typeof readonly === "boolean") { const barExitReadOnlyElement = dragElement.querySelector("#barExitReadOnly") if (readonly && !barExitReadOnlyElement) { diff --git a/app/src/layout/dock/Tag.ts b/app/src/layout/dock/Tag.ts index fa9e67917..01bdd268a 100644 --- a/app/src/layout/dock/Tag.ts +++ b/app/src/layout/dock/Tag.ts @@ -8,7 +8,7 @@ import {openGlobalSearch} from "../../search/util"; import {MenuItem} from "../../menus/Menu"; import {confirmDialog} from "../../dialog/confirmDialog"; import {escapeHtml} from "../../util/escape"; -import {renameTag} from "./util"; +import {renameTag} from "../../util/noRelyPCFunction"; export class Tag extends Model { private openNodes: string[]; diff --git a/app/src/layout/dock/util.ts b/app/src/layout/dock/util.ts index 6a3dcc658..b948d3bda 100644 --- a/app/src/layout/dock/util.ts +++ b/app/src/layout/dock/util.ts @@ -87,28 +87,3 @@ export const openOutline = (protyle: IProtyle) => { newWnd.element.style.width = "200px"; switchWnd(newWnd, protyle.model.parent.parent); }; - -export const renameTag = (labelName: string) => { - const dialog = new Dialog({ - title: window.siyuan.languages.rename, - content: `
-
-
- -
`, - width: "520px", - }); - const btnsElement = dialog.element.querySelectorAll(".b3-button"); - btnsElement[0].addEventListener("click", () => { - dialog.destroy(); - }); - const inputElement = dialog.element.querySelector("input"); - dialog.bindInput(inputElement, () => { - (btnsElement[1] as HTMLButtonElement).click(); - }); - inputElement.focus(); - inputElement.select(); - btnsElement[1].addEventListener("click", () => { - fetchPost("/api/tag/renameTag", {oldLabel: labelName, newLabel: inputElement.value}); - }); -}; diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index ed83c0c10..1814d0141 100644 --- a/app/src/menus/protyle.ts +++ b/app/src/menus/protyle.ts @@ -32,8 +32,9 @@ import {getAllModels} from "../layout/getAll"; import {pasteAsPlainText, pasteText} from "../protyle/util/paste"; /// #if !MOBILE import {openFileById, updateBacklinkGraph} from "../editor/util"; +import {openGlobalSearch} from "../search/util"; /// #endif -import {isMobile} from "../util/functions"; +import {getSearch, isMobile} from "../util/functions"; import {removeFoldHeading} from "../protyle/util/heading"; import {lineNumberRender} from "../protyle/markdown/highlightRender"; import * as dayjs from "dayjs"; @@ -46,8 +47,7 @@ import {removeLink} from "../protyle/toolbar/Link"; import {alignImgCenter, alignImgLeft} from "../protyle/wysiwyg/commonHotkey"; import {getEnableHTML} from "../protyle/wysiwyg/removeEmbed"; import {updateTitle} from "../dialog/processSystem"; -import {renameTag} from "../layout/dock/util"; -import {openGlobalSearch} from "../search/util"; +import {renameTag} from "../util/noRelyPCFunction"; export const refMenu = (protyle: IProtyle, element: HTMLElement) => { const nodeElement = hasClosestBlock(element); @@ -948,6 +948,7 @@ export const tagMenu = (protyle: IProtyle, tagElement: HTMLElement) => { }); } }).element); + /// #if !MOBILE window.siyuan.menus.menu.append(new MenuItem({ label: window.siyuan.languages.search, accelerator: "Click", @@ -956,6 +957,7 @@ export const tagMenu = (protyle: IProtyle, tagElement: HTMLElement) => { openGlobalSearch(`#${tagElement.textContent}#`, false); } }).element); + /// #endif window.siyuan.menus.menu.append(new MenuItem({ label: `${window.siyuan.languages.turnInto} ${window.siyuan.languages.text}`, icon: "iconRefresh", @@ -1018,7 +1020,7 @@ export const iframeMenu = (protyle: IProtyle, nodeElement: Element) => { const biliMatch = value.match(/(?:www\.|\/\/)bilibili\.com\/video\/(\w+)/); if (value.indexOf("bilibili.com") > -1 && (value.indexOf("bvid=") > -1 || (biliMatch && biliMatch[1]))) { const params: IObject = { - bvid: value.indexOf("bvid=") > -1 ? value.split("bvid=")[1].split("&")[0] : (biliMatch && biliMatch[1]), + bvid: getSearch("bvid", value) || (biliMatch && biliMatch[1]), page: "1", high_quality: "1", as_wide: "1", diff --git a/app/src/menus/workspace.ts b/app/src/menus/workspace.ts index 45a0dcc0b..a6140a4aa 100644 --- a/app/src/menus/workspace.ts +++ b/app/src/menus/workspace.ts @@ -224,7 +224,3 @@ const workspaceItem = (item: IWorkspace) => { }; /// #endif }; - -export const getWorkspaceName = () => { - return window.siyuan.config.system.workspaceDir.replace(/^.*[\\\/]/, ""); -}; diff --git a/app/src/util/noRelyPCFunction.ts b/app/src/util/noRelyPCFunction.ts new file mode 100644 index 000000000..277f26c4b --- /dev/null +++ b/app/src/util/noRelyPCFunction.ts @@ -0,0 +1,33 @@ +import {Dialog} from "../dialog"; +import {fetchPost} from "./fetch"; +import {isMobile} from "./functions"; + +// 需独立出来,否则移动端引用的时候会引入 pc 端大量无用代码 +export const renameTag = (labelName: string) => { + const dialog = new Dialog({ + title: window.siyuan.languages.rename, + content: `
+
+
+ +
`, + width: isMobile() ? "80vw": "520px", + }); + const btnsElement = dialog.element.querySelectorAll(".b3-button"); + btnsElement[0].addEventListener("click", () => { + dialog.destroy(); + }); + const inputElement = dialog.element.querySelector("input"); + dialog.bindInput(inputElement, () => { + (btnsElement[1] as HTMLButtonElement).click(); + }); + inputElement.focus(); + inputElement.select(); + btnsElement[1].addEventListener("click", () => { + fetchPost("/api/tag/renameTag", {oldLabel: labelName, newLabel: inputElement.value}); + }); +}; + +export const getWorkspaceName = () => { + return window.siyuan.config.system.workspaceDir.replace(/^.*[\\\/]/, ""); +}; diff --git a/app/src/util/onGetConfig.ts b/app/src/util/onGetConfig.ts index 46be67a64..16049f06a 100644 --- a/app/src/util/onGetConfig.ts +++ b/app/src/util/onGetConfig.ts @@ -27,10 +27,11 @@ import {showMessage} from "../dialog/message"; import {editor} from "../config/editor"; import {goBack, goForward} from "./backForward"; import {replaceLocalPath} from "../editor/rename"; -import {getWorkspaceName, workspaceMenu} from "../menus/workspace"; +import {workspaceMenu} from "../menus/workspace"; import {Tab} from "../layout/Tab"; import {Editor} from "../editor"; import {zoomOut} from "../menus/protyle"; +import { getWorkspaceName } from "./noRelyPCFunction"; const matchKeymap = (keymap: Record, key1: "general" | "editor", key2?: "general" | "insert" | "heading" | "list" | "table") => { if (key1 === "general") { @@ -105,16 +106,7 @@ export const setProxy = () => { }); /// #endif }; -// 获取 location.search 里特定参数,失败返回false -function getUrlArg(arg_name: string) { - var query = window.location.search.substring(1); - var vars = query.split("&"); - for (var i=0;i { const matchKeymap1 = matchKeymap(Constants.SIYUAN_KEYMAP.general, "general"); const matchKeymap2 = matchKeymap(Constants.SIYUAN_KEYMAP.editor.general, "editor", "general"); @@ -188,18 +180,6 @@ export const onGetConfig = (isStart: boolean) => { mountHelp(); } addGA(); - //根据url里的id参数打开相应的块,用于浏览器访问 - let url_doc_id=getUrlArg("id") - if (url_doc_id) { - fetchPost("/api/block/getBlockInfo", {id: url_doc_id}, response => { - if (response.code === 0 && typeof url_doc_id === "string") { - openFileById({ - id: url_doc_id, - action: [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT,] - }) - } - }) - } }; const initBar = () => {