fixed serial opening ports

This commit is contained in:
Eugene Pankov 2022-02-11 11:02:29 +01:00
parent 1fc531ecf4
commit c64654991b
No known key found for this signature in database
GPG key ID: 5896FCBBDD1CF4F4
8 changed files with 48 additions and 50 deletions

View file

@ -135,6 +135,8 @@ export class Window {
this.window.webContents.setVisualZoomLevelLimits(1, 1) this.window.webContents.setVisualZoomLevelLimits(1, 1)
this.window.webContents.setZoomFactor(1) this.window.webContents.setZoomFactor(1)
this.window.webContents.session.setPermissionCheckHandler(() => true)
this.window.webContents.session.setDevicePermissionHandler(() => true)
if (process.platform === 'darwin') { if (process.platform === 'darwin') {
this.touchBarControl = new TouchBar.TouchBarSegmentedControl({ this.touchBarControl = new TouchBar.TouchBarSegmentedControl({

View file

@ -38,6 +38,7 @@
"@tabby-gang/windows-blurbehind": "^3.0.0", "@tabby-gang/windows-blurbehind": "^3.0.0",
"macos-native-processlist": "^2.0.0", "macos-native-processlist": "^2.0.0",
"serialport": "10.2.2", "serialport": "10.2.2",
"serialport-binding-webserialapi": "^1.0.3",
"windows-native-registry": "^3.1.0", "windows-native-registry": "^3.1.0",
"windows-process-tree": "^0.3.2" "windows-process-tree": "^0.3.2"
}, },

View file

@ -16,6 +16,13 @@
update-notifier "^2.2.0" update-notifier "^2.2.0"
yargs "^8.0.2" 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": "@serialport/binding-mock@10.2.2":
version "10.2.2" version "10.2.2"
resolved "https://registry.yarnpkg.com/@serialport/binding-mock/-/binding-mock-10.2.2.tgz#d322a8116a97806addda13c62f50e73d16125874" 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" "@serialport/bindings-interface" "1.2.1"
debug "^4.3.2" 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": "@tabby-gang/node-pty@^0.11.0-beta.200":
version "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" 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: dependencies:
type-fest "^0.8.0" 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: serialport@10.2.2:
version "10.2.2" version "10.2.2"
resolved "https://registry.yarnpkg.com/serialport/-/serialport-10.2.2.tgz#ab12a423046df6b64cb3144fdb2d00fb3062ab75" resolved "https://registry.yarnpkg.com/serialport/-/serialport-10.2.2.tgz#ab12a423046df6b64cb3144fdb2d00fb3062ab75"

View file

@ -18,8 +18,7 @@
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@types/node": "14.14.14", "@types/node": "14.14.14",
"ansi-colors": "^4.1.1", "ansi-colors": "^4.1.1"
"serialport-binding-webserialapi": "^1.0.3"
}, },
"peerDependencies": { "peerDependencies": {
"@angular/animations": "^9.1.9", "@angular/animations": "^9.1.9",

View file

@ -1,5 +1,5 @@
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
import { SerialPort } from 'serialport' import { SerialPortStream } from '@serialport/stream'
import { LogService, NotificationsService, Profile } from 'tabby-core' import { LogService, NotificationsService, Profile } from 'tabby-core'
import { Subject, Observable } from 'rxjs' import { Subject, Observable } from 'rxjs'
import { Injector, NgZone } from '@angular/core' import { Injector, NgZone } from '@angular/core'
@ -41,7 +41,7 @@ class SlowFeedMiddleware extends SessionMiddleware {
} }
export class SerialSession extends BaseSession { export class SerialSession extends BaseSession {
serial: SerialPort|null serial: SerialPortStream|null
get serviceMessage$ (): Observable<string> { return this.serviceMessage } get serviceMessage$ (): Observable<string> { return this.serviceMessage }
private serviceMessage = new Subject<string>() private serviceMessage = new Subject<string>()
@ -72,7 +72,8 @@ export class SerialSession extends BaseSession {
this.profile.options.port = (await this.serialService.listPorts())[0].name 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, path: this.profile.options.port,
autoOpen: false, autoOpen: false,
baudRate: parseInt(this.profile.options.baudrate as any), baudRate: parseInt(this.profile.options.baudrate as any),

View file

@ -1,6 +1,4 @@
import slugify from 'slugify' import slugify from 'slugify'
import { SerialPort } from 'serialport'
import WSABinding from 'serialport-binding-webserialapi'
import deepClone from 'clone-deep' import deepClone from 'clone-deep'
import { Injectable } from '@angular/core' import { Injectable } from '@angular/core'
import { ProfileProvider, NewTabParameters, SelectorService, HostAppService, Platform, TranslateService } from 'tabby-core' import { ProfileProvider, NewTabParameters, SelectorService, HostAppService, Platform, TranslateService } from 'tabby-core'
@ -41,9 +39,6 @@ export class SerialProfilesService extends ProfileProvider<SerialProfile> {
private translate: TranslateService, private translate: TranslateService,
) { ) {
super() super()
if (hostApp.platform === Platform.Web) {
SerialPort['Binding'] = WSABinding
}
} }
async getBuiltinProfiles (): Promise<SerialProfile[]> { async getBuiltinProfiles (): Promise<SerialProfile[]> {

View file

@ -1,6 +1,8 @@
import { Injectable } from '@angular/core' import { Injectable } from '@angular/core'
import { SerialPort } from 'serialport' import WSABinding from 'serialport-binding-webserialapi'
import { PartialProfile, ProfilesService } from 'tabby-core' 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 { SerialPortInfo, SerialProfile } from '../api'
import { SerialTabComponent } from '../components/serialTab.component' import { SerialTabComponent } from '../components/serialTab.component'
@ -8,13 +10,23 @@ import { SerialTabComponent } from '../components/serialTab.component'
export class SerialService { export class SerialService {
private constructor ( private constructor (
private profilesService: ProfilesService, private profilesService: ProfilesService,
private hostApp: HostAppService,
) { } ) { }
detectBinding (): typeof AbstractBinding {
return this.hostApp.platform === Platform.Web ? WSABinding : autoDetect()
}
async listPorts (): Promise<SerialPortInfo[]> { async listPorts (): Promise<SerialPortInfo[]> {
return (await SerialPort.list()).map(x => ({ try {
name: x.path, return (await this.detectBinding().list()).map(x => ({
description: `${x.manufacturer ?? ''} ${x.serialNumber ?? ''}`.trim() || undefined, 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<SerialTabComponent|null> { quickConnect (query: string): Promise<SerialTabComponent|null> {

View file

@ -2,20 +2,6 @@
# yarn lockfile v1 # 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": "@types/node@14.14.14":
version "14.14.14" version "14.14.14"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.14.tgz#f7fd5f3cc8521301119f63910f0fb965c7d761ae" 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" version "4.1.1"
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348" resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348"
integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA== 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"