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