feat(serial): allow empty port selection on connect

This commit is contained in:
bluekani
2026-06-07 08:25:33 +09:00
parent f5d6ed0b40
commit 3c3dbe730c
3 changed files with 27 additions and 2 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ export interface SerialProfile extends ConnectableTerminalProfile {
}
export interface SerialProfileOptions extends StreamProcessingOptions, LoginScriptsOptions {
port: string
port: string | null
baudrate: number | null
databits: 5 | 6 | 7 | 8
stopbits: 1 | 1.5 | 2
@@ -9,6 +9,7 @@ ul.nav-tabs(ngbNav, #nav='ngbNav')
input.form-control(
type='text',
alwaysVisibleTypeahead,
placeholder='Ask every time',
[(ngModel)]='profile.options.port',
[ngbTypeahead]='portsAutocomplete',
[resultFormatter]='portsFormatter'
+25 -1
View File
@@ -83,6 +83,30 @@ export class SerialProfilesService extends ConnectableProfileProvider<SerialProf
}
async getNewTabParameters (profile: SerialProfile): Promise<NewTabParameters<SerialTabComponent>> {
// Show port selector first if not set
if (!profile.options.port) {
profile = deepClone(profile)
let port: string|undefined = undefined
try {
const ports = await this.serial.listPorts()
port = await this.selector.show(
this.translate.instant('Select port'),
[
...ports.map(x => ({
name: x.description ? `${x.name} (${x.description})` : x.name, result: x.name, weight: 0,
})),
],
)
} catch {
throw new Error('Port selection canceled')
}
profile.options.port = port
}
// Then show baudrate selector if not set
if (!profile.options.baudrate) {
profile = deepClone(profile)
let baudrate: number|undefined = undefined
@@ -132,6 +156,6 @@ export class SerialProfilesService extends ConnectableProfileProvider<SerialProf
}
getDescription (profile: SerialProfile): string {
return profile.options.port
return profile.options.port ?? ''
}
}