Skip to content

Commit d5080f4

Browse files
therockerlineedospadoni
authored andcommitted
fix(ibernation): avoid token expiration after suspend (#54)
1 parent a6dc4c6 commit d5080f4

32 files changed

+338
-252
lines changed

.eslintrc.cjs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,51 @@
11
module.exports = {
2+
env: {
3+
browser: true,
4+
es2021: true,
5+
jest: true
6+
},
27
extends: [
38
'eslint:recommended',
49
'plugin:react/recommended',
510
'plugin:react/jsx-runtime',
611
'@electron-toolkit/eslint-config-ts/recommended',
7-
'@electron-toolkit/eslint-config-prettier'
12+
'@electron-toolkit/eslint-config-prettier',
13+
'eslint:recommended',
14+
'plugin:react/recommended',
15+
'plugin:@typescript-eslint/recommended',
16+
'prettier',
17+
'react-app',
18+
'react-app/jest'
819
],
920
rules: {
1021
// disable the rule for all files
22+
'no-prototype-builtins': 'off',
23+
'no-case-declarations': 'off',
24+
'no-useless-escape': 'off',
1125
'@typescript-eslint/explicit-function-return-type': 'off',
1226
'@typescript-eslint/no-unused-vars': 'warn',
13-
'@typescript-eslint/no-explicit-any': 'warn'
27+
'@typescript-eslint/no-explicit-any': 'warn',
28+
'@typescript-eslint/no-this-alias': 'warn',
29+
'react/react-in-jsx-scope': 'off',
30+
camelcase: 'error',
31+
'spaced-comment': 'error',
32+
quotes: ['error', 'single'],
33+
'no-duplicate-imports': 'error',
34+
'react/display-name': false,
35+
'import/no-anonymous-default-export': 'off'
36+
},
37+
parser: '@typescript-eslint/parser',
38+
parserOptions: {
39+
ecmaFeatures: {
40+
jsx: true
41+
},
42+
ecmaVersion: 'latest',
43+
sourceType: 'module'
44+
},
45+
plugins: ['react', 'react-hooks', '@typescript-eslint', 'prettier'],
46+
settings: {
47+
'import/resolver': {
48+
typescript: {}
49+
}
1450
}
1551
}

.prettierrc.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
singleQuote: true
22
semi: false
3-
printWidth: 100
4-
trailingComma: none
3+
tabWidth: 2
4+
trailingComma: all
5+
jsxSingleQuote: true
6+
bracketSpacing: true

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"runtimeArgs": [
3434
"--sourcemap",
3535
"--",
36-
"DEV=true"
36+
"DEV=true",
37+
"DEBUG=false"
3738
],
3839
"env": {
3940
"REMOTE_DEBUGGING_PORT": "9222",

electron-builder.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
appId: 'com.nethesis.nethlink.app'
22
productName: 'NethLink'
3-
copyright: 'prova copyright'
3+
copyright: 'copyright'
44
afterSign: electron-builder-notarize
55
electronLanguages:
66
- en
77
- en_US
88
- en_UK
9+
- en-US
10+
- en-UK
911
- it
1012
- it_IT
13+
- it-IT
1114
directories:
1215
buildResources: build
1316
files:

src/main/classes/controllers/AccountController.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ export class AccountController {
4747
},
4848
account: undefined,
4949
theme: store.store.theme,
50-
connection: store.store.connection || false
50+
connection: store.store.connection || false,
51+
accountStatus: store.store.accountStatus || 'offline',
52+
isCallsEnabled: store.store.isCallsEnabled || false,
53+
lastDevice: store.store.lastDevice || undefined
5154
}, 'logout')
5255
store.saveToDisk()
5356
}
@@ -116,7 +119,10 @@ export class AccountController {
116119
type: account.data.default_device.type as AvailableDevices,
117120
id: account.data.default_device.id,
118121
} : undefined,
119-
connection: store.store.connection || false
122+
connection: store.store.connection || false,
123+
accountStatus: store.store.accountStatus || 'offline',
124+
isCallsEnabled: store.store.isCallsEnabled || false,
125+
lastDevice: store.store.lastDevice || undefined
120126
}, 'saveLoggedAccount')
121127
store.saveToDisk()
122128
return account
@@ -176,7 +182,7 @@ export class AccountController {
176182

177183
setAccountNethLinkBounds(nethlinkBounds: Electron.Rectangle | undefined): void {
178184
const account = store.store.account
179-
Log.info('MAIN PRESENCE BACK', account?.data?.mainPresence)
185+
Log.debug('MAIN PRESENCE BACK', account?.data?.mainPresence)
180186
const auth = store.store.auth
181187
if (account) {
182188
account!.nethlinkBounds = nethlinkBounds

src/main/classes/controllers/PhoneIslandController.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { Log } from '@shared/utils/logger'
44
import { AccountController } from './AccountController'
55
import { debouncer } from '@shared/utils/utils'
66
import { once } from '@/lib/ipcEvents'
7-
import { useNethVoiceAPI } from '@shared/useNethVoiceAPI'
8-
import { store } from '@/lib/mainStore'
97
import { screen } from 'electron'
108
import { Extension, Size } from '@shared/types'
119

@@ -23,8 +21,8 @@ export class PhoneIslandController {
2321
const { w, h } = size
2422
const window = this.window.getWindow()
2523
if (window) {
26-
let b = window.getBounds()
27-
if (b.height !== h || b.width !== w) {
24+
const bounds = window.getBounds()
25+
if (bounds.height !== h || bounds.width !== w) {
2826
window.setBounds({ width: w, height: h })
2927
PhoneIslandWindow.currentSize = { width: w, height: h }
3028
}
@@ -101,8 +99,8 @@ export class PhoneIslandController {
10199
return new Promise<void>((resolve, reject) => {
102100
try {
103101
this.window.emit(IPC_EVENTS.LOGOUT)
104-
once(IPC_EVENTS.LOGOUT_COMPLETED, () => {
105-
this.window.quit(true)
102+
once(IPC_EVENTS.LOGOUT_COMPLETED, async () => {
103+
await this.window.quit(true)
106104
resolve()
107105
})
108106
} catch (e) {
@@ -113,7 +111,11 @@ export class PhoneIslandController {
113111
}
114112

115113
call(number: string) {
116-
this.window.emit(IPC_EVENTS.START_CALL, number)
114+
try {
115+
this.window.emit(IPC_EVENTS.START_CALL, number)
116+
} catch (e) {
117+
Log.error(`Unable to call ${number}`)
118+
}
117119
}
118120

119121
callTransfer(to: string) {

src/main/classes/windows/BaseWindow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class BaseWindow {
113113

114114
window.once('ready-to-show', onReady)
115115
isDev() && window.webContents.ipc.on(IPC_EVENTS.OPEN_DEV_TOOLS, onOpenDevTools)
116-
116+
!isDev() && window.removeMenu()
117117
this._window = window
118118
}
119119
}

src/main/lib/ipcEvents.ts

Lines changed: 68 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AccountController, DevToolsController } from '@/classes/controllers'
22
import { LoginController } from '@/classes/controllers/LoginController'
33
import { PhoneIslandController } from '@/classes/controllers/PhoneIslandController'
4-
import { IPC_EVENTS, PHONE_ISLAND_EVENTS } from '@shared/constants'
4+
import { IPC_EVENTS } from '@shared/constants'
55
import { Account, OnDraggingWindow, PAGES } from '@shared/types'
66
import { BrowserWindow, app, ipcMain, screen, shell } from 'electron'
77
import { join } from 'path'
@@ -13,7 +13,7 @@ import { debouncer, getAccountUID, getPageFromQuery } from '@shared/utils/utils'
1313
import { NetworkController } from '@/classes/controllers/NetworkController'
1414
import { useLogin } from '@shared/useLogin'
1515
import { PhoneIslandWindow } from '@/classes/windows'
16-
import http from 'http'
16+
import { ClientRequest, get } from 'http'
1717

1818
function 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 () => {

src/main/lib/mainStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Store<T> {
5959

6060
updateStore(newState: T, from: string) {
6161
const diff = difference(Object.values(newState as any || {}), Object.values(this.store as any || {}))
62-
Log.info('STORE update shared store from', from, Object.keys(newState as any || {}))
62+
Log.debug('STORE update shared store from', from, Object.keys(newState as any || {}))
6363
if (diff.length > 0 || this.store === undefined) {
6464
this.store = Object.assign({}, newState)
6565
}

0 commit comments

Comments
 (0)