Vanessa 2023-01-27 22:37:22 +08:00
parent 04f47749f7
commit 22a926946c
5 changed files with 23 additions and 3 deletions

View file

@ -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)
})

View file

@ -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";

View file

@ -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

View file

@ -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<string, IKeymapItem>, 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", {}, () => {

View file

@ -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",