Skip to content

Commit 7d8d90e

Browse files
committed
feat: added command bar
1 parent a533cd1 commit 7d8d90e

File tree

18 files changed

+403
-36
lines changed

18 files changed

+403
-36
lines changed

package-lock.json

Lines changed: 26 additions & 32 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
"dmg-license": "^1.0.11"
107107
},
108108
"dependencies": {
109-
"@nut-tree-fork/nut-js": "^4.2.6"
109+
"@nut-tree-fork/nut-js": "^4.2.6",
110+
"uiohook-napi": "^1.5.4"
110111
}
111112
}

public/locales/en/translations.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,10 @@
932932
"update_available": "Update available for download",
933933
"download": "Download the update"
934934
},
935+
"CommandBar": {
936+
"Placeholder": "Enter a phone number...",
937+
"Call": "Call"
938+
},
935939
"Errors": {
936940
"browser_permissions": "Browser permissions error",
937941
"user_permissions": "Media permissions error",

public/locales/it/translations.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,10 @@
932932
"update_available": "Aggiornamento disponibile per il download",
933933
"download": "Scarica l'aggiornamento"
934934
},
935+
"CommandBar": {
936+
"Placeholder": "Inserisci un numero di telefono...",
937+
"Call": "Chiama"
938+
},
935939
"Errors": {
936940
"browser_permissions": "Errore nei permessi del browser",
937941
"user_permissions": "Errore nei permessi dei media",

src/main/classes/controllers/AccountController.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,22 @@ export class AccountController {
273273
}
274274
}
275275

276+
async updateCommandBarShortcut(commandBarShortcut: any) {
277+
if (store.store) {
278+
const account = store.store.account
279+
if (account) {
280+
account.commandBarShortcut = commandBarShortcut
281+
282+
store.set('account', account, true)
283+
const auth = store.store.auth
284+
285+
auth!.availableAccounts[getAccountUID(account)] = account
286+
store.set('auth', auth, true)
287+
}
288+
store.saveToDisk()
289+
}
290+
}
291+
276292

