add logic for handling opening files
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
AnActualEmerald 2022-09-17 12:45:26 -04:00
parent e08e508eda
commit 20af8b8164
Signed by: emerald
GPG Key ID: CC76D6B296CAC8B0
7 changed files with 82 additions and 11 deletions

2
dist/index.html vendored
View File

@ -5,7 +5,7 @@
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tauri + Svelte + TS</title>
<script type="module" crossorigin src="/assets/index.5494e677.js"></script>
<script type="module" crossorigin src="/assets/index.4fc3067b.js"></script>
<link rel="stylesheet" href="/assets/index.425121d3.css">
</head>

37
src-tauri/Cargo.lock generated
View File

@ -402,6 +402,30 @@ dependencies = [
"libloading",
]
[[package]]
name = "clap"
version = "3.2.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750"
dependencies = [
"atty",
"bitflags",
"clap_lex",
"indexmap",
"strsim",
"termcolor",
"textwrap",
]
[[package]]
name = "clap_lex"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"
dependencies = [
"os_str_bytes",
]
[[package]]
name = "cocoa"
version = "0.24.0"
@ -2064,6 +2088,12 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5"
[[package]]
name = "os_str_bytes"
version = "6.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff"
[[package]]
name = "pango"
version = "0.15.10"
@ -3137,6 +3167,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efbf22abd61d95ca9b2becd77f9db4c093892f73e8a07d21d8b0b2bf71a7bcea"
dependencies = [
"anyhow",
"clap",
"cocoa",
"dirs-next",
"embed_plist",
@ -3333,6 +3364,12 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "textwrap"
version = "0.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16"
[[package]]
name = "thin-slice"
version = "0.1.1"

View File

@ -15,7 +15,7 @@ tauri-build = { version = "1.0.0", features = [] }
[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.0.0", features = ["dialog-all", "fs-create-dir", "fs-read-dir", "fs-read-file", "fs-write-file", "macos-private-api", "window-minimize", "window-set-max-size", "window-set-min-size", "window-unminimize"] }
tauri = { version = "1.0.0", features = ["cli", "dialog-all", "fs-create-dir", "fs-read-dir", "fs-read-file", "fs-write-file", "macos-private-api", "window-minimize", "window-set-max-size", "window-set-min-size", "window-unminimize"] }
cpal = { version = "0.14.0", features = ["jack"] }
ray_format = {path = "../ray_format", version = "~0.1.0"}
anyhow = "1.0.63"

View File

@ -1,5 +1,6 @@
use std::collections::HashMap;
use std::io::Cursor;
use std::path::Path;
use base64_url as base64;
use image::ImageFormat;
@ -36,6 +37,11 @@ pub(crate) async fn open_ray() -> Option<WebRay> {
.add_filter("Rays", &["ray"])
.set_directory(home_dir()?)
.pick_file()?;
load_ray(path).await
}
pub(crate) async fn load_ray(path: impl AsRef<Path>) -> Option<WebRay> {
let ray = Ray::load(path).ok()?;
let mut frames = [String::new(), String::new(), String::new(), String::new()];
let mut meta = HashMap::new();
@ -63,7 +69,7 @@ pub(crate) async fn open_ray() -> Option<WebRay> {
Some(WebRay { frames, meta })
}
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub(crate) struct WebRay {
frames: [String; 4],
meta: HashMap<String, String>,

View File

@ -4,12 +4,14 @@
)]
use std::{
path::Path,
sync::{Arc, Mutex},
time::Duration,
};
use audio::monitor;
use log::{trace, warn};
use serde_json::Value;
use tauri::{Manager, State};
mod audio;
@ -47,6 +49,19 @@ fn main() {
}
});
if let Ok(matches) = app.get_cli_matches() {
if let Some(arg) = matches.args.get("file") {
if let Value::String(path) = arg.value.clone() {
let window = app.get_window("main").unwrap();
tauri::async_runtime::spawn(async move {
if let Some(ray) = fs::load_ray(Path::new(&path)).await {
window.emit("load-ray", ray);
}
});
}
}
}
Ok(())
})
.invoke_handler(tauri::generate_handler![

View File

@ -10,6 +10,14 @@
"version": "0.0.0"
},
"tauri": {
"cli": {
"description": "A small app for PNG-tubing",
"args": [{
"name": "file",
"index": 1,
"takesValue": true
}]
},
"macOSPrivateApi": true,
"allowlist": {
"dialog": {

View File

@ -37,6 +37,14 @@
});
}
const openRay = (ray: WebRay) => {
for (let i = 0; i < 4; i++) {
$frames[i] = ray.frames[i];
}
if (ray.meta.threshold) {
$threshold = parseFloat(ray.meta.threshold);
}
};
onMount(async () => {
await appWindow.setMinSize(new PhysicalSize(720, 600));
@ -44,6 +52,10 @@
$transparent = !focused;
});
await appWindow.listen("load-ray", (e) => {
openRay(e.payload as WebRay);
});
monitorTimer = setInterval(async () => {
if (!$transparent) {
$level = await invoke("get_audio_level");
@ -82,14 +94,7 @@
const loadRay = async () => {
const ray: WebRay = await invoke("open_ray");
await invoke("log", { msg: `${ray.meta.threshold}` });
for (let i = 0; i < 4; i++) {
await invoke("log", { msg: `Setting frame ${i}` });
$frames[i] = ray.frames[i];
}
if (ray.meta.threshold) {
$threshold = parseFloat(ray.meta.threshold);
}
openRay(ray);
};
</script>