brokenithm urls and logging
This commit is contained in:
+19
-10
@@ -9,21 +9,20 @@ mod slider_io;
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use env_logger;
|
||||
// use env_logger;
|
||||
use log::info;
|
||||
|
||||
use tauri::{
|
||||
async_runtime::Handle as AsyncHandle, AppHandle, CustomMenuItem, Event, Manager, Runtime,
|
||||
SystemTray, SystemTrayEvent, SystemTrayMenu,
|
||||
AppHandle, CustomMenuItem, Event, Manager, Runtime, SystemTray, SystemTrayEvent, SystemTrayMenu,
|
||||
};
|
||||
|
||||
fn show_window<R: Runtime>(handle: &AppHandle<R>) {
|
||||
handle.emit_all("ackShow", "");
|
||||
handle.emit_all("ackShow", "").ok();
|
||||
handle.get_window("main").unwrap().show().ok();
|
||||
}
|
||||
|
||||
fn hide_window<R: Runtime>(handle: &AppHandle<R>) {
|
||||
handle.emit_all("ackHide", "");
|
||||
handle.emit_all("ackHide", "").ok();
|
||||
handle.get_window("main").unwrap().hide().ok();
|
||||
}
|
||||
|
||||
@@ -33,9 +32,14 @@ fn quit_app() {
|
||||
|
||||
fn main() {
|
||||
// Setup logger
|
||||
env_logger::Builder::new()
|
||||
.filter_level(log::LevelFilter::Debug)
|
||||
.init();
|
||||
// env_logger::Builder::new()
|
||||
// .filter_level(log::LevelFilter::Debug)
|
||||
// .init();
|
||||
simple_logging::log_to_file(
|
||||
slider_io::Config::get_log_file_path().unwrap().as_path(),
|
||||
log::LevelFilter::Debug,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let config = Arc::new(Mutex::new(Some(slider_io::Config::default())));
|
||||
let manager = Arc::new(Mutex::new(slider_io::Manager::new()));
|
||||
@@ -105,12 +109,17 @@ fn main() {
|
||||
Some(config_handle.as_ref().unwrap().raw.as_str().to_string()),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let ips = slider_io::list_ips();
|
||||
if let Ok(ips) = ips {
|
||||
app_handle.emit_all("listIps", &ips).unwrap();
|
||||
}
|
||||
});
|
||||
|
||||
// UI update event
|
||||
let app_handle = app.handle();
|
||||
let manager_clone = Arc::clone(&manager);
|
||||
app.listen_global("queryState", move |event| {
|
||||
app.listen_global("queryState", move |_| {
|
||||
// app_handle.emit_all("showState", "@@@");
|
||||
let snapshot = {
|
||||
let manager_handle = manager_clone.lock().unwrap();
|
||||
@@ -118,7 +127,7 @@ fn main() {
|
||||
};
|
||||
match snapshot {
|
||||
Some(snapshot) => {
|
||||
app_handle.emit_all("showState", snapshot);
|
||||
app_handle.emit_all("showState", snapshot).ok();
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -153,8 +153,18 @@ impl Config {
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn get_log_file_path() -> Option<Box<PathBuf>> {
|
||||
let project_dir = ProjectDirs::from("me", "ress.imp", "slidershim").unwrap();
|
||||
let config_dir = project_dir.config_dir();
|
||||
fs::create_dir_all(config_dir).unwrap();
|
||||
|
||||
let log_path = config_dir.join("log.txt");
|
||||
|
||||
return Some(Box::new(log_path));
|
||||
}
|
||||
|
||||
fn get_saved_path() -> Option<Box<PathBuf>> {
|
||||
let project_dir = ProjectDirs::from("me", "imp.ress", "slidershim").unwrap();
|
||||
let project_dir = ProjectDirs::from("me", "ress.imp", "slidershim").unwrap();
|
||||
let config_dir = project_dir.config_dir();
|
||||
fs::create_dir_all(config_dir).unwrap();
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ use log::info;
|
||||
|
||||
use crate::slider_io::{
|
||||
brokenithm::BrokenithmJob,
|
||||
config::{Config, DeviceMode},
|
||||
config::{Config, DeviceMode, LedMode, OutputMode},
|
||||
controller_state::FullState,
|
||||
device::HidDeviceJob,
|
||||
led::LedJob,
|
||||
@@ -16,8 +16,8 @@ pub struct Context {
|
||||
config: Config,
|
||||
device_worker: Option<ThreadWorker>,
|
||||
brokenithm_worker: Option<AsyncWorker>,
|
||||
output_worker: ThreadWorker,
|
||||
led_worker: ThreadWorker,
|
||||
output_worker: Option<ThreadWorker>,
|
||||
led_worker: Option<ThreadWorker>,
|
||||
}
|
||||
|
||||
impl Context {
|
||||
@@ -30,6 +30,7 @@ impl Context {
|
||||
let state = FullState::new();
|
||||
|
||||
let (device_worker, brokenithm_worker) = match &config.device_mode {
|
||||
DeviceMode::None => (None, None),
|
||||
DeviceMode::Brokenithm { ground_only } => (
|
||||
None,
|
||||
Some(AsyncWorker::new(
|
||||
@@ -37,16 +38,28 @@ impl Context {
|
||||
BrokenithmJob::new(&state, ground_only),
|
||||
)),
|
||||
),
|
||||
other => (
|
||||
_ => (
|
||||
Some(ThreadWorker::new(
|
||||
"device",
|
||||
HidDeviceJob::from_config(&state, other),
|
||||
HidDeviceJob::from_config(&state, &config.device_mode),
|
||||
)),
|
||||
None,
|
||||
),
|
||||
};
|
||||
let output_worker = ThreadWorker::new("output", OutputJob::new(&state, &config.output_mode));
|
||||
let led_worker = ThreadWorker::new("led", LedJob::new(&state, &config.led_mode));
|
||||
let output_worker = match &config.output_mode {
|
||||
OutputMode::None => None,
|
||||
_ => Some(ThreadWorker::new(
|
||||
"output",
|
||||
OutputJob::new(&state, &config.output_mode),
|
||||
)),
|
||||
};
|
||||
let led_worker = match &config.led_mode {
|
||||
LedMode::None => None,
|
||||
_ => Some(ThreadWorker::new(
|
||||
"led",
|
||||
LedJob::new(&state, &config.led_mode),
|
||||
)),
|
||||
};
|
||||
|
||||
Self {
|
||||
state,
|
||||
|
||||
@@ -18,3 +18,4 @@ mod manager;
|
||||
|
||||
pub use config::Config;
|
||||
pub use manager::Manager;
|
||||
pub use utils::list_ips;
|
||||
|
||||
@@ -33,3 +33,14 @@ impl Error for ShimError {
|
||||
"shimError"
|
||||
}
|
||||
}
|
||||
|
||||
pub fn list_ips() -> Result<Vec<String>, Box<dyn Error>> {
|
||||
let mut ips = vec![];
|
||||
for adapter in ipconfig::get_adapters()? {
|
||||
for ip_address in adapter.ip_addresses() {
|
||||
ips.push(format!("{}", ip_address));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(ips)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user