-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
hostApp.service.ts
87 lines (72 loc) · 2.79 KB
/
hostApp.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { Injectable, NgZone, Injector } from '@angular/core'
import { isWindowsBuild, WIN_BUILD_FLUENT_BG_SUPPORTED, HostAppService, Platform, CLIHandler } from 'tabby-core'
import { ElectronService } from '../services/electron.service'
@Injectable({ providedIn: 'root' })
export class ElectronHostAppService extends HostAppService {
get platform (): Platform {
return this.configPlatform
}
get configPlatform (): Platform {
return {
win32: Platform.Windows,
darwin: Platform.macOS,
linux: Platform.Linux,
}[process.platform]
}
constructor (
private zone: NgZone,
private electron: ElectronService,
injector: Injector,
) {
super(injector)
electron.ipcRenderer.on('host:preferences-menu', () => this.zone.run(() => this.settingsUIRequest.next()))
electron.ipcRenderer.on('cli', (_$event, argv: any, cwd: string, secondInstance: boolean) => this.zone.run(async () => {
const event = { argv, cwd, secondInstance }
this.logger.info('CLI arguments received:', event)
const cliHandlers = injector.get(CLIHandler) as unknown as CLIHandler[]
cliHandlers.sort((a, b) => b.priority - a.priority)
let handled = false
for (const handler of cliHandlers) {
if (handled && handler.firstMatchOnly) {
continue
}
if (await handler.handle(event)) {
this.logger.info('CLI handler matched:', handler.constructor.name)
handled = true
}
}
}))
electron.ipcRenderer.on('host:config-change', () => this.zone.run(() => {
this.configChangeBroadcast.next()
}))
if (isWindowsBuild(WIN_BUILD_FLUENT_BG_SUPPORTED)) {
electron.ipcRenderer.send('window-set-disable-vibrancy-while-dragging', true)
}
}
newWindow (): void {
this.electron.ipcRenderer.send('app:new-window')
}
async saveConfig (data: string): Promise<void> {
await this.electron.ipcRenderer.invoke('app:save-config', data)
}
emitReady (): void {
this.electron.ipcRenderer.send('app:ready')
}
relaunch (): void {
const isPortable = !!process.env.PORTABLE_EXECUTABLE_FILE
if (isPortable) {
this.electron.app.relaunch({ execPath: process.env.PORTABLE_EXECUTABLE_FILE })
} else {
let args: string[] = []
if (this.platform === Platform.Linux) {
args = ['--no-sandbox']
}
this.electron.app.relaunch({ args })
}
this.electron.app.exit()
}
quit (): void {
this.logger.info('Quitting')
this.electron.app.quit()
}
}