11import { AccountController , DevToolsController } from '@/classes/controllers'
22import { LoginController } from '@/classes/controllers/LoginController'
33import { PhoneIslandController } from '@/classes/controllers/PhoneIslandController'
4- import { IPC_EVENTS , PHONE_ISLAND_EVENTS } from '@shared/constants'
4+ import { IPC_EVENTS } from '@shared/constants'
55import { Account , OnDraggingWindow , PAGES } from '@shared/types'
66import { BrowserWindow , app , ipcMain , screen , shell } from 'electron'
77import { join } from 'path'
@@ -13,7 +13,7 @@ import { debouncer, getAccountUID, getPageFromQuery } from '@shared/utils/utils'
1313import { NetworkController } from '@/classes/controllers/NetworkController'
1414import { useLogin } from '@shared/useLogin'
1515import { PhoneIslandWindow } from '@/classes/windows'
16- import http from 'http'
16+ import { ClientRequest , get } from 'http'
1717
1818function onSyncEmitter < T > (
1919 channel : IPC_EVENTS ,
@@ -48,31 +48,40 @@ export function registerIpcEvents() {
4848 let draggingWindows : OnDraggingWindow = { }
4949
5050 onSyncEmitter ( IPC_EVENTS . GET_LOCALE , async ( ) => {
51- return app . getSystemLocale ( )
51+ return app . getLocale ( )
5252 } )
5353
5454 ipcMain . on ( IPC_EVENTS . EMIT_START_CALL , async ( _event , phoneNumber ) => {
5555 PhoneIslandController . instance . call ( phoneNumber )
5656 } )
5757
5858 ipcMain . on ( IPC_EVENTS . START_CALL_BY_URL , async ( _event , url ) => {
59- function triggerError ( e , request : http . ClientRequest | undefined = undefined ) {
59+ function triggerError ( e , request : ClientRequest | undefined = undefined ) {
6060 Log . error ( e )
61- PhoneIslandController . instance . window . emit ( IPC_EVENTS . END_CALL )
62- NethLinkController . instance . window . emit ( IPC_EVENTS . RESPONSE_START_CALL_BY_URL , false )
63- request && request . destroy ( )
61+ try {
62+ PhoneIslandController . instance . window . emit ( IPC_EVENTS . END_CALL )
63+ NethLinkController . instance . window . emit ( IPC_EVENTS . RESPONSE_START_CALL_BY_URL , false )
64+ } catch ( e ) {
65+ Log . error ( e )
66+ } finally {
67+ request && request . destroy ( )
68+ }
6469 }
6570 try {
66- const request = http . get ( url , {
67- timeout : 3000
68- } , ( res ) => {
69- if ( res . statusCode !== 200 ) {
70- triggerError ( new Error ( 'status error' ) , request )
71+ const request = get (
72+ url ,
73+ {
74+ timeout : 3000
75+ } ,
76+ ( res ) => {
77+ if ( res . statusCode !== 200 ) {
78+ triggerError ( new Error ( 'status error' ) , request )
79+ }
80+ NethLinkController . instance . window . emit ( IPC_EVENTS . RESPONSE_START_CALL_BY_URL , true )
81+ PhoneIslandController . instance . window . show ( )
82+ Log . debug ( 'START_CALL_BY_URL' , url , res . statusCode )
7183 }
72- NethLinkController . instance . window . emit ( IPC_EVENTS . RESPONSE_START_CALL_BY_URL , true )
73- PhoneIslandController . instance . window . show ( )
74- Log . info ( 'START_CALL_BY_URL' , url , res . statusCode )
75- } )
84+ )
7685
7786 request . on ( 'error' , ( e ) => {
7887 triggerError ( e , request )
@@ -86,8 +95,13 @@ export function registerIpcEvents() {
8695 const windows = BrowserWindow . getAllWindows ( ) ;
8796 store . updateStore ( newState , `${ page } [${ selector } ]` )
8897 windows . forEach ( win => {
89- if ( page !== win . webContents . getTitle ( ) ) {
90- win . webContents . send ( IPC_EVENTS . SHARED_STATE_UPDATED , newState , page ) ;
98+ const targetPage = win . webContents . getTitle ( )
99+ try {
100+ if ( page !== targetPage ) {
101+ win . webContents . send ( IPC_EVENTS . SHARED_STATE_UPDATED , newState , page ) ;
102+ }
103+ } catch ( e ) {
104+ Log . error ( `Data origin: ${ page } , target: ${ targetPage } ` , e )
91105 }
92106 } ) ;
93107 } ) ;
@@ -173,7 +187,7 @@ export function registerIpcEvents() {
173187
174188 ipcMain . on ( IPC_EVENTS . UPDATE_CONNECTION_STATE , ( _ , isOnline ) => {
175189 if ( store . store ) {
176- Log . info ( 'INFO update connection state:' , isOnline )
190+ Log . info ( 'Update connection state:' , isOnline )
177191 store . set ( 'connection' , isOnline )
178192 if ( ! store . store . account ) {
179193 store . saveToDisk ( )
@@ -231,10 +245,16 @@ export function registerIpcEvents() {
231245
232246 ipcMain . on ( IPC_EVENTS . CHANGE_THEME , ( _ , theme ) => {
233247 AccountController . instance . updateTheme ( theme )
234- //PhoneIslandController.instance?.window?.emit(IPC_EVENTS.ON_CHANGE_THEME, theme)
235- //LoginController.instance?.window?.emit(IPC_EVENTS.ON_CHANGE_THEME, theme)
236- DevToolsController . instance ?. window ?. emit ( IPC_EVENTS . ON_CHANGE_THEME , theme )
237- NethLinkController . instance ?. window ?. emit ( IPC_EVENTS . ON_CHANGE_THEME , theme )
248+ try {
249+ NethLinkController . instance ?. window ?. emit ( IPC_EVENTS . ON_CHANGE_THEME , theme )
250+ } catch ( e ) {
251+ Log . error ( e )
252+ }
253+ try {
254+ DevToolsController . instance ?. window ?. emit ( IPC_EVENTS . ON_CHANGE_THEME , theme )
255+ } catch ( e ) {
256+ Log . error ( e )
257+ }
238258 } )
239259
240260 ipcMain . on ( IPC_EVENTS . GET_NETHVOICE_CONFIG , async ( e , account ) => {
@@ -246,23 +266,43 @@ export function registerIpcEvents() {
246266 } )
247267
248268 ipcMain . on ( IPC_EVENTS . EMIT_QUEUE_UPDATE , ( _ , queue ) => {
249- NethLinkController . instance . window . emit ( IPC_EVENTS . EMIT_QUEUE_UPDATE , queue )
269+ try {
270+ NethLinkController . instance . window . emit ( IPC_EVENTS . EMIT_QUEUE_UPDATE , queue )
271+ } catch ( e ) {
272+ Log . error ( e )
273+ }
250274 } )
251275
252276 ipcMain . on ( IPC_EVENTS . EMIT_CALL_END , ( _ ) => {
253- NethLinkController . instance . window . emit ( IPC_EVENTS . EMIT_CALL_END )
277+ try {
278+ NethLinkController . instance . window . emit ( IPC_EVENTS . EMIT_CALL_END )
279+ } catch ( e ) {
280+ Log . error ( e )
281+ }
254282 } )
255283
256284 ipcMain . on ( IPC_EVENTS . EMIT_MAIN_PRESENCE_UPDATE , ( _ , mainPresence ) => {
257- NethLinkController . instance . window . emit ( IPC_EVENTS . EMIT_MAIN_PRESENCE_UPDATE , mainPresence )
285+ try {
286+ NethLinkController . instance . window . emit ( IPC_EVENTS . EMIT_MAIN_PRESENCE_UPDATE , mainPresence )
287+ } catch ( e ) {
288+ Log . error ( e )
289+ }
258290 } )
259291
260292 ipcMain . on ( IPC_EVENTS . EMIT_PARKING_UPDATE , ( _ ) => {
261- NethLinkController . instance . window . emit ( IPC_EVENTS . EMIT_PARKING_UPDATE )
293+ try {
294+ NethLinkController . instance . window . emit ( IPC_EVENTS . EMIT_PARKING_UPDATE )
295+ } catch ( e ) {
296+ Log . error ( e )
297+ }
262298 } )
263299
264300 ipcMain . on ( IPC_EVENTS . UPDATE_ACCOUNT , ( _ ) => {
265- NethLinkController . instance . window . emit ( IPC_EVENTS . UPDATE_ACCOUNT )
301+ try {
302+ NethLinkController . instance . window . emit ( IPC_EVENTS . UPDATE_ACCOUNT )
303+ } catch ( e ) {
304+ Log . error ( e )
305+ }
266306 } )
267307
268308 ipcMain . on ( IPC_EVENTS . RECONNECT_SOCKET , async ( ) => {
0 commit comments