mirror of
https://github.com/Eugeny/tabby
synced 2024-11-14 17:07:15 +00:00
open new tabs from cli (fixes #67)
This commit is contained in:
parent
709ffadc7c
commit
fc060acd88
4 changed files with 23 additions and 12 deletions
|
@ -8,8 +8,8 @@ if (process.argv.indexOf('--debug') !== -1) {
|
|||
|
||||
let app = electron.app
|
||||
|
||||
let secondInstance = app.makeSingleInstance((argv) => {
|
||||
app.window.webContents.send('host:second-instance')
|
||||
let secondInstance = app.makeSingleInstance((argv, cwd) => {
|
||||
app.window.webContents.send('host:second-instance', argv, cwd)
|
||||
})
|
||||
|
||||
if (secondInstance) {
|
||||
|
|
|
@ -93,7 +93,7 @@ export class AppRootComponent {
|
|||
this.docking.dock()
|
||||
})
|
||||
|
||||
this.hostApp.secondInstance.subscribe(() => {
|
||||
this.hostApp.secondInstance$.subscribe(() => {
|
||||
this.onGlobalHotkey()
|
||||
})
|
||||
this.hotkeys.globalHotkey.subscribe(() => {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { Subject } from 'rxjs'
|
||||
import { Injectable, NgZone, EventEmitter } from '@angular/core'
|
||||
import { ElectronService } from '../services/electron.service'
|
||||
import { Logger, LogService } from '../services/log.service'
|
||||
|
@ -20,7 +21,7 @@ export class HostAppService {
|
|||
quitRequested = new EventEmitter<any>()
|
||||
ready = new EventEmitter<any>()
|
||||
shown = new EventEmitter<any>()
|
||||
secondInstance = new EventEmitter<any>()
|
||||
secondInstance$ = new Subject<{ argv: string[], cwd: string }>()
|
||||
|
||||
private logger: Logger
|
||||
|
||||
|
@ -39,16 +40,16 @@ export class HostAppService {
|
|||
|
||||
electron.ipcRenderer.on('host:quit-request', () => this.zone.run(() => this.quitRequested.emit()))
|
||||
|
||||
electron.ipcRenderer.on('uncaughtException', (err) => {
|
||||
electron.ipcRenderer.on('uncaughtException', ($event, err) => {
|
||||
this.logger.error('Unhandled exception:', err)
|
||||
})
|
||||
|
||||
electron.ipcRenderer.on('host:window-shown', () => {
|
||||
this.shown.emit()
|
||||
this.zone.run(() => this.shown.emit())
|
||||
})
|
||||
|
||||
electron.ipcRenderer.on('host:second-instance', () => {
|
||||
this.secondInstance.emit()
|
||||
electron.ipcRenderer.on('host:second-instance', ($event, argv: string[], cwd: string) => {
|
||||
this.zone.run(() => this.secondInstance$.next({ argv, cwd }))
|
||||
})
|
||||
|
||||
this.ready.subscribe(() => {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import * as fs from 'mz/fs'
|
||||
import * as path from 'path'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { HotkeysService, ToolbarButtonProvider, IToolbarButton, AppService, ConfigService } from 'terminus-core'
|
||||
import { HotkeysService, ToolbarButtonProvider, IToolbarButton, AppService, ConfigService, HostAppService } from 'terminus-core'
|
||||
|
||||
import { SessionsService } from './services/sessions.service'
|
||||
import { ShellsService } from './services/shells.service'
|
||||
|
@ -12,6 +14,7 @@ export class ButtonProvider extends ToolbarButtonProvider {
|
|||
private sessions: SessionsService,
|
||||
private config: ConfigService,
|
||||
private shells: ShellsService,
|
||||
hostApp: HostAppService,
|
||||
hotkeys: HotkeysService,
|
||||
) {
|
||||
super()
|
||||
|
@ -20,11 +23,18 @@ export class ButtonProvider extends ToolbarButtonProvider {
|
|||
this.openNewTab()
|
||||
}
|
||||
})
|
||||
hostApp.secondInstance$.subscribe(async ({argv, cwd}) => {
|
||||
if (argv.length === 2) {
|
||||
let arg = path.resolve(cwd, argv[1])
|
||||
if (await fs.exists(arg)) {
|
||||
this.openNewTab(arg)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async openNewTab (): Promise<void> {
|
||||
let cwd = null
|
||||
if (this.app.activeTab instanceof TerminalTabComponent) {
|
||||
async openNewTab (cwd?: string): Promise<void> {
|
||||
if (!cwd && this.app.activeTab instanceof TerminalTabComponent) {
|
||||
cwd = await this.app.activeTab.session.getWorkingDirectory()
|
||||
}
|
||||
let command = this.config.store.terminal.shell
|
||||
|
|
Loading…
Reference in a new issue