Optimize window snapping performance

This commit is contained in:
2025-09-04 00:19:02 +08:00
parent 6149bc133d
commit 8e2bafba5f
9 changed files with 297 additions and 576 deletions

View File

@@ -469,15 +469,10 @@ export class GeneralConfig {
/**
* 窗口吸附设置
* 是否启用窗口吸附功能
* 是否启用窗口吸附功能(阈值现在是自适应的)
*/
"enableWindowSnap": boolean;
/**
* 吸附距离阈值(像素)
*/
"snapThreshold": number;
/**
* 全局热键设置
* 是否启用全局热键
@@ -506,9 +501,6 @@ export class GeneralConfig {
if (!("enableWindowSnap" in $$source)) {
this["enableWindowSnap"] = false;
}
if (!("snapThreshold" in $$source)) {
this["snapThreshold"] = 0;
}
if (!("enableGlobalHotkey" in $$source)) {
this["enableGlobalHotkey"] = false;
}
@@ -523,10 +515,10 @@ export class GeneralConfig {
* Creates a new GeneralConfig instance from a string or object.
*/
static createFrom($$source: any = {}): GeneralConfig {
const $$createField7_0 = $$createType8;
const $$createField6_0 = $$createType8;
let $$parsedSource = typeof $$source === 'string' ? JSON.parse($$source) : $$source;
if ("globalHotkey" in $$parsedSource) {
$$parsedSource["globalHotkey"] = $$createField7_0($$parsedSource["globalHotkey"]);
$$parsedSource["globalHotkey"] = $$createField6_0($$parsedSource["globalHotkey"]);
}
return new GeneralConfig($$parsedSource as Partial<GeneralConfig>);
}

View File

@@ -22,11 +22,19 @@ export function Cleanup(): Promise<void> & { cancel(): void } {
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, threshold: number): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(3794787039, enabled, threshold) as any;
export function OnWindowSnapConfigChanged(enabled: boolean): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(3794787039, enabled) as any;
return $resultPromise;
}
@@ -62,22 +70,6 @@ export function SetSnapEnabled(enabled: boolean): Promise<void> & { cancel(): vo
return $resultPromise;
}
/**
* SetSnapThreshold 设置窗口吸附阈值
*/
export function SetSnapThreshold(threshold: number): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(586790049, threshold) as any;
return $resultPromise;
}
/**
* StartWindowSnapMonitor 启动窗口吸附监听器
*/
export function StartWindowSnapMonitor(): Promise<void> & { cancel(): void } {
let $resultPromise = $Call.ByID(84533508) as any;
return $resultPromise;
}
/**
* UnregisterWindow 取消注册窗口
*/

View File

@@ -64,7 +64,6 @@ const GENERAL_CONFIG_KEY_MAP: GeneralConfigKeyMap = {
enableGlobalHotkey: 'general.enableGlobalHotkey',
globalHotkey: 'general.globalHotkey',
enableWindowSnap: 'general.enableWindowSnap',
snapThreshold: 'general.snapThreshold'
} as const;
const EDITING_CONFIG_KEY_MAP: EditingConfigKeyMap = {
@@ -180,7 +179,6 @@ const DEFAULT_CONFIG: AppConfig = {
key: 'X'
},
enableWindowSnap: true,
snapThreshold: 15
},
editing: {
fontSize: CONFIG_LIMITS.fontSize.default,
@@ -527,7 +525,6 @@ export const useConfigStore = defineStore('config', () => {
// 窗口吸附配置相关方法
setEnableWindowSnap: async (value: boolean) => await updateGeneralConfig('enableWindowSnap', value),
setSnapThreshold: async (value: number) => await updateGeneralConfig('snapThreshold', value),
// 更新配置相关方法
setAutoUpdate: async (value: boolean) => await updateUpdatesConfig('autoUpdate', value),