mirror of
https://github.com/Eugeny/tabby.git
synced 2025-09-24 09:06:03 +00:00
lint
This commit is contained in:
@@ -41,7 +41,7 @@ class SlowFeedMiddleware extends SessionMiddleware {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class SerialSession extends BaseSession {
|
export class SerialSession extends BaseSession {
|
||||||
serial: SerialPort
|
serial: SerialPort|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,7 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
this.serial = new SerialPort({
|
const serial = this.serial = new SerialPort({
|
||||||
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),
|
||||||
@@ -86,27 +86,27 @@ export class SerialSession extends BaseSession {
|
|||||||
})
|
})
|
||||||
let connected = false
|
let connected = false
|
||||||
await new Promise(async (resolve, reject) => {
|
await new Promise(async (resolve, reject) => {
|
||||||
this.serial.on('open', () => {
|
serial.on('open', () => {
|
||||||
connected = true
|
connected = true
|
||||||
this.zone.run(resolve)
|
this.zone.run(resolve)
|
||||||
})
|
})
|
||||||
this.serial.on('error', error => {
|
serial.on('error', error => {
|
||||||
this.zone.run(() => {
|
this.zone.run(() => {
|
||||||
if (connected) {
|
if (connected) {
|
||||||
this.notifications.error(error.toString())
|
this.notifications.error(error.message)
|
||||||
} else {
|
} else {
|
||||||
reject(error)
|
reject(error)
|
||||||
}
|
}
|
||||||
this.destroy()
|
this.destroy()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
this.serial.on('close', () => {
|
serial.on('close', () => {
|
||||||
this.emitServiceMessage('Port closed')
|
this.emitServiceMessage('Port closed')
|
||||||
this.destroy()
|
this.destroy()
|
||||||
})
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.serial.open()
|
serial.open()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.notifications.error(e.message)
|
this.notifications.error(e.message)
|
||||||
reject(e)
|
reject(e)
|
||||||
@@ -116,11 +116,11 @@ export class SerialSession extends BaseSession {
|
|||||||
this.open = true
|
this.open = true
|
||||||
setTimeout(() => this.streamProcessor.start())
|
setTimeout(() => this.streamProcessor.start())
|
||||||
|
|
||||||
this.serial.on('readable', () => {
|
serial.on('readable', () => {
|
||||||
this.emitOutput(this.serial.read())
|
this.emitOutput(serial.read())
|
||||||
})
|
})
|
||||||
|
|
||||||
this.serial.on('end', () => {
|
serial.on('end', () => {
|
||||||
this.logger.info('Shell session ended')
|
this.logger.info('Shell session ended')
|
||||||
if (this.open) {
|
if (this.open) {
|
||||||
this.destroy()
|
this.destroy()
|
||||||
@@ -145,7 +145,7 @@ export class SerialSession extends BaseSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
kill (_?: string): void {
|
kill (_?: string): void {
|
||||||
this.serial.close()
|
this.serial?.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
emitServiceMessage (msg: string): void {
|
emitServiceMessage (msg: string): void {
|
||||||
|
@@ -13,7 +13,7 @@ export class SerialService {
|
|||||||
async listPorts (): Promise<SerialPortInfo[]> {
|
async listPorts (): Promise<SerialPortInfo[]> {
|
||||||
return (await SerialPort.list()).map(x => ({
|
return (await SerialPort.list()).map(x => ({
|
||||||
name: x.path,
|
name: x.path,
|
||||||
description: x.manufacturer || x.serialNumber ? `${x.manufacturer || ''} ${x.serialNumber || ''}` : undefined,
|
description: `${x.manufacturer ?? ''} ${x.serialNumber ?? ''}`.trim() || undefined,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user