started separating terminus-electron and terminus-web

This commit is contained in:
Eugene Pankov
2021-05-24 17:48:12 +02:00
parent c19e131d8c
commit 012986dc7e
94 changed files with 1899 additions and 972 deletions

View File

@@ -24,7 +24,7 @@ export class TerminalTabComponent extends BaseTerminalTabComponent {
ngOnInit (): void {
this.logger = this.log.create('terminalTab')
this.session = new Session(this.config)
this.session = new Session(this.injector)
const isConPTY = isWindowsBuild(WIN_BUILD_CONPTY_SUPPORTED) && this.config.store.terminal.useConPTY

View File

@@ -4,7 +4,7 @@ import { FormsModule } from '@angular/forms'
import { NgbModule } from '@ng-bootstrap/ng-bootstrap'
import { ToastrModule } from 'ngx-toastr'
import TerminusCorePlugin, { HostAppService, ToolbarButtonProvider, TabRecoveryProvider, ConfigProvider, HotkeysService, HotkeyProvider, TabContextMenuItemProvider, CLIHandler } from 'terminus-core'
import TerminusCorePlugin, { HostAppService, ToolbarButtonProvider, TabRecoveryProvider, ConfigProvider, HotkeysService, HotkeyProvider, TabContextMenuItemProvider, CLIHandler, ConfigService } from 'terminus-core'
import TerminusTerminalModule from 'terminus-terminal'
import { SettingsTabProvider } from 'terminus-settings'
@@ -104,6 +104,7 @@ export default class LocalTerminalModule { // eslint-disable-line @typescript-es
terminal: TerminalService,
hostApp: HostAppService,
dockMenu: DockMenuService,
config: ConfigService,
) {
hotkeys.matchedHotkey.subscribe(async (hotkey) => {
if (hotkey === 'new-tab') {
@@ -120,7 +121,9 @@ export default class LocalTerminalModule { // eslint-disable-line @typescript-es
}
})
dockMenu.update()
config.ready$.toPromise().then(() => {
dockMenu.update()
})
}
}

View File

@@ -26,10 +26,12 @@ export class TerminalService {
log: LogService,
) {
this.logger = log.create('terminal')
this.reloadShells()
config.changed$.subscribe(() => {
config.ready$.toPromise().then(() => {
this.reloadShells()
config.changed$.subscribe(() => {
this.reloadShells()
})
})
}

View File

@@ -1,7 +1,8 @@
import * as psNode from 'ps-node'
import * as fs from 'mz/fs'
import * as os from 'os'
import { ConfigService, WIN_BUILD_CONPTY_SUPPORTED, isWindowsBuild, getBootstrapData } from 'terminus-core'
import { Injector } from '@angular/core'
import { HostAppService, ConfigService, WIN_BUILD_CONPTY_SUPPORTED, isWindowsBuild, Platform, BootstrapData, BOOTSTRAP_DATA } from 'terminus-core'
import { BaseSession } from 'terminus-terminal'
import { ipcRenderer } from 'electron'
import { getWorkingDirectoryFromPID } from 'native-process-working-directory'
@@ -91,9 +92,15 @@ export class Session extends BaseSession {
private guessedCWD: string|null = null
private reportedCWD: string
private initialCWD: string|null = null
private config: ConfigService
private hostApp: HostAppService
private bootstrapData: BootstrapData
constructor (private config: ConfigService) {
constructor (injector: Injector) {
super()
this.config = injector.get(ConfigService)
this.hostApp = injector.get(HostAppService)
this.bootstrapData = injector.get(BOOTSTRAP_DATA) as BootstrapData
}
start (options: SessionOptions): void {
@@ -115,13 +122,13 @@ export class Session extends BaseSession {
...this.config.store.terminal.environment || {},
}
if (process.platform === 'win32') {
env.COMSPEC = getBootstrapData().executable
if (this.hostApp.platform === Platform.Windows) {
env.COMSPEC = this.bootstrapData.executable
}
delete env['']
if (process.platform === 'darwin' && !process.env.LC_ALL) {
if (this.hostApp.platform === Platform.macOS && !process.env.LC_ALL) {
const locale = process.env.LC_CTYPE ?? 'en_US.UTF-8'
Object.assign(env, {
LANG: locale,
@@ -177,7 +184,7 @@ export class Session extends BaseSession {
let data = Buffer.from(array)
data = this.processOSC1337(data)
this.emitOutput(data)
if (process.platform === 'win32') {
if (this.hostApp.platform === Platform.Windows) {
this.guessWindowsCWD(data.toString())
}
})
@@ -229,7 +236,7 @@ export class Session extends BaseSession {
if (!this.truePID) {
return []
}
if (process.platform === 'darwin') {
if (this.hostApp.platform === Platform.macOS) {
const processes = await macOSNativeProcessList.getProcessList()
return processes.filter(x => x.ppid === this.truePID).map(p => ({
pid: p.pid,
@@ -237,7 +244,7 @@ export class Session extends BaseSession {
command: p.name,
}))
}
if (process.platform === 'win32') {
if (this.hostApp.platform === Platform.Windows) {
return new Promise<ChildProcess[]>(resolve => {
windowsProcessTree.getProcessTree(this.truePID, tree => {
resolve(tree ? tree.children.map(child => ({
@@ -259,7 +266,7 @@ export class Session extends BaseSession {
}
async gracefullyKillProcess (): Promise<void> {
if (process.platform === 'win32') {
if (this.hostApp.platform === Platform.Windows) {
this.kill()
} else {
await new Promise<void>((resolve) => {
@@ -302,7 +309,7 @@ export class Session extends BaseSession {
cwd = await fs.realpath(cwd)
} catch {}
if (process.platform === 'win32' && (cwd === this.initialCWD || cwd === process.env.WINDIR)) {
if (this.hostApp.platform === Platform.Windows && (cwd === this.initialCWD || cwd === process.env.WINDIR)) {
// shell doesn't truly change its process' CWD
cwd = null
}

View File

@@ -1,6 +1,5 @@
import { MenuItemConstructorOptions } from 'electron'
import { Injectable, NgZone } from '@angular/core'
import { ConfigService, BaseTabComponent, TabContextMenuItemProvider, TabHeaderComponent, SplitTabComponent, NotificationsService } from 'terminus-core'
import { ConfigService, BaseTabComponent, TabContextMenuItemProvider, TabHeaderComponent, SplitTabComponent, NotificationsService, MenuItemOptions } from 'terminus-core'
import { TerminalTabComponent } from './components/terminalTab.component'
import { UACService } from './services/uac.service'
import { TerminalService } from './services/terminal.service'
@@ -16,11 +15,11 @@ export class SaveAsProfileContextMenu extends TabContextMenuItemProvider {
super()
}
async getItems (tab: BaseTabComponent, _tabHeader?: TabHeaderComponent): Promise<MenuItemConstructorOptions[]> {
async getItems (tab: BaseTabComponent, _tabHeader?: TabHeaderComponent): Promise<MenuItemOptions[]> {
if (!(tab instanceof TerminalTabComponent)) {
return []
}
const items: MenuItemConstructorOptions[] = [
const items: MenuItemOptions[] = [
{
label: 'Save as profile',
click: () => this.zone.run(async () => {
@@ -59,10 +58,10 @@ export class NewTabContextMenu extends TabContextMenuItemProvider {
super()
}
async getItems (tab: BaseTabComponent, tabHeader?: TabHeaderComponent): Promise<MenuItemConstructorOptions[]> {
async getItems (tab: BaseTabComponent, tabHeader?: TabHeaderComponent): Promise<MenuItemOptions[]> {
const profiles = await this.terminalService.getProfiles()
const items: MenuItemConstructorOptions[] = [
const items: MenuItemOptions[] = [
{
label: 'New terminal',
click: () => this.zone.run(() => {