USB chooser thing aaa

This commit is contained in:
wuggy 2026-09-24 10:52:09 -07:00
commit 99049da066
6 changed files with 172 additions and 15 deletions

View file

@ -0,0 +1,29 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#usb-device-picker {
min-width: 360px;
min-height: 220px;
}
#picker {
padding: 16px;
}
#message {
margin: 0 0 10px;
}
#devices {
min-height: 100px;
margin: 0 0 12px;
}
#buttons {
margin-inline-start: 8px;
}
#buttons > button + button {
margin-inline-start: 8px;
}

View file

@ -0,0 +1,50 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var USBDevicePicker = {
args: null,
init() {
this.args = window.arguments[0];
document.title = this.args.title;
document.getElementById("message").value = this.args.message;
document.getElementById("select").label = this.args.selectLabel;
document.getElementById("cancel").label = this.args.cancelLabel;
let list = document.getElementById("devices");
for (let choice of this.args.choices) {
list.appendItem(choice, choice);
}
list.selectedIndex = 0;
list.focus();
},
select() {
let list = document.getElementById("devices");
this.args.prompt.select(list.selectedIndex);
},
cancel() {
this.args.prompt.cancel();
},
destroy() {
if (this.args && !this.args.prompt.completed) {
// The window manager can close this window directly. Detach it first
// so cancel() does not try to close an already-unloading window.
this.args.prompt.window = null;
this.args.prompt.cancel();
}
this.args = null;
},
};
window.addEventListener("keydown", event => {
if (event.key == "Escape") {
USBDevicePicker.cancel();
} else if (event.key == "Enter") {
USBDevicePicker.select();
}
});

View file

@ -0,0 +1,22 @@
<?xml version="1.0"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://browser/content/usbDevicePicker.css" type="text/css"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
id="usb-device-picker" windowtype="Browser:USBDevicePicker"
width="420" height="260" onload="USBDevicePicker.init();"
onunload="USBDevicePicker.destroy();">
<script type="application/javascript" src="chrome://browser/content/usbDevicePicker.js"/>
<vbox id="picker" flex="1">
<label id="message"/>
<listbox id="devices" flex="1" rows="5"
ondblclick="USBDevicePicker.select();"/>
<hbox id="buttons" pack="end">
<button id="cancel" label="Cancel" oncommand="USBDevicePicker.cancel();"/>
<button id="select" label="Select" default="true"
oncommand="USBDevicePicker.select();"/>
</hbox>
</vbox>
</window>