delete movementmanager dependency in shortcutsservice
This commit is contained in:
		
							parent
							
								
									c0cf74273a
								
							
						
					
					
						commit
						698473007a
					
				@ -8,13 +8,11 @@ class ShortcutsService {
 | 
				
			|||||||
    constructor() {
 | 
					    constructor() {
 | 
				
			||||||
        this.lastVisibleWindows = new Set(['header']);
 | 
					        this.lastVisibleWindows = new Set(['header']);
 | 
				
			||||||
        this.mouseEventsIgnored = false;
 | 
					        this.mouseEventsIgnored = false;
 | 
				
			||||||
        this.movementManager = null;
 | 
					 | 
				
			||||||
        this.windowPool = null;
 | 
					        this.windowPool = null;
 | 
				
			||||||
        this.allWindowVisibility = true;
 | 
					        this.allWindowVisibility = true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    initialize(movementManager, windowPool) {
 | 
					    initialize(windowPool) {
 | 
				
			||||||
        this.movementManager = movementManager;
 | 
					 | 
				
			||||||
        this.windowPool = windowPool;
 | 
					        this.windowPool = windowPool;
 | 
				
			||||||
        internalBridge.on('reregister-shortcuts', () => {
 | 
					        internalBridge.on('reregister-shortcuts', () => {
 | 
				
			||||||
            console.log('[ShortcutsService] Reregistering shortcuts due to header state change.');
 | 
					            console.log('[ShortcutsService] Reregistering shortcuts due to header state change.');
 | 
				
			||||||
@ -138,7 +136,7 @@ class ShortcutsService {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async registerShortcuts(registerOnlyToggleVisibility = false) {
 | 
					    async registerShortcuts(registerOnlyToggleVisibility = false) {
 | 
				
			||||||
        if (!this.movementManager || !this.windowPool) {
 | 
					        if (!this.windowPool) {
 | 
				
			||||||
            console.error('[Shortcuts] Service not initialized. Cannot register shortcuts.');
 | 
					            console.error('[Shortcuts] Service not initialized. Cannot register shortcuts.');
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -179,7 +177,7 @@ class ShortcutsService {
 | 
				
			|||||||
        if (displays.length > 1) {
 | 
					        if (displays.length > 1) {
 | 
				
			||||||
            displays.forEach((display, index) => {
 | 
					            displays.forEach((display, index) => {
 | 
				
			||||||
                const key = `${modifier}+Shift+${index + 1}`;
 | 
					                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 }) => {
 | 
					        edgeDirections.forEach(({ key, direction }) => {
 | 
				
			||||||
            globalShortcut.register(key, () => {
 | 
					            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;
 | 
					                    break;
 | 
				
			||||||
                case 'moveUp':
 | 
					                case 'moveUp':
 | 
				
			||||||
                    callback = () => { if (header && header.isVisible()) this.movementManager.moveStep('up'); };
 | 
					                    callback = () => { if (header && header.isVisible()) internalBridge.emit('window:moveStep', { direction: 'up' }); };
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                case 'moveDown':
 | 
					                case 'moveDown':
 | 
				
			||||||
                    callback = () => { if (header && header.isVisible()) this.movementManager.moveStep('down'); };
 | 
					                    callback = () => { if (header && header.isVisible()) internalBridge.emit('window:moveStep', { direction: 'down' }); };
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                case 'moveLeft':
 | 
					                case 'moveLeft':
 | 
				
			||||||
                    callback = () => { if (header && header.isVisible()) this.movementManager.moveStep('left'); };
 | 
					                    callback = () => { if (header && header.isVisible()) internalBridge.emit('window:moveStep', { direction: 'left' }); };
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                case 'moveRight':
 | 
					                case 'moveRight':
 | 
				
			||||||
                    callback = () => { if (header && header.isVisible()) this.movementManager.moveStep('right'); };
 | 
					                    callback = () => { if (header && header.isVisible()) internalBridge.emit('window:moveStep', { direction: 'right' }); };
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                case 'toggleClickThrough':
 | 
					                case 'toggleClickThrough':
 | 
				
			||||||
                     callback = () => {
 | 
					                     callback = () => {
 | 
				
			||||||
 | 
				
			|||||||
@ -171,6 +171,7 @@ export class ShortcutSettingsView extends LitElement {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    async handleSave() {
 | 
					    async handleSave() {
 | 
				
			||||||
        if (!window.api) return;
 | 
					        if (!window.api) return;
 | 
				
			||||||
 | 
					        this.feedback = {};
 | 
				
			||||||
        const result = await window.api.shortcutSettingsView.saveShortcuts(this.shortcuts);
 | 
					        const result = await window.api.shortcutSettingsView.saveShortcuts(this.shortcuts);
 | 
				
			||||||
        if (!result.success) {
 | 
					        if (!result.success) {
 | 
				
			||||||
            alert('Failed to save shortcuts: ' + result.error);
 | 
					            alert('Failed to save shortcuts: ' + result.error);
 | 
				
			||||||
@ -179,6 +180,7 @@ export class ShortcutSettingsView extends LitElement {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    handleClose() {
 | 
					    handleClose() {
 | 
				
			||||||
        if (!window.api) return;
 | 
					        if (!window.api) return;
 | 
				
			||||||
 | 
					        this.feedback = {};
 | 
				
			||||||
        window.api.shortcutSettingsView.closeShortcutSettingsWindow();
 | 
					        window.api.shortcutSettingsView.closeShortcutSettingsWindow();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -30,8 +30,6 @@ if (shouldUseLiquidGlass) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
let isContentProtectionOn = true;
 | 
					let isContentProtectionOn = true;
 | 
				
			||||||
let lastVisibleWindows = new Set(['header']);
 | 
					let lastVisibleWindows = new Set(['header']);
 | 
				
			||||||
const HEADER_HEIGHT = 47;
 | 
					 | 
				
			||||||
const DEFAULT_WINDOW_WIDTH = 353;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
let currentHeaderState = 'apikey';
 | 
					let currentHeaderState = 'apikey';
 | 
				
			||||||
const windowPool = new Map();
 | 
					const windowPool = new Map();
 | 
				
			||||||
@ -47,22 +45,18 @@ function updateLayout() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
let movementManager = null;
 | 
					let movementManager = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
const FADE_DURATION = 250;
 | 
					 | 
				
			||||||
const FADE_FPS      = 60;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * 윈도우 투명도를 서서히 변경한다.
 | 
					 | 
				
			||||||
 * @param {BrowserWindow} win
 | 
					 * @param {BrowserWindow} win
 | 
				
			||||||
 * @param {number} from
 | 
					 * @param {number} from
 | 
				
			||||||
 * @param {number} to
 | 
					 * @param {number} to
 | 
				
			||||||
 * @param {number} duration
 | 
					 * @param {number} duration
 | 
				
			||||||
 * @param {Function=} onComplete 
 | 
					 * @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;
 | 
					  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;
 | 
					  let   currentStep = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  win.setOpacity(from);
 | 
					  win.setOpacity(from);
 | 
				
			||||||
@ -83,7 +77,7 @@ function fadeWindow(win, from, to, duration = FADE_DURATION, onComplete) {
 | 
				
			|||||||
      win.setOpacity(to);
 | 
					      win.setOpacity(to);
 | 
				
			||||||
      onComplete && onComplete();
 | 
					      onComplete && onComplete();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }, 1000 / FADE_FPS);
 | 
					  }, 1000 / FPS);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const showSettingsWindow = () => {
 | 
					const showSettingsWindow = () => {
 | 
				
			||||||
@ -106,6 +100,15 @@ function setupWindowController(windowPool, layoutManager, movementManager) {
 | 
				
			|||||||
    internalBridge.on('window:requestToggleAllWindowsVisibility', ({ targetVisibility }) => {
 | 
					    internalBridge.on('window:requestToggleAllWindowsVisibility', ({ targetVisibility }) => {
 | 
				
			||||||
        changeAllWindowsVisibility(windowPool, 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) {
 | 
					function changeAllWindowsVisibility(windowPool, targetVisibility) {
 | 
				
			||||||
@ -302,7 +305,7 @@ async function handleWindowVisibilityRequest(windowPool, layoutManager, movement
 | 
				
			|||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            const currentBounds = win.getBounds();
 | 
					            const currentBounds = win.getBounds();
 | 
				
			||||||
            fadeWindow(
 | 
					            fadeWindow(
 | 
				
			||||||
                win, 1, 0, FADE_DURATION,
 | 
					                win, 1, 0, undefined,
 | 
				
			||||||
                () => win.hide()
 | 
					                () => win.hide()
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
            if (name === 'listen') {
 | 
					            if (name === 'listen') {
 | 
				
			||||||
@ -625,6 +628,9 @@ function getDisplayById(displayId) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function createWindows() {
 | 
					function createWindows() {
 | 
				
			||||||
 | 
					    const HEADER_HEIGHT        = 47;
 | 
				
			||||||
 | 
					    const DEFAULT_WINDOW_WIDTH = 353;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const primaryDisplay = screen.getPrimaryDisplay();
 | 
					    const primaryDisplay = screen.getPrimaryDisplay();
 | 
				
			||||||
    const { y: workAreaY, width: screenWidth } = primaryDisplay.workArea;
 | 
					    const { y: workAreaY, width: screenWidth } = primaryDisplay.workArea;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -685,7 +691,7 @@ function createWindows() {
 | 
				
			|||||||
    layoutManager = new WindowLayoutManager(windowPool);
 | 
					    layoutManager = new WindowLayoutManager(windowPool);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    header.webContents.once('dom-ready', () => {
 | 
					    header.webContents.once('dom-ready', () => {
 | 
				
			||||||
        shortcutsService.initialize(movementManager, windowPool);
 | 
					        shortcutsService.initialize(windowPool);
 | 
				
			||||||
        shortcutsService.registerShortcuts();
 | 
					        shortcutsService.registerShortcuts();
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user