From ff18926bf947f4f3c3ff3b0b43b2b27b7f1a3d06 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Sun, 11 Jul 2021 22:59:39 +0200 Subject: [PATCH] WSA wip --- scripts/build-modules.js | 5 +- scripts/publish-plugins.js | 2 +- scripts/vars.js | 7 +++ tabby-community-color-schemes/package.json | 2 +- tabby-core/package.json | 2 +- tabby-core/src/services/profiles.service.ts | 1 + tabby-electron/package.json | 2 +- tabby-local/package.json | 2 +- tabby-plugin-manager/package.json | 2 +- tabby-serial/package.json | 2 +- tabby-serial/src/api.ts | 8 ++++ .../serialProfileSettings.component.pug | 2 +- .../serialProfileSettings.component.ts | 4 +- .../src/components/serialTab.component.pug | 2 +- .../src/components/serialTab.component.ts | 3 +- tabby-serial/src/profiles.ts | 48 +++++++++---------- tabby-serial/yarn.lock | 34 +++++++++++++ tabby-settings/package.json | 2 +- tabby-ssh/package.json | 2 +- tabby-telnet/package.json | 2 +- tabby-terminal/package.json | 2 +- tabby-web-demo/package.json | 2 +- tabby-web/package.json | 2 +- web/entry.preload.ts | 3 ++ web/package.json | 3 +- web/polyfills.ts | 10 ++-- web/yarn.lock | 5 ++ webpack.plugin.config.js | 2 +- 28 files changed, 112 insertions(+), 51 deletions(-) diff --git a/scripts/build-modules.js b/scripts/build-modules.js index abf8015a..b85c83b6 100755 --- a/scripts/build-modules.js +++ b/scripts/build-modules.js @@ -1,5 +1,4 @@ #!/usr/bin/env node -const sh = require('shelljs') const vars = require('./vars') const log = require('npmlog') const webpack = require('webpack') @@ -8,9 +7,7 @@ const { promisify } = require('util') const configs = [ '../app/webpack.main.config.js', '../app/webpack.config.js', - '../web/webpack.config.js', - '../tabby-web-demo/webpack.config.js', - ...vars.builtinPlugins.map(x => `../${x}/webpack.config.js`), + ...vars.allPackages.map(x => `../${x}/webpack.config.js`), ] ;(async () => { diff --git a/scripts/publish-plugins.js b/scripts/publish-plugins.js index c5b1a0cb..f1c36a7c 100755 --- a/scripts/publish-plugins.js +++ b/scripts/publish-plugins.js @@ -3,7 +3,7 @@ const sh = require('shelljs') const vars = require('./vars') const log = require('npmlog') -;[...vars.builtinPlugins, 'web', 'tabby-web-demo'].forEach(plugin => { +vars.builtinPlugins.forEach(plugin => { log.info('bump', plugin) sh.cd(plugin) sh.exec('npm --no-git-tag-version version ' + vars.version) diff --git a/scripts/vars.js b/scripts/vars.js index 1598e909..dd38e3b9 100755 --- a/scripts/vars.js +++ b/scripts/vars.js @@ -26,6 +26,13 @@ exports.builtinPlugins = [ 'tabby-serial', 'tabby-telnet', ] + +exports.allPackages = [ + ...exports.builtinPlugins, + 'web', + 'tabby-web-demo', +] + exports.bundledModules = [ '@angular', '@ng-bootstrap', diff --git a/tabby-community-color-schemes/package.json b/tabby-community-color-schemes/package.json index b2325460..a130d21e 100644 --- a/tabby-community-color-schemes/package.json +++ b/tabby-community-color-schemes/package.json @@ -1,6 +1,6 @@ { "name": "tabby-community-color-schemes", - "version": "1.0.147-nightly.1", + "version": "1.0.147-nightly.2", "description": "Community color schemes for Tabby", "keywords": [ "tabby-builtin-plugin" diff --git a/tabby-core/package.json b/tabby-core/package.json index 37722f3c..28df38d7 100644 --- a/tabby-core/package.json +++ b/tabby-core/package.json @@ -1,6 +1,6 @@ { "name": "tabby-core", - "version": "1.0.147-nightly.1", + "version": "1.0.147-nightly.2", "description": "Tabby core", "keywords": [ "tabby-builtin-plugin" diff --git a/tabby-core/src/services/profiles.service.ts b/tabby-core/src/services/profiles.service.ts index c9f80fbc..ed9ddab1 100644 --- a/tabby-core/src/services/profiles.service.ts +++ b/tabby-core/src/services/profiles.service.ts @@ -74,6 +74,7 @@ export class ProfilesService { } selectorOptionForProfile (profile: Profile): SelectorOption { + profile = this.getConfigProxyForProfile(profile) return { icon: profile.icon, name: profile.group ? `${profile.group} / ${profile.name}` : profile.name, diff --git a/tabby-electron/package.json b/tabby-electron/package.json index 79d19eab..48f131a1 100644 --- a/tabby-electron/package.json +++ b/tabby-electron/package.json @@ -1,6 +1,6 @@ { "name": "tabby-electron", - "version": "1.0.147-nightly.1", + "version": "1.0.147-nightly.2", "description": "Electron-specific bindings", "keywords": [ "tabby-builtin-plugin" diff --git a/tabby-local/package.json b/tabby-local/package.json index 6386dfdc..17f95475 100644 --- a/tabby-local/package.json +++ b/tabby-local/package.json @@ -1,6 +1,6 @@ { "name": "tabby-local", - "version": "1.0.147-nightly.1", + "version": "1.0.147-nightly.2", "description": "Tabby's local shell plugin", "keywords": [ "tabby-builtin-plugin" diff --git a/tabby-plugin-manager/package.json b/tabby-plugin-manager/package.json index 8bdea38b..4ae29b5f 100644 --- a/tabby-plugin-manager/package.json +++ b/tabby-plugin-manager/package.json @@ -1,6 +1,6 @@ { "name": "tabby-plugin-manager", - "version": "1.0.147-nightly.1", + "version": "1.0.147-nightly.2", "description": "Tabby's plugin manager", "keywords": [ "tabby-builtin-plugin" diff --git a/tabby-serial/package.json b/tabby-serial/package.json index fd433963..4f05b90e 100644 --- a/tabby-serial/package.json +++ b/tabby-serial/package.json @@ -1,6 +1,6 @@ { "name": "tabby-serial", - "version": "1.0.147-nightly.1", + "version": "1.0.147-nightly.2", "description": "Serial connections for Tabby", "keywords": [ "tabby-builtin-plugin" diff --git a/tabby-serial/src/api.ts b/tabby-serial/src/api.ts index 67624899..84b992e5 100644 --- a/tabby-serial/src/api.ts +++ b/tabby-serial/src/api.ts @@ -4,6 +4,7 @@ import { LogService, NotificationsService, Profile } from 'tabby-core' import { Subject, Observable } from 'rxjs' import { Injector, NgZone } from '@angular/core' import { BaseSession, LoginScriptsOptions, StreamProcessingOptions, TerminalStreamProcessor } from 'tabby-terminal' +import { SerialService } from './services/serial.service' export interface SerialProfile extends Profile { options: SerialProfileOptions @@ -38,9 +39,12 @@ export class SerialSession extends BaseSession { private streamProcessor: TerminalStreamProcessor private zone: NgZone private notifications: NotificationsService + private serialService: SerialService constructor (injector: Injector, public profile: SerialProfile) { super(injector.get(LogService).create(`serial-${profile.options.port}`)) + this.serialService = injector.get(SerialService) + this.zone = injector.get(NgZone) this.notifications = injector.get(NotificationsService) @@ -57,6 +61,10 @@ export class SerialSession extends BaseSession { } async start (): Promise { + if (!this.profile.options.port) { + this.profile.options.port = (await this.serialService.listPorts())[0].name + } + this.serial = new SerialPort(this.profile.options.port, { autoOpen: false, baudRate: parseInt(this.profile.options.baudrate as any), diff --git a/tabby-serial/src/components/serialProfileSettings.component.pug b/tabby-serial/src/components/serialProfileSettings.component.pug index 875362db..cd7d86d1 100644 --- a/tabby-serial/src/components/serialProfileSettings.component.pug +++ b/tabby-serial/src/components/serialProfileSettings.component.pug @@ -3,7 +3,7 @@ ul.nav-tabs(ngbNav, #nav='ngbNav') a(ngbNavLink) General ng-template(ngbNavContent) .row - .col-6 + .col-6(ng:if='hostApp.platform !== Platform.Web') .form-group label Device input.form-control( diff --git a/tabby-serial/src/components/serialProfileSettings.component.ts b/tabby-serial/src/components/serialProfileSettings.component.ts index d72e2f3e..f1f3f73d 100644 --- a/tabby-serial/src/components/serialProfileSettings.component.ts +++ b/tabby-serial/src/components/serialProfileSettings.component.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import { Component } from '@angular/core' import { debounceTime, distinctUntilChanged, map } from 'rxjs' -import { ProfileSettingsComponent } from 'tabby-core' +import { HostAppService, Platform, ProfileSettingsComponent } from 'tabby-core' import { SerialPortInfo, BAUD_RATES, SerialProfile } from '../api' import { SerialService } from '../services/serial.service' @@ -12,9 +12,11 @@ import { SerialService } from '../services/serial.service' export class SerialProfileSettingsComponent implements ProfileSettingsComponent { profile: SerialProfile foundPorts: SerialPortInfo[] + Platform = Platform constructor ( private serial: SerialService, + public hostApp: HostAppService, ) { } portsAutocomplete = text$ => text$.pipe(map(() => { diff --git a/tabby-serial/src/components/serialTab.component.pug b/tabby-serial/src/components/serialTab.component.pug index 8278bc7b..274d25fa 100644 --- a/tabby-serial/src/components/serialTab.component.pug +++ b/tabby-serial/src/components/serialTab.component.pug @@ -8,7 +8,7 @@ .mr-auto - button.btn.btn-sm.btn-link.mr-3((click)='changeBaudRate()', *ngIf='session && session.open') + button.btn.btn-sm.btn-link.mr-3((click)='changeBaudRate()', *ngIf='session && session.open && hostApp.platform !== Platform.Web') span Change baud rate button.btn.btn-sm.btn-link((click)='reconnect()', *ngIf='!session || !session.open') diff --git a/tabby-serial/src/components/serialTab.component.ts b/tabby-serial/src/components/serialTab.component.ts index 659df867..e49ba7a0 100644 --- a/tabby-serial/src/components/serialTab.component.ts +++ b/tabby-serial/src/components/serialTab.component.ts @@ -2,7 +2,7 @@ import colors from 'ansi-colors' import { Component, Injector } from '@angular/core' import { first } from 'rxjs' -import { SelectorService } from 'tabby-core' +import { Platform, SelectorService } from 'tabby-core' import { BaseTerminalTabComponent } from 'tabby-terminal' import { SerialSession, BAUD_RATES, SerialProfile } from '../api' @@ -17,6 +17,7 @@ export class SerialTabComponent extends BaseTerminalTabComponent { profile?: SerialProfile session: SerialSession|null = null serialPort: any + Platform = Platform // eslint-disable-next-line @typescript-eslint/no-useless-constructor constructor ( diff --git a/tabby-serial/src/profiles.ts b/tabby-serial/src/profiles.ts index 639119d4..3d5f8ea4 100644 --- a/tabby-serial/src/profiles.ts +++ b/tabby-serial/src/profiles.ts @@ -1,8 +1,9 @@ import slugify from 'slugify' +import SerialPort from 'serialport' +import WSABinding from 'serialport-binding-webserialapi' import deepClone from 'clone-deep' import { Injectable } from '@angular/core' -import { ProfileProvider, NewTabParameters, SelectorService } from 'tabby-core' -import { InputMode, NewlineMode } from 'tabby-terminal' +import { ProfileProvider, NewTabParameters, SelectorService, HostAppService, Platform } from 'tabby-core' import { SerialProfileSettingsComponent } from './components/serialProfileSettings.component' import { SerialTabComponent } from './components/serialTab.component' import { SerialService } from './services/serial.service' @@ -35,44 +36,43 @@ export class SerialProfilesService extends ProfileProvider { constructor ( private selector: SelectorService, private serial: SerialService, - ) { super() } + private hostApp: HostAppService, + ) { + super() + if (hostApp.platform === Platform.Web) { + SerialPort.Binding = WSABinding + } + } async getBuiltinProfiles (): Promise { + if (this.hostApp.platform === Platform.Web) { + return [ + { + id: `serial:web`, + type: 'serial', + name: 'Serial connection', + icon: 'fas fa-microchip', + isBuiltin: true, + } as SerialProfile, + ] + } + return [ { id: `serial:template`, type: 'serial', name: 'Serial connection', icon: 'fas fa-microchip', - options: { - port: '', - databits: 8, - parity: 'none', - rtscts: false, - stopbits: 1, - xany: false, - xoff: false, - xon: false, - inputMode: 'local-echo' as InputMode, - outputMode: null, - inputNewlines: null, - outputNewlines: 'crlf' as NewlineMode, - }, isBuiltin: true, isTemplate: true, - }, + } as SerialProfile, ...(await this.serial.listPorts()).map(p => ({ id: `serial:port-${slugify(p.name).replace('.', '-')}`, type: 'serial', name: p.description ? `Serial: ${p.description}` : 'Serial', icon: 'fas fa-microchip', isBuiltin: true, - options: { - port: p.name, - inputMode: 'local-echo' as InputMode, - outputNewlines: 'crlf' as NewlineMode, - }, - })), + } as SerialProfile)), ] } diff --git a/tabby-serial/yarn.lock b/tabby-serial/yarn.lock index 2ab10c7e..cfb19aa7 100644 --- a/tabby-serial/yarn.lock +++ b/tabby-serial/yarn.lock @@ -2,6 +2,20 @@ # yarn lockfile v1 +"@serialport/binding-abstract@^9.0.2": + version "9.0.7" + resolved "https://registry.yarnpkg.com/@serialport/binding-abstract/-/binding-abstract-9.0.7.tgz#d2c7ecea0f100bdf20187bfc0d34ba90f5504e1e" + integrity sha512-g1ncCMIG9rMsxo/28ObYmXZcHThlvtZygsCANmyMUuFS7SwXY4+PhcEnt2+ZcMkEDNRiOklT+ngtIVx5GGpt/A== + dependencies: + debug "^4.3.1" + +"@serialport/stream@^9.0.2": + version "9.0.7" + resolved "https://registry.yarnpkg.com/@serialport/stream/-/stream-9.0.7.tgz#0bf023eb0233a714fcc5a86de09e381e466d9882" + integrity sha512-c/h7HPAeFiryD9iTGlaSvPqHFHSZ0NMQHxC4rcmKS2Vu3qJuEtkBdTLABwsMp7iWEiSnI4KC3s7bHapaXP06FQ== + dependencies: + debug "^4.3.1" + "@types/node@14.14.14": version "14.14.14" resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.14.tgz#f7fd5f3cc8521301119f63910f0fb965c7d761ae" @@ -11,3 +25,23 @@ ansi-colors@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348" integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA== + +debug@^4.3.1: + version "4.3.2" + resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.2.tgz#f0a49c18ac8779e31d4a0c6029dfb76873c7428b" + integrity sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw== + dependencies: + ms "2.1.2" + +ms@2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" + integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== + +serialport-binding-webserialapi@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/serialport-binding-webserialapi/-/serialport-binding-webserialapi-1.0.3.tgz#cf4348c075da2de8f6cf9936c0b95645f3ae657b" + integrity sha512-TS7dsvetVoTeiWlzpsT/akjtljiYPO56FoJWSFyJSoO/E8icYJ2neQ7CW5NW/sHZDnMqAxULyAny47UFhWz9oQ== + dependencies: + "@serialport/binding-abstract" "^9.0.2" + "@serialport/stream" "^9.0.2" diff --git a/tabby-settings/package.json b/tabby-settings/package.json index 3931a7cd..3b843b0c 100644 --- a/tabby-settings/package.json +++ b/tabby-settings/package.json @@ -1,6 +1,6 @@ { "name": "tabby-settings", - "version": "1.0.147-nightly.1", + "version": "1.0.147-nightly.2", "description": "Tabby terminal settings page", "keywords": [ "tabby-builtin-plugin" diff --git a/tabby-ssh/package.json b/tabby-ssh/package.json index b0169293..48820506 100644 --- a/tabby-ssh/package.json +++ b/tabby-ssh/package.json @@ -1,6 +1,6 @@ { "name": "tabby-ssh", - "version": "1.0.147-nightly.1", + "version": "1.0.147-nightly.2", "description": "SSH connections for Tabby", "keywords": [ "tabby-builtin-plugin" diff --git a/tabby-telnet/package.json b/tabby-telnet/package.json index 55e18c07..5eeac443 100644 --- a/tabby-telnet/package.json +++ b/tabby-telnet/package.json @@ -1,6 +1,6 @@ { "name": "tabby-telnet", - "version": "1.0.147-nightly.1", + "version": "1.0.147-nightly.2", "description": "Telnet/socket connections for Tabby", "keywords": [ "tabby-builtin-plugin" diff --git a/tabby-terminal/package.json b/tabby-terminal/package.json index 5573b5e0..9e9d396d 100644 --- a/tabby-terminal/package.json +++ b/tabby-terminal/package.json @@ -1,6 +1,6 @@ { "name": "tabby-terminal", - "version": "1.0.147-nightly.1", + "version": "1.0.147-nightly.2", "description": "Tabby's terminal emulation core", "keywords": [ "tabby-builtin-plugin" diff --git a/tabby-web-demo/package.json b/tabby-web-demo/package.json index f7b92923..1cbb665f 100644 --- a/tabby-web-demo/package.json +++ b/tabby-web-demo/package.json @@ -1,6 +1,6 @@ { "name": "tabby-web-demo", - "version": "1.0.147-nightly.1", + "version": "1.0.147-nightly.2", "main": "dist/index.js", "typings": "dist/index.d.ts", "scripts": { diff --git a/tabby-web/package.json b/tabby-web/package.json index e4c08aa5..28fc3d67 100644 --- a/tabby-web/package.json +++ b/tabby-web/package.json @@ -1,6 +1,6 @@ { "name": "tabby-web", - "version": "1.0.147-nightly.1", + "version": "1.0.147-nightly.2", "description": "Web-specific bindings", "keywords": [ "tabby-builtin-plugin" diff --git a/web/entry.preload.ts b/web/entry.preload.ts index 7f9b6d88..7047da12 100644 --- a/web/entry.preload.ts +++ b/web/entry.preload.ts @@ -102,6 +102,9 @@ Object.assign(window, { stderr: {}, resourcesPath: 'resources', version: '14.0.0', + versions: { + modules: 0, + }, nextTick: (f, ...args) => setTimeout(() => f(...args)), cwd: () => '/', }, diff --git a/web/package.json b/web/package.json index 66d3f9a2..2cab796b 100644 --- a/web/package.json +++ b/web/package.json @@ -10,10 +10,11 @@ "events": "^3.3.0", "patch-package": "^6.4.7", "path-browserify": "^1.0.1", + "readline-browserify": "^0.0.4", "stream-browserify": "^3.0.0" }, "resolutions": { "**/util": "^0.12.0" }, - "version": "1.0.147-nightly.1" + "version": "1.0.147-nightly.2" } diff --git a/web/polyfills.ts b/web/polyfills.ts index 15a7acbd..cdb22bed 100644 --- a/web/polyfills.ts +++ b/web/polyfills.ts @@ -58,10 +58,6 @@ Tabby.registerMock('fs', { appendFile: () => null, constants: {}, }) -Tabby.registerMock('readline', { - cursorTo: () => null, - clearLine: stream => stream.write('\r'), -}) Tabby.registerMock('any-promise', Promise) Tabby.registerMock('tls', {}) Tabby.registerMock('module', { @@ -124,6 +120,7 @@ Tabby.registerMock('util', require('util/')) Tabby.registerMock('keytar', { getPassword: () => null, }) +Tabby.registerMock('@serialport/bindings', {}) Tabby.registerModule('net', { Socket: SocketProxy, @@ -143,6 +140,11 @@ Tabby.registerModule('assert', Object.assign( )) Tabby.registerModule('constants', require('constants-browserify')) Tabby.registerModule('stream', require('stream-browserify')) +Tabby.registerModule('readline', { + ...require('readline-browserify'), + cursorTo: () => null, + clearLine: stream => stream.write('\r'), +}) Tabby.registerModule('@angular/core', angularCoreModule) Tabby.registerModule('@angular/compiler', angularCompilerModule) diff --git a/web/yarn.lock b/web/yarn.lock index 5eb8169d..3ee94cd1 100644 --- a/web/yarn.lock +++ b/web/yarn.lock @@ -800,6 +800,11 @@ readable-stream@^3.5.0, readable-stream@^3.6.0: string_decoder "^1.1.1" util-deprecate "^1.0.1" +readline-browserify@^0.0.4: + version "0.0.4" + resolved "https://registry.yarnpkg.com/readline-browserify/-/readline-browserify-0.0.4.tgz#d4367efe1e74881ea9deb836f69a608b885ffc7c" + integrity sha1-1DZ+/h50iB6p3rg29ppgi4hf/Hw= + rimraf@^2.6.3: version "2.7.1" resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.7.1.tgz#35797f13a7fdadc566142c29d4f07ccad483e3ec" diff --git a/webpack.plugin.config.js b/webpack.plugin.config.js index 9a756443..9a8dfa5f 100644 --- a/webpack.plugin.config.js +++ b/webpack.plugin.config.js @@ -98,6 +98,7 @@ module.exports = options => { }, externals: [ '@electron/remote', + '@serialport/bindings', 'any-promise', 'child_process', 'electron-promise-ipc', @@ -112,7 +113,6 @@ module.exports = options => { 'os', 'path', 'readline', - 'serialport', 'socksv5', 'stream', 'windows-native-registry',