Skip to content
Merged
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
241 changes: 116 additions & 125 deletions public/locales/en/translations.json

Large diffs are not rendered by default.

239 changes: 115 additions & 124 deletions public/locales/it/translations.json

Large diffs are not rendered by default.

Binary file added public/tray/blankDark.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/tray/[email protected]
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/tray/blankLight.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/tray/[email protected]
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/tray/blankTemplate.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/tray/[email protected]
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/tray/checkDark.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/tray/[email protected]
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/tray/checkLight.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/tray/[email protected]
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/tray/checkTemplate.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/tray/[email protected]
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/tray/devtoolsDark.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/tray/[email protected]
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/tray/devtoolsLight.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/tray/[email protected]
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/tray/devtoolsTemplate.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/tray/[email protected]
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/tray/downloadDark.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/tray/[email protected]
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/tray/downloadLight.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/tray/[email protected]
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/tray/downloadTemplate.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/tray/[email protected]
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/tray/hideDark.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/tray/[email protected]
Binary file added public/tray/hideLight.png
Binary file added public/tray/[email protected]
Binary file added public/tray/hideTemplate.png
Binary file added public/tray/[email protected]
Binary file added public/tray/quitDark.png
Binary file added public/tray/[email protected]
Binary file added public/tray/quitLight.png
Binary file added public/tray/[email protected]
Binary file added public/tray/quitTemplate.png
Binary file added public/tray/[email protected]
Binary file added public/tray/showDark.png
Binary file added public/tray/[email protected]
Binary file added public/tray/showLight.png
Binary file added public/tray/[email protected]
Binary file added public/tray/showTemplate.png
Binary file added public/tray/[email protected]
Binary file added public/tray/themeDark.png
Binary file added public/tray/[email protected]
Binary file added public/tray/themeLight.png
Binary file added public/tray/[email protected]
Binary file added public/tray/themeTemplate.png
Binary file added public/tray/[email protected]
Binary file added public/tray/updateDark.png
Binary file added public/tray/[email protected]
Binary file added public/tray/updateLight.png
Binary file added public/tray/[email protected]
Binary file added public/tray/updateTemplate.png
Binary file added public/tray/[email protected]
4 changes: 2 additions & 2 deletions src/main/classes/controllers/NethLinkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ export class NethLinkController {
}
}

