diff --git a/app/lib/cli.ts b/app/lib/cli.ts index 4decc34d..e4d53772 100644 --- a/app/lib/cli.ts +++ b/app/lib/cli.ts @@ -25,6 +25,9 @@ export function parseArgs (argv: string[], cwd: string): any { type: 'string', }) }) + .command('recent [index]', 'open a tab with a recent profile', { + profileNumber: { type: 'number' }, + }) .version(app.getVersion()) .option('debug', { alias: 'd', diff --git a/tabby-core/src/cli.ts b/tabby-core/src/cli.ts index d8b49172..5c42667b 100644 --- a/tabby-core/src/cli.ts +++ b/tabby-core/src/cli.ts @@ -23,6 +23,10 @@ export class ProfileCLIHandler extends CLIHandler { this.handleOpenProfile(event.argv.profileName) return true } + if (op === 'recent') { + this.handleOpenRecentProfile(event.argv.profileNumber) + return true + } return false } @@ -35,6 +39,15 @@ export class ProfileCLIHandler extends CLIHandler { 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() + } } @Injectable() diff --git a/tabby-local/src/services/dockMenu.service.ts b/tabby-local/src/services/dockMenu.service.ts index 3e07cfa9..b33daa99 100644 --- a/tabby-local/src/services/dockMenu.service.ts +++ b/tabby-local/src/services/dockMenu.service.ts @@ -8,8 +8,8 @@ export class DockMenuService { appVersion: string private constructor ( + config: ConfigService, private electron: ElectronService, - private config: ConfigService, private hostApp: HostAppService, private zone: NgZone, private profilesService: ProfilesService, @@ -18,29 +18,45 @@ export class DockMenuService { config.changed$.subscribe(() => this.update()) } - update (): void { + async update (): Promise { + const profiles = await this.profilesService.getProfiles() + if (this.hostApp.platform === Platform.Windows) { - this.electron.app.setJumpList(this.config.store.profiles.length ? [{ - type: 'custom', - name: this.translate.instant('Profiles'), - items: this.config.store.profiles.map(profile => ({ - type: 'task', - program: process.execPath, - args: `profile "${profile.name}"`, - title: profile.name, - iconPath: process.execPath, - iconIndex: 0, - })), - }] : null) + 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.config.store.profiles.map(profile => ({ + [...this.profilesService.getRecentProfiles(), ...profiles].map(profile => ({ label: profile.name, click: () => this.zone.run(async () => { this.profilesService.openNewTabForProfile(profile) }), - })) + })), )) } }