blinking support

This commit is contained in:
AnActualEmerald 2022-09-03 14:21:41 -04:00
parent bb69bd9e0b
commit 0ace4490b3
Signed by: emerald
GPG Key ID: CC76D6B296CAC8B0
8 changed files with 85 additions and 5 deletions

View File

Before

Width:  |  Height:  |  Size: 848 KiB

After

Width:  |  Height:  |  Size: 848 KiB

BIN
public/images/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 855 KiB

BIN
public/images/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 844 KiB

BIN
public/images/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 849 KiB

40
src-tauri/Cargo.lock generated
View File

@ -298,11 +298,13 @@ dependencies = [
"cpal",
"env_logger",
"log",
"rand 0.8.5",
"ray_format",
"serde",
"serde_json",
"tauri",
"tauri-build",
"tokio",
]
[[package]]
@ -1725,6 +1727,18 @@ dependencies = [
"adler",
]
[[package]]
name = "mio"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf"
dependencies = [
"libc",
"log",
"wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys",
]
[[package]]
name = "ndk"
version = "0.6.0"
@ -2732,6 +2746,15 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
[[package]]
name = "signal-hook-registry"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0"
dependencies = [
"libc",
]
[[package]]
name = "siphasher"
version = "0.3.10"
@ -3232,11 +3255,28 @@ checksum = "89797afd69d206ccd11fb0ea560a44bbb87731d020670e79416d442919257d42"
dependencies = [
"autocfg",
"bytes",
"libc",
"memchr",
"mio",
"num_cpus",
"once_cell",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"winapi",
]
[[package]]
name = "tokio-macros"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484"
dependencies = [
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.99",
]
[[package]]

View File

@ -21,6 +21,8 @@ ray_format = {path = "../ray_format", version = "~0.1.0"}
anyhow = "1.0.63"
log = "0.4.17"
env_logger = "0.9.0"
rand = "0.8.5"
tokio = { version = "1.21.0", features = ["full"] }
[features]
# by default Tauri runs in production mode

View File

@ -3,10 +3,13 @@
windows_subsystem = "windows"
)]
use std::sync::{Arc, Mutex};
use std::{
sync::{Arc, Mutex},
time::Duration,
};
use audio::monitor;
use log::warn;
use log::{trace, warn};
use tauri::{Manager, State};
mod audio;
@ -16,6 +19,7 @@ const MIC_THRESHOLD: f32 = 0.5f32;
struct MicThreshold(Arc<Mutex<f32>>);
fn main() {
env_logger::init();
let threshold = Arc::new(Mutex::new(MIC_THRESHOLD));
tauri::Builder::default()
@ -26,6 +30,19 @@ fn main() {
monitor(window, threshold).await;
});
let window = app.get_window("main").unwrap();
tauri::async_runtime::spawn(async move {
loop {
if rand::random() {
trace!("Blinking");
if let Some(e) = window.emit("blink", "").err() {
warn!("Failed to emit blink event: {}", e);
}
}
tokio::time::sleep(Duration::from_millis(3000)).await;
}
});
Ok(())
})
.invoke_handler(tauri::generate_handler![

View File

@ -2,13 +2,21 @@
import { onMount } from "svelte";
import { appWindow } from "@tauri-apps/api/window";
let src = "images/test.png";
//Replace with a store in the future
const images = [
"images/1.png",
"images/3.png",
"images/2.png",
"images/4.png",
];
let src = "";
let buf = 0;
let open = false;
let closed = false;
let blink = false;
let inAnim = "jump-in";
let outAnim = "jump-out";
let outAnim = "none";
$: {
if (buf > 50) {
@ -20,6 +28,20 @@
}
}
$: {
if (closed) {
src = images[0];
} else if (open) {
src = images[2];
}
if (blink && closed) {
src = images[1] ? images[1] : images[0];
} else if (blink && open) {
src = images[3] ? images[3] : images[2];
}
}
onMount(async () => {
await appWindow.listen("mouth-open", () => {
buf = 100;
@ -38,7 +60,6 @@
</script>
<img {src} alt="tuber" class:open class:closed class="{inAnim} {outAnim}" />
<p>{buf}</p>
<style lang="scss">
@keyframes jump-out {