tabby/terminus-terminal/src/buttonProvider.ts

43 lines
1.4 KiB
TypeScript
Raw Normal View History

2017-07-05 14:22:44 +00:00
import * as fs from 'mz/fs'
2017-09-09 19:42:48 +00:00
import { Injectable } from '@angular/core'
2018-08-09 13:13:31 +00:00
import { DomSanitizer } from '@angular/platform-browser'
import { HotkeysService, ToolbarButtonProvider, IToolbarButton, HostAppService, ElectronService } from 'terminus-core'
2017-04-11 00:22:48 +00:00
2017-08-02 11:47:00 +00:00
import { TerminalService } from './services/terminal.service'
2017-03-24 21:24:12 +00:00
@Injectable()
2017-03-25 17:12:43 +00:00
export class ButtonProvider extends ToolbarButtonProvider {
2017-03-24 21:24:12 +00:00
constructor (
2017-08-02 11:47:00 +00:00
private terminal: TerminalService,
2018-08-09 13:13:31 +00:00
private domSanitizer: DomSanitizer,
2017-07-30 18:58:31 +00:00
hostApp: HostAppService,
electron: ElectronService,
2017-03-29 12:04:01 +00:00
hotkeys: HotkeysService,
2017-03-24 21:24:12 +00:00
) {
2017-03-25 17:12:43 +00:00
super()
2019-02-09 21:10:42 +00:00
if (!electron.remote.process.env.TERMINUS_DEV) {
setImmediate(async () => {
let argv: string[] = electron.remote.process.argv
2017-07-12 18:52:06 +00:00
for (let arg of argv.slice(1).concat([electron.remote.process.argv0])) {
if (await fs.exists(arg)) {
if ((await fs.stat(arg)).isDirectory()) {
this.terminal.openTab(null, arg)
}
}
}
})
}
2017-03-29 12:04:01 +00:00
}
2017-03-24 21:24:12 +00:00
provide (): IToolbarButton[] {
return [{
2018-08-09 13:13:31 +00:00
icon: this.domSanitizer.bypassSecurityTrustHtml(require('./icons/plus.svg')),
2017-03-24 21:24:12 +00:00
title: 'New terminal',
2018-08-25 08:11:32 +00:00
touchBarNSImage: 'NSTouchBarAddDetailTemplate',
2017-03-25 20:00:16 +00:00
click: async () => {
this.terminal.openTab()
2017-03-24 21:24:12 +00:00
}
}]
}
}