Skip to content

Commit 1178f0b

Browse files
authored
Merge pull request #329 from ericzundel/zundel/change-button-on-windows
[DNM for discussion] Conditionally change button text on USB connect. Resolves #328
2 parents 2dc91df + 7beab63 commit 1178f0b

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ <h1>Select Serial Device</h1>
308308
<h1>Select USB Host Folder</h1>
309309
<p>Select the root folder of your device. This is typically the CIRCUITPY Drive on your computer unless you renamed it. If your device does not appear as a drive on your computer, it will need to have the USB Host functionality enabled.</p>
310310
<p>
311-
<button class="purple-button hidden" id="useHostFolder">Use <span id="workingFolder"></span></button>
311+
<button class="purple-button hidden" id="useHostFolder"><span id="workingFolder"></span></button>
312312
<button class="purple-button first-item" id="selectHostFolder">Select New Folder</button>
313313
</p>
314314
</div>

js/common/utilities.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,25 @@ function isLocal() {
5656
return (isMdns() || location.hostname == "localhost" || isIp()) && (location.pathname == "/code/");
5757
}
5858

59+
// Test to see if browser is running on Microsoft Windows OS
60+
function isMicrosoftWindows() {
61+
// Newer test on Chromium
62+
if (navigator.userAgentData?.platform === "Windows") {
63+
return true;
64+
} else if (navigator.userAgent.includes("Windows")) {
65+
return true;
66+
}
67+
return false;
68+
}
69+
70+
// Test to see if browser is running on Microsoft Windows OS
71+
function isChromeOs() {
72+
if (navigator.userAgent.includes("CrOS")) {
73+
return true;
74+
}
75+
return false;
76+
}
77+
5978
// Parse out the url parameters from the current url
6079
function getUrlParams() {
6180
// This should look for and validate very specific values
@@ -146,6 +165,8 @@ export {
146165
isMdns,
147166
isIp,
148167
isLocal,
168+
isMicrosoftWindows,
169+
isChromeOs,
149170
getUrlParams,
150171
getUrlParam,
151172
timeout,

js/workflows/usb.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {GenericModal, DeviceInfoModal} from '../common/dialogs.js';
44
import {FileOps} from '@adafruit/circuitpython-repl-js'; // Use this to determine which FileTransferClient to load
55
import {FileTransferClient as ReplFileTransferClient} from '../common/repl-file-transfer.js';
66
import {FileTransferClient as FSAPIFileTransferClient} from '../common/fsapi-file-transfer.js';
7+
import { isChromeOs, isMicrosoftWindows } from '../common/utilities.js';
78

89
let btnRequestSerialDevice, btnSelectHostFolder, btnUseHostFolder, lblWorkingfolder;
910

@@ -247,7 +248,11 @@ class USBWorkflow extends Workflow {
247248
console.log("New folder name:", folderName);
248249
if (folderName) {
249250
// Set the working folder label
250-
lblWorkingfolder.innerHTML = folderName;
251+
if (isMicrosoftWindows() || isChromeOs()) {
252+
lblWorkingfolder.innerHTML = "OK";
253+
} else {
254+
lblWorkingfolder.innerHTML = `Use ${folderName}`;
255+
}
251256
btnUseHostFolder.classList.remove("hidden");
252257
btnSelectHostFolder.innerHTML = "Select Different Folder";
253258
btnSelectHostFolder.classList.add("inverted");

0 commit comments

Comments
 (0)