From a735c910d5115b330bec77eb8d032a2514dc3278 Mon Sep 17 00:00:00 2001 From: Austin Warren Date: Tue, 16 Jul 2019 20:36:24 -0700 Subject: [PATCH 1/8] Added basic support for multiple windows in windows 10 --- app/lib/app.ts | 2 +- app/lib/index.ts | 1 - app/lib/window.ts | 4 ++++ terminus-core/src/services/hostApp.service.ts | 2 ++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/lib/app.ts b/app/lib/app.ts index b67cce41..e48ac638 100644 --- a/app/lib/app.ts +++ b/app/lib/app.ts @@ -58,7 +58,7 @@ export class Application { if (!this.hasWindows()) { await this.newWindow() } - this.windows[0].send(event, ...args) + this.windows.filter(w => !w.isDestroyed())[0].send(event, ...args) } enableTray () { diff --git a/app/lib/index.ts b/app/lib/index.ts index d479f630..d6632593 100644 --- a/app/lib/index.ts +++ b/app/lib/index.ts @@ -39,7 +39,6 @@ const argv = parseArgs(process.argv, process.cwd()) if (!app.requestSingleInstanceLock()) { app.quit() - process.exit(0) } if (argv.d) { diff --git a/app/lib/window.ts b/app/lib/window.ts index 8966e931..c7311c42 100644 --- a/app/lib/window.ts +++ b/app/lib/window.ts @@ -147,6 +147,10 @@ export class Window { this.window.webContents.send(event, ...args) } + isDestroyed() { + return !this.window || this.window.isDestroyed(); + } + private setupWindowManagement () { this.window.on('show', () => { this.visible.next(true) diff --git a/terminus-core/src/services/hostApp.service.ts b/terminus-core/src/services/hostApp.service.ts index 05bf11c6..6765d72a 100644 --- a/terminus-core/src/services/hostApp.service.ts +++ b/terminus-core/src/services/hostApp.service.ts @@ -147,6 +147,8 @@ export class HostAppService { this.cliPaste.next(text) } else if (op === 'profile') { this.cliOpenProfile.next(argv.profileName) + } else if (op === undefined) { + this.newWindow(); } else { this.secondInstance.next() } From 041a2a92d541fe63d0236e737d3e4a7e501d8fd8 Mon Sep 17 00:00:00 2001 From: Austin Warren Date: Wed, 17 Jul 2019 17:10:22 -0700 Subject: [PATCH 2/8] Dont emit destroyed event when we're closing all tabs. This is to ensure we don't save the state of our open tabs innapropriately --- terminus-core/src/components/baseTab.component.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/terminus-core/src/components/baseTab.component.ts b/terminus-core/src/components/baseTab.component.ts index 982e88a1..8b4eb942 100644 --- a/terminus-core/src/components/baseTab.component.ts +++ b/terminus-core/src/components/baseTab.component.ts @@ -147,13 +147,15 @@ export abstract class BaseTabComponent { /** * Called before the tab is closed */ - destroy (): void { + destroy (skipDestroyedEvent = false): void { this.focused.complete() this.blurred.complete() this.titleChange.complete() this.progress.complete() this.recoveryStateChangedHint.complete() - this.destroyed.next() + if (!skipDestroyedEvent) { + this.destroyed.next() + } this.destroyed.complete() } } From eccbd66c1836155a4cfb6ada10cb10c641f16fec Mon Sep 17 00:00:00 2001 From: Austin Warren Date: Wed, 17 Jul 2019 17:15:14 -0700 Subject: [PATCH 3/8] Alter tab recovery system to only keep track of tabs in main window. Also fix issue where closing main window would remove all tabs from saved tab state --- terminus-core/src/services/app.service.ts | 36 +++++++++++++---------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/terminus-core/src/services/app.service.ts b/terminus-core/src/services/app.service.ts index 69d18325..e32422f1 100644 --- a/terminus-core/src/services/app.service.ts +++ b/terminus-core/src/services/app.service.ts @@ -1,8 +1,11 @@ + import { Observable, Subject, AsyncSubject } from 'rxjs' import { takeUntil } from 'rxjs/operators' import { Injectable } from '@angular/core' + import { BaseTabComponent } from '../components/baseTab.component' import { SplitTabComponent } from '../components/splitTab.component' + import { ConfigService } from './config.service' import { HostAppService } from './hostApp.service' import { TabRecoveryService } from './tabRecovery.service' @@ -67,18 +70,19 @@ export class AppService { private tabRecovery: TabRecoveryService, private tabsService: TabsService, ) { - this.tabRecovery.recoverTabs().then(tabs => { - for (const tab of tabs) { - this.openNewTabRaw(tab.type, tab.options) - } - - this.tabsChanged$.subscribe(() => { - tabRecovery.saveTabs(this.tabs) + if (hostApp.getWindow().id === 1) { + this.tabRecovery.recoverTabs().then(tabs => { + for (const tab of tabs) { + this.openNewTabRaw(tab.type, tab.options) + } + this.tabsChanged$.subscribe(() => { + tabRecovery.saveTabs(this.tabs) + }) + setInterval(() => { + tabRecovery.saveTabs(this.tabs) + }, 30000) }) - setInterval(() => { - tabRecovery.saveTabs(this.tabs) - }, 30000) - }) + } } addTabRaw (tab: BaseTabComponent) { @@ -87,9 +91,11 @@ export class AppService { this.tabsChanged.next() this.tabOpened.next(tab) - tab.recoveryStateChangedHint$.subscribe(() => { - this.tabRecovery.saveTabs(this.tabs) - }) + if (this.hostApp.getWindow().id === 1) { + tab.recoveryStateChangedHint$.subscribe(() => { + this.tabRecovery.saveTabs(this.tabs) + }) + } tab.titleChange$.subscribe(title => { if (tab === this._activeTab) { @@ -213,7 +219,7 @@ export class AppService { } } for (const tab of this.tabs) { - tab.destroy() + tab.destroy(true); } } From 6a9d5693452afd545de5a4e12c61afc2350cc0c7 Mon Sep 17 00:00:00 2001 From: Austin Warren Date: Wed, 17 Jul 2019 17:15:51 -0700 Subject: [PATCH 4/8] Do not save settings tab into list of tabs to recover --- terminus-settings/src/components/settingsTab.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terminus-settings/src/components/settingsTab.component.ts b/terminus-settings/src/components/settingsTab.component.ts index 454f11b4..69ffe7e7 100644 --- a/terminus-settings/src/components/settingsTab.component.ts +++ b/terminus-settings/src/components/settingsTab.component.ts @@ -100,7 +100,7 @@ export class SettingsTabComponent extends BaseTabComponent { } async getRecoveryToken (): Promise { - return { type: 'app:settings' } + return false; } ngOnDestroy () { From 5679d5edf1021d0b2ecb8ebbb9ccc7a42d9a60c3 Mon Sep 17 00:00:00 2001 From: Austin Warren Date: Wed, 17 Jul 2019 17:16:42 -0700 Subject: [PATCH 5/8] Fix code from xterm-addon-fit so that we don't run into issues with the first recovered console.. I'm sure there's a better way. --- .../src/frontends/xtermFrontend.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/terminus-terminal/src/frontends/xtermFrontend.ts b/terminus-terminal/src/frontends/xtermFrontend.ts index a6cb2909..ea80bd9c 100644 --- a/terminus-terminal/src/frontends/xtermFrontend.ts +++ b/terminus-terminal/src/frontends/xtermFrontend.ts @@ -85,8 +85,21 @@ export class XTermFrontend extends Frontend { this.resizeHandler = () => { try { - if (getComputedStyle(this.xtermCore.element).getPropertyValue('height') !== 'auto') { - this.fitAddon.fit() + if (this.xtermCore.element && getComputedStyle(this.xtermCore.element).getPropertyValue('height') !== 'auto') { + + let t = window.getComputedStyle(this.xtermCore.element.parentElement) + let r = parseInt(t.getPropertyValue("height")) + let n = Math.max(0, parseInt(t.getPropertyValue("width"))) + let o = window.getComputedStyle(this.xtermCore.element) + let i = r - (parseInt(o.getPropertyValue("padding-top")) + parseInt(o.getPropertyValue("padding-bottom"))) + let l = n - (parseInt(o.getPropertyValue("padding-right")) + parseInt(o.getPropertyValue("padding-left"))) - this.xtermCore.viewport.scrollBarWidth + let actualCellWidth = this.xtermCore._renderService.dimensions.actualCellWidth || 9; + let actualCellHeight = this.xtermCore._renderService.dimensions.actualCellHeight || 17; + let cols = Math.floor(l / actualCellWidth) + let rows = Math.floor(i / actualCellHeight); + + console.log("resizing to: ", cols, rows); + this.xterm.resize(cols, rows); } } catch (e) { // tends to throw when element wasn't shown yet From 380266a57c411d0c3e6894cbcee558e18a52d874 Mon Sep 17 00:00:00 2001 From: Austin Warren Date: Wed, 17 Jul 2019 17:17:50 -0700 Subject: [PATCH 6/8] Do not auto-open tab if we've started the console and pointed it to open in a specific location --- terminus-terminal/src/index.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/terminus-terminal/src/index.ts b/terminus-terminal/src/index.ts index 9fe78b04..8ea0b1f1 100644 --- a/terminus-terminal/src/index.ts +++ b/terminus-terminal/src/index.ts @@ -156,9 +156,17 @@ export default class TerminalModule { // eslint-disable-line @typescript-eslint/ } }) if (config.store.terminal.autoOpen) { - app.ready$.subscribe(() => { - terminal.openTab() - }) + + let argv = require('electron').remote.process.argv; + if (argv[0].includes('node')) { + argv = argv.slice(1) + } + + if(require('yargs').parse(argv.slice(1))._[0] !== "open"){ + app.ready$.subscribe(() => { + terminal.openTab() + }) + } } hotkeys.matchedHotkey.subscribe(async (hotkey) => { From 8920cc7924fcd3dc719d47a7ed9050321f346977 Mon Sep 17 00:00:00 2001 From: Austin Warren Date: Wed, 17 Jul 2019 20:56:39 -0700 Subject: [PATCH 7/8] remove console log --- terminus-terminal/src/frontends/xtermFrontend.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/terminus-terminal/src/frontends/xtermFrontend.ts b/terminus-terminal/src/frontends/xtermFrontend.ts index 02cba016..b6e3fdd3 100644 --- a/terminus-terminal/src/frontends/xtermFrontend.ts +++ b/terminus-terminal/src/frontends/xtermFrontend.ts @@ -97,7 +97,6 @@ export class XTermFrontend extends Frontend { let cols = Math.floor(l / actualCellWidth) let rows = Math.floor(i / actualCellHeight); - console.log("resizing to: ", cols, rows); this.xterm.resize(cols, rows); } } catch (e) { From 43f6ad3530c86a750524937ea029cb2accaf3735 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Wed, 7 Aug 2019 15:10:00 +0200 Subject: [PATCH 8/8] Update index.ts --- app/lib/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/app/lib/index.ts b/app/lib/index.ts index d6632593..2ad3a113 100644 --- a/app/lib/index.ts +++ b/app/lib/index.ts @@ -39,6 +39,7 @@ const argv = parseArgs(process.argv, process.cwd()) if (!app.requestSingleInstanceLock()) { app.quit() + app.exit(0) } if (argv.d) {