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'
|
2019-06-14 21:47:48 +00:00
|
|
|
import { ToolbarButtonProvider, ToolbarButton, 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
|
|
|
|
2019-03-07 01:05:26 +00:00
|
|
|
/** @hidden */
|
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 (
|
2019-06-14 21:47:48 +00:00
|
|
|
electron: ElectronService,
|
2017-08-02 11:47:00 +00:00
|
|
|
private terminal: TerminalService,
|
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) {
|
2017-07-10 15:57:58 +00:00
|
|
|
setImmediate(async () => {
|
2019-06-14 15:49:42 +00:00
|
|
|
const argv: string[] = electron.remote.process.argv
|
|
|
|
for (const arg of argv.slice(1).concat([electron.remote.process.argv0])) {
|
2017-07-10 15:57:58 +00:00
|
|
|
if (await fs.exists(arg)) {
|
|
|
|
if ((await fs.stat(arg)).isDirectory()) {
|
2019-09-18 18:56:59 +00:00
|
|
|
this.terminal.openTab(undefined, arg)
|
2017-07-10 15:57:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2017-03-29 12:04:01 +00:00
|
|
|
}
|
|
|
|
|
2019-06-14 21:47:48 +00:00
|
|
|
provide (): ToolbarButton[] {
|
2019-05-11 19:28:04 +00:00
|
|
|
return [
|
|
|
|
{
|
2019-06-30 21:08:30 +00:00
|
|
|
icon: require('./icons/plus.svg'),
|
2019-05-11 19:28:04 +00:00
|
|
|
title: 'New terminal',
|
|
|
|
touchBarNSImage: 'NSTouchBarAddDetailTemplate',
|
|
|
|
click: async () => {
|
|
|
|
this.terminal.openTab()
|
2019-06-14 21:47:48 +00:00
|
|
|
},
|
2019-05-11 19:28:04 +00:00
|
|
|
},
|
|
|
|
{
|
2019-06-30 21:08:30 +00:00
|
|
|
icon: require('./icons/profiles.svg'),
|
2019-05-11 19:28:04 +00:00
|
|
|
title: 'New terminal with profile',
|
|
|
|
submenu: async () => {
|
2019-06-14 15:49:42 +00:00
|
|
|
const profiles = await this.terminal.getProfiles()
|
2019-05-11 19:28:04 +00:00
|
|
|
return profiles.map(profile => ({
|
2019-05-17 21:48:59 +00:00
|
|
|
icon: profile.icon,
|
2019-05-11 19:28:04 +00:00
|
|
|
title: profile.name,
|
|
|
|
click: () => this.terminal.openTab(profile),
|
|
|
|
}))
|
2019-06-14 21:47:48 +00:00
|
|
|
},
|
2019-05-11 19:28:04 +00:00
|
|
|
},
|
|
|
|
]
|
2017-03-24 21:24:12 +00:00
|
|
|
}
|
|
|
|
}
|