Compare commits
2 Commits
d5a0b07f2a
...
7f97b4a937
Author | SHA1 | Date | |
---|---|---|---|
7f97b4a937 | |||
8522a47b5f |
@@ -360,6 +360,11 @@ export class GeneralConfig {
|
|||||||
*/
|
*/
|
||||||
"dataPath": string;
|
"dataPath": string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否启用系统托盘
|
||||||
|
*/
|
||||||
|
"enableSystemTray": boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局热键设置
|
* 全局热键设置
|
||||||
* 是否启用全局热键
|
* 是否启用全局热键
|
||||||
@@ -379,6 +384,9 @@ export class GeneralConfig {
|
|||||||
if (!("dataPath" in $$source)) {
|
if (!("dataPath" in $$source)) {
|
||||||
this["dataPath"] = "";
|
this["dataPath"] = "";
|
||||||
}
|
}
|
||||||
|
if (!("enableSystemTray" in $$source)) {
|
||||||
|
this["enableSystemTray"] = false;
|
||||||
|
}
|
||||||
if (!("enableGlobalHotkey" in $$source)) {
|
if (!("enableGlobalHotkey" in $$source)) {
|
||||||
this["enableGlobalHotkey"] = false;
|
this["enableGlobalHotkey"] = false;
|
||||||
}
|
}
|
||||||
@@ -393,10 +401,10 @@ export class GeneralConfig {
|
|||||||
* Creates a new GeneralConfig instance from a string or object.
|
* Creates a new GeneralConfig instance from a string or object.
|
||||||
*/
|
*/
|
||||||
static createFrom($$source: any = {}): GeneralConfig {
|
static createFrom($$source: any = {}): GeneralConfig {
|
||||||
const $$createField3_0 = $$createType7;
|
const $$createField4_0 = $$createType7;
|
||||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||||
if ("globalHotkey" in $$parsedSource) {
|
if ("globalHotkey" in $$parsedSource) {
|
||||||
$$parsedSource["globalHotkey"] = $$createField3_0($$parsedSource["globalHotkey"]);
|
$$parsedSource["globalHotkey"] = $$createField4_0($$parsedSource["globalHotkey"]);
|
||||||
}
|
}
|
||||||
return new GeneralConfig($$parsedSource as Partial<GeneralConfig>);
|
return new GeneralConfig($$parsedSource as Partial<GeneralConfig>);
|
||||||
}
|
}
|
||||||
|
@@ -7,13 +7,15 @@ import * as DocumentService from "./documentservice.js";
|
|||||||
import * as HotkeyService from "./hotkeyservice.js";
|
import * as HotkeyService from "./hotkeyservice.js";
|
||||||
import * as MigrationService from "./migrationservice.js";
|
import * as MigrationService from "./migrationservice.js";
|
||||||
import * as SystemService from "./systemservice.js";
|
import * as SystemService from "./systemservice.js";
|
||||||
|
import * as TrayService from "./trayservice.js";
|
||||||
export {
|
export {
|
||||||
ConfigService,
|
ConfigService,
|
||||||
DialogService,
|
DialogService,
|
||||||
DocumentService,
|
DocumentService,
|
||||||
HotkeyService,
|
HotkeyService,
|
||||||
MigrationService,
|
MigrationService,
|
||||||
SystemService
|
SystemService,
|
||||||
|
TrayService
|
||||||
};
|
};
|
||||||
|
|
||||||
export * from "./models.js";
|
export * from "./models.js";
|
||||||
|
63
frontend/bindings/voidraft/internal/services/trayservice.ts
Normal file
63
frontend/bindings/voidraft/internal/services/trayservice.ts
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||||
|
// This file is automatically generated. DO NOT EDIT
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TrayService 系统托盘服务
|
||||||
|
* @module
|
||||||
|
*/
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore: Unused imports
|
||||||
|
import {Call as $Call, Create as $Create} from "@wailsio/runtime";
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||||
|
// @ts-ignore: Unused imports
|
||||||
|
import * as application$0 from "../../../github.com/wailsapp/wails/v3/pkg/application/models.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HandleWindowClose 处理窗口关闭事件
|
||||||
|
*/
|
||||||
|
export function HandleWindowClose(): Promise<void> & { cancel(): void } {
|
||||||
|
let $resultPromise = $Call.ByID(1824247204) as any;
|
||||||
|
return $resultPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HandleWindowMinimize 处理窗口最小化事件
|
||||||
|
*/
|
||||||
|
export function HandleWindowMinimize(): Promise<void> & { cancel(): void } {
|
||||||
|
let $resultPromise = $Call.ByID(178686624) as any;
|
||||||
|
return $resultPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MinimizeButtonClicked 处理标题栏最小化按钮点击
|
||||||
|
*/
|
||||||
|
export function MinimizeButtonClicked(): Promise<void> & { cancel(): void } {
|
||||||
|
let $resultPromise = $Call.ByID(2477618539) as any;
|
||||||
|
return $resultPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SetAppReferences 设置应用引用
|
||||||
|
*/
|
||||||
|
export function SetAppReferences(app: application$0.App | null, mainWindow: application$0.WebviewWindow | null): Promise<void> & { cancel(): void } {
|
||||||
|
let $resultPromise = $Call.ByID(3544515719, app, mainWindow) as any;
|
||||||
|
return $resultPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ShouldMinimizeToTray 检查是否应该最小化到托盘
|
||||||
|
*/
|
||||||
|
export function ShouldMinimizeToTray(): Promise<boolean> & { cancel(): void } {
|
||||||
|
let $resultPromise = $Call.ByID(3403884012) as any;
|
||||||
|
return $resultPromise;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ShowWindow 显示主窗口
|
||||||
|
*/
|
||||||
|
export function ShowWindow(): Promise<void> & { cancel(): void } {
|
||||||
|
let $resultPromise = $Call.ByID(1315913255) as any;
|
||||||
|
return $resultPromise;
|
||||||
|
}
|
1
frontend/components.d.ts
vendored
1
frontend/components.d.ts
vendored
@@ -12,5 +12,6 @@ declare module 'vue' {
|
|||||||
RouterLink: typeof import('vue-router')['RouterLink']
|
RouterLink: typeof import('vue-router')['RouterLink']
|
||||||
RouterView: typeof import('vue-router')['RouterView']
|
RouterView: typeof import('vue-router')['RouterView']
|
||||||
Toolbar: typeof import('./src/components/toolbar/Toolbar.vue')['default']
|
Toolbar: typeof import('./src/components/toolbar/Toolbar.vue')['default']
|
||||||
|
WindowTitleBar: typeof import('./src/components/titlebar/WindowTitleBar.vue')['default']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted } from 'vue';
|
import { onMounted } from 'vue';
|
||||||
import { useConfigStore } from '@/stores/configStore';
|
import { useConfigStore } from '@/stores/configStore';
|
||||||
|
import WindowTitleBar from '@/components/titlebar/WindowTitleBar.vue';
|
||||||
|
|
||||||
const configStore = useConfigStore();
|
const configStore = useConfigStore();
|
||||||
|
|
||||||
@@ -14,7 +15,10 @@ onMounted(async () => {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<router-view/>
|
<WindowTitleBar />
|
||||||
|
<div class="app-content">
|
||||||
|
<router-view/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -24,5 +28,14 @@ onMounted(async () => {
|
|||||||
height: 100vh;
|
height: 100vh;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-content {
|
||||||
|
flex: 1;
|
||||||
|
margin-top: 32px;
|
||||||
|
overflow: hidden;
|
||||||
|
position: relative;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
247
frontend/src/components/titlebar/WindowTitleBar.vue
Normal file
247
frontend/src/components/titlebar/WindowTitleBar.vue
Normal file
@@ -0,0 +1,247 @@
|
|||||||
|
<template>
|
||||||
|
<div class="windows-titlebar" style="--wails-draggable:drag" @contextmenu.prevent @mouseenter="checkMaximizedState" @mouseup="checkMaximizedState">
|
||||||
|
<div class="titlebar-content" @dblclick="toggleMaximize" @contextmenu.prevent>
|
||||||
|
<div class="titlebar-icon">
|
||||||
|
<img src="/appicon.png" alt="voidraft" />
|
||||||
|
</div>
|
||||||
|
<div class="titlebar-title">voidraft</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="titlebar-controls" style="--wails-draggable:no-drag" @contextmenu.prevent>
|
||||||
|
<button
|
||||||
|
class="titlebar-button minimize-button"
|
||||||
|
@click="minimizeWindow"
|
||||||
|
:title="t('titlebar.minimize')"
|
||||||
|
>
|
||||||
|
<span class="titlebar-icon"></span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
class="titlebar-button maximize-button"
|
||||||
|
@click="toggleMaximize"
|
||||||
|
:title="isMaximized ? t('titlebar.restore') : t('titlebar.maximize')"
|
||||||
|
>
|
||||||
|
<span class="titlebar-icon" v-html="maximizeIcon"></span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
class="titlebar-button close-button"
|
||||||
|
@click="closeWindow"
|
||||||
|
:title="t('titlebar.close')"
|
||||||
|
>
|
||||||
|
<span class="titlebar-icon"></span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, onMounted, onUnmounted, computed } from 'vue';
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import * as runtime from '@wailsio/runtime';
|
||||||
|
|
||||||
|
const { t } = useI18n();
|
||||||
|
const isMaximized = ref(false);
|
||||||
|
|
||||||
|
// 计算属性用于图标,减少重复渲染
|
||||||
|
const maximizeIcon = computed(() => isMaximized.value ? '' : '');
|
||||||
|
|
||||||
|
const minimizeWindow = async () => {
|
||||||
|
try {
|
||||||
|
await runtime.Window.Minimise();
|
||||||
|
} catch (error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const toggleMaximize = async () => {
|
||||||
|
try {
|
||||||
|
// 立即更新UI状态,提供即时反馈
|
||||||
|
const newState = !isMaximized.value;
|
||||||
|
isMaximized.value = newState;
|
||||||
|
|
||||||
|
// 然后执行实际操作
|
||||||
|
if (newState) {
|
||||||
|
await runtime.Window.Maximise();
|
||||||
|
} else {
|
||||||
|
await runtime.Window.UnMaximise();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 操作完成后再次确认状态(防止操作失败时状态不一致)
|
||||||
|
setTimeout(async () => {
|
||||||
|
await checkMaximizedState();
|
||||||
|
}, 100);
|
||||||
|
} catch (error) {
|
||||||
|
// 如果操作失败,恢复原状态
|
||||||
|
isMaximized.value = !isMaximized.value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const closeWindow = async () => {
|
||||||
|
try {
|
||||||
|
// 使用Window的Close方法,会触发窗口关闭事件
|
||||||
|
await runtime.Window.Close();
|
||||||
|
} catch (error) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkMaximizedState = async () => {
|
||||||
|
try {
|
||||||
|
isMaximized.value = await runtime.Window.IsMaximised();
|
||||||
|
} catch (error) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
// 检查初始最大化状态
|
||||||
|
await checkMaximizedState();
|
||||||
|
|
||||||
|
// 监听窗口状态变化事件
|
||||||
|
runtime.Events.On('window:maximised', () => {
|
||||||
|
isMaximized.value = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
runtime.Events.On('window:unmaximised', () => {
|
||||||
|
isMaximized.value = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 监听窗口焦点事件,确保状态同步
|
||||||
|
runtime.Events.On('window:focus', async () => {
|
||||||
|
await checkMaximizedState();
|
||||||
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
// 清理事件监听器
|
||||||
|
runtime.Events.Off('window:maximised');
|
||||||
|
runtime.Events.Off('window:unmaximised');
|
||||||
|
runtime.Events.Off('window:focus');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.windows-titlebar {
|
||||||
|
display: flex;
|
||||||
|
height: 32px;
|
||||||
|
background: #202020;
|
||||||
|
user-select: none;
|
||||||
|
-webkit-user-select: none;
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
z-index: 1000;
|
||||||
|
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
|
||||||
|
|
||||||
|
/* 禁用右键菜单 */
|
||||||
|
-webkit-context-menu: none;
|
||||||
|
-moz-context-menu: none;
|
||||||
|
context-menu: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.titlebar-content {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex: 1;
|
||||||
|
padding-left: 8px;
|
||||||
|
gap: 8px;
|
||||||
|
color: #ffffff;
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 400;
|
||||||
|
cursor: default;
|
||||||
|
|
||||||
|
/* 禁用右键菜单 */
|
||||||
|
-webkit-context-menu: none;
|
||||||
|
-moz-context-menu: none;
|
||||||
|
context-menu: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.titlebar-content .titlebar-icon {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
|
||||||
|
img {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: contain;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.titlebar-title {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.titlebar-controls {
|
||||||
|
display: flex;
|
||||||
|
height: 100%;
|
||||||
|
|
||||||
|
/* 禁用右键菜单 */
|
||||||
|
-webkit-context-menu: none;
|
||||||
|
-moz-context-menu: none;
|
||||||
|
context-menu: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.titlebar-button {
|
||||||
|
width: 46px;
|
||||||
|
height: 32px;
|
||||||
|
border: none;
|
||||||
|
background: transparent;
|
||||||
|
color: #ffffff;
|
||||||
|
cursor: pointer;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
transition: background-color 0.1s ease;
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.0605);
|
||||||
|
}
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
background: rgba(255, 255, 255, 0.0837);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.titlebar-button .titlebar-icon {
|
||||||
|
font-family: 'Segoe MDL2 Assets', 'Segoe UI Symbol', 'Segoe UI', system-ui;
|
||||||
|
font-size: 9px;
|
||||||
|
line-height: 1;
|
||||||
|
display: inline-block;
|
||||||
|
opacity: 0.9;
|
||||||
|
transition: opacity 0.1s ease;
|
||||||
|
|
||||||
|
.titlebar-button:hover & {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.minimize-button:hover,
|
||||||
|
.maximize-button:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.0605);
|
||||||
|
}
|
||||||
|
|
||||||
|
.minimize-button:active,
|
||||||
|
.maximize-button:active {
|
||||||
|
background: rgba(255, 255, 255, 0.0837);
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-button:hover {
|
||||||
|
background: #c42b1c;
|
||||||
|
color: #ffffff;
|
||||||
|
|
||||||
|
.titlebar-icon {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.close-button:active {
|
||||||
|
background: #a93226;
|
||||||
|
|
||||||
|
.titlebar-icon {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
@@ -1,4 +1,10 @@
|
|||||||
export default {
|
export default {
|
||||||
|
titlebar: {
|
||||||
|
minimize: 'Minimize',
|
||||||
|
maximize: 'Maximize',
|
||||||
|
restore: 'Restore Down',
|
||||||
|
close: 'Close'
|
||||||
|
},
|
||||||
toolbar: {
|
toolbar: {
|
||||||
editor: {
|
editor: {
|
||||||
lines: 'Ln',
|
lines: 'Ln',
|
||||||
@@ -76,6 +82,7 @@ export default {
|
|||||||
enableGlobalHotkey: 'Enable Global Hotkeys',
|
enableGlobalHotkey: 'Enable Global Hotkeys',
|
||||||
window: 'Window/Application',
|
window: 'Window/Application',
|
||||||
showInSystemTray: 'Show in System Tray',
|
showInSystemTray: 'Show in System Tray',
|
||||||
|
enableSystemTray: 'Enable System Tray',
|
||||||
alwaysOnTop: 'Always on Top',
|
alwaysOnTop: 'Always on Top',
|
||||||
dataStorage: 'Data Storage',
|
dataStorage: 'Data Storage',
|
||||||
dataPath: 'Data Storage Path',
|
dataPath: 'Data Storage Path',
|
||||||
|
@@ -1,4 +1,10 @@
|
|||||||
export default {
|
export default {
|
||||||
|
titlebar: {
|
||||||
|
minimize: '最小化',
|
||||||
|
maximize: '最大化',
|
||||||
|
restore: '向下还原',
|
||||||
|
close: '关闭'
|
||||||
|
},
|
||||||
toolbar: {
|
toolbar: {
|
||||||
editor: {
|
editor: {
|
||||||
lines: 'Ln',
|
lines: 'Ln',
|
||||||
@@ -76,6 +82,7 @@ export default {
|
|||||||
enableGlobalHotkey: '启用全局热键',
|
enableGlobalHotkey: '启用全局热键',
|
||||||
window: '窗口/应用程序',
|
window: '窗口/应用程序',
|
||||||
showInSystemTray: '在系统托盘中显示',
|
showInSystemTray: '在系统托盘中显示',
|
||||||
|
enableSystemTray: '启用系统托盘',
|
||||||
alwaysOnTop: '窗口始终置顶',
|
alwaysOnTop: '窗口始终置顶',
|
||||||
dataStorage: '数据存储',
|
dataStorage: '数据存储',
|
||||||
dataPath: '数据存储路径',
|
dataPath: '数据存储路径',
|
||||||
|
@@ -49,6 +49,7 @@ type NumberConfigKey = 'fontSize' | 'tabSize' | 'lineHeight';
|
|||||||
const GENERAL_CONFIG_KEY_MAP: GeneralConfigKeyMap = {
|
const GENERAL_CONFIG_KEY_MAP: GeneralConfigKeyMap = {
|
||||||
alwaysOnTop: 'general.always_on_top',
|
alwaysOnTop: 'general.always_on_top',
|
||||||
dataPath: 'general.data_path',
|
dataPath: 'general.data_path',
|
||||||
|
enableSystemTray: 'general.enable_system_tray',
|
||||||
enableGlobalHotkey: 'general.enable_global_hotkey',
|
enableGlobalHotkey: 'general.enable_global_hotkey',
|
||||||
globalHotkey: 'general.global_hotkey'
|
globalHotkey: 'general.global_hotkey'
|
||||||
} as const;
|
} as const;
|
||||||
@@ -116,6 +117,7 @@ const DEFAULT_CONFIG: AppConfig = {
|
|||||||
general: {
|
general: {
|
||||||
alwaysOnTop: false,
|
alwaysOnTop: false,
|
||||||
dataPath: '',
|
dataPath: '',
|
||||||
|
enableSystemTray: true,
|
||||||
enableGlobalHotkey: false,
|
enableGlobalHotkey: false,
|
||||||
globalHotkey: {
|
globalHotkey: {
|
||||||
ctrl: false,
|
ctrl: false,
|
||||||
@@ -406,6 +408,9 @@ export const useConfigStore = defineStore('config', () => {
|
|||||||
|
|
||||||
// 热键配置相关方法
|
// 热键配置相关方法
|
||||||
setEnableGlobalHotkey: (value: boolean) => safeCall(() => updateGeneralConfig('enableGlobalHotkey', value), 'config.saveFailed', 'config.saveSuccess'),
|
setEnableGlobalHotkey: (value: boolean) => safeCall(() => updateGeneralConfig('enableGlobalHotkey', value), 'config.saveFailed', 'config.saveSuccess'),
|
||||||
setGlobalHotkey: (hotkey: any) => safeCall(() => updateGeneralConfig('globalHotkey', hotkey), 'config.saveFailed', 'config.saveSuccess')
|
setGlobalHotkey: (hotkey: any) => safeCall(() => updateGeneralConfig('globalHotkey', hotkey), 'config.saveFailed', 'config.saveSuccess'),
|
||||||
|
|
||||||
|
// 系统托盘配置相关方法
|
||||||
|
setEnableSystemTray: (value: boolean) => safeCall(() => updateGeneralConfig('enableSystemTray', value), 'config.saveFailed', 'config.saveSuccess')
|
||||||
};
|
};
|
||||||
});
|
});
|
@@ -187,6 +187,12 @@ const alwaysOnTop = computed({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 计算属性 - 启用系统托盘
|
||||||
|
const enableSystemTray = computed({
|
||||||
|
get: () => configStore.config.general.enableSystemTray,
|
||||||
|
set: (value: boolean) => configStore.setEnableSystemTray(value)
|
||||||
|
});
|
||||||
|
|
||||||
// 修饰键配置 - 只读计算属性
|
// 修饰键配置 - 只读计算属性
|
||||||
const modifierKeys = computed(() => ({
|
const modifierKeys = computed(() => ({
|
||||||
ctrl: configStore.config.general.globalHotkey.ctrl,
|
ctrl: configStore.config.general.globalHotkey.ctrl,
|
||||||
@@ -338,6 +344,9 @@ onUnmounted(() => {
|
|||||||
<SettingItem :title="t('settings.alwaysOnTop')">
|
<SettingItem :title="t('settings.alwaysOnTop')">
|
||||||
<ToggleSwitch v-model="alwaysOnTop"/>
|
<ToggleSwitch v-model="alwaysOnTop"/>
|
||||||
</SettingItem>
|
</SettingItem>
|
||||||
|
<SettingItem :title="t('settings.enableSystemTray')">
|
||||||
|
<ToggleSwitch v-model="enableSystemTray"/>
|
||||||
|
</SettingItem>
|
||||||
</SettingSection>
|
</SettingSection>
|
||||||
|
|
||||||
<SettingSection :title="t('settings.dataStorage')">
|
<SettingSection :title="t('settings.dataStorage')">
|
||||||
|
@@ -2,13 +2,14 @@ package events
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
"voidraft/internal/services"
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v3/pkg/application"
|
"github.com/wailsapp/wails/v3/pkg/application"
|
||||||
wailsevents "github.com/wailsapp/wails/v3/pkg/events"
|
wailsevents "github.com/wailsapp/wails/v3/pkg/events"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RegisterTrayEvents 注册与系统托盘相关的所有事件
|
// RegisterTrayEvents 注册与系统托盘相关的所有事件
|
||||||
func RegisterTrayEvents(app *application.App, systray *application.SystemTray, mainWindow *application.WebviewWindow) {
|
func RegisterTrayEvents(app *application.App, systray *application.SystemTray, mainWindow *application.WebviewWindow, trayService *services.TrayService) {
|
||||||
// 不附加窗口到系统托盘,避免失去焦点自动缩小
|
// 不附加窗口到系统托盘,避免失去焦点自动缩小
|
||||||
// systray.AttachWindow(mainWindow)
|
// systray.AttachWindow(mainWindow)
|
||||||
|
|
||||||
@@ -17,32 +18,19 @@ func RegisterTrayEvents(app *application.App, systray *application.SystemTray, m
|
|||||||
|
|
||||||
// 设置点击托盘图标显示主窗口
|
// 设置点击托盘图标显示主窗口
|
||||||
systray.OnClick(func() {
|
systray.OnClick(func() {
|
||||||
mainWindow.Show()
|
trayService.ShowWindow()
|
||||||
mainWindow.Restore()
|
|
||||||
mainWindow.Focus()
|
|
||||||
// 通知前端窗口已显示
|
|
||||||
app.EmitEvent("window:shown", nil)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// 处理窗口关闭事件 - 隐藏到托盘
|
// 处理窗口关闭事件 - 根据配置决定是隐藏到托盘还是直接退出
|
||||||
mainWindow.RegisterHook(wailsevents.Common.WindowClosing, func(event *application.WindowEvent) {
|
mainWindow.RegisterHook(wailsevents.Common.WindowClosing, func(event *application.WindowEvent) {
|
||||||
// 取消默认关闭行为
|
// 取消默认关闭行为
|
||||||
event.Cancel()
|
event.Cancel()
|
||||||
// 隐藏窗口到托盘
|
// 使用托盘服务处理关闭事件
|
||||||
mainWindow.Hide()
|
trayService.HandleWindowClose()
|
||||||
// 通知前端窗口已隐藏
|
|
||||||
app.EmitEvent("window:hidden", nil)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// 处理窗口最小化事件 - 也隐藏到托盘
|
// 不再拦截窗口最小化事件,让任务栏点击保持正常行为
|
||||||
mainWindow.RegisterHook(wailsevents.Common.WindowMinimise, func(event *application.WindowEvent) {
|
// 最小化到托盘的逻辑由前端标题栏按钮直接处理
|
||||||
// 取消默认最小化行为
|
|
||||||
event.Cancel()
|
|
||||||
// 隐藏窗口到托盘
|
|
||||||
mainWindow.Hide()
|
|
||||||
// 通知前端窗口已隐藏
|
|
||||||
app.EmitEvent("window:hidden", nil)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterTrayMenuEvents 注册系统托盘菜单事件
|
// RegisterTrayMenuEvents 注册系统托盘菜单事件
|
||||||
|
@@ -58,8 +58,9 @@ const (
|
|||||||
|
|
||||||
// GeneralConfig 通用设置配置
|
// GeneralConfig 通用设置配置
|
||||||
type GeneralConfig struct {
|
type GeneralConfig struct {
|
||||||
AlwaysOnTop bool `json:"alwaysOnTop" yaml:"always_on_top" mapstructure:"always_on_top"` // 窗口是否置顶
|
AlwaysOnTop bool `json:"alwaysOnTop" yaml:"always_on_top" mapstructure:"always_on_top"` // 窗口是否置顶
|
||||||
DataPath string `json:"dataPath" yaml:"data_path" mapstructure:"data_path"` // 数据存储路径
|
DataPath string `json:"dataPath" yaml:"data_path" mapstructure:"data_path"` // 数据存储路径
|
||||||
|
EnableSystemTray bool `json:"enableSystemTray" yaml:"enable_system_tray" mapstructure:"enable_system_tray"` // 是否启用系统托盘
|
||||||
|
|
||||||
// 全局热键设置
|
// 全局热键设置
|
||||||
EnableGlobalHotkey bool `json:"enableGlobalHotkey" yaml:"enable_global_hotkey" mapstructure:"enable_global_hotkey"` // 是否启用全局热键
|
EnableGlobalHotkey bool `json:"enableGlobalHotkey" yaml:"enable_global_hotkey" mapstructure:"enable_global_hotkey"` // 是否启用全局热键
|
||||||
@@ -139,6 +140,7 @@ func NewDefaultAppConfig() *AppConfig {
|
|||||||
General: GeneralConfig{
|
General: GeneralConfig{
|
||||||
AlwaysOnTop: false,
|
AlwaysOnTop: false,
|
||||||
DataPath: dataDir,
|
DataPath: dataDir,
|
||||||
|
EnableSystemTray: true, // 默认启用系统托盘
|
||||||
EnableGlobalHotkey: false,
|
EnableGlobalHotkey: false,
|
||||||
GlobalHotkey: HotkeyCombo{
|
GlobalHotkey: HotkeyCombo{
|
||||||
Ctrl: false,
|
Ctrl: false,
|
||||||
|
@@ -106,6 +106,7 @@ func setDefaults(v *viper.Viper) {
|
|||||||
// 通用设置默认值
|
// 通用设置默认值
|
||||||
v.SetDefault("general.always_on_top", defaultConfig.General.AlwaysOnTop)
|
v.SetDefault("general.always_on_top", defaultConfig.General.AlwaysOnTop)
|
||||||
v.SetDefault("general.data_path", defaultConfig.General.DataPath)
|
v.SetDefault("general.data_path", defaultConfig.General.DataPath)
|
||||||
|
v.SetDefault("general.enable_system_tray", defaultConfig.General.EnableSystemTray)
|
||||||
v.SetDefault("general.enable_global_hotkey", defaultConfig.General.EnableGlobalHotkey)
|
v.SetDefault("general.enable_global_hotkey", defaultConfig.General.EnableGlobalHotkey)
|
||||||
v.SetDefault("general.global_hotkey.ctrl", defaultConfig.General.GlobalHotkey.Ctrl)
|
v.SetDefault("general.global_hotkey.ctrl", defaultConfig.General.GlobalHotkey.Ctrl)
|
||||||
v.SetDefault("general.global_hotkey.shift", defaultConfig.General.GlobalHotkey.Shift)
|
v.SetDefault("general.global_hotkey.shift", defaultConfig.General.GlobalHotkey.Shift)
|
||||||
@@ -240,6 +241,7 @@ func (cs *ConfigService) ResetConfig() {
|
|||||||
// 通用设置 - 批量设置到viper中
|
// 通用设置 - 批量设置到viper中
|
||||||
cs.viper.Set("general.always_on_top", defaultConfig.General.AlwaysOnTop)
|
cs.viper.Set("general.always_on_top", defaultConfig.General.AlwaysOnTop)
|
||||||
cs.viper.Set("general.data_path", defaultConfig.General.DataPath)
|
cs.viper.Set("general.data_path", defaultConfig.General.DataPath)
|
||||||
|
cs.viper.Set("general.enable_system_tray", defaultConfig.General.EnableSystemTray)
|
||||||
cs.viper.Set("general.enable_global_hotkey", defaultConfig.General.EnableGlobalHotkey)
|
cs.viper.Set("general.enable_global_hotkey", defaultConfig.General.EnableGlobalHotkey)
|
||||||
cs.viper.Set("general.global_hotkey.ctrl", defaultConfig.General.GlobalHotkey.Ctrl)
|
cs.viper.Set("general.global_hotkey.ctrl", defaultConfig.General.GlobalHotkey.Ctrl)
|
||||||
cs.viper.Set("general.global_hotkey.shift", defaultConfig.General.GlobalHotkey.Shift)
|
cs.viper.Set("general.global_hotkey.shift", defaultConfig.General.GlobalHotkey.Shift)
|
||||||
|
@@ -17,6 +17,7 @@ type ServiceManager struct {
|
|||||||
dialogService *DialogService
|
dialogService *DialogService
|
||||||
websocketService *WebSocketService
|
websocketService *WebSocketService
|
||||||
httpService *HTTPService
|
httpService *HTTPService
|
||||||
|
trayService *TrayService
|
||||||
logger *log.LoggerService
|
logger *log.LoggerService
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,6 +50,9 @@ func NewServiceManager() *ServiceManager {
|
|||||||
// 初始化 HTTP 服务
|
// 初始化 HTTP 服务
|
||||||
httpService := NewHTTPService(logger, websocketService)
|
httpService := NewHTTPService(logger, websocketService)
|
||||||
|
|
||||||
|
// 初始化托盘服务
|
||||||
|
trayService := NewTrayService(logger, configService)
|
||||||
|
|
||||||
// 设置迁移服务的WebSocket广播
|
// 设置迁移服务的WebSocket广播
|
||||||
migrationService.SetProgressBroadcaster(func(progress MigrationProgress) {
|
migrationService.SetProgressBroadcaster(func(progress MigrationProgress) {
|
||||||
websocketService.BroadcastMigrationProgress(progress)
|
websocketService.BroadcastMigrationProgress(progress)
|
||||||
@@ -95,6 +99,7 @@ func NewServiceManager() *ServiceManager {
|
|||||||
dialogService: dialogService,
|
dialogService: dialogService,
|
||||||
websocketService: websocketService,
|
websocketService: websocketService,
|
||||||
httpService: httpService,
|
httpService: httpService,
|
||||||
|
trayService: trayService,
|
||||||
logger: logger,
|
logger: logger,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,6 +113,7 @@ func (sm *ServiceManager) GetServices() []application.Service {
|
|||||||
application.NewService(sm.systemService),
|
application.NewService(sm.systemService),
|
||||||
application.NewService(sm.hotkeyService),
|
application.NewService(sm.hotkeyService),
|
||||||
application.NewService(sm.dialogService),
|
application.NewService(sm.dialogService),
|
||||||
|
application.NewService(sm.trayService),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,3 +126,18 @@ func (sm *ServiceManager) GetHotkeyService() *HotkeyService {
|
|||||||
func (sm *ServiceManager) GetDialogService() *DialogService {
|
func (sm *ServiceManager) GetDialogService() *DialogService {
|
||||||
return sm.dialogService
|
return sm.dialogService
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetLogger 获取日志服务实例
|
||||||
|
func (sm *ServiceManager) GetLogger() *log.LoggerService {
|
||||||
|
return sm.logger
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetConfigService 获取配置服务实例
|
||||||
|
func (sm *ServiceManager) GetConfigService() *ConfigService {
|
||||||
|
return sm.configService
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTrayService 获取托盘服务实例
|
||||||
|
func (sm *ServiceManager) GetTrayService() *TrayService {
|
||||||
|
return sm.trayService
|
||||||
|
}
|
||||||
|
86
internal/services/tray_service.go
Normal file
86
internal/services/tray_service.go
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/wailsapp/wails/v3/pkg/application"
|
||||||
|
"github.com/wailsapp/wails/v3/pkg/services/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TrayService 系统托盘服务
|
||||||
|
type TrayService struct {
|
||||||
|
logger *log.LoggerService
|
||||||
|
configService *ConfigService
|
||||||
|
app *application.App
|
||||||
|
mainWindow *application.WebviewWindow
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewTrayService 创建新的系统托盘服务实例
|
||||||
|
func NewTrayService(logger *log.LoggerService, configService *ConfigService) *TrayService {
|
||||||
|
return &TrayService{
|
||||||
|
logger: logger,
|
||||||
|
configService: configService,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetAppReferences 设置应用引用
|
||||||
|
func (ts *TrayService) SetAppReferences(app *application.App, mainWindow *application.WebviewWindow) {
|
||||||
|
ts.app = app
|
||||||
|
ts.mainWindow = mainWindow
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShouldMinimizeToTray 检查是否应该最小化到托盘
|
||||||
|
func (ts *TrayService) ShouldMinimizeToTray() bool {
|
||||||
|
config, err := ts.configService.GetConfig()
|
||||||
|
if err != nil {
|
||||||
|
ts.logger.Error("TrayService: Failed to get config", "error", err)
|
||||||
|
return true // 默认行为:隐藏到托盘
|
||||||
|
}
|
||||||
|
|
||||||
|
return config.General.EnableSystemTray
|
||||||
|
}
|
||||||
|
|
||||||
|
// HandleWindowClose 处理窗口关闭事件
|
||||||
|
func (ts *TrayService) HandleWindowClose() {
|
||||||
|
if ts.ShouldMinimizeToTray() {
|
||||||
|
// 隐藏到托盘
|
||||||
|
ts.mainWindow.Hide()
|
||||||
|
ts.app.EmitEvent("window:hidden", nil)
|
||||||
|
ts.logger.Info("TrayService: Window hidden to system tray")
|
||||||
|
} else {
|
||||||
|
// 直接退出应用
|
||||||
|
ts.app.Quit()
|
||||||
|
ts.logger.Info("TrayService: Application quit")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HandleWindowMinimize 处理窗口最小化事件
|
||||||
|
func (ts *TrayService) HandleWindowMinimize() {
|
||||||
|
if ts.ShouldMinimizeToTray() {
|
||||||
|
// 隐藏到托盘
|
||||||
|
ts.mainWindow.Hide()
|
||||||
|
ts.app.EmitEvent("window:hidden", nil)
|
||||||
|
ts.logger.Info("TrayService: Window minimized to system tray")
|
||||||
|
} else {
|
||||||
|
// 允许正常最小化(不处理,让系统处理)
|
||||||
|
ts.logger.Info("TrayService: Window minimized normally")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ShowWindow 显示主窗口
|
||||||
|
func (ts *TrayService) ShowWindow() {
|
||||||
|
if ts.mainWindow != nil {
|
||||||
|
ts.mainWindow.Show()
|
||||||
|
ts.mainWindow.Restore()
|
||||||
|
ts.mainWindow.Focus()
|
||||||
|
if ts.app != nil {
|
||||||
|
ts.app.EmitEvent("window:shown", nil)
|
||||||
|
}
|
||||||
|
ts.logger.Info("TrayService: Window shown from system tray")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MinimizeButtonClicked 处理标题栏最小化按钮点击
|
||||||
|
func (ts *TrayService) MinimizeButtonClicked() {
|
||||||
|
// 最小化按钮总是执行正常最小化到任务栏,不隐藏到托盘
|
||||||
|
ts.mainWindow.Minimise()
|
||||||
|
ts.logger.Info("TrayService: Window minimized to taskbar via titlebar button")
|
||||||
|
}
|
@@ -4,10 +4,11 @@ import (
|
|||||||
"embed"
|
"embed"
|
||||||
"github.com/wailsapp/wails/v3/pkg/application"
|
"github.com/wailsapp/wails/v3/pkg/application"
|
||||||
"voidraft/internal/events"
|
"voidraft/internal/events"
|
||||||
|
"voidraft/internal/services"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetupSystemTray 设置系统托盘及其功能
|
// SetupSystemTray 设置系统托盘及其功能
|
||||||
func SetupSystemTray(app *application.App, mainWindow *application.WebviewWindow, assets embed.FS) {
|
func SetupSystemTray(app *application.App, mainWindow *application.WebviewWindow, assets embed.FS, trayService *services.TrayService) {
|
||||||
// 创建系统托盘
|
// 创建系统托盘
|
||||||
systray := app.NewSystemTray()
|
systray := app.NewSystemTray()
|
||||||
|
|
||||||
@@ -27,5 +28,5 @@ func SetupSystemTray(app *application.App, mainWindow *application.WebviewWindow
|
|||||||
systray.SetMenu(menu)
|
systray.SetMenu(menu)
|
||||||
|
|
||||||
// 注册托盘相关事件
|
// 注册托盘相关事件
|
||||||
events.RegisterTrayEvents(app, systray, mainWindow)
|
events.RegisterTrayEvents(app, systray, mainWindow, trayService)
|
||||||
}
|
}
|
||||||
|
20
main.go
20
main.go
@@ -75,22 +75,32 @@ func main() {
|
|||||||
// 'URL' is the URL that will be loaded into the webview.
|
// 'URL' is the URL that will be loaded into the webview.
|
||||||
log.Println("Creating main window...")
|
log.Println("Creating main window...")
|
||||||
mainWindow := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
mainWindow := app.NewWebviewWindowWithOptions(application.WebviewWindowOptions{
|
||||||
Title: "voidraft",
|
Title: "voidraft",
|
||||||
Width: 700,
|
Width: 700,
|
||||||
Height: 800,
|
Height: 800,
|
||||||
Hidden: false,
|
Hidden: false,
|
||||||
|
Frameless: true,
|
||||||
|
DevToolsEnabled: false,
|
||||||
|
DefaultContextMenuDisabled: false,
|
||||||
Mac: application.MacWindow{
|
Mac: application.MacWindow{
|
||||||
InvisibleTitleBarHeight: 50,
|
InvisibleTitleBarHeight: 50,
|
||||||
Backdrop: application.MacBackdropTranslucent,
|
Backdrop: application.MacBackdropTranslucent,
|
||||||
TitleBar: application.MacTitleBarHiddenInset,
|
TitleBar: application.MacTitleBarHiddenInset,
|
||||||
},
|
},
|
||||||
|
Windows: application.WindowsWindow{
|
||||||
|
Theme: application.SystemDefault,
|
||||||
|
},
|
||||||
BackgroundColour: application.NewRGB(27, 38, 54),
|
BackgroundColour: application.NewRGB(27, 38, 54),
|
||||||
URL: "/#/",
|
URL: "/#/",
|
||||||
})
|
})
|
||||||
mainWindow.Center()
|
mainWindow.Center()
|
||||||
|
|
||||||
|
// 获取托盘服务并设置应用引用
|
||||||
|
trayService := serviceManager.GetTrayService()
|
||||||
|
trayService.SetAppReferences(app, mainWindow)
|
||||||
|
|
||||||
// 设置系统托盘
|
// 设置系统托盘
|
||||||
systray.SetupSystemTray(app, mainWindow, assets)
|
systray.SetupSystemTray(app, mainWindow, assets, trayService)
|
||||||
|
|
||||||
// 初始化热键服务
|
// 初始化热键服务
|
||||||
hotkeyService := serviceManager.GetHotkeyService()
|
hotkeyService := serviceManager.GetHotkeyService()
|
||||||
|
Reference in New Issue
Block a user