esp32tool 1.6.0 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/electron/main.cjs CHANGED
@@ -21,10 +21,10 @@ const grantedDevices = new Map();
21
21
 
22
22
  function createWindow() {
23
23
  mainWindow = new BrowserWindow({
24
- width: 1200,
25
- height: 800,
26
- minWidth: 800,
27
- minHeight: 600,
24
+ width: 1400,
25
+ height: 900,
26
+ minWidth: 1024,
27
+ minHeight: 700,
28
28
  webPreferences: {
29
29
  nodeIntegration: false,
30
30
  contextIsolation: true,
@@ -52,102 +52,97 @@ function createWindow() {
52
52
  }
53
53
 
54
54
  function setupSerialPortHandlers(ses) {
55
- let lastSelectedPort = null;
56
- let esp32s2ReconnectPending = false;
57
- let portSelectionQueue = [];
58
-
55
+ const isLikelyEspPort = (port) => {
56
+ const name = `${port?.displayName || ''} ${port?.portName || ''}`.toLowerCase();
57
+ return (
58
+ name.includes('cp2102') ||
59
+ name.includes('cp2103') ||
60
+ name.includes('cp2104') ||
61
+ name.includes('cp2105') ||
62
+ name.includes('cp2108') ||
63
+ name.includes('ch9102') ||
64
+ name.includes('ch9104') ||
65
+ name.includes('ch340') ||
66
+ name.includes('ch341') ||
67
+ name.includes('ch343') ||
68
+ name.includes('ftdi') ||
69
+ name.includes('ft232') ||
70
+ name.includes('usb') ||
71
+ name.includes('uart') ||
72
+ name.includes('silicon labs') ||
73
+ name.includes('esp32') ||
74
+ name.includes('esp8266') ||
75
+ name.includes('esp')
76
+ );
77
+ };
78
+
79
+ const getPortLabel = (port) => port?.displayName || port?.portName || port?.portId || 'Unknown port';
80
+
81
+ const getPortButtonLabel = (port, isRecommended = false) => {
82
+ const shortId = port?.portName || port?.displayName || port?.portId || 'Unknown';
83
+ return isRecommended ? `${shortId} (Recommended)` : shortId;
84
+ };
85
+
86
+ const toHexId = (value) =>
87
+ typeof value === 'number' ? `0x${value.toString(16).toUpperCase().padStart(4, '0')}` : null;
88
+
89
+ // Guard against Electron re-firing select-serial-port while a dialog is open
90
+ let activeSelectionId = 0;
91
+
59
92
  // Handle serial port selection - shows when navigator.serial.requestPort() is called
60
93
  ses.on('select-serial-port', (event, portList, webContents, callback) => {
61
94
  event.preventDefault();
62
95
 
63
- console.log('Available serial ports:', portList.map(p => ({
64
- portId: p.portId,
65
- portName: p.portName,
66
- displayName: p.displayName
67
- })));
68
-
69
- if (portList && portList.length > 0) {
70
- // Try to find ESP-compatible port
71
- const espPort = portList.find(port => {
72
- const name = (port.displayName || port.portName || '').toLowerCase();
73
- return name.includes('cp2102') ||
74
- name.includes('cp2103') ||
75
- name.includes('cp2104') ||
76
- name.includes('cp2105') ||
77
- name.includes('cp2108') ||
78
- name.includes('ch9102') ||
79
- name.includes('ch9104') ||
80
- name.includes('ch340') ||
81
- name.includes('ch341') ||
82
- name.includes('ch343') ||
83
- name.includes('ftdi') ||
84
- name.includes('usb') ||
85
- name.includes('uart') ||
86
- name.includes('silicon labs') ||
87
- name.includes('esp');
88
- });
89
-
90
- // Select ESP-compatible port or first available
91
- const selectedPort = espPort || portList[0];
92
- console.log('Selected port:', selectedPort.portId, selectedPort.displayName || selectedPort.portName);
93
- lastSelectedPort = selectedPort;
94
-
95
- callback(selectedPort.portId);
96
- } else {
97
- console.log('No serial ports available - queuing selection');
98
- // No ports available yet - queue this callback for when a port appears
99
- portSelectionQueue.push(callback);
96
+ // Filter to only show ESP-compatible ports
97
+ const espPorts = (portList || []).filter(isLikelyEspPort);
98
+
99
+ if (espPorts.length === 0) {
100
+ callback('');
101
+ return;
102
+ }
103
+
104
+ // Single matching port - auto-select
105
+ if (espPorts.length === 1) {
106
+ callback(espPorts[0].portId);
107
+ return;
100
108
  }
109
+
110
+ // Track this selection so stale dialog results are ignored
111
+ const mySelectionId = ++activeSelectionId;
112
+
113
+ const buttonLabels = espPorts.map((port) => getPortButtonLabel(port));
114
+ const cancelIndex = buttonLabels.length;
115
+
116
+ const ownerWindow = BrowserWindow.fromWebContents(webContents) || mainWindow;
117
+ dialog.showMessageBox(ownerWindow, {
118
+ type: 'question',
119
+ title: 'ESP32Tool',
120
+ message: 'Select the serial port for your ESP device.',
121
+ buttons: [...buttonLabels, 'Cancel'],
122
+ defaultId: 0,
123
+ cancelId: cancelIndex,
124
+ noLink: true,
125
+ }).then((result) => {
126
+ // Ignore if a newer select-serial-port event superseded this one
127
+ if (mySelectionId !== activeSelectionId) return;
128
+ const selectedPort = espPorts[result.response];
129
+ callback(selectedPort ? selectedPort.portId : '');
130
+ });
101
131
  });
102
132
 
103
- // Track port additions - handle ESP32-S2 reconnect
104
133
  ses.on('serial-port-added', (event, port) => {
105
134
  console.log('Serial port added:', port);
106
-
107
- // If we have queued port selections, handle them now
108
- if (portSelectionQueue.length > 0) {
109
- console.log('Processing queued port selection');
110
- const callback = portSelectionQueue.shift();
111
- callback(port.portId);
112
- lastSelectedPort = port;
113
- }
114
-
115
- // Check if this looks like an ESP32-S2 CDC port appearing after ROM port disappeared
116
- if (lastSelectedPort && port.portName !== lastSelectedPort.portName) {
117
- const name = (port.displayName || port.portName || '').toLowerCase();
118
- if (name.includes('esp') || name.includes('usb') || name.includes('uart')) {
119
- console.log('ESP32-S2 reconnect detected - new CDC port available');
120
- esp32s2ReconnectPending = true;
121
- }
122
- }
123
135
  });
124
136
 
125
- // Track port removals - detect ESP32-S2 disconnect
126
137
  ses.on('serial-port-removed', (event, port) => {
127
138
  console.log('Serial port removed:', port);
128
-
129
- // If the last selected port was removed, prepare for reconnect
130
- if (lastSelectedPort && port.portId === lastSelectedPort.portId) {
131
- console.log('Last selected port removed - may be ESP32-S2 mode switch');
132
- // Don't clear lastSelectedPort yet, we might need it for comparison
133
- }
134
139
  });
135
140
 
136
- // Grant permission for serial port access checks
137
- ses.setPermissionCheckHandler((webContents, permission, requestingOrigin, details) => {
138
- if (permission === 'serial') {
139
- return true;
140
- }
141
- return true;
142
- });
141
+ ses.setPermissionCheckHandler(() => true);
143
142
 
144
- // Handle device permission requests
145
143
  ses.setDevicePermissionHandler((details) => {
146
- if (details.deviceType === 'serial') {
147
- if (details.device) {
148
- grantedDevices.set(details.device.deviceId, details.device);
149
- }
150
- return true;
144
+ if (details.deviceType === 'serial' && details.device) {
145
+ grantedDevices.set(details.device.deviceId, details.device);
151
146
  }
152
147
  return true;
153
148
  });
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/icons/icon-72.png CHANGED
Binary file
package/icons/icon-96.png CHANGED
Binary file