From 698473007a91c74ac5f201c001ad599a1a747362 Mon Sep 17 00:00:00 2001 From: sanio Date: Tue, 15 Jul 2025 14:59:14 +0900 Subject: [PATCH] delete movementmanager dependency in shortcutsservice --- src/features/shortcuts/shortcutsService.js | 18 ++++++------- src/ui/settings/ShortCutSettingsView.js | 2 ++ src/window/windowManager.js | 30 +++++++++++++--------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/features/shortcuts/shortcutsService.js b/src/features/shortcuts/shortcutsService.js index 44ad6e7..ec2cc2c 100644 --- a/src/features/shortcuts/shortcutsService.js +++ b/src/features/shortcuts/shortcutsService.js @@ -8,13 +8,11 @@ class ShortcutsService { constructor() { this.lastVisibleWindows = new Set(['header']); this.mouseEventsIgnored = false; - this.movementManager = null; this.windowPool = null; this.allWindowVisibility = true; } - initialize(movementManager, windowPool) { - this.movementManager = movementManager; + initialize(windowPool) { this.windowPool = windowPool; internalBridge.on('reregister-shortcuts', () => { console.log('[ShortcutsService] Reregistering shortcuts due to header state change.'); @@ -138,7 +136,7 @@ class ShortcutsService { } async registerShortcuts(registerOnlyToggleVisibility = false) { - if (!this.movementManager || !this.windowPool) { + if (!this.windowPool) { console.error('[Shortcuts] Service not initialized. Cannot register shortcuts.'); return; } @@ -179,7 +177,7 @@ class ShortcutsService { if (displays.length > 1) { displays.forEach((display, index) => { const key = `${modifier}+Shift+${index + 1}`; - globalShortcut.register(key, () => this.movementManager.moveToDisplay(display.id)); + globalShortcut.register(key, () => internalBridge.emit('window:moveToDisplay', { displayId: display.id })); }); } @@ -190,7 +188,7 @@ class ShortcutsService { ]; edgeDirections.forEach(({ key, direction }) => { globalShortcut.register(key, () => { - if (header && header.isVisible()) this.movementManager.moveToEdge(direction); + if (header && header.isVisible()) internalBridge.emit('window:moveToEdge', { direction }); }); }); @@ -232,16 +230,16 @@ class ShortcutsService { }; break; case 'moveUp': - callback = () => { if (header && header.isVisible()) this.movementManager.moveStep('up'); }; + callback = () => { if (header && header.isVisible()) internalBridge.emit('window:moveStep', { direction: 'up' }); }; break; case 'moveDown': - callback = () => { if (header && header.isVisible()) this.movementManager.moveStep('down'); }; + callback = () => { if (header && header.isVisible()) internalBridge.emit('window:moveStep', { direction: 'down' }); }; break; case 'moveLeft': - callback = () => { if (header && header.isVisible()) this.movementManager.moveStep('left'); }; + callback = () => { if (header && header.isVisible()) internalBridge.emit('window:moveStep', { direction: 'left' }); }; break; case 'moveRight': - callback = () => { if (header && header.isVisible()) this.movementManager.moveStep('right'); }; + callback = () => { if (header && header.isVisible()) internalBridge.emit('window:moveStep', { direction: 'right' }); }; break; case 'toggleClickThrough': callback = () => { diff --git a/src/ui/settings/ShortCutSettingsView.js b/src/ui/settings/ShortCutSettingsView.js index 691a059..808eab4 100644 --- a/src/ui/settings/ShortCutSettingsView.js +++ b/src/ui/settings/ShortCutSettingsView.js @@ -171,6 +171,7 @@ export class ShortcutSettingsView extends LitElement { async handleSave() { if (!window.api) return; + this.feedback = {}; const result = await window.api.shortcutSettingsView.saveShortcuts(this.shortcuts); if (!result.success) { alert('Failed to save shortcuts: ' + result.error); @@ -179,6 +180,7 @@ export class ShortcutSettingsView extends LitElement { handleClose() { if (!window.api) return; + this.feedback = {}; window.api.shortcutSettingsView.closeShortcutSettingsWindow(); } diff --git a/src/window/windowManager.js b/src/window/windowManager.js index 692199e..ac558db 100644 --- a/src/window/windowManager.js +++ b/src/window/windowManager.js @@ -30,8 +30,6 @@ if (shouldUseLiquidGlass) { let isContentProtectionOn = true; let lastVisibleWindows = new Set(['header']); -const HEADER_HEIGHT = 47; -const DEFAULT_WINDOW_WIDTH = 353; let currentHeaderState = 'apikey'; const windowPool = new Map(); @@ -47,22 +45,18 @@ function updateLayout() { } let movementManager = null; - -const FADE_DURATION = 250; -const FADE_FPS = 60; - /** - * 윈도우 투명도를 서서히 변경한다. * @param {BrowserWindow} win * @param {number} from * @param {number} to * @param {number} duration * @param {Function=} onComplete */ -function fadeWindow(win, from, to, duration = FADE_DURATION, onComplete) { +function fadeWindow(win, from, to, duration = 250, onComplete) { if (!win || win.isDestroyed()) return; - const steps = Math.max(1, Math.round(duration / (1000 / FADE_FPS))); + const FPS = 60; + const steps = Math.max(1, Math.round(duration / (1000 / FPS))); let currentStep = 0; win.setOpacity(from); @@ -83,7 +77,7 @@ function fadeWindow(win, from, to, duration = FADE_DURATION, onComplete) { win.setOpacity(to); onComplete && onComplete(); } - }, 1000 / FADE_FPS); + }, 1000 / FPS); } const showSettingsWindow = () => { @@ -106,6 +100,15 @@ function setupWindowController(windowPool, layoutManager, movementManager) { internalBridge.on('window:requestToggleAllWindowsVisibility', ({ targetVisibility }) => { changeAllWindowsVisibility(windowPool, targetVisibility); }); + internalBridge.on('window:moveToDisplay', ({ displayId }) => { + movementManager.moveToDisplay(displayId); + }); + internalBridge.on('window:moveToEdge', ({ direction }) => { + movementManager.moveToEdge(direction); + }); + internalBridge.on('window:moveStep', ({ direction }) => { + movementManager.moveStep(direction); + }); } function changeAllWindowsVisibility(windowPool, targetVisibility) { @@ -302,7 +305,7 @@ async function handleWindowVisibilityRequest(windowPool, layoutManager, movement } else { const currentBounds = win.getBounds(); fadeWindow( - win, 1, 0, FADE_DURATION, + win, 1, 0, undefined, () => win.hide() ); if (name === 'listen') { @@ -625,6 +628,9 @@ function getDisplayById(displayId) { function createWindows() { + const HEADER_HEIGHT = 47; + const DEFAULT_WINDOW_WIDTH = 353; + const primaryDisplay = screen.getPrimaryDisplay(); const { y: workAreaY, width: screenWidth } = primaryDisplay.workArea; @@ -685,7 +691,7 @@ function createWindows() { layoutManager = new WindowLayoutManager(windowPool); header.webContents.once('dom-ready', () => { - shortcutsService.initialize(movementManager, windowPool); + shortcutsService.initialize(windowPool); shortcutsService.registerShortcuts(); });