add blink interval to config

This commit is contained in:
emerald 2022-10-12 10:34:19 -04:00
parent 56f7e1f11b
commit df884108e2
Signed by: emerald
GPG Key ID: 5648BBF928C9DC43
4 changed files with 45 additions and 13 deletions

View File

@ -8,6 +8,13 @@ use tauri::api::path::config_dir;
pub struct Config {
#[serde(default)]
pub background_color: BGColor,
#[serde(default = "default_interval")]
pub blink_interval: u64,
}
#[inline(always)]
fn default_interval() -> u64 {
1500
}
#[derive(Debug, Clone, Deserialize, Serialize)]

View File

@ -43,7 +43,7 @@ fn main() {
if let Some(d) = cache_dir() {
use std::fs;
if let Ok(s) = fs::read_to_string(d.join("last_selected")) {
if let Ok(s) = fs::read_to_string(d.join("cathode").join("last_selected")) {
debug!("Found selected ray in cache");
ray = Some(Path::new(&s).to_path_buf());
}
@ -52,6 +52,10 @@ fn main() {
// Create the config directory if needed
let config = config::load_config();
{
*blink_interval.lock().unwrap() = config.blink_interval
}
let current_conf = Arc::new(Mutex::new(config));
let config = current_conf.clone();
@ -84,7 +88,6 @@ fn main() {
tauri::async_runtime::spawn(async move {
use notify::{event::AccessKind, Event, EventKind, RecursiveMode, Result, Watcher};
if let Some(path) = config_dir() {
// let window = app.get_window("main").unwrap();
let mut watcher =
notify::recommended_watcher(move |res: Result<Event>| match res {
Ok(event) => {
@ -138,6 +141,8 @@ fn main() {
set_mic_threshold,
get_mic_threshold,
get_audio_level,
get_blink_interval,
set_blink_interval,
get_config,
fs::open_image,
fs::save_ray,
@ -167,6 +172,16 @@ fn get_audio_level(level: State<'_, AudioLevel>) -> f32 {
*level.0.lock().unwrap()
}
#[tauri::command]
fn get_blink_interval(current: State<'_, BlinkInterval>) -> u64 {
*current.0.lock().unwrap()
}
#[tauri::command]
fn set_blink_interval(value: u64, current: State<'_, BlinkInterval>) {
*current.0.lock().unwrap() = value;
}
#[tauri::command]
fn get_config(current: State<'_, CurrentConfig>) -> Config {
current.0.lock().unwrap().clone()

View File

@ -1,25 +1,23 @@
<script lang="ts" context="module">
type Config = {
background_color: "transparent" | "blue" | "green" | "pink" | {custom: string};
}
</script>
<script lang="ts">
import MainView from "./views/main.svelte";
import {appWindow} from "@tauri-apps/api/window";
import {invoke} from "@tauri-apps/api";
import {onMount} from "svelte";
import {config} from "./store";
import type {Config} from "./store";
let config: Config = {background_color: "transparent"};
$: transparent = config.background_color == "transparent";
$: color = typeof config.background_color == "object" ? config.background_color.custom : config.background_color;
$: transparent = $config.background_color == "transparent";
$: color = typeof $config.background_color == "object" ? $config.background_color.custom : $config.background_color;
$: {
invoke("set_blink_interval", {value: $config.blink_interval}).catch();
}
onMount(async () => {
config = await invoke("get_config") as Config;
$config = await invoke("get_config") as Config;
await appWindow.listen("reload-config", async () => {
config = await invoke("get_config") as Config;
$config = await invoke("get_config") as Config;
});
});

View File

@ -1,3 +1,15 @@
import {writable} from "svelte/store";
type BGColor ="transparent" | "blue" | "green" | "pink" | {custom: string} ;
export class Config {
background_color: BGColor;
blink_interval: number;
constructor(){
this.background_color = "transparent";
this.blink_interval = 1500;
}
}
export let frames = writable(new Array<string>(4));
export let config = writable(new Config());