mirror of
https://github.com/4yn/slidershim.git
synced 2024-11-24 05:50:12 +01:00
fix warnings
This commit is contained in:
parent
263d21c0a6
commit
bfb7f7dc95
@ -7,3 +7,9 @@
|
||||
- ouptut websocket
|
||||
- led websocket
|
||||
- comments
|
||||
|
||||
```
|
||||
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
|
||||
$env:RUST_BACKTRACE = "1";
|
||||
yarn tauri dev
|
||||
```
|
||||
|
@ -13,7 +13,8 @@ use env_logger;
|
||||
use log::info;
|
||||
|
||||
use tauri::{
|
||||
AppHandle, CustomMenuItem, Event, Manager, Runtime, SystemTray, SystemTrayEvent, SystemTrayMenu,
|
||||
async_runtime::Handle as AsyncHandle, AppHandle, CustomMenuItem, Event, Manager, Runtime,
|
||||
SystemTray, SystemTrayEvent, SystemTrayMenu,
|
||||
};
|
||||
|
||||
fn show_window<R: Runtime>(handle: &AppHandle<R>) {
|
||||
@ -29,6 +30,7 @@ fn quit_app() {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Setup logger
|
||||
env_logger::Builder::new()
|
||||
.filter_level(log::LevelFilter::Debug)
|
||||
.init();
|
||||
@ -39,13 +41,14 @@ fn main() {
|
||||
let config_handle = config.lock().unwrap();
|
||||
let config_handle_ref = config_handle.as_ref().unwrap();
|
||||
config_handle_ref.save();
|
||||
let mut manager_handle = manager.lock().unwrap();
|
||||
manager_handle.take();
|
||||
manager_handle.replace(slider_io::Manager::new(config_handle_ref.clone()));
|
||||
// let mut manager_handle = manager.lock().unwrap();
|
||||
// manager_handle.take();
|
||||
// manager_handle.replace(slider_io::Manager::new(config_handle_ref.clone()));
|
||||
}
|
||||
|
||||
tauri::Builder::default()
|
||||
.system_tray(
|
||||
// System tray content
|
||||
SystemTray::new().with_menu(
|
||||
SystemTrayMenu::new()
|
||||
.add_item(CustomMenuItem::new("slidershim".to_string(), "slidershim").disabled())
|
||||
@ -54,6 +57,7 @@ fn main() {
|
||||
),
|
||||
)
|
||||
.on_system_tray_event(|app_handle, event| match event {
|
||||
// System tray events
|
||||
SystemTrayEvent::LeftClick {
|
||||
position: _,
|
||||
size: _,
|
||||
@ -75,9 +79,26 @@ fn main() {
|
||||
_ => {}
|
||||
})
|
||||
.setup(move |app| {
|
||||
// Before app starts
|
||||
|
||||
// Hide event
|
||||
let app_handle = app.handle();
|
||||
app.listen_global("hide", move |_| {
|
||||
hide_window(&app_handle);
|
||||
});
|
||||
|
||||
// Quit event
|
||||
app.listen_global("quit", |_| {
|
||||
quit_app();
|
||||
});
|
||||
|
||||
// UI ready event
|
||||
let app_handle = app.handle();
|
||||
let config_clone = Arc::clone(&config);
|
||||
app.listen_global("heartbeat", move |_| {
|
||||
let handle = AsyncHandle::try_current();
|
||||
println!("handle, {:?}", handle);
|
||||
|
||||
let config_handle = config_clone.lock().unwrap();
|
||||
info!("Heartbeat received");
|
||||
app_handle
|
||||
@ -88,6 +109,7 @@ fn main() {
|
||||
.unwrap();
|
||||
});
|
||||
|
||||
// Config set event
|
||||
let config_clone = Arc::clone(&config);
|
||||
let manager_clone = Arc::clone(&manager);
|
||||
app.listen_global("setConfig", move |event| {
|
||||
@ -105,20 +127,12 @@ fn main() {
|
||||
}
|
||||
});
|
||||
|
||||
let app_handle = app.handle();
|
||||
app.listen_global("hide", move |_| {
|
||||
hide_window(&app_handle);
|
||||
});
|
||||
|
||||
app.listen_global("quit", |_| {
|
||||
quit_app();
|
||||
});
|
||||
|
||||
Ok(())
|
||||
})
|
||||
.build(tauri::generate_context!())
|
||||
.expect("error while running tauri application")
|
||||
.run(|app_handle, event| match event {
|
||||
// After app starts
|
||||
Event::CloseRequested { label, api, .. } if label.as_str() == "main" => {
|
||||
api.prevent_close();
|
||||
hide_window(app_handle);
|
||||
|
@ -10,10 +10,10 @@ use hyper::{
|
||||
use log::{error, info};
|
||||
use path_clean::PathClean;
|
||||
use std::{convert::Infallible, future::Future, net::SocketAddr, path::PathBuf};
|
||||
use tokio::{fs::File, select};
|
||||
use tokio::fs::File;
|
||||
use tokio_tungstenite::WebSocketStream;
|
||||
use tokio_util::codec::{BytesCodec, FramedRead};
|
||||
use tungstenite::{handshake, Error, Message};
|
||||
use tungstenite::{handshake, Message};
|
||||
|
||||
use crate::slider_io::{controller_state::FullState, worker::AsyncJob};
|
||||
|
||||
@ -58,7 +58,10 @@ async fn handle_brokenithm(ws_stream: WebSocketStream<Upgraded>, state: FullStat
|
||||
let head = chars.next().unwrap();
|
||||
match head {
|
||||
'a' => {
|
||||
ws_write.send(Message::Text("alive".to_string())).await;
|
||||
ws_write
|
||||
.send(Message::Text("alive".to_string()))
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
'b' => {
|
||||
let flat_state: Vec<bool> = chars
|
||||
@ -155,10 +158,13 @@ async fn handle_request(
|
||||
let method = request.method();
|
||||
let path = request.uri().path();
|
||||
if method != Method::GET {
|
||||
error!("Server unknown method {} {}", method, path);
|
||||
error!(
|
||||
"Server unknown method {} -> {} {}",
|
||||
remote_addr, method, path
|
||||
);
|
||||
return error_response().await;
|
||||
}
|
||||
info!("Server {} {}", method, path);
|
||||
info!("Server {} -> {} {}", remote_addr, method, path);
|
||||
|
||||
match (
|
||||
request.uri().path(),
|
||||
|
@ -1,9 +1,7 @@
|
||||
use std::{convert::TryFrom, fs, path::PathBuf};
|
||||
|
||||
use log::info;
|
||||
|
||||
use directories::ProjectDirs;
|
||||
use log::info;
|
||||
use serde_json::Value;
|
||||
use std::{convert::TryFrom, fs, path::PathBuf};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum DeviceMode {
|
||||
@ -158,7 +156,7 @@ impl Config {
|
||||
fn get_saved_path() -> Option<Box<PathBuf>> {
|
||||
let project_dir = ProjectDirs::from("me", "imp.ress", "slidershim").unwrap();
|
||||
let config_dir = project_dir.config_dir();
|
||||
fs::create_dir_all(config_dir);
|
||||
fs::create_dir_all(config_dir).unwrap();
|
||||
|
||||
let config_path = config_dir.join("config.json");
|
||||
|
||||
@ -171,7 +169,7 @@ impl Config {
|
||||
return None;
|
||||
}
|
||||
info!("Config file found at {:?}", config_path);
|
||||
let mut saved_data = fs::read_to_string(config_path.as_path()).ok()?;
|
||||
let saved_data = fs::read_to_string(config_path.as_path()).ok()?;
|
||||
return Self::from_str(saved_data.as_str());
|
||||
}
|
||||
|
||||
|
@ -79,8 +79,8 @@ impl FullState {
|
||||
impl Clone for FullState {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
controller_state: Arc::clone(&self.controller_state),
|
||||
led_state: Arc::clone(&self.led_state),
|
||||
controller_state: self.clone_controller(),
|
||||
led_state: self.clone_led(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,11 @@
|
||||
use log::{error, info};
|
||||
use rusb::{self, DeviceHandle, GlobalContext};
|
||||
use std::{
|
||||
error::Error,
|
||||
ops::{Deref, DerefMut},
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use log::{error, info};
|
||||
|
||||
use rusb::{self, DeviceHandle, GlobalContext};
|
||||
|
||||
use crate::slider_io::{
|
||||
config::DeviceMode,
|
||||
controller_state::{ControllerState, FullState, LedState},
|
||||
@ -215,12 +212,12 @@ const TIMEOUT: Duration = Duration::from_millis(20);
|
||||
impl ThreadJob for HidDeviceJob {
|
||||
fn setup(&mut self) -> bool {
|
||||
match self.setup_impl() {
|
||||
Ok(r) => {
|
||||
Ok(_) => {
|
||||
info!("Device OK");
|
||||
true
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Device setup failed, exiting thread early");
|
||||
error!("Device setup failed: {}", e);
|
||||
false
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use vigem_client::{Client, TargetId, XButtons, XGamepad, Xbox360Wired};
|
||||
|
||||
use crate::slider_io::{output::OutputHandler, voltex::VoltexState};
|
||||
|
@ -1,5 +1,4 @@
|
||||
use std::mem;
|
||||
|
||||
use winapi::{
|
||||
ctypes::c_int,
|
||||
um::winuser::{SendInput, INPUT, INPUT_KEYBOARD, KEYBDINPUT, KEYEVENTF_KEYUP},
|
||||
@ -64,8 +63,7 @@ const VOLTEX_KB_MAP: [usize; 41] = [
|
||||
pub struct KeyboardOutput {
|
||||
ground_to_idx: [usize; 41],
|
||||
idx_to_keycode: [u16; 41],
|
||||
keycode_to_idx: [usize; 256],
|
||||
|
||||
// keycode_to_idx: [usize; 256],
|
||||
next_keys: [bool; 41],
|
||||
last_keys: [bool; 41],
|
||||
|
||||
@ -114,7 +112,7 @@ impl KeyboardOutput {
|
||||
Self {
|
||||
ground_to_idx,
|
||||
idx_to_keycode,
|
||||
keycode_to_idx,
|
||||
// keycode_to_idx,
|
||||
next_keys: [false; 41],
|
||||
last_keys: [false; 41],
|
||||
kb_buf,
|
||||
@ -131,20 +129,20 @@ impl KeyboardOutput {
|
||||
.zip(self.last_keys.iter_mut())
|
||||
.enumerate()
|
||||
{
|
||||
let wVk = self.idx_to_keycode[i];
|
||||
if wVk == 0 {
|
||||
let keycode = self.idx_to_keycode[i];
|
||||
if keycode == 0 {
|
||||
continue;
|
||||
}
|
||||
match (*n, *l) {
|
||||
(false, true) => {
|
||||
let inner: &mut KEYBDINPUT = unsafe { self.kb_buf[self.n_kb_buf as usize].u.ki_mut() };
|
||||
inner.wVk = self.idx_to_keycode[i];
|
||||
inner.wVk = keycode;
|
||||
inner.dwFlags = 0;
|
||||
self.n_kb_buf += 1;
|
||||
}
|
||||
(true, false) => {
|
||||
let inner: &mut KEYBDINPUT = unsafe { self.kb_buf[self.n_kb_buf as usize].u.ki_mut() };
|
||||
inner.wVk = self.idx_to_keycode[i];
|
||||
inner.wVk = keycode;
|
||||
inner.dwFlags = KEYEVENTF_KEYUP;
|
||||
self.n_kb_buf += 1;
|
||||
}
|
||||
|
@ -1,14 +1,12 @@
|
||||
use log::{error, info};
|
||||
use palette::{FromColor, Hsv, Srgb};
|
||||
use serialport::{ClearBuffer, SerialPort};
|
||||
use std::{
|
||||
ops::DerefMut,
|
||||
thread,
|
||||
time::{Duration, Instant},
|
||||
};
|
||||
|
||||
use log::{error, info};
|
||||
|
||||
use palette::{FromColor, Hsv, Srgb};
|
||||
use serialport::{ClearBuffer, SerialPort, StopBits};
|
||||
|
||||
use crate::slider_io::{
|
||||
config::{LedMode, ReactiveLayout},
|
||||
controller_state::{FullState, LedState},
|
||||
@ -165,7 +163,7 @@ impl ThreadJob for LedJob {
|
||||
Some(s)
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Serial port could not open, exiting thread early");
|
||||
error!("Serial port could not open: {}", e);
|
||||
None
|
||||
}
|
||||
};
|
||||
@ -205,7 +203,7 @@ impl ThreadJob for LedJob {
|
||||
}
|
||||
|
||||
if serial_data_avail > 0 {
|
||||
serial_port.clear(ClearBuffer::All);
|
||||
serial_port.clear(ClearBuffer::All).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ use crate::slider_io::{
|
||||
worker::{AsyncWorker, ThreadWorker},
|
||||
};
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct Manager {
|
||||
state: FullState,
|
||||
config: Config,
|
||||
|
@ -8,7 +8,7 @@ use crate::slider_io::{
|
||||
worker::ThreadJob,
|
||||
};
|
||||
|
||||
pub trait OutputHandler: Send + Drop {
|
||||
pub trait OutputHandler: Send {
|
||||
fn tick(&mut self, flat_controller_state: &Vec<bool>);
|
||||
fn reset(&mut self);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ pub struct Buffer {
|
||||
pub len: usize,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl Buffer {
|
||||
pub fn new() -> Self {
|
||||
Buffer {
|
||||
|
@ -2,7 +2,6 @@ use async_trait::async_trait;
|
||||
use log::info;
|
||||
use std::{
|
||||
future::Future,
|
||||
pin::Pin,
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc,
|
||||
@ -10,11 +9,7 @@ use std::{
|
||||
thread,
|
||||
};
|
||||
|
||||
use tokio::{
|
||||
runtime::Runtime,
|
||||
sync::oneshot::{self, Receiver},
|
||||
task,
|
||||
};
|
||||
use tokio::{runtime::Runtime, sync::oneshot, task};
|
||||
|
||||
pub trait ThreadJob: Send {
|
||||
fn setup(&mut self) -> bool;
|
||||
@ -95,7 +90,7 @@ impl AsyncWorker {
|
||||
let task = runtime.spawn(async move {
|
||||
job
|
||||
.run(async move {
|
||||
recv_stop.await;
|
||||
recv_stop.await.unwrap();
|
||||
})
|
||||
.await;
|
||||
});
|
||||
@ -121,8 +116,6 @@ impl Drop for AsyncWorker {
|
||||
// });
|
||||
}
|
||||
|
||||
let name = self.name;
|
||||
|
||||
if self.task.is_some() {
|
||||
// let task = self.task.take().unwrap();
|
||||
// self.runtime.block_on(async move {
|
||||
|
Loading…
Reference in New Issue
Block a user