Skip to content

Commit 57916ef

Browse files
therockerlineedospadonitonyco97
authored
feat: add preferred devices management (#64)
Co-authored-by: Edoardo Spadoni <[email protected]> Co-authored-by: tonyco97 <[email protected]>
1 parent 055e283 commit 57916ef

File tree

26 files changed

+933
-227
lines changed

26 files changed

+933
-227
lines changed

package-lock.json

Lines changed: 104 additions & 94 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@
4444
"@fortawesome/free-regular-svg-icons": "^6.5.1",
4545
"@fortawesome/free-solid-svg-icons": "^6.5.1",
4646
"@fortawesome/react-fontawesome": "^0.2.0",
47-
"@headlessui/react": "^1.7.18",
47+
"@headlessui/react": "^2.1.9",
4848
"@hookform/resolvers": "^3.3.4",
4949
"@nethesis/nethesis-brands-svg-icons": "github:nethesis/Font-Awesome#ns-brands",
5050
"@nethesis/nethesis-light-svg-icons": "github:nethesis/Font-Awesome#ns-light",
5151
"@nethesis/nethesis-solid-svg-icons": "github:nethesis/Font-Awesome#ns-solid",
52-
"@nethesis/phone-island": "^0.14.0",
52+
"@nethesis/phone-island": "^0.14.1",
5353
"@tailwindcss/forms": "^0.5.7",
5454
"@types/lodash": "^4.14.202",
5555
"@types/node": "^18.19.9",

public/locales/en/translations.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@
321321
"Upload image to continue": "Upload image to continue",
322322
"Wrong file type": "Wrong file type",
323323
"Delete profile picture": "Delete profile picture",
324-
"Devices": "Devices",
324+
"Devices": "Audio and Video",
325325
"Time preferences": "Time preferences",
326326
"Login/logout preferences": "Login/logout preferences",
327327
"Logout from queue automatically": "Logout from queue automatically",
@@ -367,8 +367,12 @@
367367
"Shortcut": "Shortcut",
368368
"Keyboard shortcut to call": "Keyboard shortcut to call",
369369
"Shortcut title description": "Choose a keyboard shortcut to dial any selected number. ",
370-
"Shortcut subtitle description": "Warning: avoid using system-reserved shortcuts.",
371-
"Shortcut body description": "Keys not supported: tab, capsLock, numLock, insert, esc, shift"
370+
"Shortcut subtitle description": "Avoid using system-reserved shortcuts.",
371+
"Shortcut body description": "Keys not supported: tab, capsLock, numLock, insert, esc, shift",
372+
"Preferred devices": "Audio and Video settings",
373+
"Microphone": "Microphone",
374+
"Speaker": "Speaker",
375+
"Camera": "Camera"
372376
},
373377
"OperatorDrawer": {
374378
"Book": "Book",
@@ -893,7 +897,8 @@
893897
"Try changing your search query": "Try changing your search query",
894898
"Keys configuration information tooltip": "Configure line keys of your physical device",
895899
"Key position information tooltip": "Choose a position for your key",
896-
"Click on confirm": "Click on Confirm"
900+
"Click on confirm": "Click on Confirm",
901+
"Inline warning message devices": "Changes to audio and video settings can only be applied if the pair device is set to NethLink and your status is Online."
897902
},
898903
"DropdownContent": {
899904
"Microphones": "MICROPHONES",

public/locales/it/translations.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@
321321
"Upload image to continue": "Carica immagine per continuare",
322322
"Wrong file type": "Formato file errato",
323323
"Delete profile picture": "Elimina immagine profilo",
324-
"Devices": "Dispositivi",
324+
"Devices": "Audio e Video",
325325
"Time preferences": "Preferenze di tempo",
326326
"Login/logout preferences": "Preferenze di entrata/uscita",
327327
"Logout from queue automatically": "Esci dalla coda automaticamente",
@@ -367,8 +367,12 @@
367367
"Shortcut": "Scorciatoia",
368368
"Keyboard shortcut to call": "Scorciatoia per chiamare",
369369
"Shortcut title description": "Scegli una combinazione di tasti per avviare una chiamata dopo aver selezionato un testo.",
370-
"Shortcut subtitle description": "Attenzione: non usare scorciatoie già presenti nel sistema.",
371-
"Shortcut body description": "Tasti non consentiti: tab, capsLock, numLock, insert, esc, shift"
370+
"Shortcut subtitle description": "Non usare scorciatoie già presenti nel sistema.",
371+
"Shortcut body description": "Tasti non consentiti: tab, capsLock, numLock, insert, esc, shift",
372+
"Preferred devices": "Impostazioni Audio e Video",
373+
"Microphone": "Microfono",
374+
"Speaker": "Altoparlante",
375+
"Camera": "Video"
372376
},
373377
"OperatorDrawer": {
374378
"Book": "Prenota",
@@ -893,7 +897,8 @@
893897
"Try changing your search query": "Prova a cambiare la tua ricerca",
894898
"Keys configuration information tooltip": "Configura i tasti linea del tuo telefono",
895899
"Key position information tooltip": "Scegli una posizione per il pulsante",
896-
"Click on confirm": "Clicca su Conferma"
900+
"Click on confirm": "Clicca su Conferma",
901+
"Inline warning message devices": "Le modifiche relative alle impostazioni audio e video possono essere applicate solo se il dispositivo abbinato è NethLink e il proprio stato è Online."
897902
},
898903
"DropdownContent": {
899904
"Microphones": "MICROFONI",

src/main/classes/controllers/AccountController.ts

Lines changed: 38 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { store } from '@/lib/mainStore'
55
import { useNethVoiceAPI } from '@shared/useNethVoiceAPI'
66
import { useLogin } from '@shared/useLogin'
77
import { NetworkController } from './NetworkController'
8-
import { getAccountUID } from '@shared/utils/utils'
8+
import { delay, getAccountUID } from '@shared/utils/utils'
99

1010
const defaultConfig: ConfigFile = {
1111
lastUser: undefined,
@@ -80,7 +80,7 @@ export class AccountController {
8080
let loggedAccount: Account = {
8181
...lastLoggedAccount,
8282
...tempLoggedAccount,
83-
theme: lastLoggedAccount.theme || tempLoggedAccount.theme
83+
theme: lastLoggedAccount.theme || tempLoggedAccount.theme,
8484
}
8585

8686
const { parseConfig } = useLogin()
@@ -99,10 +99,19 @@ export class AccountController {
9999

100100
async saveLoggedAccount(account: Account, password: string): Promise<Account> {
101101
try {
102-
//
103102
const clearString = JSON.stringify({ host: account.host, username: account.username, password: password })
104103
const cryptString = safeStorage.encryptString(clearString)
105104
const accountUID = getAccountUID(account)
105+
const authAppData = store.store.auth
106+
if (authAppData) {
107+
const accountPreviousData = authAppData.availableAccounts[accountUID]
108+
if (accountPreviousData) {
109+
account = {
110+
...accountPreviousData,
111+
...account
112+
}
113+
}
114+
}
106115
store.updateStore({
107116
account,
108117
theme: account.theme,
@@ -135,33 +144,48 @@ export class AccountController {
135144

136145

137146

138-
updateTheme(theme: any) {
147+
async updateTheme(theme: any) {
139148
if (store.store) {
140149
const account = store.store.account
141-
store.set('theme', theme)
150+
store.set('theme', theme, true)
142151
if (account) {
143152
account.theme = theme
153+
store.set('account', account, true)
154+
const auth = store.store.auth
155+
auth!.availableAccounts[getAccountUID(account)] = account
156+
store.set('auth', auth, true)
157+
}
158+
store.saveToDisk()
159+
}
160+
}
144161

145-
store.set('account', account)
162+
async updatePreferredDevice(preferredDevices: any) {
163+
if (store.store) {
164+
const account = store.store.account
165+
if (account) {
166+
account.preferredDevices = preferredDevices
167+
168+
store.set('account', account, true)
146169
const auth = store.store.auth
147170

148171
auth!.availableAccounts[getAccountUID(account)] = account
149-
store.set('auth', auth)
172+
store.set('auth', auth, true)
150173
}
151174
store.saveToDisk()
152175
}
153176
}
154177

155-
updateShortcut(shortcut: any) {
178+
async updateShortcut(shortcut: any) {
156179
if (store.store) {
157180
const account = store.store.account
158181
if (account) {
159182
account.shortcut = shortcut
160-
store.set('account', account)
183+
184+
store.set('account', account, true)
161185
const auth = store.store.auth
162186

163187
auth!.availableAccounts[getAccountUID(account)] = account
164-
store.set('auth', auth)
188+
store.set('auth', auth, true)
165189
}
166190
store.saveToDisk()
167191
}
@@ -177,15 +201,15 @@ export class AccountController {
177201
const auth = store.store.auth
178202
if (account) {
179203
account!.phoneIslandPosition = phoneIslandPosition
180-
store.set('account', account)
204+
store.set('account', account, true)
181205
const _auth = {
182206
...auth,
183207
availableAccounts: {
184208
...auth?.availableAccounts,
185209
[getAccountUID(account)]: account
186210
}
187211
}
188-
store.set('auth', _auth)
212+
store.set('auth', _auth, true)
189213
store.saveToDisk()
190214
}
191215
}
@@ -200,15 +224,15 @@ export class AccountController {
200224
const auth = store.store.auth
201225
if (account) {
202226
account!.nethlinkBounds = nethlinkBounds
203-
store.set('account', account)
227+
store.set('account', account, true)
204228
const _auth = {
205229
...auth,
206230
availableAccounts: {
207231
...auth?.availableAccounts,
208232
[getAccountUID(account)]: account
209233
}
210234
}
211-
store.set('auth', _auth)
235+
store.set('auth', _auth, true)
212236
store.saveToDisk()
213237
}
214238
}

src/main/lib/ipcEvents.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ export function registerIpcEvents() {
269269
}
270270
})
271271

272+
ipcMain.on(IPC_EVENTS.CHANGE_PREFERRED_DEVICES, (_, devices) => {
273+
Log.info('CHANGE_PREFERRED_DEVICES:', devices)
274+
AccountController.instance.updatePreferredDevice(devices)
275+
PhoneIslandController.instance.window.emit(IPC_EVENTS.CHANGE_PREFERRED_DEVICES, devices)
276+
})
277+
272278
ipcMain.on(IPC_EVENTS.CHANGE_SHORTCUT, async (_, combo) => {
273279
// unregister previous shortcut
274280
await globalShortcut.unregisterAll();

src/main/main.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,6 @@ function attachOnReadyProcess() {
251251
})
252252
})
253253
}
254-
255-
// read shortcut from config and set it to app
256-
const account: Account = store.get('account') as Account
257-
Log.info("Shortcut readed:", store.get('shortcut'), account.shortcut)
258-
if (account.shortcut && account.shortcut?.length > 0) {
259-
ipcMain.emit(IPC_EVENTS.CHANGE_SHORTCUT, undefined, account.shortcut)
260-
}
261254
})
262255

263256
async function startApp(attempt = 0) {
@@ -687,6 +680,20 @@ async function createNethLink(show: boolean = true) {
687680
await delay(1000)
688681
new PhoneIslandController()
689682
checkForUpdate()
683+
const account = store.get('account') as Account
684+
if (account) {
685+
// read preffered devices for phone-island
686+
Log.info("Preferred devices readed:", account.preferredDevices)
687+
if (account.preferredDevices) {
688+
ipcMain.emit(IPC_EVENTS.CHANGE_PREFERRED_DEVICES, undefined, account.preferredDevices)
689+
}
690+
691+
// read shortcut from config and set it to app
692+
Log.info("Shortcut readed:", account.shortcut)
693+
if (account.shortcut && account.shortcut?.length > 0) {
694+
ipcMain.emit(IPC_EVENTS.CHANGE_SHORTCUT, undefined, account.shortcut)
695+
}
696+
}
690697
}
691698

692699
async function checkForUpdate() {

src/renderer/public/locales/en/translations.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@
321321
"Upload image to continue": "Upload image to continue",
322322
"Wrong file type": "Wrong file type",
323323
"Delete profile picture": "Delete profile picture",
324-
"Devices": "Devices",
324+
"Devices": "Audio and Video",
325325
"Time preferences": "Time preferences",
326326
"Login/logout preferences": "Login/logout preferences",
327327
"Logout from queue automatically": "Logout from queue automatically",
@@ -367,8 +367,12 @@
367367
"Shortcut": "Shortcut",
368368
"Keyboard shortcut to call": "Keyboard shortcut to call",
369369
"Shortcut title description": "Choose a keyboard shortcut to dial any selected number. ",
370-
"Shortcut subtitle description": "Warning: avoid using system-reserved shortcuts.",
371-
"Shortcut body description": "Keys not supported: tab, capsLock, numLock, insert, esc, shift"
370+
"Shortcut subtitle description": "Avoid using system-reserved shortcuts.",
371+
"Shortcut body description": "Keys not supported: tab, capsLock, numLock, insert, esc, shift",
372+
"Preferred devices": "Audio and Video settings",
373+
"Microphone": "Microphone",
374+
"Speaker": "Speaker",
375+
"Camera": "Camera"
372376
},
373377
"OperatorDrawer": {
374378
"Book": "Book",
@@ -893,7 +897,8 @@
893897
"Try changing your search query": "Try changing your search query",
894898
"Keys configuration information tooltip": "Configure line keys of your physical device",
895899
"Key position information tooltip": "Choose a position for your key",
896-
"Click on confirm": "Click on Confirm"
900+
"Click on confirm": "Click on Confirm",
901+
"Inline warning message devices": "Changes to audio and video settings can only be applied if the pair device is set to NethLink and your status is Online."
897902
},
898903
"DropdownContent": {
899904
"Microphones": "MICROPHONES",

src/renderer/public/locales/it/translations.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@
321321
"Upload image to continue": "Carica immagine per continuare",
322322
"Wrong file type": "Formato file errato",
323323
"Delete profile picture": "Elimina immagine profilo",
324-
"Devices": "Dispositivi",
324+
"Devices": "Audio e Video",
325325
"Time preferences": "Preferenze di tempo",
326326
"Login/logout preferences": "Preferenze di entrata/uscita",
327327
"Logout from queue automatically": "Esci dalla coda automaticamente",
@@ -367,8 +367,12 @@
367367
"Shortcut": "Scorciatoia",
368368
"Keyboard shortcut to call": "Scorciatoia per chiamare",
369369
"Shortcut title description": "Scegli una combinazione di tasti per avviare una chiamata dopo aver selezionato un testo.",
370-
"Shortcut subtitle description": "Attenzione: non usare scorciatoie già presenti nel sistema.",
371-
"Shortcut body description": "Tasti non consentiti: tab, capsLock, numLock, insert, esc, shift"
370+
"Shortcut subtitle description": "Non usare scorciatoie già presenti nel sistema.",
371+
"Shortcut body description": "Tasti non consentiti: tab, capsLock, numLock, insert, esc, shift",
372+
"Preferred devices": "Impostazioni Audio e Video",
373+
"Microphone": "Microfono",
374+
"Speaker": "Altoparlante",
375+
"Camera": "Video"
372376
},
373377
"OperatorDrawer": {
374378
"Book": "Prenota",
@@ -893,7 +897,8 @@
893897
"Try changing your search query": "Prova a cambiare la tua ricerca",
894898
"Keys configuration information tooltip": "Configura i tasti linea del tuo telefono",
895899
"Key position information tooltip": "Scegli una posizione per il pulsante",
896-
"Click on confirm": "Clicca su Conferma"
900+
"Click on confirm": "Clicca su Conferma",
901+
"Inline warning message devices": "Le modifiche relative alle impostazioni audio e video possono essere applicate solo se il dispositivo abbinato è NethLink e il proprio stato è Online."
897902
},
898903
"DropdownContent": {
899904
"Microphones": "MICROFONI",

src/renderer/src/components/Modules/NethVoice/BaseModule/Navbar.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { SearchBox } from '../SearchResults/SearchBox'
1010
import { ProfileDialog } from './ProfileDialog'
1111
import { PresenceForwardDialog } from './ProfileDialog/PresenceSettings/PresenceForwardDialog'
1212
import { SettingsShortcutDialog } from './ProfileDialog/SettingsSettings/SettingsShortcutDialog'
13+
import { SettingsDeviceDialog } from './ProfileDialog/SettingsSettings/SettingsDevicesDialog'
1314

1415
export interface NavbarProps {
1516
onClickAccount: () => void
@@ -21,6 +22,7 @@ export function Navbar({ onClickAccount }: NavbarProps): JSX.Element {
2122
const [operators] = useNethlinkData('operators')
2223
const [isForwardDialogOpen] = useNethlinkData('isForwardDialogOpen')
2324
const [isShortcutDialogOpen] = useNethlinkData('isShortcutDialogOpen')
25+
const [isDeviceDialogOpen] = useNethlinkData('isDeviceDialogOpen')
2426

2527
const [isProfileDialogOpen, setIsProfileDialogOpen] = useState(false)
2628

@@ -53,6 +55,7 @@ export function Navbar({ onClickAccount }: NavbarProps): JSX.Element {
5355
</div>
5456
{isForwardDialogOpen && <PresenceForwardDialog />}
5557
{isShortcutDialogOpen && <SettingsShortcutDialog />}
58+
{isDeviceDialogOpen && <SettingsDeviceDialog />}
5659
<ProfileDialog
5760
isOpen={isProfileDialogOpen}
5861
onClose={() => setIsProfileDialogOpen(false)}

0 commit comments

Comments
 (0)