moved electron-specific parts of tabby-local into tabby-electron

This commit is contained in:
Eugene Pankov
2023-03-19 12:39:31 +01:00
parent 2e72774548
commit 35ca7015c8
52 changed files with 120 additions and 110 deletions

View File

@@ -0,0 +1,69 @@
import { NgZone, Injectable } from '@angular/core'
import { ConfigService, HostAppService, Platform, ProfilesService, TranslateService } from 'tabby-core'
import { ElectronService } from './electron.service'
/** @hidden */
@Injectable({ providedIn: 'root' })
export class DockMenuService {
appVersion: string
private constructor (
config: ConfigService,
private electron: ElectronService,
private hostApp: HostAppService,
private zone: NgZone,
private profilesService: ProfilesService,
private translate: TranslateService,
) {
config.changed$.subscribe(() => this.update())
}
async update (): Promise<void> {
const profiles = await this.profilesService.getProfiles()
if (this.hostApp.platform === Platform.Windows) {
this.electron.app.setJumpList([
{
type: 'custom',
name: this.translate.instant('Recent'),
items: this.profilesService.getRecentProfiles().map((profile, index) => ({
type: 'task',
program: process.execPath,
args: `recent ${index}`,
title: profile.name,
iconPath: process.execPath,
iconIndex: 0,
})),
},
{
type: 'custom',
name: this.translate.instant('Profiles'),
items: profiles.map(profile => ({
type: 'task',
program: process.execPath,
args: `profile "${profile.name}"`,
title: profile.name,
iconPath: process.execPath,
iconIndex: 0,
})),
},
])
}
if (this.hostApp.platform === Platform.macOS) {
this.electron.app.dock.setMenu(this.electron.Menu.buildFromTemplate(
[
...[...this.profilesService.getRecentProfiles(), ...profiles].map(profile => ({
label: profile.name,
click: () => this.zone.run(async () => {
this.profilesService.openNewTabForProfile(profile)
}),
})),
{
label: this.translate.instant('New Window'),
click: () => this.zone.run(() => this.hostApp.newWindow()),
},
],
))
}
}
}

View File

@@ -234,6 +234,15 @@ export class ElectronPlatformService extends PlatformService {
handler(err)
})
}
async pickDirectory (): Promise<string> {
return (await this.electron.dialog.showOpenDialog(
this.hostWindow.getWindow(),
{
properties: ['openDirectory', 'showHiddenFiles'],
},
)).filePaths[0]
}
}
class ElectronFileUpload extends FileUpload {

View File

@@ -0,0 +1,39 @@
import { Injectable } from '@angular/core'
import * as path from 'path'
import { WIN_BUILD_CONPTY_SUPPORTED, isWindowsBuild } from 'tabby-core'
import { SessionOptions, UACService } from 'tabby-local'
import { ElectronService } from './electron.service'
/** @hidden */
@Injectable()
export class ElectronUACService extends UACService {
constructor (
private electron: ElectronService,
) {
super()
this.isAvailable = isWindowsBuild(WIN_BUILD_CONPTY_SUPPORTED)
}
patchSessionOptionsForUAC (sessionOptions: SessionOptions): SessionOptions {
let helperPath = path.join(
path.dirname(this.electron.app.getPath('exe')),
'resources',
'extras',
'UAC.exe',
)
if (process.env.TABBY_DEV) {
helperPath = path.join(
path.dirname(this.electron.app.getPath('exe')),
'..', '..', '..',
'extras',
'UAC.exe',
)
}
const options = { ...sessionOptions }
options.args = [options.command, ...options.args ?? []]
options.command = helperPath
return options
}
}