Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
taichunmin committed Jun 21, 2024
1 parent 792cd88 commit eb53f5e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/plugin/SerialPortAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ export default class SerialPortAdapter implements ChameleonPlugin {
await ultra.disconnect(new Error('adapter replaced'))
}

const adapter: any = {}

adapter.isSupported = (): boolean => !_.isNil(SerialPort)
const adapter: AdapterInstallResp = {
isSupported: () => !_.isNil(SerialPort),
}

ultra.addHook('connect', async (ctx: any, next: () => Promise<unknown>) => {
if (ultra.$adapter !== adapter) return await next() // 代表已經被其他 adapter 接管

try {
if (adapter.isSupported() !== true) throw new Error('SerialPort not supported')
if (!adapter.isSupported()) throw new Error('SerialPort not supported')

const baudRate = pluginOption?.baudRate ?? 115200
const path = pluginOption?.path ?? await findDevicePath()
Expand Down Expand Up @@ -62,7 +62,7 @@ export default class SerialPortAdapter implements ChameleonPlugin {
delete this.duplex
})

return adapter as AdapterInstallResp
return adapter
}
}

Expand All @@ -78,5 +78,5 @@ export interface SerialPortOption {
}

interface AdapterInstallResp {
isSuppored: () => boolean
isSupported: () => boolean
}

0 comments on commit eb53f5e

Please sign in to comment.