Skip to content

[DNM for discussion] Conditionally change button text on USB connect. Resolves #328 #329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ <h1>Select Serial Device</h1>
<h1>Select USB Host Folder</h1>
<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>
<p>
<button class="purple-button hidden" id="useHostFolder">Use <span id="workingFolder"></span></button>
<button class="purple-button hidden" id="useHostFolder"><span id="workingFolder"></span></button>
<button class="purple-button first-item" id="selectHostFolder">Select New Folder</button>
</p>
</div>
Expand Down
21 changes: 21 additions & 0 deletions js/common/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ function isLocal() {
return (isMdns() || location.hostname == "localhost" || isIp()) && (location.pathname == "/code/");
}

// Test to see if browser is running on Microsoft Windows OS
function isMicrosoftWindows() {
// Newer test on Chromium
if (navigator.userAgentData?.platform === "Windows") {
return true;
} else if (navigator.userAgent.includes("Windows")) {
return true;
}
return false;
}

// Test to see if browser is running on Microsoft Windows OS
function isChromeOs() {
if (navigator.userAgent.includes("CrOS")) {
return true;
}
return false;
}

// Parse out the url parameters from the current url
function getUrlParams() {
// This should look for and validate very specific values
Expand Down Expand Up @@ -146,6 +165,8 @@ export {
isMdns,
isIp,
isLocal,
isMicrosoftWindows,
isChromeOs,
getUrlParams,
getUrlParam,
timeout,
Expand Down
7 changes: 6 additions & 1 deletion js/workflows/usb.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {GenericModal, DeviceInfoModal} from '../common/dialogs.js';
import {FileOps} from '@adafruit/circuitpython-repl-js'; // Use this to determine which FileTransferClient to load
import {FileTransferClient as ReplFileTransferClient} from '../common/repl-file-transfer.js';
import {FileTransferClient as FSAPIFileTransferClient} from '../common/fsapi-file-transfer.js';
import { isChromeOs, isMicrosoftWindows } from '../common/utilities.js';

let btnRequestSerialDevice, btnSelectHostFolder, btnUseHostFolder, lblWorkingfolder;

Expand Down Expand Up @@ -247,7 +248,11 @@ class USBWorkflow extends Workflow {
console.log("New folder name:", folderName);
if (folderName) {
// Set the working folder label
lblWorkingfolder.innerHTML = folderName;
if (isMicrosoftWindows() || isChromeOs()) {
lblWorkingfolder.innerHTML = "OK";
} else {
lblWorkingfolder.innerHTML = `Use ${folderName}`;
}
btnUseHostFolder.classList.remove("hidden");
btnSelectHostFolder.innerHTML = "Select Different Folder";
btnSelectHostFolder.classList.add("inverted");
Expand Down