@@ -3,6 +3,7 @@ import { EventBus } from "../components/eventBus";
33import { serial } from "./serial.js" ;
44import WEBUSBDFU from "./protocols/webusbdfu" ;
55import { reactive } from "vue" ;
6+ import { isTauri } from "@tauri-apps/api/core" ;
67import {
78 checkBrowserCompatibility ,
89 checkWebBluetoothSupport ,
@@ -37,7 +38,8 @@ const PortHandler = new (function () {
3738 checkBrowserCompatibility ( ) ;
3839
3940 this . showBluetoothOption = checkWebBluetoothSupport ( ) ;
40- this . showSerialOption = checkWebSerialSupport ( ) ;
41+ // In Tauri, native serial is available via plugin even if Web Serial API isn't.
42+ this . showSerialOption = checkWebSerialSupport ( ) || isTauri ( ) ;
4143 this . showUsbOption = checkWebUSBSupport ( ) ;
4244
4345 console . log ( `${ this . logHead } Bluetooth available: ${ this . showBluetoothOption } ` ) ;
@@ -47,23 +49,30 @@ const PortHandler = new (function () {
4749 this . showVirtualMode = getConfig ( "showVirtualMode" , false ) . showVirtualMode ;
4850 this . showManualMode = getConfig ( "showManualMode" , false ) . showManualMode ;
4951 this . showAllSerialDevices = getConfig ( "showAllSerialDevices" , false ) . showAllSerialDevices ;
52+ // Decide which serial protocol to prefer at runtime
53+ this . serialProtocol = isTauri ( ) ? "tauriserial" : "webserial" ;
54+ console . log ( `${ this . logHead } ### Using serial protocol: ${ this . serialProtocol } ` ) ;
5055} ) ( ) ;
5156
5257PortHandler . initialize = function ( ) {
5358 EventBus . $on ( "ports-input:request-permission-bluetooth" , ( ) => this . requestDevicePermission ( "webbluetooth" ) ) ;
54- EventBus . $on ( "ports-input:request-permission-serial" , ( ) => this . requestDevicePermission ( "webserial" ) ) ;
59+ EventBus . $on ( "ports-input:request-permission-serial" , ( ) => this . requestDevicePermission ( this . serialProtocol ) ) ;
5560 EventBus . $on ( "ports-input:request-permission-usb" , ( ) => this . requestDevicePermission ( "usb" ) ) ;
5661 EventBus . $on ( "ports-input:change" , this . onChangeSelectedPort . bind ( this ) ) ;
5762
5863 // Use serial for all protocol events
5964 serial . addEventListener ( "addedDevice" , ( event ) => {
6065 const detail = event . detail ;
66+ const proto = ( detail ?. protocolType || "" ) . toLowerCase ( ) ;
6167
62- if ( detail ?. path ?. startsWith ( "bluetooth" ) ) {
68+ if ( detail ?. path ?. startsWith ( "bluetooth" ) || proto === "webbluetooth" ) {
6369 this . handleDeviceAdded ( detail , "webbluetooth" ) ;
70+ } else if ( proto === "tauriserial" ) {
71+ this . handleDeviceAdded ( detail , "tauriserial" ) ;
6472 } else {
6573 this . handleDeviceAdded ( detail , "webserial" ) ;
6674 }
75+ console . log ( `${ this . logHead } #### Device addition event received:` , event . detail , proto ) ;
6776 } ) ;
6877
6978 serial . addEventListener ( "removedDevice" , ( event ) => {
@@ -81,7 +90,7 @@ PortHandler.initialize = function () {
8190PortHandler . refreshAllDeviceLists = async function ( ) {
8291 // Update all device lists in parallel
8392 return Promise . all ( [
84- this . updateDeviceList ( "webserial" ) ,
93+ this . updateDeviceList ( this . serialProtocol ) ,
8594 this . updateDeviceList ( "webbluetooth" ) ,
8695 this . updateDeviceList ( "usb" ) ,
8796 ] ) . then ( ( ) => {
@@ -108,11 +117,12 @@ PortHandler.removedSerialDevice = function (device) {
108117
109118 // Get device path safely
110119 const devicePath = device ?. path || ( typeof device === "string" ? device : null ) ;
120+ const proto = ( device ?. protocolType || "" ) . toLowerCase ( ) ;
111121
112122 if ( ! devicePath ) {
113123 console . warn ( `${ this . logHead } Device removal event missing path information` , device ) ;
114124 // Still update ports, but don't try to use the undefined path
115- this . updateDeviceList ( "webserial" ) . then ( ( ) => {
125+ this . updateDeviceList ( this . serialProtocol ) . then ( ( ) => {
116126 this . selectActivePort ( ) ;
117127 } ) ;
118128 return ;
@@ -121,7 +131,7 @@ PortHandler.removedSerialDevice = function (device) {
121131 // Update the appropriate ports list based on the device type
122132 const updatePromise = devicePath . startsWith ( "bluetooth" )
123133 ? this . updateDeviceList ( "webbluetooth" )
124- : this . updateDeviceList ( "webserial" ) ;
134+ : this . updateDeviceList ( proto === "tauriserial" ? "tauriserial" : "webserial" ) ;
125135
126136 const wasSelectedPort = this . portPicker . selectedPort === devicePath ;
127137
@@ -274,7 +284,9 @@ PortHandler.handleDeviceAdded = function (device, deviceType) {
274284
275285 // Update the appropriate device list
276286 const updatePromise =
277- deviceType === "webbluetooth" ? this . updateDeviceList ( "webbluetooth" ) : this . updateDeviceList ( "webserial" ) ;
287+ deviceType === "webbluetooth"
288+ ? this . updateDeviceList ( "webbluetooth" )
289+ : this . updateDeviceList ( deviceType === "tauriserial" ? "tauriserial" : "webserial" ) ;
278290
279291 updatePromise . then ( ( ) => {
280292 const selectedPort = this . selectActivePort ( device ) ;
@@ -310,6 +322,11 @@ PortHandler.updateDeviceList = async function (deviceType) {
310322 ports = await serial . getDevices ( "webserial" ) ;
311323 }
312324 break ;
325+ case "tauriserial" :
326+ if ( this . showSerialOption ) {
327+ ports = await serial . getDevices ( "tauriserial" ) ;
328+ }
329+ break ;
313330 default :
314331 console . warn ( `${ this . logHead } Unknown device type: ${ deviceType } ` ) ;
315332 return [ ] ;
@@ -331,6 +348,7 @@ PortHandler.updateDeviceList = async function (deviceType) {
331348 console . log ( `${ this . logHead } Found DFU port(s)` , orderedPorts ) ;
332349 break ;
333350 case "webserial" :
351+ case "tauriserial" :
334352 this . portAvailable = orderedPorts . length > 0 ;
335353 this . currentSerialPorts = [ ...orderedPorts ] ;
336354 console . log ( `${ this . logHead } Found serial port(s)` , orderedPorts ) ;
0 commit comments