Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Eugeny/terminus
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Jan 24, 2021
2 parents 78bd90a + 712589e commit ecf5297
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/lib/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
7 changes: 5 additions & 2 deletions app/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if (argv.d) {
})
}

app.on('ready', () => {
app.on('ready', async () => {
if (process.platform === 'darwin') {
app.dock.setMenu(Menu.buildFromTemplate([
{
Expand All @@ -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)
})
5 changes: 3 additions & 2 deletions app/lib/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class Window {
enableRemoteModule: true,
contextIsolation: false,
},
maximizable: true,
frame: false,
show: false,
backgroundColor: '#00000000',
Expand Down Expand Up @@ -229,8 +230,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 () {
Expand Down
10 changes: 8 additions & 2 deletions terminus-core/src/services/hostApp.service.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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') {
Expand All @@ -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()
}
}))
Expand Down
3 changes: 3 additions & 0 deletions terminus-terminal/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ecf5297

Please sign in to comment.