Skip to content

Commit af40b08

Browse files
committed
fix: try autologin after 401 error
1 parent 5e2ea86 commit af40b08

File tree

5 files changed

+53
-36
lines changed

5 files changed

+53
-36
lines changed

src/main/classes/windows/BaseWindow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ export class BaseWindow {
110110
function onOpenDevTools(e, page) {
111111
instance.openDevTool(page)
112112
}
113-
114113
window.once('ready-to-show', onReady)
115114
isDev() && window.webContents.ipc.on(IPC_EVENTS.OPEN_DEV_TOOLS, onOpenDevTools)
115+
!isDev() && window.removeMenu()
116116

117117
this._window = window
118118
}

src/main/main.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { app, ipcMain, nativeTheme, powerMonitor, protocol, systemPreferences } from 'electron'
1+
import { app, globalShortcut, ipcMain, nativeTheme, powerMonitor, protocol, systemPreferences } from 'electron'
22
import { registerIpcEvents } from '@/lib/ipcEvents'
33
import { AccountController } from './classes/controllers'
44
import { PhoneIslandController } from './classes/controllers/PhoneIslandController'
@@ -230,6 +230,11 @@ function attachOnReadyProcess() {
230230
}
231231
})
232232

233+
//Override globalShortcut to prevent the user from opening developer tools
234+
globalShortcut.register('alt', () => {
235+
return false
236+
})
237+
233238
if (isDev()) {
234239
const events: string[] = [
235240
'accessibility-support-changed',

src/renderer/src/components/pageComponents/login/DisplayedAccountLogin.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ export function DisplayedAccountLogin({
3737
<div className='flex flex-row justify-between items-center w-[325px]'>
3838
<p className="w-[300px] truncate">
3939
{account
40-
? `${account.data?.name} (${account.data?.endpoints.mainextension[0].id})`
40+
? <span>
41+
<span>
42+
{account.data?.name}
43+
</span>
44+
{isDev() && <div className='text-xs'>[{account.data?.endpoints.mainextension[0].id} - {account.host}]</div>}
45+
</span>
4146
: t('Login.Use Another Account')}
4247
</p>
4348
{

src/renderer/src/hooks/useAccount.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,25 @@ export const useAccount = () => {
4747
}
4848

4949
const updateAccountData = async () => {
50-
const me = await NethVoiceAPI.User.me()
51-
Log.debug('phone-island-default-device-updated', me.default_device)
52-
const device = {
53-
type: me.default_device.type as AvailableDevices,
54-
id: me.default_device.id
55-
}
56-
setDevice(() => device)
57-
setAccount((p) => ({
58-
...p!,
59-
data: {
60-
...p?.data,
61-
...me
50+
try {
51+
const me = await NethVoiceAPI.User.me()
52+
Log.debug('phone-island-default-device-updated', me.default_device)
53+
const device = {
54+
type: me.default_device.type as AvailableDevices,
55+
id: me.default_device.id
6256
}
63-
}))
64-
57+
setDevice(() => device)
58+
setAccount((p) => ({
59+
...p!,
60+
data: {
61+
...p?.data,
62+
...me
63+
}
64+
}))
65+
} catch (e) {
66+
Log.error(e)
67+
throw e
68+
}
6569
}
6670

6771
return {

src/renderer/src/pages/NethLinkPage.tsx

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ import { ConnectionErrorDialog } from '@renderer/components'
1212
import { debouncer } from '@shared/utils/utils'
1313
import { useAccount } from '@renderer/hooks/useAccount'
1414
import { Sidebar } from '@renderer/components/Modules/NethVoice/BaseModule/Sidebar'
15-
import { AvailableDevices } from '@shared/types'
1615
import { sendNotification } from '@renderer/utils'
17-
import { AxiosError } from 'axios'
1816

1917

2018
export interface NethLinkPageProps {
@@ -107,33 +105,38 @@ export function NethLinkPage({ handleRefreshConnection }: NethLinkPageProps) {
107105
}
108106

109107
async function loadData() {
110-
Log.debug('update account')
111-
NethVoiceAPI.fetchOperators().then((op) => {
112-
saveOperators(op)
113-
updateAccountData()
114-
})
115-
NethVoiceAPI.HistoryCall.interval().then(saveLastCalls)
116-
117-
NethVoiceAPI.AstProxy.getQueues().then(onQueueUpdate)
118-
if (hasPermission(PERMISSION.PARKINGS))
119-
NethVoiceAPI.AstProxy.getParkings().then(onParkingsUpdate)
120-
reloadData()
108+
Log.info('update account')
109+
try {
110+
await updateAccountData()
111+
NethVoiceAPI.fetchOperators().then(saveOperators)
112+
NethVoiceAPI.HistoryCall.interval().then(saveLastCalls)
113+
NethVoiceAPI.AstProxy.getQueues().then(onQueueUpdate)
114+
if (hasPermission(PERMISSION.PARKINGS))
115+
NethVoiceAPI.AstProxy.getParkings().then(onParkingsUpdate)
116+
reloadData()
117+
} catch (e) {
118+
Log.warning(e)
119+
if (e['status'] === 401) {
120+
Log.error(e)
121+
window.electron.send(IPC_EVENTS.RESUME)
122+
}
123+
}
121124
}
122125

123126
async function reloadData() {
124127
Log.debug('RELOAD DATA', isFetching.current)
125128
if (!isFetching.current) {
126129
isFetching.current = true
127-
NethVoiceAPI.Phonebook.getSpeeddials().then((s) => {
128-
saveSpeeddials(s)
129-
updateAccountData()
130-
}).catch((e: AxiosError) => {
130+
try {
131+
await updateAccountData()
132+
} catch (e) {
131133
Log.warning(e)
132-
if (e.status === 401) {
134+
if (e['status'] === 401) {
133135
Log.error(e)
134136
window.electron.send(IPC_EVENTS.RESUME)
135137
}
136-
})
138+
}
139+
NethVoiceAPI.Phonebook.getSpeeddials().then(saveSpeeddials)
137140
}
138141
debouncer('speeddial-fetch', () => {
139142
isFetching.current = false

0 commit comments

Comments
 (0)