From f103e71285d70eb8e54592a26cfdf011f9e6797c Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Sun, 24 Jan 2021 19:06:41 +0100 Subject: [PATCH 1/2] better handling of CLI args - fixes #1436 --- app/lib/app.ts | 2 +- app/lib/index.ts | 7 +++++-- app/lib/window.ts | 5 +++-- terminus-core/src/services/hostApp.service.ts | 10 ++++++++-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/lib/app.ts b/app/lib/app.ts index aae8caee..6382eec1 100644 --- a/app/lib/app.ts +++ b/app/lib/app.ts @@ -147,7 +147,7 @@ export class Application { handleSecondInstance (argv: string[], cwd: string): void { this.presentAllWindows() - this.windows[this.windows.length - 1].handleSecondInstance(argv, cwd) + this.windows[this.windows.length - 1].passCliArguments(argv, cwd, true) } private setupMenu () { diff --git a/app/lib/index.ts b/app/lib/index.ts index 46fdf9e2..61b24045 100644 --- a/app/lib/index.ts +++ b/app/lib/index.ts @@ -53,7 +53,7 @@ if (argv.d) { }) } -app.on('ready', () => { +app.on('ready', async () => { if (process.platform === 'darwin') { app.dock.setMenu(Menu.buildFromTemplate([ { @@ -65,5 +65,8 @@ app.on('ready', () => { ])) } application.init() - application.newWindow({ hidden: argv.hidden }) + + const window = await application.newWindow({ hidden: argv.hidden }) + await window.ready + window.passCliArguments(process.argv, process.cwd(), false) }) diff --git a/app/lib/window.ts b/app/lib/window.ts index c5e8300c..6ec7395b 100644 --- a/app/lib/window.ts +++ b/app/lib/window.ts @@ -65,6 +65,7 @@ export class Window { enableRemoteModule: true, contextIsolation: false, }, + maximizable: true, frame: false, show: false, backgroundColor: '#00000000', @@ -225,8 +226,8 @@ export class Window { } } - handleSecondInstance (argv: string[], cwd: string): void { - this.send('host:second-instance', parseArgs(argv, cwd), cwd) + passCliArguments (argv: string[], cwd: string, secondInstance: boolean): void { + this.send('cli', parseArgs(argv, cwd), cwd, secondInstance) } private setupWindowManagement () { diff --git a/terminus-core/src/services/hostApp.service.ts b/terminus-core/src/services/hostApp.service.ts index 507c5385..2c674a06 100644 --- a/terminus-core/src/services/hostApp.service.ts +++ b/terminus-core/src/services/hostApp.service.ts @@ -1,5 +1,6 @@ import type { BrowserWindow, TouchBar, MenuItemConstructorOptions } from 'electron' import * as path from 'path' +import * as fs from 'mz/fs' import shellEscape from 'shell-escape' import { Observable, Subject } from 'rxjs' import { Injectable, NgZone, EventEmitter } from '@angular/core' @@ -150,9 +151,10 @@ export class HostAppService { this.zone.run(() => this.displaysChanged.next()) }) - electron.ipcRenderer.on('host:second-instance', (_$event, argv: any, cwd: string) => this.zone.run(() => { + electron.ipcRenderer.on('cli', (_$event, argv: any, cwd: string, secondInstance: boolean) => this.zone.run(async () => { this.logger.info('Second instance', argv) const op = argv._[0] + const opAsPath = path.resolve(cwd, op) if (op === 'open') { this.cliOpenDirectory.next(path.resolve(cwd, argv.directory)) } else if (op === 'run') { @@ -167,7 +169,11 @@ export class HostAppService { this.cliOpenProfile.next(argv.profileName) } else if (op === undefined) { this.newWindow() - } else { + } else if ((await fs.lstat(opAsPath)).isDirectory()) { + this.cliOpenDirectory.next(opAsPath) + } + + if (secondInstance) { this.secondInstance.next() } })) From 712589eb93881aacb04d851497b584797a927ce0 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Sun, 24 Jan 2021 19:06:51 +0100 Subject: [PATCH 2/2] fixed #1510 --- terminus-terminal/src/index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/terminus-terminal/src/index.ts b/terminus-terminal/src/index.ts index d2b9e6a7..d2f218ed 100644 --- a/terminus-terminal/src/index.ts +++ b/terminus-terminal/src/index.ts @@ -194,6 +194,9 @@ export default class TerminalModule { // eslint-disable-line @typescript-eslint/ }) hostApp.cliOpenDirectory$.subscribe(async directory => { + if (directory.length > 1 && (directory.endsWith('/') || directory.endsWith('\\'))) { + directory = directory.substring(0, directory.length - 1) + } if (await fs.exists(directory)) { if ((await fs.stat(directory)).isDirectory()) { terminal.openTab(undefined, directory)