Merge branch 'pr/1249'

This commit is contained in:
Eugene Pankov 2019-08-07 15:10:19 +02:00
commit 62efe406f5
9 changed files with 57 additions and 24 deletions

View File

@ -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 () {

View File

@ -39,7 +39,7 @@ const argv = parseArgs(process.argv, process.cwd())
if (!app.requestSingleInstanceLock()) {
app.quit()
process.exit(0)
app.exit(0)
}
if (argv.d) {

View File

@ -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)

View File

@ -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()
}
}

View File

@ -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) {
@ -216,7 +222,7 @@ export class AppService {
}
}
for (const tab of this.tabs) {
tab.destroy()
tab.destroy(true);
}
return true
}

View File

@ -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()
}

View File

@ -100,7 +100,7 @@ export class SettingsTabComponent extends BaseTabComponent {
}
async getRecoveryToken (): Promise<any> {
return { type: 'app:settings' }
return false;
}
ngOnDestroy () {

View File

@ -86,7 +86,18 @@ export class XTermFrontend extends Frontend {
this.resizeHandler = () => {
try {
if (this.xtermCore.element && getComputedStyle(this.xtermCore.element).getPropertyValue('height') !== 'auto') {
this.fitAddon.fit()
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);
this.xterm.resize(cols, rows);
}
} catch (e) {
// tends to throw when element wasn't shown yet

View File

@ -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) => {