Initial commit
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
use tauri::State;
|
||||
use crate::state::AppState;
|
||||
use dsp_thomann::dsp408::DSP408;
|
||||
use std::{net::IpAddr, str::FromStr};
|
||||
|
||||
#[tauri::command]
|
||||
pub fn device_count(
|
||||
state: State<AppState>
|
||||
) -> usize {
|
||||
let devices = state.devices.lock().unwrap();
|
||||
devices.len()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn create_dsp408(
|
||||
state: State<AppState>,
|
||||
ip: String,
|
||||
port: u16,
|
||||
device_id: u8,
|
||||
) -> Result<usize, String> {
|
||||
|
||||
let mut devices = state
|
||||
.devices
|
||||
.lock()
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
let ip = IpAddr::from_str(&ip).map_err(|e| e.to_string())?;
|
||||
|
||||
let dsp = DSP408::new(ip, port, device_id)
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
devices.push(dsp);
|
||||
|
||||
Ok(devices.len())
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
mod state;
|
||||
mod commands;
|
||||
|
||||
use state::AppState;
|
||||
|
||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||
#[tauri::command]
|
||||
fn greet(name: &str) -> String {
|
||||
format!("Hello, {}! You've been greeted from Rust!", name)
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.manage(AppState::new())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
greet,
|
||||
commands::device_count,
|
||||
commands::create_dsp408,
|
||||
]
|
||||
)
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
fn main() {
|
||||
thomann_dsp_app_lib::run()
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
use std::sync::Mutex;
|
||||
use dsp_thomann::dsp408::DSP408;
|
||||
|
||||
pub struct AppState {
|
||||
pub devices: Mutex<Vec<DSP408>>,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
devices: Mutex::new(Vec::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user