@@ -8,6 +8,14 @@ import {
88} from '../../../utils'
99import { config } from '../../../lib/config'
1010
11+ /**
12+ * Handles getting the window title for the current window.
13+ */
14+ ipcMain . handle ( 'get-window-title' , ( event ) => {
15+ const win = BrowserWindow . fromWebContents ( event . sender )
16+ return win ?. getTitle ( ) || null
17+ } )
18+
1119/**
1220 * Handles the reloading of a widget window.
1321 * @param event - The event object.
@@ -29,50 +37,77 @@ ipcMain.handle(IpcChannels.RECREATE_WIDGET, (event, widgetKey) => {
2937/**
3038 * Handles the resizing of a widget window.
3139 */
32- ipcMain . handle ( IpcChannels . RESIZE_WIDGET_WINDOW , ( ) => {
33- const win = BrowserWindow . getFocusedWindow ( )
34- if ( win ?. title !== config . applicationName ) {
35- const title : string = BrowserWindow . getFocusedWindow ( ) ?. getTitle ( ) as string
36- const widgets : WidgetsConfig = getWidgetsJson ( config . widgetsJsonPath )
37- if (
38- win &&
39- widgets [ title ] &&
40- widgets [ title ] . title !== config . applicationName &&
41- widgets [ title ] . locked === false
42- ) {
43- widgets [ title ] . width = win . getSize ( ) [ 0 ]
44- widgets [ title ] . height = win . getSize ( ) [ 1 ]
45- setWidgetsJson ( widgets , config . widgetsJsonPath )
46- } else {
47- console . error (
48- `Widget with title "${ title } " not found in widgets config.` ,
49- dialog . showErrorBox (
50- 'Widget not found' ,
51- `Widget with title "${ title } " not found in widgets config.` ,
52- ) ,
53- )
54- }
40+ ipcMain . handle ( IpcChannels . RESIZE_WIDGET_WINDOW , ( event , widgetKey : string ) => {
41+ if ( ! widgetKey ) {
42+ console . warn ( 'No widget key provided during resize operation' )
43+ }
44+
45+ const win =
46+ BrowserWindow . fromWebContents ( event . sender ) ||
47+ BrowserWindow . getAllWindows ( ) . find ( ( w ) => w . getTitle ( ) === widgetKey )
48+
49+ if ( ! win ) {
50+ console . warn ( `Window not found for widget: ${ widgetKey } ` )
51+ return
52+ }
53+
54+ const resolvedKey = widgetKey || win . getTitle ( )
55+ if ( win . getTitle ( ) === config . applicationName ) {
56+ return
57+ }
58+
59+ const widgets : WidgetsConfig = getWidgetsJson ( config . widgetsJsonPath )
60+ const widget = widgets [ resolvedKey ]
61+ if ( ! widget ) {
62+ console . error ( `Widget "${ resolvedKey } " not found in widgets config.` )
63+ return
64+ }
65+
66+ if ( widget . locked === true ) {
67+ return
5568 }
69+
70+ const [ width , height ] = win . getSize ( )
71+ widget . width = width
72+ widget . height = height
73+ setWidgetsJson ( widgets , config . widgetsJsonPath )
5674} )
5775
5876/**
5977 * Handles the dragging of a widget window.
6078 */
61- ipcMain . handle ( IpcChannels . DRAG_WIDGET_WINDOW , ( ) => {
79+ ipcMain . handle ( IpcChannels . DRAG_WIDGET_WINDOW , ( event , widgetKey : string ) => {
80+ if ( ! widgetKey ) {
81+ console . warn ( 'No widget key provided during drag operation' )
82+ }
83+
84+ const win =
85+ BrowserWindow . fromWebContents ( event . sender ) ||
86+ BrowserWindow . getAllWindows ( ) . find ( ( w ) => w . getTitle ( ) === widgetKey )
87+
88+ if ( ! win ) {
89+ return
90+ }
91+
92+ const resolvedKey = widgetKey || win . getTitle ( )
93+ if ( win . getTitle ( ) === config . applicationName ) {
94+ return
95+ }
96+
6297 const widgets : WidgetsConfig = getWidgetsJson ( config . widgetsJsonPath )
63- const win = BrowserWindow . getFocusedWindow ( )
64- const title : string = win ?. getTitle ( ) as string
65- if (
66- win &&
67- widgets [ title ] &&
68- win ?. isFocused ( ) &&
69- widgets [ title ] . title !== config . applicationName &&
70- widgets [ title ] . locked === false
71- ) {
72- widgets [ title ] . x = win . getPosition ( ) [ 0 ]
73- widgets [ title ] . y = win . getPosition ( ) [ 1 ]
74- setWidgetsJson ( widgets , config . widgetsJsonPath )
98+ const widget = widgets [ resolvedKey ]
99+ if ( ! widget ) {
100+ return
75101 }
102+
103+ if ( widget . locked === true ) {
104+ return
105+ }
106+
107+ const [ x , y ] = win . getPosition ( )
108+ widget . x = x
109+ widget . y = y
110+ setWidgetsJson ( widgets , config . widgetsJsonPath )
76111} )
77112
78113/**
0 commit comments