277293
getAccountPhoneIslandPosition(): { x: number; y: number } | undefined {
278294
return store.store.account?.phoneIslandPosition
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { CommandBarWindow } from '../windows'
2+
import { IPC_EVENTS } from '@shared/constants'
3+
import { Log } from '@shared/utils/logger'
4+
import { screen } from 'electron'
5+
6+
export class CommandBarController {
7+
static instance: CommandBarController
8+
window: CommandBarWindow
9+
private isVisible: boolean = false
10+
11+
constructor() {
12+
CommandBarController.instance = this
13+
this.window = new CommandBarWindow()
14+
this.setupBlurListener()
15+
}
16+
17+
private setupBlurListener() {
18+
this.window.addOnBuildListener(() => {
19+
const window = this.window.getWindow()
20+
if (window) {
21+
window.on('blur', () => {
22+
this.hide()
23+
})
24+
}
25+
})
26+
}
27+
28+
show() {
29+
try {
30+
const window = this.window.getWindow()
31+
if (window && !this.isVisible) {
32+
const cursorPoint = screen.getCursorScreenPoint()
33+
const currentDisplay = screen.getDisplayNearestPoint(cursorPoint)
34+
const { x, y, width, height } = currentDisplay.workArea
35+
const windowBounds = window.getBounds()
36+
37+
const centerX = x + Math.round((width - windowBounds.width) / 2)
38+
const centerY = y + Math.round(height * 0.3)
39+
40+
window.setBounds({ x: centerX, y: centerY })
41+
window.show()
42+
window.setAlwaysOnTop(true, 'screen-saver')
43+
window.focus()
44+
this.isVisible = true
45+
this.window.emit(IPC_EVENTS.SHOW_COMMAND_BAR)
46+
}
47+
} catch (e) {
48+
Log.warning('error during showing CommandBarWindow:', e)
49+
}
50+
}
51+
52+
hide() {
53+
try {
54+
const window = this.window.getWindow()
55+
if (window && this.isVisible) {
56+
window.hide()
57+
this.isVisible = false
58+
this.window.emit(IPC_EVENTS.HIDE_COMMAND_BAR)
59+
}
60+
} catch (e) {
61+
Log.warning('error during hiding CommandBarWindow:', e)
62+
}
63+
}
64+
65+
toggle() {
66+
if (this.isVisible) {
67+
this.hide()
68+
} else {
69+
this.show()
70+
}
71+
}
72+
73+
isOpen(): boolean {
74+
return this.isVisible
75+
}
76+
77+
async safeQuit() {
78+
await this.window.quit(true)
79+
}
80+
}

src/main/classes/controllers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './LoginController'
33
export * from './PhoneIslandController'
44
export * from './TrayController'
55
export * from './DevToolsController'
6+
export * from './CommandBarController'
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { PAGES } from '@shared/types'
2+
import { BaseWindow } from './BaseWindow'
3+
4+
export class CommandBarWindow extends BaseWindow {
5+
constructor() {
6+
super(PAGES.COMMANDBAR, {
7+
width: 500,
8+
height: 80,
9+
show: false,
10+
fullscreenable: false,
11+
autoHideMenuBar: true,
12+
closable: false,
13+
alwaysOnTop: true,
14+
minimizable: false,
15+
maximizable: false,
16+
movable: false,
17+
resizable: false,
18+
skipTaskbar: true,
19+
roundedCorners: true,
20+
parent: undefined,
21+
transparent: true,
22+
hiddenInMissionControl: true,
23+
hasShadow: true,
24+
center: true,
25+
fullscreen: false,
26+
enableLargerThanScreen: false,
27+
frame: false,
28+
thickFrame: false,
29+
trafficLightPosition: { x: 0, y: 0 },
30+
webPreferences: {
31+
nodeIntegration: true
32+
}
33+
})
34+
35+
this.addOnBuildListener(() => {
36+
const window = this.getWindow()
37+
if (window) {
38+
window.setAlwaysOnTop(true, 'screen-saver')
39+
}
40+
})
41+
}
42+
}

src/main/classes/windows/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './SplashScreenWindow'
33
export * from './NethLinkWindow'
44
export * from './PhoneIslandWindow'
55
export * from './DevToolsWindow'
6+
export * from './CommandBarWindow'

src/main/lib/ipcEvents.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +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 { CommandBarController } from '@/classes/controllers/CommandBarController'
45
import { IPC_EVENTS } from '@shared/constants'
56
import { Account, OnDraggingWindow, PAGES } from '@shared/types'
67
import { BrowserWindow, app, ipcMain, screen, shell, desktopCapturer, globalShortcut, clipboard } from 'electron'
@@ -462,4 +463,33 @@ export function registerIpcEvents() {
462463
Log.error('URL PARAM error', e)
463464
}
464465
})
466+
467+
ipcMain.on(IPC_EVENTS.TOGGLE_COMMAND_BAR, () => {
468+
try {
469+
CommandBarController.instance?.toggle()
470+
} catch (e) {
471+
Log.error('TOGGLE_COMMAND_BAR error', e)
472+
}
473+
})
474+
475+
ipcMain.on(IPC_EVENTS.SHOW_COMMAND_BAR, () => {
476+
try {
477+
CommandBarController.instance?.show()
478+
} catch (e) {
479+
Log.error('SHOW_COMMAND_BAR error', e)
480+
}
481+
})
482+
483+
ipcMain.on(IPC_EVENTS.HIDE_COMMAND_BAR, () => {
484+
try {
485+
CommandBarController.instance?.hide()
486+
} catch (e) {
487+
Log.error('HIDE_COMMAND_BAR error', e)
488+
}
489+
})
490+
491+
ipcMain.on(IPC_EVENTS.CHANGE_COMMAND_BAR_SHORTCUT, async (_, combo) => {
492+
AccountController.instance.updateCommandBarShortcut(combo)
493+
Log.info('Command Bar shortcut changed to:', combo)
494+
})
465495
}

0 commit comments

Comments
 (0)