From 62e35b5c520354a860cbb9aa8748a7eb8e858e4a Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 26 Jan 2023 22:52:22 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/2955 --- app/appearance/langs/en_US.json | 1 + app/appearance/langs/es_ES.json | 1 + app/appearance/langs/fr_FR.json | 1 + app/appearance/langs/zh_CHT.json | 3 ++- app/appearance/langs/zh_CN.json | 1 + app/src/assets/scss/base.scss | 12 ++++++++++ app/src/menus/tab.ts | 13 +++++++---- app/src/util/onGetConfig.ts | 2 +- app/src/{window.ts => window/index.ts} | 32 +++++++++++++------------- app/src/window/init.ts | 29 ++++++++--------------- app/src/window/setHeader.ts | 2 +- app/webpack.config.js | 2 +- 12 files changed, 55 insertions(+), 44 deletions(-) rename app/src/{window.ts => window/index.ts} (89%) diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json index c2acc177b..0e47b9c35 100644 --- a/app/appearance/langs/en_US.json +++ b/app/appearance/langs/en_US.json @@ -1,4 +1,5 @@ { + "tabToWindow": "Move Tab to New Window", "exitFocus": "Exit focus", "pointExchangeSize": "Point Exchange", "panel": "Panel", diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json index 8f6eb88d0..6924026a3 100644 --- a/app/appearance/langs/es_ES.json +++ b/app/appearance/langs/es_ES.json @@ -1,4 +1,5 @@ { + "tabToWindow": "Mover pestaña a nueva ventana", "exitFocus": "Salir del enfoque", "pointExchangeSize": "Intercambio de puntos", "panel": "Panel", diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json index 36fb2d97d..461468f07 100644 --- a/app/appearance/langs/fr_FR.json +++ b/app/appearance/langs/fr_FR.json @@ -1,4 +1,5 @@ { + "tabToWindow": "Déplacer l'onglet vers une nouvelle fenêtre", "exitFocus": "Quitter le focus", "pointExchangeSize": "Échange de points", "panel": "Panneau", diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json index ade184f41..3baffa7da 100644 --- a/app/appearance/langs/zh_CHT.json +++ b/app/appearance/langs/zh_CHT.json @@ -1,4 +1,5 @@ { + "tabToWindow": "移動頁簽到新窗口", "exitFocus": "退出聚焦", "pointExchangeSize": "積分兌換", "panel": "面板", @@ -1074,4 +1075,4 @@ "184": "由思源筆記強力驅動", "185": "索引校驗完畢" } -} \ No newline at end of file +} diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index 93a2c7183..4540ea8aa 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -1,4 +1,5 @@ { + "tabToWindow": "移动页签到新窗口", "exitFocus": "退出聚焦", "pointExchangeSize": "积分兑换", "panel": "面板", diff --git a/app/src/assets/scss/base.scss b/app/src/assets/scss/base.scss index 72e0f6d4c..4ed2d99d6 100644 --- a/app/src/assets/scss/base.scss +++ b/app/src/assets/scss/base.scss @@ -184,6 +184,18 @@ progressLoading: 400 padding-left: 0; } + &__window { + position: fixed; + top: 0; + right: 0; + display: flex; + z-index: 502; + + .toolbar__item { + padding: 14px; + } + } + #windowAppIcon { -webkit-app-region: drag; width: 42px; diff --git a/app/src/menus/tab.ts b/app/src/menus/tab.ts index a8a27b622..d0dbedb01 100644 --- a/app/src/menus/tab.ts +++ b/app/src/menus/tab.ts @@ -1,7 +1,7 @@ import {Tab} from "../layout/Tab"; import {MenuItem} from "./Menu"; import {Editor} from "../editor"; -import {copyTab} from "../layout/util"; +import {copyTab, layoutToJSON} from "../layout/util"; /// #if !BROWSER import {BrowserWindow} from "@electron/remote"; import * as path from "path"; @@ -168,7 +168,7 @@ export const initTabMenu = (tab: Tab) => { submenu: splitSubMenu(tab) }).element); const model = tab.model; - let rootId:string; + let rootId: string; if ((model && model instanceof Editor)) { rootId = model.editor.protyle.block.rootID; } else { @@ -205,10 +205,12 @@ export const initTabMenu = (tab: Tab) => { } /// #if !BROWSER window.siyuan.menus.menu.append(new MenuItem({ - label: "new window", + label: window.siyuan.languages.tabToWindow, + icon: "iconMove", click: () => { const win = new BrowserWindow({ show: true, + trafficLightPosition: {x: 8, y: 13}, width: 1032, height: 650, frame: "darwin" === window.siyuan.config.system.os, @@ -221,7 +223,10 @@ export const initTabMenu = (tab: Tab) => { webSecurity: false, }, }); - win.loadURL(`${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&id=${rootId}`) + const json = {} + layoutToJSON(tab, json) + win.loadURL(`${window.location.protocol}//${window.location.host}/stage/build/app/window.html?v=${Constants.SIYUAN_VERSION}&json=${JSON.stringify(json)}`) + tab.parent.removeTab(tab.id); } }).element); /// #endif diff --git a/app/src/util/onGetConfig.ts b/app/src/util/onGetConfig.ts index f2ac342b0..7d19e9c3b 100644 --- a/app/src/util/onGetConfig.ts +++ b/app/src/util/onGetConfig.ts @@ -518,7 +518,7 @@ export const initWindow = () => { `; if (isWindow()) { - document.body.insertAdjacentHTML("beforeend", `
${controlsHTML}
`) + document.body.insertAdjacentHTML("beforeend", `
${controlsHTML}
`) } else { document.getElementById("windowControls").innerHTML = controlsHTML; } diff --git a/app/src/window.ts b/app/src/window/index.ts similarity index 89% rename from app/src/window.ts rename to app/src/window/index.ts index 8d7dda027..e2ecc0ab9 100644 --- a/app/src/window.ts +++ b/app/src/window/index.ts @@ -1,13 +1,13 @@ -import {Constants} from "./constants"; -import {Menus} from "./menus"; -import {Model} from "./layout/Model"; -import "./assets/scss/base.scss"; -import {initBlockPopover} from "./block/popover"; -import {addScript, addScriptSync} from "./protyle/util/addScript"; -import {genUUID} from "./util/genID"; -import {fetchGet, fetchPost} from "./util/fetch"; -import {addBaseURL, setNoteBook} from "./util/pathName"; -import {openFileById} from "./editor/util"; +import {Constants} from "../constants"; +import {Menus} from "../menus"; +import {Model} from "../layout/Model"; +import "../assets/scss/base.scss"; +import {initBlockPopover} from "../block/popover"; +import {addScript, addScriptSync} from "../protyle/util/addScript"; +import {genUUID} from "../util/genID"; +import {fetchGet, fetchPost} from "../util/fetch"; +import {addBaseURL, setNoteBook} from "../util/pathName"; +import {openFileById} from "../editor/util"; import { downloadProgress, processSync, progressBackgroundTask, @@ -15,12 +15,12 @@ import { progressStatus, setTitle, transactionError -} from "./dialog/processSystem"; -import {promiseTransactions} from "./protyle/wysiwyg/transaction"; -import {initMessage} from "./dialog/message"; -import {getAllTabs} from "./layout/getAll"; -import {getLocalStorage} from "./protyle/util/compatibility"; -import {init} from "./window/init"; +} from "../dialog/processSystem"; +import {promiseTransactions} from "../protyle/wysiwyg/transaction"; +import {initMessage} from "../dialog/message"; +import {getAllTabs} from "../layout/getAll"; +import {getLocalStorage} from "../protyle/util/compatibility"; +import {init} from "../window/init"; class App { constructor() { diff --git a/app/src/window/init.ts b/app/src/window/init.ts index 603311c79..97c8b1f88 100644 --- a/app/src/window/init.ts +++ b/app/src/window/init.ts @@ -16,27 +16,16 @@ export const init = () => { globalShortcut(); fetchPost("/api/system/getEmojiConf", {}, response => { window.siyuan.emojis = response.data as IEmoji[]; - const id = getSearch("id"); + const tabJSON = JSON.parse(getSearch("json")); JSONToCenter({ - "direction": "lr", - "resize": "lr", - "size": "auto", - "type": "center", - "instance": "Layout", - "children": [{ - "instance": "Wnd", - "children": [{ - "instance": "Tab", - active: true, - docIcon: "1f389", - title: "请从这里开始", - "children": [{ - rootId: id, - blockId: id, - instance: "Editor", - mode: "wysiwyg" - }] - }] + direction: "lr", + resize: "lr", + size: "auto", + type: "center", + instance: "Layout", + children: [{ + instance: "Wnd", + children: [tabJSON] }] }); window.siyuan.layout.centerLayout = window.siyuan.layout.layout; diff --git a/app/src/window/setHeader.ts b/app/src/window/setHeader.ts index cc655475f..c954b7e88 100644 --- a/app/src/window/setHeader.ts +++ b/app/src/window/setHeader.ts @@ -39,7 +39,7 @@ export const setTabPosition = () => { } } else { if (rect.top <= 0 && rect.right >= window.innerWidth) { - (headerElement.lastElementChild as HTMLElement).style.paddingRight = (32 * 3) + "px"; + (headerElement.lastElementChild as HTMLElement).style.paddingRight = (42 * 3) + "px"; } else { (headerElement.lastElementChild as HTMLElement).style.paddingRight = ""; } diff --git a/app/webpack.config.js b/app/webpack.config.js index 1b031b1a6..876005720 100644 --- a/app/webpack.config.js +++ b/app/webpack.config.js @@ -19,7 +19,7 @@ module.exports = (env, argv) => { }, entry: { 'main': './src/index.ts', - 'window': './src/window.ts', + 'window': './src/window/index.ts', }, resolve: { extensions: ['.ts', '.js', '.tpl', '.scss', '.png', '.svg'],