Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@hookform/resolvers": "^3.3.4",
"@nethesis/chat-island": "0.1.73",
"@nethesis/nethesis-solid-svg-icons": "github:nethesis/Font-Awesome#ns-solid",
"@nethesis/phone-island": "^1.1.8",
"@nethesis/phone-island": "^1.1.9-dev.1",
"@tailwindcss/forms": "^0.5.7",
"@types/lodash": "^4.14.202",
"@types/node": "^18.19.9",
Expand Down
Binary file added public/TrayToolbarIconOfflineBlack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/TrayToolbarIconOfflineWhite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions public/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"Quit": "Quit",
"Hide": "Hide",
"Show": "Show",
"Offline": "Not connected",
"Theme": "Theme",
"System": "System",
"Light": "Light",
Expand Down Expand Up @@ -85,6 +86,9 @@
"No internet connection title": "No internet connection",
"No internet connection description": "Please check your connection and try again",
"Refresh": "Refresh",
"Connection lost banner": "No connection: you can't make or receive calls",
"Connection lost notification title": "NethLink is not connected",
"Connection lost notification body": "You can't make or receive calls until the connection is back",
"Answer phone to start recording": "Answer phone to start recording",
"Close the call to stop recording": "Close the call to stop recording",
"Search or type a contact": "Search or type a contact",
Expand Down
4 changes: 4 additions & 0 deletions public/locales/it/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"Quit": "Chiudi",
"Hide": "Nascondi",
"Show": "Mostra",
"Offline": "Non connesso",
"Theme": "Tema",
"System": "Sistema",
"Light": "Chiaro",
Expand Down Expand Up @@ -85,6 +86,9 @@
"No internet connection title": "Nessuna connessione internet",
"No internet connection description": "Si prega di controllare la connessione e riprovare",
"Refresh": "Aggiorna",
"Connection lost banner": "Connessione assente: non puoi ricevere né fare chiamate",
"Connection lost notification title": "NethLink non è connesso",
"Connection lost notification body": "Non puoi ricevere né fare chiamate finché la connessione non torna",
"Answer phone to start recording": "Rispondi al telefono per iniziare la registrazione",
"Close the call to stop recording": "Chiudi la chiamata per fermare la registrazione",
"Search or type a contact": "Cerca o digita un contatto",
Expand Down
29 changes: 20 additions & 9 deletions src/main/classes/controllers/TrayController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ export type TrayUpdaterProps = {
export class TrayController {
tray: Tray
static instance: TrayController
theme: 'light' | 'dark'
offline = false
constructor() {
TrayController.instance = this
const theme = nativeTheme.shouldUseDarkColors ? 'dark' : 'light'
this.theme = theme
const image = this.getImage(theme)
this.tray = new Tray(image)
this.updateTray()
Expand All @@ -43,20 +46,27 @@ export class TrayController {
}

getImage(theme: 'light' | 'dark') {
let pathImage = '../../public/TrayToolbarIconWhite.png'
if (process.platform === 'win32') {
pathImage =
theme === 'light'
? '../../public/TrayToolbarIconBlack.png'
: '../../public/TrayToolbarIconWhite.png'
}
const name = this.offline ? 'TrayToolbarIconOffline' : 'TrayToolbarIcon'
const followsTheme =
process.platform === 'win32' ||
(process.platform === 'darwin' && this.offline)
const color = followsTheme && theme === 'light' ? 'Black' : 'White'
const image = nativeImage
.createFromPath(path.join(__dirname, pathImage))
.createFromPath(path.join(__dirname, `../../public/${name}${color}.png`))
.resize({ height: 18, width: 18 })
image.setTemplateImage(true)
image.setTemplateImage(!this.offline)
return image
}

setOffline(offline: boolean) {
if (this.offline === offline) return
this.offline = offline
this.tray.setImage(this.getImage(this.theme))
this.tray.setToolTip(
offline ? `NethLink - ${t('Tray.Offline')}` : 'NethLink',
)
}

// a 16px icon of the menu, from public/tray (the @2x file is picked up on
// HiDPI screens): a template image on macOS, which follows the menu bar,
// the color of the system theme elsewhere
Expand Down Expand Up @@ -86,6 +96,7 @@ export class TrayController {
}

changeIconByTheme(theme: 'light' | 'dark') {
this.theme = theme
const image = this.getImage(theme)
this.tray.setImage(image)
}
Expand Down
24 changes: 24 additions & 0 deletions src/main/lib/ipcEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { NethLinkController } from '@/classes/controllers/NethLinkController'
import { AppController } from '@/classes/controllers/AppController'
import { TrayController } from '@/classes/controllers/TrayController'
import { store } from './mainStore'
import { t } from 'i18next'
import { debouncer, getAccountUID, getPageFromQuery } from '@shared/utils/utils'
import { NetworkController } from '@/classes/controllers/NetworkController'
import { useLogin } from '@shared/useLogin'
Expand Down Expand Up @@ -56,6 +57,28 @@ let isPhoneIslandReloadPending = false
const SERVER_CONFIG_CHECK_MIN_INTERVAL = 10_000
let lastServerConfigCheck = 0

let lastConnection: boolean | undefined = undefined

function onConnectionStateChange(state: any) {
const connection: boolean | undefined = state?.account
? state.connection
: undefined
if (connection === lastConnection) return
const previous = lastConnection
lastConnection = connection
TrayController.instance?.setOffline(connection === false)
if (connection === false && previous === true) {
const isNethLinkFocused =
NethLinkController.instance?.window?.getWindow()?.isFocused() ?? false
if (!isNethLinkFocused) {
new Notification({
title: `${t('Common.Connection lost notification title')}`,
body: `${t('Common.Connection lost notification body')}`,
}).show()
}
}
}

/**
* Reload the PhoneIsland so that it registers again with the current SIP host/port.
* When a call is active the reload is deferred to the call end, since it would drop the call.
Expand Down Expand Up @@ -205,6 +228,7 @@ export function registerIpcEvents() {
ipcMain.on(IPC_EVENTS.UPDATE_SHARED_STATE, (_, newState, page, selector) => {
const windows = BrowserWindow.getAllWindows()
store.updateStore(newState, `${page}[${selector}]`)
onConnectionStateChange(store.store)
windows.forEach((win) => {
const targetPage = win.webContents.getTitle()
try {
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/public/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"Quit": "Quit",
"Hide": "Hide",
"Show": "Show",
"Offline": "Not connected",
"Theme": "Theme",
"System": "System",
"Light": "Light",
Expand Down Expand Up @@ -85,6 +86,9 @@
"No internet connection title": "No internet connection",
"No internet connection description": "Please check your connection and try again",
"Refresh": "Refresh",
"Connection lost banner": "No connection: you can't make or receive calls",
"Connection lost notification title": "NethLink is not connected",
"Connection lost notification body": "You can't make or receive calls until the connection is back",
"Answer phone to start recording": "Answer phone to start recording",
"Close the call to stop recording": "Close the call to stop recording",
"Search or type a contact": "Search or type a contact",
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/public/locales/it/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"Quit": "Chiudi",
"Hide": "Nascondi",
"Show": "Mostra",
"Offline": "Non connesso",
"Theme": "Tema",
"System": "Sistema",
"Light": "Chiaro",
Expand Down Expand Up @@ -85,6 +86,9 @@
"No internet connection title": "Nessuna connessione internet",
"No internet connection description": "Si prega di controllare la connessione e riprovare",
"Refresh": "Aggiorna",
"Connection lost banner": "Connessione assente: non puoi ricevere né fare chiamate",
"Connection lost notification title": "NethLink non è connesso",
"Connection lost notification body": "Non puoi ricevere né fare chiamate finché la connessione non torna",
"Answer phone to start recording": "Rispondi al telefono per iniziare la registrazione",
"Close the call to stop recording": "Chiudi la chiamata per fermare la registrazione",
"Search or type a contact": "Cerca o digita un contatto",
Expand Down
32 changes: 32 additions & 0 deletions src/renderer/src/components/ConnectionBanner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { faTriangleExclamation } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { t } from 'i18next'

interface ConnectionBannerProps {
onRetry: () => void
}

export const ConnectionBanner = ({ onRetry }: ConnectionBannerProps) => {
return (
<div
role='alert'
className='flex w-full shrink-0 flex-row items-center gap-2 border-b border-amber-400 bg-amber-100 px-4 py-1.5 dark:border-amber-500 dark:bg-amber-700'
>
<FontAwesomeIcon
icon={faTriangleExclamation}
className='h-4 w-4 shrink-0 text-amber-700 dark:text-amber-200'
aria-hidden='true'
/>
<p className='min-w-0 flex-1 text-sm font-medium text-amber-800 dark:text-amber-100'>
{t('Common.Connection lost banner')}
</p>
<button
type='button'
onClick={onRetry}
className='shrink-0 rounded text-sm font-medium text-amber-800 underline hover:text-amber-900 focus:outline-none focus-visible:ring-2 focus-visible:ring-amber-500 dark:text-amber-100 dark:hover:text-white'
>
{t('Common.Retry')}
</button>
</div>
)
}
1 change: 1 addition & 0 deletions src/renderer/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './Modal'
export * from './ConnectionErrorDialog'
export * from './ConnectionBanner'
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const PhoneIslandContainer = ({
dataConfig={dataConfig}
uaType='mobile'
preferredSummaryExtensionType='nethlink'
hideConnectionAlerts
/>
)
)
Expand Down
11 changes: 10 additions & 1 deletion src/renderer/src/hooks/usePhoneIslandEventListeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ let isWebRTCRegistered = false
let isSocketAuthorized = false
let hasTriggeredPhoneIslandReady = false

const OFFLINE_FAILURES_THRESHOLD = 3

const defaultSize: PhoneIslandSizes = {
sizes: {
width: '0px',
Expand Down Expand Up @@ -66,6 +68,7 @@ export const usePhoneIslandEventListener = () => {
accountRef.current = account
const connectedRef = useRef(connected)
connectedRef.current = connected
const internetFailuresRef = useRef(0)
const [availableRingtones, setAvailableRingtones] =
useSharedState('availableRingtones')
const notifiedSummaryIdsRef = useRef<Set<string>>(new Set())
Expand Down Expand Up @@ -393,6 +396,7 @@ export const usePhoneIslandEventListener = () => {
...eventHandler(
PHONE_ISLAND_EVENTS['phone-island-internet-connected'],
() => {
internetFailuresRef.current = 0
if (accountRef.current && !connectedRef.current) {
setConnected(true)
}
Expand All @@ -401,7 +405,12 @@ export const usePhoneIslandEventListener = () => {
...eventHandler(
PHONE_ISLAND_EVENTS['phone-island-internet-disconnected'],
() => {
if (accountRef.current && connectedRef.current) {
internetFailuresRef.current += 1
if (
accountRef.current &&
connectedRef.current &&
internetFailuresRef.current >= OFFLINE_FAILURES_THRESHOLD
) {
setConnected(false)
}
},
Expand Down
14 changes: 5 additions & 9 deletions src/renderer/src/pages/NethLinkPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { NethLinkModules } from '@renderer/components/Modules'
import { usePhoneIslandEventHandler } from '@renderer/hooks/usePhoneIslandEventHandler'
import { useLoggedNethVoiceAPI } from '@renderer/hooks/useLoggedNethVoiceAPI'
import { IPC_EVENTS, PERMISSION } from '@shared/constants'
import { ConnectionErrorDialog } from '@renderer/components'
import { ConnectionBanner } from '@renderer/components'
import { debouncer } from '@shared/utils/utils'
import { useAccount } from '@renderer/hooks/useAccount'
import { Sidebar } from '@renderer/components/Modules/NethVoice/BaseModule/Sidebar'
Expand Down Expand Up @@ -233,7 +233,10 @@ export function NethLinkPage({ handleRefreshConnection }: NethLinkPageProps) {
<div className='h-screen w-screen'>
<div className='absolute flex h-full w-full flex-col items-center justify-end text-sm'>
<div className='flex h-full w-full flex-col items-center justify-between'>
<div className='relative z-10 flex h-full w-full flex-row bg-bgLight dark:bg-bgDark'>
{!connection && (
<ConnectionBanner onRetry={handleRefreshConnection} />
)}
<div className='relative z-10 flex h-full min-h-0 w-full flex-row bg-bgLight dark:bg-bgDark'>
<div className='flex h-full w-full min-w-0 flex-col gap-3'>
<Navbar onClickAccount={() => updateAccountData()} />
<NethLinkModules />
Expand All @@ -242,13 +245,6 @@ export function NethLinkPage({ handleRefreshConnection }: NethLinkPageProps) {
</div>
</div>
</div>
{!connection && (
<ConnectionErrorDialog
variant='nethlink'
onButtonClick={handleRefreshConnection}
buttonText={t('Common.Refresh')}
/>
)}
</div>
)
}