Skip to content

Commit

Permalink
feat(webview): 添加 使用新窗口打开思源编辑器 功能 | Add `Open SiYuan Editor in a ne…
Browse files Browse the repository at this point in the history
…w window` function.
  • Loading branch information
Zuoqiu-Yingyi committed May 27, 2023
1 parent 6f60f22 commit 009d4c4
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 19 deletions.
35 changes: 33 additions & 2 deletions public/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,37 @@
"title": "List of active URL schemes"
},
"shortcut": "Shortcut",
"siyuan": {
"editorType": {
"description": "The type of SiYuan editor that opens in a new window by default",
"options": {
"desktop": "Desktop Editor",
"mobile": "Mobile Editor"
},
"title": "Editor Type"
},
"enable": {
"description": "Open SiYuan Editor in a new window",
"title": "Enable"
},
"focus": {
"description": "Whether the SiYuan editor opened in a new window is focused by default",
"title": "Focus"
},
"open": {
"desktop": {
"description": "Open a window of SiYuan desktop editor",
"text": "Open",
"title": "Desktop Editor"
},
"mobile": {
"description": "Open a window of SiYuan mobile editor",
"text": "Open",
"title": "Mobile Editor"
}
},
"title": "SiYuan"
},
"window": {
"height": {
"description": "The default height of the new window",
Expand All @@ -62,9 +93,9 @@
"menuBar": {
"description": "The visible state of the menu bar",
"options": {
"alwaysShow": "Always Show",
"autoHide": "Auto Hide",
"disabled": "Disabled",
"alwaysShow": "Always Show"
"disabled": "Disabled"
},
"title": "Menu Bar"
},
Expand Down
41 changes: 36 additions & 5 deletions public/i18n/zh_CHT.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,37 @@
"title": "激活的 URL 協議列表"
},
"shortcut": "快捷鍵",
"siyuan": {
"editorType": {
"description": "默認在新窗口中打開的思源編輯器類型",
"options": {
"desktop": "桌面端編輯器",
"mobile": "移動端編輯器"
},
"title": "編輯器類型"
},
"enable": {
"description": "在新窗口中打開思源編輯器",
"title": "啟用"
},
"focus": {
"description": "在新窗口中打開的思源編輯器是否默認聚焦",
"title": "聚焦"
},
"open": {
"desktop": {
"description": "打開一個思源桌面端編輯器窗口",
"text": "打開",
"title": "桌面端編輯器"
},
"mobile": {
"description": "打開一個思源移動端編輯器窗口",
"text": "打開",
"title": "移動端編輯器"
}
},
"title": "思遠"
},
"window": {
"height": {
"description": "新窗口的默認高度",
Expand All @@ -62,19 +93,19 @@
"menuBar": {
"description": "菜單欄的可見狀態",
"options": {
"alwaysShow": "總是顯示",
"autoHide": "自動隱藏",
"disabled": "禁用",
"alwaysShow": "總是顯示"
"disabled": "禁用"
},
"title": "菜单栏"
"title": "菜單欄"
},
"top": {
"description": "打开的新窗口是否默认置顶",
"title": "窗口置顶"
"title": "窗口置頂"
},
"width": {
"description": "新窗口的默认宽度",
"title": "窗口宽度"
"title": "窗口寬度"
}
}
},
Expand Down
35 changes: 33 additions & 2 deletions public/i18n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,37 @@
"title": "激活的 URL 协议列表"
},
"shortcut": "快捷键",
"siyuan": {
"editorType": {
"description": "默认在新窗口中打开的思源编辑器类型",
"options": {
"desktop": "桌面端编辑器",
"mobile": "移动端编辑器"
},
"title": "编辑器类型"
},
"enable": {
"description": "在新窗口中打开思源编辑器",
"title": "启用"
},
"focus": {
"description": "在新窗口中打开的思源编辑器是否默认聚焦",
"title": "聚焦"
},
"open": {
"desktop": {
"description": "打开一个思源桌面端编辑器窗口",
"text": "打开",
"title": "桌面端编辑器"
},
"mobile": {
"description": "打开一个思源移动端编辑器窗口",
"text": "打开",
"title": "移动端编辑器"
}
},
"title": "思源"
},
"window": {
"height": {
"description": "新窗口的默认高度",
Expand All @@ -62,9 +93,9 @@
"menuBar": {
"description": "菜单栏的可见状态",
"options": {
"alwaysShow": "总是显示",
"autoHide": "自动隐藏",
"disabled": "禁用",
"alwaysShow": "总是显示"
"disabled": "禁用"
},
"title": "菜单栏"
},
Expand Down
97 changes: 97 additions & 0 deletions src/components/Settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import type { IConfig } from "@/types/config";
import type { I18N } from "@/utils/i18n";
import { MenuBarStatus } from "@/utils/window";
import { EditorType } from "~/../../packages/utils/siyuan";
export let config: IConfig; // 传入的配置项
export let plugin: InstanceType<typeof WebviewPlugin>; // 插件实例
Expand Down Expand Up @@ -68,6 +69,7 @@
general,
protocol,
shortcut,
siyuan,
}
let panels_focus_key = PanelKey.general;
Expand Down Expand Up @@ -114,6 +116,12 @@
name: i18n.settings.shortcut,
icon: "",
},
{
key: TabKey.siyuan,
text: i18n.settings.siyuan.title,
name: i18n.settings.siyuan.title,
icon: "📝",
},
] as ITab[],
};
</script>
Expand Down Expand Up @@ -466,6 +474,95 @@
on:changed={updated}
/>
</div>

