🎨 Optimize code
This commit is contained in:
@@ -5,303 +5,6 @@
|
||||
// @ts-ignore: Unused imports
|
||||
import {Create as $Create} from "@wailsio/runtime";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import * as slog$0 from "../../../../../../log/slog/models.js";
|
||||
|
||||
export class App {
|
||||
/**
|
||||
* Manager pattern for organized API
|
||||
*/
|
||||
"Window": WindowManager | null;
|
||||
"ContextMenu": ContextMenuManager | null;
|
||||
"KeyBinding": KeyBindingManager | null;
|
||||
"Browser": BrowserManager | null;
|
||||
"Env": EnvironmentManager | null;
|
||||
"Dialog": DialogManager | null;
|
||||
"Event": EventManager | null;
|
||||
"Menu": MenuManager | null;
|
||||
"Screen": ScreenManager | null;
|
||||
"Clipboard": ClipboardManager | null;
|
||||
"SystemTray": SystemTrayManager | null;
|
||||
"Logger": slog$0.Logger | null;
|
||||
|
||||
/** Creates a new App instance. */
|
||||
constructor($$source: Partial<App> = {}) {
|
||||
if (!("Window" in $$source)) {
|
||||
this["Window"] = null;
|
||||
}
|
||||
if (!("ContextMenu" in $$source)) {
|
||||
this["ContextMenu"] = null;
|
||||
}
|
||||
if (!("KeyBinding" in $$source)) {
|
||||
this["KeyBinding"] = null;
|
||||
}
|
||||
if (!("Browser" in $$source)) {
|
||||
this["Browser"] = null;
|
||||
}
|
||||
if (!("Env" in $$source)) {
|
||||
this["Env"] = null;
|
||||
}
|
||||
if (!("Dialog" in $$source)) {
|
||||
this["Dialog"] = null;
|
||||
}
|
||||
if (!("Event" in $$source)) {
|
||||
this["Event"] = null;
|
||||
}
|
||||
if (!("Menu" in $$source)) {
|
||||
this["Menu"] = null;
|
||||
}
|
||||
if (!("Screen" in $$source)) {
|
||||
this["Screen"] = null;
|
||||
}
|
||||
if (!("Clipboard" in $$source)) {
|
||||
this["Clipboard"] = null;
|
||||
}
|
||||
if (!("SystemTray" in $$source)) {
|
||||
this["SystemTray"] = null;
|
||||
}
|
||||
if (!("Logger" in $$source)) {
|
||||
this["Logger"] = null;
|
||||
}
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new App instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): App {
|
||||
const $$createField0_0 = $$createType1;
|
||||
const $$createField1_0 = $$createType3;
|
||||
const $$createField2_0 = $$createType5;
|
||||
const $$createField3_0 = $$createType7;
|
||||
const $$createField4_0 = $$createType9;
|
||||
const $$createField5_0 = $$createType11;
|
||||
const $$createField6_0 = $$createType13;
|
||||
const $$createField7_0 = $$createType15;
|
||||
const $$createField8_0 = $$createType17;
|
||||
const $$createField9_0 = $$createType19;
|
||||
const $$createField10_0 = $$createType21;
|
||||
const $$createField11_0 = $$createType23;
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
if ("Window" in $$parsedSource) {
|
||||
$$parsedSource["Window"] = $$createField0_0($$parsedSource["Window"]);
|
||||
}
|
||||
if ("ContextMenu" in $$parsedSource) {
|
||||
$$parsedSource["ContextMenu"] = $$createField1_0($$parsedSource["ContextMenu"]);
|
||||
}
|
||||
if ("KeyBinding" in $$parsedSource) {
|
||||
$$parsedSource["KeyBinding"] = $$createField2_0($$parsedSource["KeyBinding"]);
|
||||
}
|
||||
if ("Browser" in $$parsedSource) {
|
||||
$$parsedSource["Browser"] = $$createField3_0($$parsedSource["Browser"]);
|
||||
}
|
||||
if ("Env" in $$parsedSource) {
|
||||
$$parsedSource["Env"] = $$createField4_0($$parsedSource["Env"]);
|
||||
}
|
||||
if ("Dialog" in $$parsedSource) {
|
||||
$$parsedSource["Dialog"] = $$createField5_0($$parsedSource["Dialog"]);
|
||||
}
|
||||
if ("Event" in $$parsedSource) {
|
||||
$$parsedSource["Event"] = $$createField6_0($$parsedSource["Event"]);
|
||||
}
|
||||
if ("Menu" in $$parsedSource) {
|
||||
$$parsedSource["Menu"] = $$createField7_0($$parsedSource["Menu"]);
|
||||
}
|
||||
if ("Screen" in $$parsedSource) {
|
||||
$$parsedSource["Screen"] = $$createField8_0($$parsedSource["Screen"]);
|
||||
}
|
||||
if ("Clipboard" in $$parsedSource) {
|
||||
$$parsedSource["Clipboard"] = $$createField9_0($$parsedSource["Clipboard"]);
|
||||
}
|
||||
if ("SystemTray" in $$parsedSource) {
|
||||
$$parsedSource["SystemTray"] = $$createField10_0($$parsedSource["SystemTray"]);
|
||||
}
|
||||
if ("Logger" in $$parsedSource) {
|
||||
$$parsedSource["Logger"] = $$createField11_0($$parsedSource["Logger"]);
|
||||
}
|
||||
return new App($$parsedSource as Partial<App>);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* BrowserManager manages browser-related operations
|
||||
*/
|
||||
export class BrowserManager {
|
||||
|
||||
/** Creates a new BrowserManager instance. */
|
||||
constructor($$source: Partial<BrowserManager> = {}) {
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new BrowserManager instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): BrowserManager {
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
return new BrowserManager($$parsedSource as Partial<BrowserManager>);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ClipboardManager manages clipboard operations
|
||||
*/
|
||||
export class ClipboardManager {
|
||||
|
||||
/** Creates a new ClipboardManager instance. */
|
||||
constructor($$source: Partial<ClipboardManager> = {}) {
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ClipboardManager instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): ClipboardManager {
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
return new ClipboardManager($$parsedSource as Partial<ClipboardManager>);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ContextMenuManager manages all context menu operations
|
||||
*/
|
||||
export class ContextMenuManager {
|
||||
|
||||
/** Creates a new ContextMenuManager instance. */
|
||||
constructor($$source: Partial<ContextMenuManager> = {}) {
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ContextMenuManager instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): ContextMenuManager {
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
return new ContextMenuManager($$parsedSource as Partial<ContextMenuManager>);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* DialogManager manages dialog-related operations
|
||||
*/
|
||||
export class DialogManager {
|
||||
|
||||
/** Creates a new DialogManager instance. */
|
||||
constructor($$source: Partial<DialogManager> = {}) {
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new DialogManager instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): DialogManager {
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
return new DialogManager($$parsedSource as Partial<DialogManager>);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* EnvironmentManager manages environment-related operations
|
||||
*/
|
||||
export class EnvironmentManager {
|
||||
|
||||
/** Creates a new EnvironmentManager instance. */
|
||||
constructor($$source: Partial<EnvironmentManager> = {}) {
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new EnvironmentManager instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): EnvironmentManager {
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
return new EnvironmentManager($$parsedSource as Partial<EnvironmentManager>);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* EventManager manages event-related operations
|
||||
*/
|
||||
export class EventManager {
|
||||
|
||||
/** Creates a new EventManager instance. */
|
||||
constructor($$source: Partial<EventManager> = {}) {
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new EventManager instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): EventManager {
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
return new EventManager($$parsedSource as Partial<EventManager>);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* KeyBindingManager manages all key binding operations
|
||||
*/
|
||||
export class KeyBindingManager {
|
||||
|
||||
/** Creates a new KeyBindingManager instance. */
|
||||
constructor($$source: Partial<KeyBindingManager> = {}) {
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new KeyBindingManager instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): KeyBindingManager {
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
return new KeyBindingManager($$parsedSource as Partial<KeyBindingManager>);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MenuManager manages menu-related operations
|
||||
*/
|
||||
export class MenuManager {
|
||||
|
||||
/** Creates a new MenuManager instance. */
|
||||
constructor($$source: Partial<MenuManager> = {}) {
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new MenuManager instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): MenuManager {
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
return new MenuManager($$parsedSource as Partial<MenuManager>);
|
||||
}
|
||||
}
|
||||
|
||||
export class ScreenManager {
|
||||
|
||||
/** Creates a new ScreenManager instance. */
|
||||
constructor($$source: Partial<ScreenManager> = {}) {
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ScreenManager instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): ScreenManager {
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
return new ScreenManager($$parsedSource as Partial<ScreenManager>);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ServiceOptions provides optional parameters for calls to [NewService].
|
||||
*/
|
||||
@@ -359,26 +62,6 @@ export class ServiceOptions {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* SystemTrayManager manages system tray-related operations
|
||||
*/
|
||||
export class SystemTrayManager {
|
||||
|
||||
/** Creates a new SystemTrayManager instance. */
|
||||
constructor($$source: Partial<SystemTrayManager> = {}) {
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new SystemTrayManager instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): SystemTrayManager {
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
return new SystemTrayManager($$parsedSource as Partial<SystemTrayManager>);
|
||||
}
|
||||
}
|
||||
|
||||
export class WebviewWindow {
|
||||
|
||||
/** Creates a new WebviewWindow instance. */
|
||||
@@ -395,49 +78,3 @@ export class WebviewWindow {
|
||||
return new WebviewWindow($$parsedSource as Partial<WebviewWindow>);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* WindowManager manages all window-related operations
|
||||
*/
|
||||
export class WindowManager {
|
||||
|
||||
/** Creates a new WindowManager instance. */
|
||||
constructor($$source: Partial<WindowManager> = {}) {
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new WindowManager instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): WindowManager {
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
return new WindowManager($$parsedSource as Partial<WindowManager>);
|
||||
}
|
||||
}
|
||||
|
||||
// Private type creation functions
|
||||
const $$createType0 = WindowManager.createFrom;
|
||||
const $$createType1 = $Create.Nullable($$createType0);
|
||||
const $$createType2 = ContextMenuManager.createFrom;
|
||||
const $$createType3 = $Create.Nullable($$createType2);
|
||||
const $$createType4 = KeyBindingManager.createFrom;
|
||||
const $$createType5 = $Create.Nullable($$createType4);
|
||||
const $$createType6 = BrowserManager.createFrom;
|
||||
const $$createType7 = $Create.Nullable($$createType6);
|
||||
const $$createType8 = EnvironmentManager.createFrom;
|
||||
const $$createType9 = $Create.Nullable($$createType8);
|
||||
const $$createType10 = DialogManager.createFrom;
|
||||
const $$createType11 = $Create.Nullable($$createType10);
|
||||
const $$createType12 = EventManager.createFrom;
|
||||
const $$createType13 = $Create.Nullable($$createType12);
|
||||
const $$createType14 = MenuManager.createFrom;
|
||||
const $$createType15 = $Create.Nullable($$createType14);
|
||||
const $$createType16 = ScreenManager.createFrom;
|
||||
const $$createType17 = $Create.Nullable($$createType16);
|
||||
const $$createType18 = ClipboardManager.createFrom;
|
||||
const $$createType19 = $Create.Nullable($$createType18);
|
||||
const $$createType20 = SystemTrayManager.createFrom;
|
||||
const $$createType21 = $Create.Nullable($$createType20);
|
||||
const $$createType22 = slog$0.Logger.createFrom;
|
||||
const $$createType23 = $Create.Nullable($$createType22);
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
export * from "./models.js";
|
||||
@@ -1,31 +0,0 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import {Create as $Create} from "@wailsio/runtime";
|
||||
|
||||
/**
|
||||
* A Logger records structured information about each call to its
|
||||
* Log, Debug, Info, Warn, and Error methods.
|
||||
* For each call, it creates a [Record] and passes it to a [Handler].
|
||||
*
|
||||
* To create a new Logger, call [New] or a Logger method
|
||||
* that begins "With".
|
||||
*/
|
||||
export class Logger {
|
||||
|
||||
/** Creates a new Logger instance. */
|
||||
constructor($$source: Partial<Logger> = {}) {
|
||||
|
||||
Object.assign(this, $$source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Logger instance from a string or object.
|
||||
*/
|
||||
static createFrom($$source: any = {}): Logger {
|
||||
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
|
||||
return new Logger($$parsedSource as Partial<Logger>);
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,6 @@
|
||||
// @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";
|
||||
|
||||
/**
|
||||
* SelectDirectory 打开目录选择对话框
|
||||
*/
|
||||
@@ -29,11 +25,3 @@ export function SelectFile(): Promise<string> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(37302920) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* SetWindow 设置绑定的窗口
|
||||
*/
|
||||
export function SetWindow(window: application$0.WebviewWindow | null): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(968177170, window) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ export function GetCurrentHotkey(): Promise<models$0.HotkeyCombo | null> & { can
|
||||
/**
|
||||
* Initialize 初始化热键服务
|
||||
*/
|
||||
export function Initialize(app: application$0.App | null, mainWindow: application$0.WebviewWindow | null): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(3671360458, app, mainWindow) as any;
|
||||
export function Initialize(): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(3671360458) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
@@ -61,6 +61,14 @@ export function ServiceShutdown(): Promise<void> & { cancel(): void } {
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* ServiceStartup initializes the service when the application starts
|
||||
*/
|
||||
export function ServiceStartup(options: application$0.ServiceOptions): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(3079990808, options) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* UnregisterHotkey 取消注册全局热键
|
||||
*/
|
||||
|
||||
@@ -18,6 +18,7 @@ import * as ThemeService from "./themeservice.js";
|
||||
import * as TranslationService from "./translationservice.js";
|
||||
import * as TrayService from "./trayservice.js";
|
||||
import * as WindowService from "./windowservice.js";
|
||||
import * as WindowSnapService from "./windowsnapservice.js";
|
||||
export {
|
||||
BackupService,
|
||||
ConfigService,
|
||||
@@ -35,7 +36,8 @@ export {
|
||||
ThemeService,
|
||||
TranslationService,
|
||||
TrayService,
|
||||
WindowService
|
||||
WindowService,
|
||||
WindowSnapService
|
||||
};
|
||||
|
||||
export * from "./models.js";
|
||||
|
||||
@@ -287,7 +287,7 @@ export class SystemInfo {
|
||||
}
|
||||
|
||||
/**
|
||||
* WindowInfo 窗口信息(简化版)
|
||||
* WindowInfo 窗口信息
|
||||
*/
|
||||
export class WindowInfo {
|
||||
"Window": application$0.WebviewWindow | null;
|
||||
|
||||
@@ -10,10 +10,6 @@
|
||||
// @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";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import * as $models from "./models.js";
|
||||
@@ -50,14 +46,6 @@ export function GetSystemInfo(): Promise<$models.SystemInfo | null> & { cancel()
|
||||
return $typingPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* SetAppReferences 设置应用引用
|
||||
*/
|
||||
export function SetAppReferences(app: application$0.App | null): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(3873053414, app) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* TriggerGC 手动触发垃圾回收
|
||||
*/
|
||||
|
||||
@@ -10,10 +10,6 @@
|
||||
// @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 处理窗口关闭事件
|
||||
*/
|
||||
@@ -38,14 +34,6 @@ export function MinimizeButtonClicked(): Promise<void> & { cancel(): void } {
|
||||
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 检查是否应该最小化到托盘
|
||||
*/
|
||||
|
||||
@@ -10,10 +10,6 @@
|
||||
// @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";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore: Unused imports
|
||||
import * as $models from "./models.js";
|
||||
@@ -54,14 +50,6 @@ export function ServiceShutdown(): Promise<void> & { cancel(): void } {
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* SetAppReferences 设置应用和主窗口引用
|
||||
*/
|
||||
export function SetAppReferences(app: application$0.App | null, mainWindow: application$0.WebviewWindow | null): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(1120840759, app, mainWindow) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* SetWindowSnapService 设置窗口吸附服务引用
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL
|
||||
// This file is automatically generated. DO NOT EDIT
|
||||
|
||||
/**
|
||||
* WindowSnapService 窗口吸附服务
|
||||
* @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";
|
||||
|
||||
/**
|
||||
* Cleanup 清理资源
|
||||
*/
|
||||
export function Cleanup(): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(2155505498) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* GetCurrentThreshold 获取当前自适应阈值(用于调试或显示)
|
||||
*/
|
||||
export function GetCurrentThreshold(): Promise<number> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(3176419026) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* OnWindowSnapConfigChanged 处理窗口吸附配置变更
|
||||
*/
|
||||
export function OnWindowSnapConfigChanged(enabled: boolean): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(3794787039, enabled) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* RegisterWindow 注册需要吸附管理的窗口
|
||||
*/
|
||||
export function RegisterWindow(documentID: number, window: application$0.WebviewWindow | null, title: string): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(1000222723, documentID, window, title) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* ServiceShutdown 实现服务关闭接口
|
||||
*/
|
||||
export function ServiceShutdown(): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(1172710495) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* ServiceStartup 服务启动时初始化
|
||||
*/
|
||||
export function ServiceStartup(options: application$0.ServiceOptions): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(2456823262, options) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* SetSnapEnabled 设置是否启用窗口吸附
|
||||
*/
|
||||
export function SetSnapEnabled(enabled: boolean): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(2280126835, enabled) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
|
||||
/**
|
||||
* UnregisterWindow 取消注册窗口
|
||||
*/
|
||||
export function UnregisterWindow(documentID: number): Promise<void> & { cancel(): void } {
|
||||
let $resultPromise = $Call.ByID(2844230768, documentID) as any;
|
||||
return $resultPromise;
|
||||
}
|
||||
10
internal/common/constant/constant.go
Normal file
10
internal/common/constant/constant.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package constant
|
||||
|
||||
// VOIDRAFT_MAIN_WINDOW_NAME is the name of the main window of the Voidcraft client.
|
||||
const VOIDRAFT_MAIN_WINDOW_NAME = "voidraft-main-window"
|
||||
|
||||
const VOIDRAFT_WINDOW_TITLE = "voidraft"
|
||||
|
||||
const VOIDRAFT_WINDOW_WIDTH = 700
|
||||
|
||||
const VOIDRAFT_WINDOW_HEIGHT = 800
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
// DialogService 对话框服务,处理文件选择等对话框操作
|
||||
type DialogService struct {
|
||||
logger *log.LogService
|
||||
window *application.WebviewWindow // 绑定的窗口
|
||||
windowHelper *WindowHelper
|
||||
}
|
||||
|
||||
// NewDialogService 创建新的对话框服务实例
|
||||
@@ -19,15 +19,10 @@ func NewDialogService(logger *log.LogService) *DialogService {
|
||||
|
||||
return &DialogService{
|
||||
logger: logger,
|
||||
window: nil, // 初始为空,后续通过 SetWindow 设置
|
||||
windowHelper: NewWindowHelper(),
|
||||
}
|
||||
}
|
||||
|
||||
// SetWindow 设置绑定的窗口
|
||||
func (ds *DialogService) SetWindow(window *application.WebviewWindow) {
|
||||
ds.window = window
|
||||
}
|
||||
|
||||
// SelectDirectory 打开目录选择对话框
|
||||
func (ds *DialogService) SelectDirectory() (string, error) {
|
||||
dialog := application.OpenFileDialog()
|
||||
@@ -59,7 +54,7 @@ func (ds *DialogService) SelectDirectory() (string, error) {
|
||||
Directory: "",
|
||||
|
||||
// 绑定到主窗口
|
||||
Window: ds.window,
|
||||
Window: ds.windowHelper.MustGetMainWindow(),
|
||||
})
|
||||
|
||||
path, err := dialog.PromptForSingleSelection()
|
||||
@@ -100,7 +95,7 @@ func (ds *DialogService) SelectFile() (string, error) {
|
||||
Directory: "",
|
||||
|
||||
// 绑定到主窗口
|
||||
Window: ds.window,
|
||||
Window: ds.windowHelper.MustGetMainWindow(),
|
||||
})
|
||||
|
||||
path, err := dialog.PromptForSingleSelection()
|
||||
|
||||
@@ -27,8 +27,7 @@ type HotkeyService struct {
|
||||
logger *log.LogService
|
||||
configService *ConfigService
|
||||
windowService *WindowService
|
||||
app *application.App
|
||||
mainWindow *application.WebviewWindow
|
||||
windowHelper *WindowHelper
|
||||
|
||||
mu sync.RWMutex
|
||||
currentHotkey *models.HotkeyCombo
|
||||
@@ -84,6 +83,7 @@ func NewHotkeyService(configService *ConfigService, windowService *WindowService
|
||||
logger: logger,
|
||||
configService: configService,
|
||||
windowService: windowService,
|
||||
windowHelper: NewWindowHelper(),
|
||||
ctx: ctx,
|
||||
}
|
||||
// 初始化时设置cancel函数
|
||||
@@ -91,11 +91,14 @@ func NewHotkeyService(configService *ConfigService, windowService *WindowService
|
||||
return service
|
||||
}
|
||||
|
||||
// Initialize 初始化热键服务
|
||||
func (hs *HotkeyService) Initialize(app *application.App, mainWindow *application.WebviewWindow) error {
|
||||
hs.app = app
|
||||
hs.mainWindow = mainWindow
|
||||
// ServiceStartup initializes the service when the application starts
|
||||
func (ds *HotkeyService) ServiceStartup(ctx context.Context, options application.ServiceOptions) error {
|
||||
ds.ctx = ctx
|
||||
return ds.Initialize()
|
||||
}
|
||||
|
||||
// Initialize 初始化热键服务
|
||||
func (hs *HotkeyService) Initialize() error {
|
||||
config, err := hs.configService.GetConfig()
|
||||
if err != nil {
|
||||
return &HotkeyError{"load_config", err}
|
||||
@@ -229,13 +232,14 @@ func cBool(b bool) C.int {
|
||||
|
||||
// toggleWindow 切换窗口显示状态
|
||||
func (hs *HotkeyService) toggleWindow() {
|
||||
if hs.mainWindow == nil {
|
||||
hs.logger.Error("main window not set")
|
||||
mainWindow := hs.windowHelper.MustGetMainWindow()
|
||||
if mainWindow == nil {
|
||||
hs.logger.Error("main window not found")
|
||||
return
|
||||
}
|
||||
|
||||
// 检查主窗口是否可见
|
||||
if hs.isWindowVisible(hs.mainWindow) {
|
||||
if mainWindow.IsVisible() {
|
||||
// 如果主窗口可见,隐藏所有窗口
|
||||
hs.hideAllWindows()
|
||||
} else {
|
||||
@@ -252,7 +256,7 @@ func (hs *HotkeyService) isWindowVisible(window *application.WebviewWindow) bool
|
||||
// hideAllWindows 隐藏所有窗口
|
||||
func (hs *HotkeyService) hideAllWindows() {
|
||||
// 隐藏主窗口
|
||||
hs.mainWindow.Hide()
|
||||
hs.windowHelper.HideMainWindow()
|
||||
|
||||
// 隐藏所有子窗口
|
||||
if hs.windowService != nil {
|
||||
@@ -268,9 +272,7 @@ func (hs *HotkeyService) hideAllWindows() {
|
||||
// showAllWindows 显示所有窗口
|
||||
func (hs *HotkeyService) showAllWindows() {
|
||||
// 显示主窗口
|
||||
hs.mainWindow.Show()
|
||||
hs.mainWindow.Restore()
|
||||
hs.mainWindow.Focus()
|
||||
hs.windowHelper.FocusMainWindow()
|
||||
|
||||
// 显示所有子窗口
|
||||
if hs.windowService != nil {
|
||||
|
||||
@@ -84,12 +84,12 @@ type HotkeyService struct {
|
||||
logger *log.LogService
|
||||
configService *ConfigService
|
||||
windowService *WindowService
|
||||
app *application.App
|
||||
mainWindow *application.WebviewWindow
|
||||
windowHelper *WindowHelper
|
||||
mu sync.RWMutex
|
||||
isRegistered atomic.Bool
|
||||
currentHotkey *models.HotkeyCombo
|
||||
cancelFunc atomic.Value // 使用atomic.Value存储cancel函数,避免竞态条件
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
// HotkeyError 热键错误
|
||||
@@ -138,6 +138,7 @@ func NewHotkeyService(configService *ConfigService, windowService *WindowService
|
||||
logger: logger,
|
||||
configService: configService,
|
||||
windowService: windowService,
|
||||
windowHelper: NewWindowHelper(),
|
||||
}
|
||||
|
||||
// 设置全局实例
|
||||
@@ -146,12 +147,14 @@ func NewHotkeyService(configService *ConfigService, windowService *WindowService
|
||||
return service
|
||||
}
|
||||
|
||||
// Initialize 初始化热键服务
|
||||
func (hs *HotkeyService) Initialize(app *application.App, mainWindow *application.WebviewWindow) error {
|
||||
hs.app = app
|
||||
hs.mainWindow = mainWindow
|
||||
// ServiceStartup initializes the service when the application starts
|
||||
func (ds *HotkeyService) ServiceStartup(ctx context.Context, options application.ServiceOptions) error {
|
||||
ds.ctx = ctx
|
||||
return ds.Initialize()
|
||||
}
|
||||
|
||||
// 加载并应用当前配置
|
||||
// Initialize 初始化热键服务
|
||||
func (hs *HotkeyService) Initialize() error {
|
||||
config, err := hs.configService.GetConfig()
|
||||
if err != nil {
|
||||
return &HotkeyError{"load_config", err}
|
||||
@@ -311,13 +314,14 @@ func (hs *HotkeyService) IsRegistered() bool {
|
||||
|
||||
// ToggleWindow 切换窗口显示状态
|
||||
func (hs *HotkeyService) ToggleWindow() {
|
||||
if hs.mainWindow == nil {
|
||||
hs.logger.Error("main window not set")
|
||||
mainWindow := hs.windowHelper.MustGetMainWindow()
|
||||
if mainWindow == nil {
|
||||
hs.logger.Error("main window not found")
|
||||
return
|
||||
}
|
||||
|
||||
// 检查主窗口是否可见
|
||||
if hs.isWindowVisible(hs.mainWindow) {
|
||||
if mainWindow.IsVisible() {
|
||||
// 如果主窗口可见,隐藏所有窗口
|
||||
hs.hideAllWindows()
|
||||
} else {
|
||||
@@ -334,7 +338,7 @@ func (hs *HotkeyService) isWindowVisible(window *application.WebviewWindow) bool
|
||||
// hideAllWindows 隐藏所有窗口
|
||||
func (hs *HotkeyService) hideAllWindows() {
|
||||
// 隐藏主窗口
|
||||
hs.mainWindow.Hide()
|
||||
hs.windowHelper.HideMainWindow()
|
||||
|
||||
// 隐藏所有子窗口
|
||||
if hs.windowService != nil {
|
||||
@@ -350,9 +354,7 @@ func (hs *HotkeyService) hideAllWindows() {
|
||||
// showAllWindows 显示所有窗口
|
||||
func (hs *HotkeyService) showAllWindows() {
|
||||
// 显示主窗口
|
||||
hs.mainWindow.Show()
|
||||
hs.mainWindow.Restore()
|
||||
hs.mainWindow.Focus()
|
||||
hs.windowHelper.FocusMainWindow()
|
||||
|
||||
// 显示所有子窗口
|
||||
if hs.windowService != nil {
|
||||
@@ -374,7 +376,7 @@ func (hs *HotkeyService) ServiceShutdown() error {
|
||||
//export hotkeyTriggered
|
||||
func hotkeyTriggered() {
|
||||
// 通过全局实例调用ToggleWindow
|
||||
if globalHotkeyService != nil && globalHotkeyService.app != nil {
|
||||
if globalHotkeyService != nil {
|
||||
globalHotkeyService.ToggleWindow()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,8 +144,7 @@ type HotkeyService struct {
|
||||
logger *log.LogService
|
||||
configService *ConfigService
|
||||
windowService *WindowService
|
||||
app *application.App
|
||||
mainWindow *application.WebviewWindow
|
||||
windowHelper *WindowHelper
|
||||
|
||||
mu sync.RWMutex
|
||||
currentHotkey *models.HotkeyCombo
|
||||
@@ -202,6 +201,7 @@ func NewHotkeyService(configService *ConfigService, windowService *WindowService
|
||||
logger: logger,
|
||||
configService: configService,
|
||||
windowService: windowService,
|
||||
windowHelper: NewWindowHelper(),
|
||||
ctx: ctx,
|
||||
}
|
||||
// 初始化时设置cancel函数
|
||||
@@ -209,11 +209,14 @@ func NewHotkeyService(configService *ConfigService, windowService *WindowService
|
||||
return service
|
||||
}
|
||||
|
||||
// Initialize 初始化热键服务
|
||||
func (hs *HotkeyService) Initialize(app *application.App, mainWindow *application.WebviewWindow) error {
|
||||
hs.app = app
|
||||
hs.mainWindow = mainWindow
|
||||
// ServiceStartup initializes the service when the application starts
|
||||
func (ds *HotkeyService) ServiceStartup(ctx context.Context, options application.ServiceOptions) error {
|
||||
ds.ctx = ctx
|
||||
return ds.Initialize()
|
||||
}
|
||||
|
||||
// Initialize 初始化热键服务
|
||||
func (hs *HotkeyService) Initialize() error {
|
||||
if int(C.initX11Display()) == 0 {
|
||||
return &HotkeyError{"init_x11", fmt.Errorf("failed to initialize X11 display")}
|
||||
}
|
||||
@@ -346,13 +349,14 @@ func (hs *HotkeyService) hotkeyListener(ctx context.Context, ready chan<- error)
|
||||
|
||||
// toggleWindow 切换窗口显示状态
|
||||
func (hs *HotkeyService) toggleWindow() {
|
||||
if hs.mainWindow == nil {
|
||||
hs.logger.Error("main window not set")
|
||||
mainWindow := hs.windowHelper.MustGetMainWindow()
|
||||
if mainWindow == nil {
|
||||
hs.logger.Error("main window not found")
|
||||
return
|
||||
}
|
||||
|
||||
// 检查主窗口是否可见
|
||||
if hs.isWindowVisible(hs.mainWindow) {
|
||||
if mainWindow.IsVisible() {
|
||||
// 如果主窗口可见,隐藏所有窗口
|
||||
hs.hideAllWindows()
|
||||
} else {
|
||||
@@ -369,7 +373,7 @@ func (hs *HotkeyService) isWindowVisible(window *application.WebviewWindow) bool
|
||||
// hideAllWindows 隐藏所有窗口
|
||||
func (hs *HotkeyService) hideAllWindows() {
|
||||
// 隐藏主窗口
|
||||
hs.mainWindow.Hide()
|
||||
hs.windowHelper.HideMainWindow()
|
||||
|
||||
// 隐藏所有子窗口
|
||||
if hs.windowService != nil {
|
||||
@@ -385,9 +389,7 @@ func (hs *HotkeyService) hideAllWindows() {
|
||||
// showAllWindows 显示所有窗口
|
||||
func (hs *HotkeyService) showAllWindows() {
|
||||
// 显示主窗口
|
||||
hs.mainWindow.Show()
|
||||
hs.mainWindow.Restore()
|
||||
hs.mainWindow.Focus()
|
||||
hs.windowHelper.FocusMainWindow()
|
||||
|
||||
// 显示所有子窗口
|
||||
if hs.windowService != nil {
|
||||
|
||||
@@ -142,6 +142,7 @@ func NewServiceManager() *ServiceManager {
|
||||
databaseService: databaseService,
|
||||
documentService: documentService,
|
||||
windowService: windowService,
|
||||
windowSnapService: windowSnapService,
|
||||
migrationService: migrationService,
|
||||
systemService: systemService,
|
||||
hotkeyService: hotkeyService,
|
||||
@@ -168,6 +169,7 @@ func (sm *ServiceManager) GetServices() []application.Service {
|
||||
application.NewService(sm.databaseService),
|
||||
application.NewService(sm.documentService),
|
||||
application.NewService(sm.windowService),
|
||||
application.NewService(sm.windowSnapService),
|
||||
application.NewService(sm.keyBindingService),
|
||||
application.NewService(sm.extensionService),
|
||||
application.NewService(sm.migrationService),
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
// SystemService 系统监控服务
|
||||
type SystemService struct {
|
||||
logger *log.LogService
|
||||
app *application.App
|
||||
}
|
||||
|
||||
// MemoryStats 内存统计信息
|
||||
@@ -54,11 +53,6 @@ func NewSystemService(logger *log.LogService) *SystemService {
|
||||
}
|
||||
}
|
||||
|
||||
// SetAppReferences 设置应用引用
|
||||
func (ss *SystemService) SetAppReferences(app *application.App) {
|
||||
ss.app = app
|
||||
}
|
||||
|
||||
// GetMemoryStats 获取当前内存统计信息
|
||||
func (ss *SystemService) GetMemoryStats() MemoryStats {
|
||||
var m runtime.MemStats
|
||||
@@ -76,11 +70,8 @@ func (ss *SystemService) GetMemoryStats() MemoryStats {
|
||||
|
||||
// GetSystemInfo 获取系统环境信息
|
||||
func (ss *SystemService) GetSystemInfo() (*SystemInfo, error) {
|
||||
if ss.app == nil {
|
||||
return nil, fmt.Errorf("app reference not set")
|
||||
}
|
||||
|
||||
envInfo := ss.app.Env.Info()
|
||||
app := application.Get()
|
||||
envInfo := app.Env.Info()
|
||||
|
||||
systemInfo := &SystemInfo{
|
||||
OS: envInfo.OS,
|
||||
|
||||
@@ -9,8 +9,7 @@ import (
|
||||
type TrayService struct {
|
||||
logger *log.LogService
|
||||
configService *ConfigService
|
||||
app *application.App
|
||||
mainWindow *application.WebviewWindow
|
||||
windowHelper *WindowHelper
|
||||
}
|
||||
|
||||
// NewTrayService 创建新的系统托盘服务实例
|
||||
@@ -18,15 +17,10 @@ func NewTrayService(logger *log.LogService, configService *ConfigService) *TrayS
|
||||
return &TrayService{
|
||||
logger: logger,
|
||||
configService: configService,
|
||||
windowHelper: NewWindowHelper(),
|
||||
}
|
||||
}
|
||||
|
||||
// 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()
|
||||
@@ -41,10 +35,10 @@ func (ts *TrayService) ShouldMinimizeToTray() bool {
|
||||
func (ts *TrayService) HandleWindowClose() {
|
||||
if ts.ShouldMinimizeToTray() {
|
||||
// 隐藏到托盘
|
||||
ts.mainWindow.Hide()
|
||||
ts.windowHelper.HideMainWindow()
|
||||
} else {
|
||||
// 直接退出应用
|
||||
ts.app.Quit()
|
||||
application.Get().Quit()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,21 +46,16 @@ func (ts *TrayService) HandleWindowClose() {
|
||||
func (ts *TrayService) HandleWindowMinimize() {
|
||||
if ts.ShouldMinimizeToTray() {
|
||||
// 隐藏到托盘
|
||||
ts.mainWindow.Hide()
|
||||
ts.windowHelper.HideMainWindow()
|
||||
}
|
||||
}
|
||||
|
||||
// ShowWindow 显示主窗口
|
||||
func (ts *TrayService) ShowWindow() {
|
||||
if ts.mainWindow != nil {
|
||||
ts.mainWindow.Show()
|
||||
ts.mainWindow.Restore()
|
||||
ts.mainWindow.Focus()
|
||||
}
|
||||
ts.windowHelper.FocusMainWindow()
|
||||
}
|
||||
|
||||
// MinimizeButtonClicked 处理标题栏最小化按钮点击
|
||||
func (ts *TrayService) MinimizeButtonClicked() {
|
||||
// 最小化按钮总是执行正常最小化到任务栏,不隐藏到托盘
|
||||
ts.mainWindow.Minimise()
|
||||
ts.windowHelper.MinimiseMainWindow()
|
||||
}
|
||||
|
||||
69
internal/services/window_helper.go
Normal file
69
internal/services/window_helper.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
"voidraft/internal/common/constant"
|
||||
)
|
||||
|
||||
// WindowHelper 窗口辅助工具
|
||||
type WindowHelper struct{}
|
||||
|
||||
// NewWindowHelper 创建窗口辅助工具实例
|
||||
func NewWindowHelper() *WindowHelper {
|
||||
return &WindowHelper{}
|
||||
}
|
||||
|
||||
// GetMainWindow 获取主窗口实例
|
||||
// 返回窗口对象和是否找到的标志
|
||||
func (wh *WindowHelper) GetMainWindow() (application.Window, bool) {
|
||||
app := application.Get()
|
||||
return app.Window.GetByName(constant.VOIDRAFT_MAIN_WINDOW_NAME)
|
||||
}
|
||||
|
||||
// MustGetMainWindow 获取主窗口实例
|
||||
// 如果窗口不存在则返回 nil
|
||||
func (wh *WindowHelper) MustGetMainWindow() application.Window {
|
||||
window, ok := wh.GetMainWindow()
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return window
|
||||
}
|
||||
|
||||
// ShowMainWindow 显示主窗口
|
||||
func (wh *WindowHelper) ShowMainWindow() bool {
|
||||
if window := wh.MustGetMainWindow(); window != nil {
|
||||
window.Show()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// HideMainWindow 隐藏主窗口
|
||||
func (wh *WindowHelper) HideMainWindow() bool {
|
||||
if window := wh.MustGetMainWindow(); window != nil {
|
||||
window.Hide()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// MinimiseMainWindow 最小化主窗口
|
||||
func (wh *WindowHelper) MinimiseMainWindow() bool {
|
||||
if window := wh.MustGetMainWindow(); window != nil {
|
||||
window.Minimise()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// FocusMainWindow 聚焦主窗口
|
||||
func (wh *WindowHelper) FocusMainWindow() bool {
|
||||
if window := wh.MustGetMainWindow(); window != nil {
|
||||
window.Show()
|
||||
window.Restore()
|
||||
window.Focus()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -2,14 +2,16 @@ package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"sync"
|
||||
"voidraft/internal/common/constant"
|
||||
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
"github.com/wailsapp/wails/v3/pkg/events"
|
||||
"github.com/wailsapp/wails/v3/pkg/services/log"
|
||||
)
|
||||
|
||||
// WindowInfo 窗口信息(简化版)
|
||||
// WindowInfo 窗口信息
|
||||
type WindowInfo struct {
|
||||
Window *application.WebviewWindow
|
||||
DocumentID int64
|
||||
@@ -20,8 +22,6 @@ type WindowInfo struct {
|
||||
type WindowService struct {
|
||||
logger *log.LogService
|
||||
documentService *DocumentService
|
||||
app *application.App
|
||||
mainWindow *application.WebviewWindow
|
||||
windows map[int64]*WindowInfo // documentID -> WindowInfo
|
||||
mu sync.RWMutex
|
||||
|
||||
@@ -47,17 +47,6 @@ func (ws *WindowService) SetWindowSnapService(snapService *WindowSnapService) {
|
||||
ws.windowSnapService = snapService
|
||||
}
|
||||
|
||||
// SetAppReferences 设置应用和主窗口引用
|
||||
func (ws *WindowService) SetAppReferences(app *application.App, mainWindow *application.WebviewWindow) {
|
||||
ws.app = app
|
||||
ws.mainWindow = mainWindow
|
||||
|
||||
// 如果吸附服务已设置,也为它设置引用
|
||||
if ws.windowSnapService != nil {
|
||||
ws.windowSnapService.SetAppReferences(app, mainWindow)
|
||||
}
|
||||
}
|
||||
|
||||
// OpenDocumentWindow 为指定文档ID打开新窗口
|
||||
func (ws *WindowService) OpenDocumentWindow(documentID int64) error {
|
||||
ws.mu.Lock()
|
||||
@@ -81,11 +70,13 @@ func (ws *WindowService) OpenDocumentWindow(documentID int64) error {
|
||||
return fmt.Errorf("document not found: %d", documentID)
|
||||
}
|
||||
|
||||
app := application.Get()
|
||||
// 创建新窗口
|
||||
newWindow := ws.app.Window.NewWithOptions(application.WebviewWindowOptions{
|
||||
newWindow := app.Window.NewWithOptions(application.WebviewWindowOptions{
|
||||
Name: strconv.FormatInt(doc.ID, 10),
|
||||
Title: fmt.Sprintf("voidraft - %s", doc.Title),
|
||||
Width: 700,
|
||||
Height: 800,
|
||||
Width: constant.VOIDRAFT_WINDOW_WIDTH,
|
||||
Height: constant.VOIDRAFT_WINDOW_HEIGHT,
|
||||
Hidden: false,
|
||||
Frameless: true,
|
||||
DevToolsEnabled: false,
|
||||
@@ -104,7 +95,7 @@ func (ws *WindowService) OpenDocumentWindow(documentID int64) error {
|
||||
|
||||
newWindow.Center()
|
||||
|
||||
ws.app.Window.Add(newWindow)
|
||||
app.Window.Add(newWindow)
|
||||
|
||||
// 保存窗口信息
|
||||
windowInfo := &WindowInfo{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -15,8 +16,7 @@ import (
|
||||
type WindowSnapService struct {
|
||||
logger *log.LogService
|
||||
configService *ConfigService
|
||||
app *application.App
|
||||
mainWindow *application.WebviewWindow
|
||||
windowHelper *WindowHelper
|
||||
mu sync.RWMutex
|
||||
|
||||
// 吸附配置
|
||||
@@ -53,6 +53,7 @@ func NewWindowSnapService(logger *log.LogService, configService *ConfigService)
|
||||
return &WindowSnapService{
|
||||
logger: logger,
|
||||
configService: configService,
|
||||
windowHelper: NewWindowHelper(),
|
||||
snapEnabled: snapEnabled,
|
||||
baseThresholdRatio: 0.025, // 2.5%的主窗口宽度作为基础阈值
|
||||
minThreshold: 8, // 最小8像素(小屏幕保底)
|
||||
@@ -62,18 +63,14 @@ func NewWindowSnapService(logger *log.LogService, configService *ConfigService)
|
||||
}
|
||||
}
|
||||
|
||||
// SetAppReferences 设置应用和主窗口引用
|
||||
func (wss *WindowSnapService) SetAppReferences(app *application.App, mainWindow *application.WebviewWindow) {
|
||||
wss.app = app
|
||||
wss.mainWindow = mainWindow
|
||||
|
||||
// ServiceStartup 服务启动时初始化
|
||||
func (wss *WindowSnapService) ServiceStartup(ctx context.Context, options application.ServiceOptions) error {
|
||||
// 初始化主窗口位置缓存
|
||||
wss.updateMainWindowCache()
|
||||
|
||||
// 设置主窗口移动事件监听
|
||||
if mainWindow != nil {
|
||||
wss.setupMainWindowEvents()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterWindow 注册需要吸附管理的窗口
|
||||
@@ -171,8 +168,14 @@ func (wss *WindowSnapService) OnWindowSnapConfigChanged(enabled bool) error {
|
||||
|
||||
// setupMainWindowEvents 设置主窗口事件监听
|
||||
func (wss *WindowSnapService) setupMainWindowEvents() {
|
||||
// 获取主窗口
|
||||
mainWindow, ok := wss.windowHelper.GetMainWindow()
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
// 监听主窗口移动事件
|
||||
wss.mainWindow.RegisterHook(events.Common.WindowDidMove, func(event *application.WindowEvent) {
|
||||
mainWindow.RegisterHook(events.Common.WindowDidMove, func(event *application.WindowEvent) {
|
||||
wss.onMainWindowMoved()
|
||||
})
|
||||
}
|
||||
@@ -187,12 +190,13 @@ func (wss *WindowSnapService) setupWindowEvents(window *application.WebviewWindo
|
||||
|
||||
// updateMainWindowCache 更新主窗口缓存
|
||||
func (wss *WindowSnapService) updateMainWindowCache() {
|
||||
if wss.mainWindow == nil {
|
||||
mainWindow := wss.windowHelper.MustGetMainWindow()
|
||||
if mainWindow == nil {
|
||||
return
|
||||
}
|
||||
|
||||
x, y := wss.mainWindow.Position()
|
||||
w, h := wss.mainWindow.Size()
|
||||
x, y := mainWindow.Position()
|
||||
w, h := mainWindow.Size()
|
||||
|
||||
wss.lastMainWindowPos = models.WindowPosition{X: x, Y: y}
|
||||
wss.lastMainWindowSize = [2]int{w, h}
|
||||
|
||||
@@ -9,7 +9,8 @@ import (
|
||||
)
|
||||
|
||||
// SetupSystemTray 设置系统托盘及其功能
|
||||
func SetupSystemTray(app *application.App, mainWindow *application.WebviewWindow, assets embed.FS, trayService *services.TrayService) {
|
||||
func SetupSystemTray(mainWindow *application.WebviewWindow, assets embed.FS, trayService *services.TrayService) {
|
||||
app := application.Get()
|
||||
// 创建系统托盘
|
||||
systray := app.SystemTray.New()
|
||||
// 设置提示
|
||||
|
||||
45
main.go
45
main.go
@@ -6,6 +6,7 @@ import (
|
||||
"log"
|
||||
"log/slog"
|
||||
"time"
|
||||
"voidraft/internal/common/constant"
|
||||
"voidraft/internal/services"
|
||||
"voidraft/internal/systray"
|
||||
|
||||
@@ -70,9 +71,10 @@ func main() {
|
||||
// 'BackgroundColour' is the background colour of the window.
|
||||
// 'URL' is the URL that will be loaded into the webview.
|
||||
mainWindow := app.Window.NewWithOptions(application.WebviewWindowOptions{
|
||||
Title: "voidraft",
|
||||
Width: 700,
|
||||
Height: 800,
|
||||
Name: constant.VOIDRAFT_MAIN_WINDOW_NAME,
|
||||
Title: constant.VOIDRAFT_WINDOW_TITLE,
|
||||
Width: constant.VOIDRAFT_WINDOW_WIDTH,
|
||||
Height: constant.VOIDRAFT_WINDOW_HEIGHT,
|
||||
Hidden: false,
|
||||
Frameless: true,
|
||||
DevToolsEnabled: false,
|
||||
@@ -89,46 +91,15 @@ func main() {
|
||||
URL: "/",
|
||||
})
|
||||
mainWindow.Center()
|
||||
mainWindow.Focus()
|
||||
window = mainWindow
|
||||
|
||||
// 获取系统服务并设置应用引用
|
||||
systemService := serviceManager.GetSystemService()
|
||||
systemService.SetAppReferences(app)
|
||||
|
||||
// 获取托盘服务并设置应用引用
|
||||
trayService := serviceManager.GetTrayService()
|
||||
trayService.SetAppReferences(app, mainWindow)
|
||||
|
||||
// 获取窗口服务并设置应用引用
|
||||
windowService := serviceManager.GetWindowService()
|
||||
windowService.SetAppReferences(app, mainWindow)
|
||||
|
||||
// 设置系统托盘
|
||||
systray.SetupSystemTray(app, mainWindow, assets, trayService)
|
||||
|
||||
// 初始化热键服务
|
||||
hotkeyService := serviceManager.GetHotkeyService()
|
||||
err := hotkeyService.Initialize(app, mainWindow)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// 设置对话框服务的窗口绑定
|
||||
dialogService := serviceManager.GetDialogService()
|
||||
dialogService.SetWindow(mainWindow)
|
||||
|
||||
// Create a goroutine that emits an event containing the current time every second.
|
||||
// The frontend can listen to this event and update the UI accordingly.
|
||||
go func() {
|
||||
for {
|
||||
now := time.Now().Format(time.RFC1123)
|
||||
app.Event.Emit("time", now)
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}()
|
||||
systray.SetupSystemTray(mainWindow, assets, trayService)
|
||||
|
||||
// Run the application. This blocks until the application has been exited.
|
||||
err = app.Run()
|
||||
err := app.Run()
|
||||
|
||||
// If an error occurred while running the application, log it and exit.
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user