diff --git a/app/lib/window.ts b/app/lib/window.ts index caf0a029..6143e8a2 100644 --- a/app/lib/window.ts +++ b/app/lib/window.ts @@ -135,6 +135,8 @@ export class Window { this.window.webContents.setVisualZoomLevelLimits(1, 1) this.window.webContents.setZoomFactor(1) + this.window.webContents.session.setPermissionCheckHandler(() => true) + this.window.webContents.session.setDevicePermissionHandler(() => true) if (process.platform === 'darwin') { this.touchBarControl = new TouchBar.TouchBarSegmentedControl({ diff --git a/app/package.json b/app/package.json index 0501ec44..da962a4e 100644 --- a/app/package.json +++ b/app/package.json @@ -38,6 +38,7 @@ "@tabby-gang/windows-blurbehind": "^3.0.0", "macos-native-processlist": "^2.0.0", "serialport": "10.2.2", + "serialport-binding-webserialapi": "^1.0.3", "windows-native-registry": "^3.1.0", "windows-process-tree": "^0.3.2" }, diff --git a/app/yarn.lock b/app/yarn.lock index 7cdb82f7..aafcf7c3 100644 --- a/app/yarn.lock +++ b/app/yarn.lock @@ -16,6 +16,13 @@ update-notifier "^2.2.0" yargs "^8.0.2" +"@serialport/binding-abstract@^9.0.2": + version "9.2.3" + resolved "https://registry.yarnpkg.com/@serialport/binding-abstract/-/binding-abstract-9.2.3.tgz#e7dd273357b6a698af7ad58db6f57f62443a0acb" + integrity sha512-cQs9tbIlG3P0IrOWyVirqlhWuJ7Ms2Zh9m2108z6Y5UW/iVj6wEOiW8EmK9QX9jmJXYllE7wgGgvVozP5oCj3w== + dependencies: + debug "^4.3.2" + "@serialport/binding-mock@10.2.2": version "10.2.2" resolved "https://registry.yarnpkg.com/@serialport/binding-mock/-/binding-mock-10.2.2.tgz#d322a8116a97806addda13c62f50e73d16125874" @@ -100,6 +107,13 @@ "@serialport/bindings-interface" "1.2.1" debug "^4.3.2" +"@serialport/stream@^9.0.2": + version "9.2.4" + resolved "https://registry.yarnpkg.com/@serialport/stream/-/stream-9.2.4.tgz#9fce093d0b46ed4599953b4fae81718e050d2b33" + integrity sha512-bLye8Ub4vUFQGmkh8qEqehr7SE7EJs2yDs0h9jzuL5oKi+F34CFmWkEErO8GAOQ8YNn7p6b3GxUgs+0BrHHDZQ== + dependencies: + debug "^4.3.2" + "@tabby-gang/node-pty@^0.11.0-beta.200": version "0.11.0-beta.200" resolved "https://registry.yarnpkg.com/@tabby-gang/node-pty/-/node-pty-0.11.0-beta.200.tgz#485cd6d85a04f4b272b81a9862578d7fc38cdfb5" @@ -3242,6 +3256,14 @@ serialize-error@^5.0.0: dependencies: type-fest "^0.8.0" +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" + serialport@10.2.2: version "10.2.2" resolved "https://registry.yarnpkg.com/serialport/-/serialport-10.2.2.tgz#ab12a423046df6b64cb3144fdb2d00fb3062ab75" diff --git a/tabby-serial/package.json b/tabby-serial/package.json index c2185786..680168e0 100644 --- a/tabby-serial/package.json +++ b/tabby-serial/package.json @@ -18,8 +18,7 @@ "license": "MIT", "devDependencies": { "@types/node": "14.14.14", - "ansi-colors": "^4.1.1", - "serialport-binding-webserialapi": "^1.0.3" + "ansi-colors": "^4.1.1" }, "peerDependencies": { "@angular/animations": "^9.1.9", diff --git a/tabby-serial/src/api.ts b/tabby-serial/src/api.ts index 7f3bb37b..d4acbf21 100644 --- a/tabby-serial/src/api.ts +++ b/tabby-serial/src/api.ts @@ -1,5 +1,5 @@ import stripAnsi from 'strip-ansi' -import { SerialPort } from 'serialport' +import { SerialPortStream } from '@serialport/stream' import { LogService, NotificationsService, Profile } from 'tabby-core' import { Subject, Observable } from 'rxjs' import { Injector, NgZone } from '@angular/core' @@ -41,7 +41,7 @@ class SlowFeedMiddleware extends SessionMiddleware { } export class SerialSession extends BaseSession { - serial: SerialPort|null + serial: SerialPortStream|null get serviceMessage$ (): Observable { return this.serviceMessage } private serviceMessage = new Subject() @@ -72,7 +72,8 @@ export class SerialSession extends BaseSession { this.profile.options.port = (await this.serialService.listPorts())[0].name } - const serial = this.serial = new SerialPort({ + const serial = this.serial = new SerialPortStream({ + binding: this.serialService.detectBinding(), path: this.profile.options.port, autoOpen: false, baudRate: parseInt(this.profile.options.baudrate as any), diff --git a/tabby-serial/src/profiles.ts b/tabby-serial/src/profiles.ts index 453152db..314bb92b 100644 --- a/tabby-serial/src/profiles.ts +++ b/tabby-serial/src/profiles.ts @@ -1,6 +1,4 @@ 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, HostAppService, Platform, TranslateService } from 'tabby-core' @@ -41,9 +39,6 @@ export class SerialProfilesService extends ProfileProvider { private translate: TranslateService, ) { super() - if (hostApp.platform === Platform.Web) { - SerialPort['Binding'] = WSABinding - } } async getBuiltinProfiles (): Promise { diff --git a/tabby-serial/src/services/serial.service.ts b/tabby-serial/src/services/serial.service.ts index 0a6c155f..63228b70 100644 --- a/tabby-serial/src/services/serial.service.ts +++ b/tabby-serial/src/services/serial.service.ts @@ -1,6 +1,8 @@ import { Injectable } from '@angular/core' -import { SerialPort } from 'serialport' -import { PartialProfile, ProfilesService } from 'tabby-core' +import WSABinding from 'serialport-binding-webserialapi' +import AbstractBinding from '@serialport/binding-abstract' +import { autoDetect } from '@serialport/bindings-cpp' +import { HostAppService, PartialProfile, Platform, ProfilesService } from 'tabby-core' import { SerialPortInfo, SerialProfile } from '../api' import { SerialTabComponent } from '../components/serialTab.component' @@ -8,13 +10,23 @@ import { SerialTabComponent } from '../components/serialTab.component' export class SerialService { private constructor ( private profilesService: ProfilesService, + private hostApp: HostAppService, ) { } + detectBinding (): typeof AbstractBinding { + return this.hostApp.platform === Platform.Web ? WSABinding : autoDetect() + } + async listPorts (): Promise { - return (await SerialPort.list()).map(x => ({ - name: x.path, - description: `${x.manufacturer ?? ''} ${x.serialNumber ?? ''}`.trim() || undefined, - })) + try { + return (await this.detectBinding().list()).map(x => ({ + name: x.path, + description: `${x.manufacturer ?? ''} ${x.serialNumber ?? ''}`.trim() || undefined, + })) + } catch (err) { + console.error('Failed to list serial ports', err) + return [] + } } quickConnect (query: string): Promise { diff --git a/tabby-serial/yarn.lock b/tabby-serial/yarn.lock index cfb19aa7..2ab10c7e 100644 --- a/tabby-serial/yarn.lock +++ b/tabby-serial/yarn.lock @@ -2,20 +2,6 @@ # 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" @@ -25,23 +11,3 @@ 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"