sendUpdateNotification() {
sendUpdateNotification(update: { version: string; url: string }) {
try {
this.window.emit(IPC_EVENTS.UPDATE_APP_NOTIFICATION)
this.window.emit(IPC_EVENTS.UPDATE_APP_NOTIFICATION, update)
} catch (e) {
Log.warning(
'error during send update notification to the NethLinkWindow: ',
Expand Down
131 changes: 121 additions & 10 deletions src/main/classes/controllers/TrayController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import {
MenuItem,
MenuItemConstructorOptions,
Tray,
app,
nativeImage,
nativeTheme,
shell,
} from 'electron'
import path from 'path'
import { LoginController } from './LoginController'
Expand All @@ -15,6 +17,8 @@ import { isDev } from '@shared/utils/utils'
import { DevToolsController } from './DevToolsController'
import { Log } from '@shared/utils/logger'
import { t } from 'i18next'
import { AccountController } from './AccountController'
import { AvailableThemes } from '@shared/types'

export type TrayUpdaterProps = {
enableShowButton?: boolean
Expand Down Expand Up @@ -53,6 +57,34 @@ export class TrayController {
return image
}

// 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
getMenuIcon(
name:
| 'show'
| 'hide'
| 'quit'
| 'devtools'
| 'theme'
| 'download'
| 'update'
| 'check'
| 'blank',
) {
const variant =
process.platform === 'darwin'
? 'Template'
: nativeTheme.shouldUseDarkColors
Comment thread
edospadoni marked this conversation as resolved.
Resolved
? 'Dark'
: 'Light'
const image = nativeImage.createFromPath(
path.join(__dirname, `../../public/tray/${name}${variant}.png`),
)
if (process.platform === 'darwin') image.setTemplateImage(true)
return image
}

changeIconByTheme(theme: 'light' | 'dark') {
const image = this.getImage(theme)
this.tray.setImage(image)
Expand All @@ -76,6 +108,8 @@ export class TrayController {
LoginController.instance.hide()
else LoginController.instance.show()
}
// the label of the item at once: the window events update it later
this.refresh()
}
} catch (e) {
Log.warning(
Expand All @@ -85,49 +119,126 @@ export class TrayController {
}
}

// the last options of the menu, to rebuild it when the theme or the update change
private lastProps: TrayUpdaterProps = { isShowButtonVisible: true }
// the newer release found by the update check, if any
private update?: { version: string; url: string }
// set by the main process: checks for updates now, from the menu
checkForUpdates?: () => void

// rebuilds the menu with its last options, such as after a theme change
refresh() {
this.updateTray(this.lastProps)
}

setUpdate(update?: { version: string; url: string }) {
this.update = update
this.updateTray(this.lastProps)
}

private changeTheme(theme: AvailableThemes) {
AccountController.instance?.updateTheme(theme)
this.updateTray(this.lastProps)
}

updateTray(
{ enableShowButton, isShowButtonVisible }: TrayUpdaterProps = {
isShowButtonVisible: true,
},
) {
try {
this.lastProps = { enableShowButton, isShowButtonVisible }
const _isShowButtonVisible =
isShowButtonVisible === undefined ? true : isShowButtonVisible
// TODO: add check if window is focused and add the focus option
const label = store.store.account
? NethLinkController.instance &&
NethLinkController.instance.window?.isOpen()
? `${t('Tray.Hide')} NethLink`
: `${t('Tray.Show')} NethLink`
: LoginController.instance && LoginController.instance.window?.isOpen()
? `${t('Tray.Hide')} Login`
: `${t('Tray.Show')} Login`
const isWindowOpen = store.store.account
? !!(
NethLinkController.instance &&
NethLinkController.instance.window?.isOpen()
)
: !!(
LoginController.instance &&
LoginController.instance.window?.isOpen()
)
const label = `${t(isWindowOpen ? 'Tray.Hide' : 'Tray.Show')} ${
store.store.account ? 'NethLink' : 'Login'
}`
const currentTheme: AvailableThemes =
(store.store.account?.theme as AvailableThemes) || 'system'
// a check icon instead of a radio item: macOS would add a column for the
// check mark and push every icon of the menu to the right
const themeItem = (theme: AvailableThemes, labelKey: string) =>
({
label: t(labelKey) as string,
icon: this.getMenuIcon(currentTheme === theme ? 'check' : 'blank'),
click: () => this.changeTheme(theme),
}) as MenuItemConstructorOptions

const menu: (MenuItemConstructorOptions | MenuItem)[] = [
// the name and the version, as a title
{ label: `NethLink ${app.getVersion()}`, enabled: false },
{ type: 'separator' },
{
role: 'window',
label: label + (store.assignedInstanceID || ''),
icon: this.getMenuIcon(isWindowOpen ? 'hide' : 'show'),
commandId: 1,
enabled: enableShowButton ?? false,
visible: _isShowButtonVisible,
click: (_menuItem, _window, _event) => {
this.toggleWindow(enableShowButton ?? false)
},
},
]

// the theme of the account, once signed in
if (store.store.account) {
menu.push(
{ type: 'separator' },
{
label: t('Tray.Theme') as string,
icon: this.getMenuIcon('theme'),
enabled: false,
},
themeItem('system', 'Tray.System'),
themeItem('light', 'Tray.Light'),
themeItem('dark', 'Tray.Dark'),
)
}

menu.push(
{ type: 'separator' },
this.update
? {
label: t('Tray.Download version', {
version: this.update.version,
}) as string,
icon: this.getMenuIcon('download'),
click: () => shell.openExternal(this.update!.url),
}
: {
label: t('Tray.Check for updates') as string,
icon: this.getMenuIcon('update'),
enabled: !!this.checkForUpdates,
click: () => this.checkForUpdates?.(),
},
{ type: 'separator' },
{
role: process.platform === 'win32' ? 'close' : 'window',
label: `${t('Tray.Quit')} NethLink`,
icon: this.getMenuIcon('quit'),
commandId: 2,
enabled: enableShowButton ?? false,
click: (_menuItem, _window, _event) => {
AppController.safeQuit()
},
},
]
)

if (isDev()) {
menu.push({
role: 'window',
label: 'DevTool',
icon: this.getMenuIcon('devtools'),
commandId: 3,
enabled: true,
click: (menuItem, window, event) => {
Expand Down
4 changes: 3 additions & 1 deletion src/main/classes/windows/CommandBarWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export class CommandBarWindow extends BaseWindow {
movable: false,
resizable: false,
skipTaskbar: true,
roundedCorners: true,
// the page draws its own rounded corners and border: the macOS mask has
// a larger radius and would cut the border at the corners
roundedCorners: false,
parent: undefined,
transparent: true,
hiddenInMissionControl: true,
Expand Down
2 changes: 2 additions & 0 deletions src/main/classes/windows/LoginWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { BaseWindow } from './BaseWindow'
import { LoginPageSize } from '@shared/constants'
import { Log } from '@shared/utils/logger'
import { debouncer } from '@shared/utils/utils'
import { syncDockWithWindows } from '@/lib/dock'

export const LOGIN_WINDOW_WIDTH = 500
export class LoginWindow extends BaseWindow {
Expand Down Expand Up @@ -74,6 +75,7 @@ export class LoginWindow extends BaseWindow {
}

async toggleVisibility() {
syncDockWithWindows()
debouncer('loginToggleVisibility', async () => {
TrayController.instance.updateTray({
enableShowButton: true,
Expand Down
3 changes: 3 additions & 0 deletions src/main/classes/windows/NethLinkWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { NethLinkPageSize } from '@shared/constants'
import { Log } from '@shared/utils/logger'
import { debouncer, delay } from '@shared/utils/utils'
import { AccountController } from '../controllers'
import { syncDockWithWindows } from '@/lib/dock'

export class NethLinkWindow extends BaseWindow {
static instance: NethLinkWindow
Expand Down Expand Up @@ -171,6 +172,8 @@ export class NethLinkWindow extends BaseWindow {
}

async toggleVisibility() {
// in the Dock and in Cmd+Tab while the window is open
syncDockWithWindows()
debouncer('nethlinkToggleVisibility', async () => {
await delay(250)
TrayController.instance.updateTray({
Expand Down
19 changes: 19 additions & 0 deletions src/main/lib/dock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { app } from 'electron'
import { Log } from '@shared/utils/logger'
import { LoginController } from '@/classes/controllers/LoginController'
import { NethLinkController } from '@/classes/controllers/NethLinkController'

// NethLink lives in the menu bar without a Dock icon. While the login or the
// main window is open, the icon is shown: without it macOS leaves the app out
// of the Dock and of Cmd+Tab
export function syncDockWithWindows() {
if (process.platform !== 'darwin' || !app.dock) return
const isAnyWindowOpen =
!!LoginController.instance?.window?.isOpen() ||
!!NethLinkController.instance?.window?.isOpen()
if (isAnyWindowOpen && !app.dock.isVisible()) {
app.dock.show().catch((e) => Log.warning('cannot show the Dock icon', e))
} else if (!isAnyWindowOpen && app.dock.isVisible()) {
app.dock.hide()
}
}
14 changes: 14 additions & 0 deletions src/main/lib/ipcEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { Log } from '@shared/utils/logger'
import { NethLinkController } from '@/classes/controllers/NethLinkController'
import { AppController } from '@/classes/controllers/AppController'
import { TrayController } from '@/classes/controllers/TrayController'
import { store } from './mainStore'
import { debouncer, getAccountUID, getPageFromQuery } from '@shared/utils/utils'
import { NetworkController } from '@/classes/controllers/NetworkController'
Expand Down Expand Up @@ -454,6 +455,8 @@ export function registerIpcEvents() {

ipcMain.on(IPC_EVENTS.CHANGE_THEME, (_, theme) => {
AccountController.instance.updateTheme(theme)
// the theme items of the tray menu
TrayController.instance?.refresh()
})

ipcMain.on(IPC_EVENTS.PHONE_ISLAND_READY, () => {
Expand Down Expand Up @@ -709,6 +712,17 @@ export function registerIpcEvents() {
}
})

ipcMain.on(IPC_EVENTS.EMIT_QUEUE_MEMBER_UPDATE, (_, member) => {
try {
NethLinkController.instance.window.emit(
IPC_EVENTS.EMIT_QUEUE_MEMBER_UPDATE,
member,
)
} catch (e) {
Log.error(e)
}
})

ipcMain.on(IPC_EVENTS.EMIT_CALL_ACTIVE, (_) => {
if (!hasActiveCall) {
Log.info(
Expand Down
Loading
Loading