diff --git a/app/electron/main.js b/app/electron/main.js index 47105e224..1c82199d9 100644 --- a/app/electron/main.js +++ b/app/electron/main.js @@ -670,6 +670,11 @@ app.whenReady().then(() => { } }) }) + ipcMain.on('siyuan-closetab', (event, data) => { + BrowserWindow.getAllWindows().forEach(item => { + item.webContents.send('siyuan-closetab', data) + }) + }) ipcMain.on('siyuan-export-pdf', (event, data) => { BrowserWindow.fromId(data.id).webContents.send('siyuan-export-pdf', data) }) diff --git a/app/src/constants.ts b/app/src/constants.ts index b48d551b5..fa68e68c4 100644 --- a/app/src/constants.ts +++ b/app/src/constants.ts @@ -29,6 +29,7 @@ export abstract class Constants { public static readonly SIYUAN_HOTKEY: string = "siyuan-hotkey"; public static readonly SIYUAN_INIT: string = "siyuan-init"; public static readonly SIYUAN_OPENURL: string = "siyuan-openurl"; + public static readonly SIYUAN_CLOSETAB: string = "siyuan-closetab"; public static readonly SIYUAN_SAVE_CLOSE: string = "siyuan-save-close"; public static readonly SIYUAN_EXPORT_PDF: string = "siyuan-export-pdf"; public static readonly SIYUAN_EXPORT_CLOSE: string = "siyuan-export-close"; diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.ts index 261ea654e..e63ab4ada 100644 --- a/app/src/layout/Wnd.ts +++ b/app/src/layout/Wnd.ts @@ -15,7 +15,7 @@ import {Graph} from "./dock/Graph"; import {hasClosestByAttribute, hasClosestByClassName, hasClosestByTag} from "../protyle/util/hasClosest"; import {Constants} from "../constants"; /// #if !BROWSER -import {webFrame} from "electron"; +import {webFrame, ipcRenderer} from "electron"; import {getCurrentWindow} from "@electron/remote"; import {setTabPosition} from "../window/setHeader"; /// #endif @@ -298,9 +298,15 @@ export class Wnd { const targetWnd = getInstanceById(targetWndElement.getAttribute("data-id")) as Wnd; const tabId = event.dataTransfer.getData(Constants.SIYUAN_DROP_TAB); let oldTab = getInstanceById(tabId) as Tab; - if (isWindow() && !oldTab) { // 从主窗口拖拽到页签新窗口 + /// #if !BROWSER + if (!oldTab) { // 从主窗口拖拽到页签新窗口 JSONToCenter(JSON.parse(event.dataTransfer.getData(Constants.SIYUAN_DROP_TABTOWINDOW)), this); oldTab = this.children[this.children.length - 1]; + ipcRenderer.send(Constants.SIYUAN_CLOSETAB, tabId); + } + /// #endif + if (!oldTab) { + return; } if (oldTab.model instanceof Asset) { // https://github.com/siyuan-note/siyuan/issues/6890 diff --git a/app/src/util/onGetConfig.ts b/app/src/util/onGetConfig.ts index b425acfd9..a2ad776ab 100644 --- a/app/src/util/onGetConfig.ts +++ b/app/src/util/onGetConfig.ts @@ -1,5 +1,5 @@ import {openSearch} from "../search/spread"; -import {exportLayout, JSONToLayout, resetLayout, resizeDrag, resizeTabs} from "../layout/util"; +import {exportLayout, getInstanceById, JSONToLayout, resetLayout, resizeDrag, resizeTabs} from "../layout/util"; import {hotKey2Electron, setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility"; /// #if !BROWSER import {dialog, getCurrentWindow} from "@electron/remote"; @@ -30,6 +30,7 @@ import {replaceLocalPath} from "../editor/rename"; import {workspaceMenu} from "../menus/workspace"; import {getWorkspaceName} from "./noRelyPCFunction"; import {setTabPosition} from "../window/setHeader"; +import { Tab } from "../layout/Tab"; const matchKeymap = (keymap: Record, key1: "general" | "editor", key2?: "general" | "insert" | "heading" | "list" | "table") => { if (key1 === "general") { @@ -355,6 +356,12 @@ export const initWindow = () => { winOnClose(currentWindow, close); }); } + ipcRenderer.on(Constants.SIYUAN_CLOSETAB, (e, ipcData) => { + const tab = getInstanceById(ipcData); + if (tab && tab instanceof Tab) { + tab.parent.removeTab(ipcData); + } + }); ipcRenderer.on(Constants.SIYUAN_LOCK_SCREEN, () => { exportLayout(false, () => { fetchPost("/api/system/logoutAuth", {}, () => { diff --git a/app/src/window/init.ts b/app/src/window/init.ts index 4a5851457..c5d956684 100644 --- a/app/src/window/init.ts +++ b/app/src/window/init.ts @@ -16,6 +16,7 @@ export const init = () => { fetchPost("/api/system/getEmojiConf", {}, response => { window.siyuan.emojis = response.data as IEmoji[]; const tabJSON = JSON.parse(getSearch("json")); + tabJSON.active = true; JSONToCenter({ direction: "lr", resize: "lr",