From 3039a657577f93db01f664549aeaa83238d4a704 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Tue, 12 Feb 2019 11:19:17 +0100 Subject: [PATCH] fixed conpty detection (fixes #653) --- .../src/components/shellSettingsTab.component.ts | 11 ++++------- terminus-terminal/src/services/sessions.service.ts | 4 +++- terminus-terminal/src/services/uac.service.ts | 10 ++++------ terminus-terminal/src/utils.ts | 8 ++++++++ 4 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 terminus-terminal/src/utils.ts diff --git a/terminus-terminal/src/components/shellSettingsTab.component.ts b/terminus-terminal/src/components/shellSettingsTab.component.ts index b32ba545..50ffbd68 100644 --- a/terminus-terminal/src/components/shellSettingsTab.component.ts +++ b/terminus-terminal/src/components/shellSettingsTab.component.ts @@ -1,4 +1,3 @@ -import * as os from 'os' import { Component } from '@angular/core' import { NgbModal } from '@ng-bootstrap/ng-bootstrap' import { Subscription } from 'rxjs' @@ -6,7 +5,7 @@ import { ConfigService, ElectronService, HostAppService, Platform } from 'termin import { EditProfileModalComponent } from './editProfileModal.component' import { IShell, Profile } from '../api' import { TerminalService } from '../services/terminal.service' -import { UACService } from '../services/uac.service' +import { WIN_BUILD_CONPTY_SUPPORTED, WIN_BUILD_CONPTY_STABLE, isWindowsBuild } from '../utils' @Component({ template: require('./shellSettingsTab.component.pug'), @@ -20,7 +19,6 @@ export class ShellSettingsTabComponent { private configSubscription: Subscription constructor ( - uac: UACService, public config: ConfigService, public hostApp: HostAppService, private electron: ElectronService, @@ -32,10 +30,9 @@ export class ShellSettingsTabComponent { this.reload() }) this.reload() - this.isConPTYAvailable = uac.isAvailable - this.isConPTYStable = hostApp.platform === Platform.Windows - && parseFloat(os.release()) >= 10 - && parseInt(os.release().split('.')[2]) >= 18309 + + this.isConPTYAvailable = isWindowsBuild(WIN_BUILD_CONPTY_SUPPORTED) + this.isConPTYStable = isWindowsBuild(WIN_BUILD_CONPTY_STABLE) } async ngOnInit () { diff --git a/terminus-terminal/src/services/sessions.service.ts b/terminus-terminal/src/services/sessions.service.ts index 8a86ff3c..521463b8 100644 --- a/terminus-terminal/src/services/sessions.service.ts +++ b/terminus-terminal/src/services/sessions.service.ts @@ -7,6 +7,7 @@ import { Injectable } from '@angular/core' import { Logger, LogService, ConfigService } from 'terminus-core' import { exec } from 'mz/child_process' import { SessionOptions } from '../api' +import { WIN_BUILD_CONPTY_SUPPORTED, isWindowsBuild } from '../utils' let macOSNativeProcessList try { @@ -118,7 +119,8 @@ export class Session extends BaseSession { rows: options.height || 30, cwd, env: env, - experimentalUseConpty: this.config.store.terminal.useConPTY && 1, + // `1` instead of `true` forces ConPTY even if unstable + experimentalUseConpty: (isWindowsBuild(WIN_BUILD_CONPTY_SUPPORTED) && this.config.store.terminal.useConPTY) ? 1 : false, }) this.guessedCWD = cwd diff --git a/terminus-terminal/src/services/uac.service.ts b/terminus-terminal/src/services/uac.service.ts index c6eef136..5b96e9cb 100644 --- a/terminus-terminal/src/services/uac.service.ts +++ b/terminus-terminal/src/services/uac.service.ts @@ -1,20 +1,18 @@ import * as path from 'path' -import * as os from 'os' import { Injectable } from '@angular/core' -import { ElectronService, HostAppService, Platform } from 'terminus-core' +import { ElectronService } from 'terminus-core' import { SessionOptions } from '../api' +import { WIN_BUILD_CONPTY_SUPPORTED, isWindowsBuild } from '../utils' + @Injectable({ providedIn: 'root' }) export class UACService { isAvailable = false constructor ( - hostApp: HostAppService, private electron: ElectronService, ) { - this.isAvailable = hostApp.platform === Platform.Windows - && parseFloat(os.release()) >= 10 - && parseInt(os.release().split('.')[2]) >= 17692 + this.isAvailable = isWindowsBuild(WIN_BUILD_CONPTY_SUPPORTED) } patchSessionOptionsForUAC (sessionOptions: SessionOptions): SessionOptions { diff --git a/terminus-terminal/src/utils.ts b/terminus-terminal/src/utils.ts new file mode 100644 index 00000000..53fb0c81 --- /dev/null +++ b/terminus-terminal/src/utils.ts @@ -0,0 +1,8 @@ +import * as os from 'os' + +export const WIN_BUILD_CONPTY_SUPPORTED = 17692 +export const WIN_BUILD_CONPTY_STABLE = 18309 + +export function isWindowsBuild (build: number): boolean { + return process.platform === 'win32' && parseFloat(os.release()) >= 10 && parseInt(os.release().split('.')[2]) >= build +}