mirror of
https://github.com/4yn/slidershim.git
synced 2024-11-12 00:40:49 +01:00
add option to change brokenithm port number
This commit is contained in:
parent
1fe10cf615
commit
3ce8f47905
@ -39,22 +39,19 @@
|
||||
<ul class="links"></ul>
|
||||
<script>
|
||||
(function () {
|
||||
const search = window.location.search;
|
||||
if (search.slice(0, 3) !== "?d=" || search.length <= 3) {
|
||||
return;
|
||||
}
|
||||
const ul = document.querySelector(".links");
|
||||
search
|
||||
.slice(3)
|
||||
.split(";")
|
||||
.map((x) => atob(x))
|
||||
.forEach((ip) => {
|
||||
const li = document.createElement("li");
|
||||
const a = document.createElement("a");
|
||||
a.innerText = ip;
|
||||
var params = new URLSearchParams(window.location.search);
|
||||
var d = params.get("d") || "";
|
||||
var p = params.get("p") || "1606";
|
||||
var ul = document.querySelector(".links");
|
||||
d.split(";").forEach(function (aip) {
|
||||
var ip = atob(aip);
|
||||
console.log(aip, ip);
|
||||
var li = document.createElement("li");
|
||||
var a = document.createElement("a");
|
||||
a.innerText = "".concat(ip, ":").concat(p);
|
||||
a.setAttribute("target", "_blank");
|
||||
a.setAttribute("rel", "noopener");
|
||||
a.href = `http://${ip}:1606/`;
|
||||
a.href = "http://".concat(ip, ":").concat(p, "/");
|
||||
li.appendChild(a);
|
||||
ul.appendChild(li);
|
||||
});
|
||||
|
@ -18,7 +18,7 @@ async fn main() {
|
||||
|
||||
let _worker = AsyncHaltableWorker::new(
|
||||
"brokenithm",
|
||||
BrokenithmJob::new(&state, &BrokenithmSpec::Nostalgia, &false),
|
||||
BrokenithmJob::new(&state, &BrokenithmSpec::Nostalgia, &false, &1606),
|
||||
);
|
||||
let mut input = String::new();
|
||||
io::stdin().read_line(&mut input).unwrap();
|
||||
|
@ -35,6 +35,7 @@ impl Config {
|
||||
"disableAirStrings": false,
|
||||
"divaSerialPort": "COM1",
|
||||
"divaBrightness": 63,
|
||||
"brokenithmPort": 1606,
|
||||
"keyboardSensitivity": 20,
|
||||
"outputPolling": "100",
|
||||
"outputWebsocketUrl": "localhost:3000",
|
||||
|
@ -42,12 +42,13 @@ impl Context {
|
||||
DeviceMode::Brokenithm {
|
||||
spec,
|
||||
lights_enabled,
|
||||
port,
|
||||
} => (
|
||||
None,
|
||||
None,
|
||||
Some(AsyncHaltableWorker::new(
|
||||
"brokenithm",
|
||||
BrokenithmJob::new(&state, spec, lights_enabled),
|
||||
BrokenithmJob::new(&state, spec, lights_enabled, port),
|
||||
)),
|
||||
),
|
||||
DeviceMode::Hardware { spec, disable_air } => (
|
||||
|
@ -268,14 +268,21 @@ pub struct BrokenithmJob {
|
||||
state: SliderState,
|
||||
spec: BrokenithmSpec,
|
||||
lights_enabled: bool,
|
||||
port: u16,
|
||||
}
|
||||
|
||||
impl BrokenithmJob {
|
||||
pub fn new(state: &SliderState, spec: &BrokenithmSpec, lights_enabled: &bool) -> Self {
|
||||
pub fn new(
|
||||
state: &SliderState,
|
||||
spec: &BrokenithmSpec,
|
||||
lights_enabled: &bool,
|
||||
port: &u16,
|
||||
) -> Self {
|
||||
Self {
|
||||
state: state.clone(),
|
||||
spec: spec.clone(),
|
||||
lights_enabled: *lights_enabled,
|
||||
port: *port,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -299,7 +306,7 @@ impl AsyncHaltableJob for BrokenithmJob {
|
||||
}
|
||||
});
|
||||
|
||||
let addr = SocketAddr::from(([0, 0, 0, 0], 1606));
|
||||
let addr = SocketAddr::from(([0, 0, 0, 0], self.port));
|
||||
info!("Brokenithm server listening on {}", addr);
|
||||
|
||||
let server = Server::bind(&addr)
|
||||
|
@ -25,6 +25,7 @@ pub enum DeviceMode {
|
||||
Brokenithm {
|
||||
spec: BrokenithmSpec,
|
||||
lights_enabled: bool,
|
||||
port: u16,
|
||||
},
|
||||
DivaSlider {
|
||||
port: String,
|
||||
@ -62,6 +63,9 @@ impl DeviceMode {
|
||||
true => BrokenithmSpec::GroundOnly,
|
||||
},
|
||||
lights_enabled: false,
|
||||
port: u16::try_from(v["brokenithmPort"].as_i64()?)
|
||||
.ok()
|
||||
.or(Some(1606))?,
|
||||
},
|
||||
"brokenithm-led" => DeviceMode::Brokenithm {
|
||||
spec: match v["disableAirStrings"].as_bool()? {
|
||||
@ -69,12 +73,25 @@ impl DeviceMode {
|
||||
true => BrokenithmSpec::GroundOnly,
|
||||
},
|
||||
lights_enabled: true,
|
||||
port: u16::try_from(v["brokenithmPort"].as_i64()?)
|
||||
.ok()
|
||||
.or(Some(1606))?,
|
||||
},
|
||||
"brokenithm-nostalgia" => DeviceMode::Brokenithm {
|
||||
spec: BrokenithmSpec::Nostalgia,
|
||||
lights_enabled: false,
|
||||
port: u16::try_from(v["brokenithmPort"].as_i64()?)
|
||||
.ok()
|
||||
.or(Some(1606))?,
|
||||
},
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_port(&self) -> Option<u16> {
|
||||
match self {
|
||||
DeviceMode::Brokenithm { port, .. } => Some(*port),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
use directories::ProjectDirs;
|
||||
use image::Luma;
|
||||
use log::info;
|
||||
use qrcode::QrCode;
|
||||
use std::{error::Error, fs, path::PathBuf};
|
||||
|
||||
@ -25,7 +26,7 @@ fn get_config_dir() -> Option<Box<PathBuf>> {
|
||||
}
|
||||
|
||||
/// Generates a helper QR for connecting with brokenithm
|
||||
pub fn get_brokenithm_qr_path() -> Option<Box<PathBuf>> {
|
||||
pub fn get_brokenithm_qr_path(port: Option<u16>) -> Option<Box<PathBuf>> {
|
||||
let config_dir = get_config_dir()?;
|
||||
let brokenithm_qr_path = config_dir.join("brokenithm.png");
|
||||
|
||||
@ -36,7 +37,10 @@ pub fn get_brokenithm_qr_path() -> Option<Box<PathBuf>> {
|
||||
.filter(|s| s.as_str().chars().filter(|x| *x == '.').count() == 3)
|
||||
.map(|s| base64::encode_config(s, base64::URL_SAFE_NO_PAD))
|
||||
.collect::<Vec<String>>()
|
||||
.join(";");
|
||||
.join(";")
|
||||
+ "&p="
|
||||
+ port.or(Some(1606)).unwrap().to_string().as_str();
|
||||
info!("Url generated {}", link);
|
||||
let qr = QrCode::new(link).ok()?;
|
||||
let image = qr.render::<Luma<u8>>().build();
|
||||
image.save(brokenithm_qr_path.as_path()).ok()?;
|
||||
|
@ -110,8 +110,15 @@ fn main() {
|
||||
});
|
||||
|
||||
// Show brokenithm qr
|
||||
app.listen_global("openBrokenithmQr", |_| {
|
||||
let brokenithm_qr_path = slider_io::get_brokenithm_qr_path();
|
||||
let config_clone = Arc::clone(&config);
|
||||
app.listen_global("openBrokenithmQr", move |_| {
|
||||
let config_handle = config_clone.lock();
|
||||
let brokenithm_qr_path = slider_io::get_brokenithm_qr_path(
|
||||
config_handle
|
||||
.as_ref()
|
||||
.map(|c| c.device_mode.get_port())
|
||||
.unwrap_or(None),
|
||||
);
|
||||
if let Some(brokenithm_qr_path) = brokenithm_qr_path {
|
||||
open::that(brokenithm_qr_path.as_path()).ok();
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
let disableAirStrings = false;
|
||||
let divaSerialPort = "COM1";
|
||||
let divaBrightness = 63;
|
||||
let brokenithmPort = 1606;
|
||||
let keyboardSensitivity = 20;
|
||||
let outputPolling = "100";
|
||||
let outputWebsocketUrl = "http://localhost:3000";
|
||||
@ -65,6 +66,7 @@
|
||||
disableAirStrings = payload.disableAirStrings || false;
|
||||
divaSerialPort = payload.divaSerialPort || "COM1";
|
||||
divaBrightness = payload.divaBrightness || 63;
|
||||
brokenithmPort = payload.brokenithmPort || 1606;
|
||||
keyboardSensitivity = payload.keyboardSensitivity || 20;
|
||||
outputPolling = payload.outputPolling || "100";
|
||||
outputWebsocketUrl =
|
||||
@ -119,6 +121,7 @@
|
||||
disableAirStrings,
|
||||
divaSerialPort,
|
||||
divaBrightness,
|
||||
brokenithmPort,
|
||||
keyboardSensitivity,
|
||||
outputPolling,
|
||||
outputWebsocketUrl,
|
||||
@ -207,14 +210,27 @@
|
||||
</div>
|
||||
{/if}
|
||||
{#if deviceMode.slice(0, 10) === "brokenithm"}
|
||||
<div class="row">
|
||||
<div class="label">Brokenithm Port</div>
|
||||
<div class="input">
|
||||
<input
|
||||
type="number"
|
||||
min="1024"
|
||||
max="65535"
|
||||
step="1"
|
||||
bind:value={brokenithmPort}
|
||||
on:change={markDirty}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="label" />
|
||||
<div class="input">
|
||||
<div class="serverlist">
|
||||
Brokenithm server running, access at one of:
|
||||
Brokenithm will be running at one of:
|
||||
<div class="iplist">
|
||||
{ips
|
||||
.map((x) => `http://${x}:1606/`)
|
||||
.map((x) => `http://${x}:${brokenithmPort || 1606}/`)
|
||||
.join("\n")
|
||||
.trim()}
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user