mirror of
https://github.com/nekename/OpenDeck.git
synced 2026-10-28 18:02:23 +00:00
Resolve linter warnings
This commit is contained in:
1 parent
913951a096
commit
353a5dbb33
4 files changed
+49
-67
No files matched your search
@@ -62,13 +62,10 @@ lazy_static! {
|
||||
pub fn initialise_devices() {
|
||||
// Iterate through available serial ports and attempt to register them as ProntoKey devices.
|
||||
for port in serialport::available_ports().unwrap_or_default() {
|
||||
match port.port_type {
|
||||
serialport::SerialPortType::UsbPort(info) => {
|
||||
if info.vid == 0x10c4 && info.pid == 0xea60 {
|
||||
tokio::spawn(prontokey::ProntoKeyDevice::init(port.port_name));
|
||||
}
|
||||
if let serialport::SerialPortType::UsbPort(info) = port.port_type {
|
||||
if info.vid == 0x10c4 && info.pid == 0xea60 {
|
||||
tokio::spawn(prontokey::ProntoKeyDevice::init(port.port_name));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ impl ProntoKeyDevice {
|
||||
.open()
|
||||
{
|
||||
Ok(p) => p,
|
||||
Err(e) => panic!("Failed to open serial port: {}", e.description)
|
||||
Err(error) => panic!("Failed to open serial port: {}", error)
|
||||
};
|
||||
let _ = port.write("register".as_bytes());
|
||||
|
||||
@@ -62,8 +62,8 @@ impl ProntoKeyDevice {
|
||||
Err(_) => break
|
||||
}
|
||||
// Iterate through JSON objects received from device that are being held in the buffer.
|
||||
while holding_string.contains("}") {
|
||||
let index = holding_string.find("}").unwrap_or_default();
|
||||
while holding_string.contains('}') {
|
||||
let index = holding_string.find('}').unwrap_or_default();
|
||||
let chunk = holding_string[..=index].trim();
|
||||
let j: Value = match serde_json::from_str(chunk) {
|
||||
Ok(data) => data,
|
||||
@@ -73,15 +73,11 @@ impl ProntoKeyDevice {
|
||||
|
||||
// If the device is uninitialised, attempt to read its MAC address and initialise.
|
||||
if device.is_none() {
|
||||
match &j["address"] {
|
||||
Value::String(address) => {
|
||||
device = Some(ProntoKeyDevice { address: address.clone() });
|
||||
match &device {
|
||||
Some(device) => super::DEVICES.lock().unwrap().push(super::DeviceInfo::new(device)),
|
||||
_ => {}
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
if let Value::String(address) = &j["address"] {
|
||||
device = Some(ProntoKeyDevice { address: address.clone() });
|
||||
if let Some(device) = &device {
|
||||
super::DEVICES.lock().unwrap().push(super::DeviceInfo::new(device));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -89,46 +85,37 @@ impl ProntoKeyDevice {
|
||||
let device = device.as_ref().unwrap();
|
||||
|
||||
// Handle key presses and releases.
|
||||
match &j["key"] {
|
||||
Value::Number(num) => {
|
||||
match num.as_u64().unwrap_or_default() as u8 {
|
||||
0 => device.key_up(last_key),
|
||||
val => {
|
||||
device.key_down(val);
|
||||
last_key = val;
|
||||
}
|
||||
if let Value::Number(num) = &j["key"] {
|
||||
match num.as_u64().unwrap_or_default() as u8 {
|
||||
0 => device.key_up(last_key),
|
||||
val => {
|
||||
device.key_down(val);
|
||||
last_key = val;
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle slider value changes.
|
||||
match &j["slider0"] {
|
||||
Value::Number(val) => {
|
||||
let val: i16 = match val.as_i64() {
|
||||
Some(v) => v as i16,
|
||||
_ => last_sliders[0]
|
||||
};
|
||||
device.dial_rotate(0, val - last_sliders[0]);
|
||||
last_sliders[0] = val;
|
||||
},
|
||||
_ => ()
|
||||
if let Value::Number(val) = &j["slider0"] {
|
||||
let val: i16 = match val.as_i64() {
|
||||
Some(v) => v as i16,
|
||||
_ => last_sliders[0]
|
||||
};
|
||||
device.dial_rotate(0, val - last_sliders[0]);
|
||||
last_sliders[0] = val;
|
||||
}
|
||||
match &j["slider1"] {
|
||||
Value::Number(val) => {
|
||||
let val: i16 = match val.as_i64() {
|
||||
Some(v) => v as i16,
|
||||
_ => last_sliders[1]
|
||||
};
|
||||
device.dial_rotate(1, val - last_sliders[1]);
|
||||
last_sliders[1] = val;
|
||||
},
|
||||
_ => {}
|
||||
if let Value::Number(val) = &j["slider1"] {
|
||||
let val: i16 = match val.as_i64() {
|
||||
Some(v) => v as i16,
|
||||
_ => last_sliders[1]
|
||||
};
|
||||
device.dial_rotate(1, val - last_sliders[1]);
|
||||
last_sliders[1] = val;
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(ref e) if e.kind() == std::io::ErrorKind::TimedOut => (),
|
||||
Err(e) => eprintln!("{:?}", e)
|
||||
Err(ref error) if error.kind() == std::io::ErrorKind::TimedOut => (),
|
||||
Err(error) => eprintln!("{:?}", error)
|
||||
}
|
||||
thread::sleep(Duration::from_millis(10));
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ mod devices;
|
||||
async fn main() {
|
||||
let app = match tauri::Builder::default().build(tauri::generate_context!()) {
|
||||
Ok(app) => app,
|
||||
Err(e) => panic!("Failed to create Tauri application: {}", e.to_string())
|
||||
Err(error) => panic!("Failed to create Tauri application: {}", error)
|
||||
};
|
||||
devices::initialise_devices();
|
||||
plugins::initialise_plugins(app.handle());
|
||||
|
||||
@@ -44,11 +44,11 @@ fn initialise_plugin(path: path::PathBuf, app: &AppHandle) -> anyhow::Result<()>
|
||||
for os in manifest.os {
|
||||
if os.platform == platform {
|
||||
#[cfg(target_os = "windows")]
|
||||
if let Some(_) = &manifest.code_path_windows { code_path = manifest.code_path_windows; }
|
||||
if manifest.code_path_windows.is_some() { code_path = manifest.code_path_windows; }
|
||||
#[cfg(target_os = "macos")]
|
||||
if let Some(_) = &manifest.code_path_macos { code_path = manifest.code_path_macos; }
|
||||
if manifest.code_path_macos.is_some() { code_path = manifest.code_path_macos; }
|
||||
#[cfg(target_os = "linux")]
|
||||
if let Some(_) = &manifest.code_path_linux { code_path = manifest.code_path_linux; }
|
||||
if manifest.code_path_linux.is_some() { code_path = manifest.code_path_linux; }
|
||||
|
||||
if let Some(code_path) = &code_path {
|
||||
use_browser = code_path.ends_with(".html");
|
||||
@@ -95,10 +95,10 @@ fn initialise_plugin(path: path::PathBuf, app: &AppHandle) -> anyhow::Result<()>
|
||||
|
||||
if use_browser {
|
||||
// Create a webview window for the plugin and call its registration function.
|
||||
let url = String::from("http://localhost:57118/") + &path.join(code_path).to_str().unwrap();
|
||||
let url = String::from("http://localhost:57118/") + path.join(code_path).to_str().unwrap();
|
||||
let window = tauri::WindowBuilder::new(
|
||||
app,
|
||||
plugin_uuid.replace(".", "_"),
|
||||
plugin_uuid.replace('.', "_"),
|
||||
tauri::WindowUrl::External(url.parse().unwrap())
|
||||
)
|
||||
.visible(false)
|
||||
@@ -159,21 +159,21 @@ pub fn initialise_plugins(app: AppHandle) {
|
||||
|
||||
let entries = match fs::read_dir(&plugin_dir) {
|
||||
Ok(p) => p,
|
||||
Err(e) => panic!("Failed to read plugins directory at {}: {}", plugin_dir.display(), e.to_string())
|
||||
Err(error) => panic!("Failed to read plugins directory at {}: {}", plugin_dir.display(), error)
|
||||
};
|
||||
|
||||
// Iterate through all directory entries in the plugins folder and initialise them as plugins if appropriate
|
||||
for entry in entries {
|
||||
if let Ok(entry) = entry {
|
||||
if entry.metadata().unwrap().is_dir() {
|
||||
if let Err(e) = initialise_plugin(entry.path(), &app) {
|
||||
eprintln!("{}\n\tCaused by: {}", e.to_string(), e.root_cause());
|
||||
if let Err(error) = initialise_plugin(entry.path(), &app) {
|
||||
eprintln!("{}\n\tCaused by: {}", error, error.root_cause());
|
||||
}
|
||||
} else {
|
||||
eprintln!("Failed to initialise plugin at {}: is a file", entry.path().display());
|
||||
}
|
||||
} else if let Err(e) = entry {
|
||||
eprintln!("Failed to read plugin directory: {}", e.to_string())
|
||||
} else if let Err(error) = entry {
|
||||
eprintln!("Failed to read plugin directory: {}", error)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -183,7 +183,7 @@ async fn init_websocket_server() {
|
||||
let listener = match TcpListener::bind("localhost:57116").await {
|
||||
Ok(listener) => listener,
|
||||
Err(error) => {
|
||||
eprintln!("Failed to bind to socket: {}", error.to_string());
|
||||
eprintln!("Failed to bind to socket: {}", error);
|
||||
return;
|
||||
}
|
||||
};
|
||||
@@ -198,15 +198,13 @@ async fn accept_connection(stream: TcpStream) {
|
||||
let mut socket = match tokio_tungstenite::accept_async(stream).await {
|
||||
Ok(socket) => socket,
|
||||
Err(error) => {
|
||||
eprintln!("Failed to complete WebSocket handshake: {}", error.to_string());
|
||||
eprintln!("Failed to complete WebSocket handshake: {}", error);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
while let Some(data) = socket.next().await {
|
||||
crate::events::register_plugin(serde_json::from_str(&data.unwrap().into_text().unwrap()).unwrap(), socket).await;
|
||||
break;
|
||||
}
|
||||
let register_event = socket.next().await.unwrap().unwrap();
|
||||
crate::events::register_plugin(serde_json::from_str(®ister_event.into_text().unwrap()).unwrap(), socket).await;
|
||||
}
|
||||
|
||||
/// Start a simple webserver to serve files of plugins that run in a browser environment.
|
||||
|
||||
Reference in new issue
Block a user