experiments in a post-browser web
10
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(windows): add center window and center all windows commands

+92
+68
backend/electron/ipc.ts
··· 108 108 import { 109 109 APP_DEF_WIDTH, 110 110 APP_DEF_HEIGHT, 111 + WEB_CORE_ADDRESS, 111 112 getPreloadPath, 112 113 IPC_CHANNELS, 113 114 isHeadless, ··· 2986 2987 return { success: true }; 2987 2988 } catch (error) { 2988 2989 console.error('Failed to move window:', error); 2990 + const message = error instanceof Error ? error.message : String(error); 2991 + return { success: false, error: message }; 2992 + } 2993 + }); 2994 + 2995 + ipcMain.handle('window-center', async (ev, msg) => { 2996 + DEBUG && console.log('window-center', msg); 2997 + 2998 + try { 2999 + let win: BrowserWindow | null = null; 3000 + if (msg?.id) { 3001 + win = BrowserWindow.fromId(msg.id); 3002 + } else { 3003 + const wc = ev.sender; 3004 + win = BrowserWindow.fromWebContents(wc); 3005 + } 3006 + 3007 + if (!win || win.isDestroyed()) { 3008 + return { success: false, error: 'Window not found' }; 3009 + } 3010 + 3011 + const bounds = win.getBounds(); 3012 + const display = screen.getDisplayNearestPoint({ 3013 + x: bounds.x + Math.round(bounds.width / 2), 3014 + y: bounds.y + Math.round(bounds.height / 2) 3015 + }); 3016 + const wa = display.workArea; 3017 + const x = wa.x + Math.round((wa.width - bounds.width) / 2); 3018 + const y = wa.y + Math.round((wa.height - bounds.height) / 2); 3019 + win.setBounds({ x, y, width: bounds.width, height: bounds.height }); 3020 + 3021 + return { success: true }; 3022 + } catch (error) { 3023 + console.error('Failed to center window:', error); 3024 + const message = error instanceof Error ? error.message : String(error); 3025 + return { success: false, error: message }; 3026 + } 3027 + }); 3028 + 3029 + ipcMain.handle('window-center-all', async () => { 3030 + DEBUG && console.log('window-center-all'); 3031 + 3032 + try { 3033 + const windows = BrowserWindow.getAllWindows(); 3034 + let centered = 0; 3035 + 3036 + for (const win of windows) { 3037 + if (win.isDestroyed() || !win.isVisible()) continue; 3038 + 3039 + const info = getWindowInfo(win.id); 3040 + if (info?.params?.address === WEB_CORE_ADDRESS) continue; 3041 + 3042 + const bounds = win.getBounds(); 3043 + const display = screen.getDisplayNearestPoint({ 3044 + x: bounds.x + Math.round(bounds.width / 2), 3045 + y: bounds.y + Math.round(bounds.height / 2) 3046 + }); 3047 + const wa = display.workArea; 3048 + const x = wa.x + Math.round((wa.width - bounds.width) / 2); 3049 + const y = wa.y + Math.round((wa.height - bounds.height) / 2); 3050 + win.setBounds({ x, y, width: bounds.width, height: bounds.height }); 3051 + centered++; 3052 + } 3053 + 3054 + return { success: true, centered }; 3055 + } catch (error) { 3056 + console.error('Failed to center all windows:', error); 2989 3057 const message = error instanceof Error ? error.message : String(error); 2990 3058 return { success: false, error: message }; 2991 3059 }
+16
extensions/windows/background.js
··· 75 75 console.log('[ext:windows] Opening windows view'); 76 76 openWindowsView(); 77 77 } 78 + }, 79 + { 80 + name: 'center window', 81 + description: 'Center the active window on its display', 82 + execute: async (ctx) => { 83 + const windowId = await api.window.getFocusedVisibleWindowId(); 84 + if (!windowId) return { success: false, error: 'No active window' }; 85 + return api.window.center(windowId); 86 + } 87 + }, 88 + { 89 + name: 'center all windows', 90 + description: 'Center all windows on their respective displays', 91 + execute: async (ctx) => { 92 + return api.window.centerAll(); 93 + } 78 94 } 79 95 ]; 80 96
+8
preload.js
··· 367 367 */ 368 368 isTransient: () => { 369 369 return ipcRenderer.invoke('window-is-transient'); 370 + }, 371 + center: (id) => { 372 + DEBUG && console.log('window.center', id); 373 + return ipcRenderer.invoke('window-center', { source: sourceAddress, id }); 374 + }, 375 + centerAll: () => { 376 + DEBUG && console.log('window.centerAll'); 377 + return ipcRenderer.invoke('window-center-all'); 370 378 } 371 379 }; 372 380