mirror of
https://github.com/eugeny/tabby
synced 2026-07-10 08:57:10 +00:00
b31a48677d
Package-Build / Lint (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Docs / build (push) Has been cancelled
Package-Build / macOS-Build (arm64, aarch64-apple-darwin) (push) Has been cancelled
Package-Build / macOS-Build (x86_64, x86_64-apple-darwin) (push) Has been cancelled
Package-Build / Linux-Build (amd64, x64, ubuntu-24.04, x86_64-unknown-linux-gnu) (push) Has been cancelled
Package-Build / Linux-Build (arm64, arm64, ubuntu-24.04-arm, aarch64-unknown-linux-gnu, aarch64-linux-gnu-) (push) Has been cancelled
Package-Build / Linux-Build (armhf, arm, ubuntu-24.04, arm-unknown-linux-gnueabihf, arm-linux-gnueabihf-) (push) Has been cancelled
Package-Build / Windows-Build (arm64, aarch64-pc-windows-msvc) (push) Has been cancelled
Package-Build / Windows-Build (x64, x86_64-pc-windows-msvc) (push) Has been cancelled
Co-authored-by: Eugene <inbox@null.page>
93 lines
3.0 KiB
TypeScript
93 lines
3.0 KiB
TypeScript
import { Injectable } from '@angular/core'
|
|
import { HostAppService } from './api/hostApp'
|
|
import { CLIHandler, CLIEvent } from './api/cli'
|
|
import { HostWindowService } from './api/hostWindow'
|
|
import { QuickConnectProfileProvider } from './api/profileProvider'
|
|
import { ProfilesService } from './services/profiles.service'
|
|
|
|
@Injectable()
|
|
export class ProfileCLIHandler extends CLIHandler {
|
|
firstMatchOnly = true
|
|
priority = 0
|
|
|
|
constructor (
|
|
private profiles: ProfilesService,
|
|
private hostWindow: HostWindowService,
|
|
) {
|
|
super()
|
|
}
|
|
|
|
async handle (event: CLIEvent): Promise<boolean> {
|
|
const op = event.argv._[0]
|
|
|
|
if (op === 'profile') {
|
|
this.handleOpenProfile(event.argv.profileName!)
|
|
return true
|
|
}
|
|
if (op === 'recent') {
|
|
this.handleOpenRecentProfile(event.argv.profileNumber!)
|
|
return true
|
|
}
|
|
if (op === 'quickConnect') {
|
|
this.handleOpenQuickConnect(event.argv.providerId!, event.argv.query!)
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
private async handleOpenProfile (profileName: string) {
|
|
const profile = (await this.profiles.getProfiles()).find(x => x.name === profileName)
|
|
if (!profile) {
|
|
console.error('Requested profile', profileName, 'not found')
|
|
return
|
|
}
|
|
this.profiles.openNewTabForProfile(profile)
|
|
this.hostWindow.bringToFront()
|
|
}
|
|
|
|
private async handleOpenRecentProfile (profileNumber: number) {
|
|
const profiles = this.profiles.getRecentProfiles()
|
|
if (profileNumber >= profiles.length) {
|
|
return
|
|
}
|
|
this.profiles.openNewTabForProfile(profiles[profileNumber])
|
|
this.hostWindow.bringToFront()
|
|
}
|
|
|
|
private async handleOpenQuickConnect (providerId: string, query: string) {
|
|
const quickConnectProviders = this.profiles.getProviders()
|
|
.filter((x): x is QuickConnectProfileProvider<any> => x instanceof QuickConnectProfileProvider)
|
|
const provider = quickConnectProviders.find(x => x.id === providerId)
|
|
if(!provider) {
|
|
const available = quickConnectProviders.map(x => x.id).join(', ')
|
|
console.error(`Requested provider "${providerId}" not found. Available providers: ${available}`)
|
|
return
|
|
}
|
|
const profile = provider.quickConnect(query)
|
|
if(!profile) {
|
|
console.error(`Could not parse quick connect query "${query}"`)
|
|
return
|
|
}
|
|
this.profiles.openNewTabForProfile(profile)
|
|
this.hostWindow.bringToFront()
|
|
}
|
|
}
|
|
|
|
@Injectable()
|
|
export class LastCLIHandler extends CLIHandler {
|
|
firstMatchOnly = true
|
|
priority = -999
|
|
|
|
constructor (private hostApp: HostAppService) {
|
|
super()
|
|
}
|
|
|
|
async handle (event: CLIEvent): Promise<boolean> {
|
|
if (event.secondInstance) {
|
|
this.hostApp.newWindow()
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
}
|