Compare commits

..

3 Commits

Author SHA1 Message Date
ef0c80d099 merge
All checks were successful
publish / publish-tauri (ubuntu-20.04) (push) Successful in 4m21s
2023-10-27 15:03:38 +02:00
6af55a17bf Merge branch 'main' of https://gitea.xeovalyte.dev/xeovalyte/toos-halloween 2023-10-27 15:03:04 +02:00
422f4c68c6 feat: Added relative audio path 2023-10-27 10:34:47 +02:00
4 changed files with 20 additions and 2 deletions

View File

@@ -13,7 +13,7 @@ edition = "2021"
tauri-build = { version = "1.5", features = [] }
[dependencies]
tauri = { version = "1.5", features = [ "dialog-all", "shell-open"] }
tauri = { version = "1.5", features = ["dialog-all", "shell-open"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serialport = "4.2.2"

View File

@@ -5,6 +5,7 @@ use std::io::BufReader;
use rodio::{Decoder, OutputStream, Sink};
use std::sync::Mutex;
use once_cell::sync::Lazy;
use std::path::{Path, PathBuf};
use crate::serial;
@@ -16,6 +17,7 @@ struct Timings {
static TIMINGS: Mutex<Lazy<Timings>> = Mutex::new(Lazy::new(|| Timings { charging_start_delay: 1600, charging_delay: 450, charging_end_delay: 400 } ));
static PLAYING: Mutex<bool> = Mutex::new(false);
pub static AUDIO_PATH: Mutex<Lazy<PathBuf>> = Mutex::new(Lazy::new(|| Path::new("assets/audio.mp3").to_path_buf()));
#[tauri::command]
pub fn start() {
@@ -47,7 +49,9 @@ fn play_sound() {
let (_stream, stream_handle) = OutputStream::try_default().unwrap();
let sink = Sink::try_new(&stream_handle).unwrap();
let file = BufReader::new(File::open("assets/audio.mp3").unwrap());
let path = AUDIO_PATH.lock().unwrap();
let file = BufReader::new(File::open(&**path).unwrap());
let source = Decoder::new(file).unwrap();
sink.append(source);

View File

@@ -7,6 +7,17 @@ mod animation;
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![serial::get_serial_ports, serial::write_serial, serial::open_port, serial::close_port, animation::start])
.setup(|app| {
let resource_path = app.path_resolver()
.resolve_resource("assets/audio.mp3")
.expect("failed to resolve resource");
let mut audio_path = animation::AUDIO_PATH.lock().unwrap();
**audio_path = resource_path;
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

View File

@@ -31,6 +31,9 @@
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"resources": [
"assets/audio.mp3"
]
},
"security": {