<!-- 标签页 4 - 思源窗口设置 -->
<div
data-type={tabs.tab[3].name}
class:fn__none={tabs.tab[3].key !== focusTab}
>
<!-- 是否启用 -->
<Item
title={i18n.settings.siyuan.enable.title}
text={i18n.settings.siyuan.enable.description}
>
<Input
slot="input"
type={ItemType.checkbox}
settingKey="enable"
settingValue={config.window.siyuan.enable}
on:changed={e => {
config.window.siyuan.enable = e.detail.value;
updated();
}}
/>
</Item>

<!-- 打开一个桌面端编辑器 -->
<Item
title={i18n.settings.siyuan.open.desktop.title}
text={i18n.settings.siyuan.open.desktop.description}
>
<Input
slot="input"
type={ItemType.button}
settingKey="Reset"
settingValue={i18n.settings.siyuan.open.desktop.text}
on:clicked={e => plugin.openSiyuanDesktopWindow(e.detail.event)}
/>
</Item>

<!-- 打开一个移动端编辑器 -->
<Item
title={i18n.settings.siyuan.open.mobile.title}
text={i18n.settings.siyuan.open.mobile.description}
>
<Input
slot="input"
type={ItemType.button}
settingKey="Reset"
settingValue={i18n.settings.siyuan.open.mobile.text}
on:clicked={e => plugin.openSiyuanMobileWindow(e.detail.event)}
/>
</Item>

<!-- 是否默认聚焦 -->
<Item
title={i18n.settings.siyuan.focus.title}
text={i18n.settings.siyuan.focus.description}
>
<Input
slot="input"
type={ItemType.checkbox}
settingKey="focus"
settingValue={config.window.siyuan.focus}
on:changed={e => {
config.window.siyuan.focus = e.detail.value;
updated();
}}
/>
</Item>

<!-- 默认打开的思源编辑器 -->
<Item
title={i18n.settings.siyuan.editorType.title}
text={i18n.settings.siyuan.editorType.description}
>
<Input
slot="input"
type={ItemType.select}
settingKey="menuBar"
settingValue={config.window.siyuan.editorType}
on:changed={e => {
config.window.siyuan.editorType = e.detail.value;
updated();
}}
options={[
{ key: EditorType.mobile, text: i18n.settings.siyuan.editorType.options.mobile },
{ key: EditorType.desktop, text: i18n.settings.siyuan.editorType.options.desktop },
]}
/>
</Item>
</div>
</Tabs>
</Panel>
</Panels>
Expand Down
17 changes: 12 additions & 5 deletions src/configs/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
*/

import type { IConfig } from "@/types/config";

import { MouseButton } from "@workspace/utils/shortcut";
import { EditorType } from "@workspace/utils/siyuan";

/* 默认配置选项 */
export const DEFAULT_CONFIG: IConfig = {
Expand Down Expand Up @@ -96,10 +98,10 @@ export const DEFAULT_CONFIG: IConfig = {
}
},
protocols: {
// siyuan: {
// enable: true,
// prefix: "siyuan://",
// },
siyuan: {
enable: true,
prefix: "siyuan://",
},
https: {
enable: true,
prefix: "https://",
Expand Down Expand Up @@ -133,6 +135,11 @@ export const DEFAULT_CONFIG: IConfig = {
alwaysOnTop: true,
autoHideMenuBar: true,
enableMenuBar: true,
}
},
siyuan: {
enable: true,
focus: false,
editorType: EditorType.mobile,
},
},
};
3 changes: 1 addition & 2 deletions src/configs/menuTemplae.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export function createMenuTemplate(
) as Array<Electron.MenuItemConstructorOptions>,

{ role: "close" }, // 关闭
{ role: "quit" }, // 退出
];
const editMenu: Array<Electron.MenuItemConstructorOptions> = [ // 编辑菜单
{ role: "undo" }, // 撤销
Expand Down Expand Up @@ -103,7 +102,7 @@ export function createMenuTemplate(

{ type: "separator" },
{ role: "resetZoom" }, // 重置缩放
{ role: "zoomIn" }, // 放大
{ role: 'zoomIn', accelerator: 'CmdOrCtrl+=' }, // 放大
{ role: "zoomOut" }, // 缩小

...(isMacOS
Expand Down
Loading

0 comments on commit 009d4c4

Please sign in to comment.