From 6dd22fe0c31624d5756ff3c146bce19a59994749 Mon Sep 17 00:00:00 2001 From: MCorange Date: Sun, 23 Jun 2024 14:16:27 +0300 Subject: [PATCH] extra stuff --- .gitignore | 2 ++ Cargo.lock | 12 ++++++++++++ Cargo.toml | 1 + "\\" | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 "\\" diff --git a/.gitignore b/.gitignore index 771fc85..80e59c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ /target /plugins /.cache +/config/* +!/config/main.template.toml compile_commands.json diff --git a/Cargo.lock b/Cargo.lock index 8f2c974..301e687 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -592,6 +592,18 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +[[package]] +name = "volume" +version = "0.1.0" +dependencies = [ + "anyhow", + "dim_sdk", + "lazy_static", + "regex", + "serde", + "toml", +] + [[package]] name = "wasm-bindgen" version = "0.2.92" diff --git a/Cargo.toml b/Cargo.toml index 853e18e..88ce0a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,6 +5,7 @@ members = [ "dim_plugins/clock", "dim_plugins/counter", "dim_plugins/battery", + "dim_plugins/volume", ] [package] diff --git "a/\\" "b/\\" new file mode 100644 index 0000000..9ee3963 --- /dev/null +++ "b/\\" @@ -0,0 +1,55 @@ +// Lord have mercy on me +#[macro_export] +macro_rules! plugin_info { + ($typ:ty, $name:literal, $version:literal, $license:literal) => { + + lazy_static::lazy_static!( + static ref PLUGIN_INFO: $crate::PluginInfo = $crate::PluginInfo::new($name, $version, $license); + ); + + static mut PLUG: *mut $typ = std::ptr::null_mut() as *mut $typ; + + #[no_mangle] + unsafe extern "C" fn plug_get_info() -> *const std::ffi::c_void { + PLUGIN_INFO.get_raw_ptr() + } + + #[no_mangle] + unsafe extern "C" fn plug_init(ctx: *const $crate::ContextRaw) { + PLUG = std::alloc::alloc(std::alloc::Layout::new::<$typ>()) as *mut $typ; + *PLUG = <$typ>::new(); + + let ctx = $crate::Context::new(ctx); + (&mut *PLUG).init(ctx); + } + + #[no_mangle] + unsafe extern "C" fn plug_pre_reload() -> *mut $typ { + //TODO: Untested + (&mut *PLUG).pre_reload(); + return PLUG; + } + + #[no_mangle] + unsafe extern "C" fn plug_post_reload(state: *mut $typ) { + //TODO: Untested + PLUG = state; + (&mut *PLUG).post_reload(); + } + + #[no_mangle] + unsafe extern "C" fn plug_poll(buf: *mut i8, len: std::ffi::c_uint) { + let mut buf = $crate::CBuffer::from_raw_parts_mut(buf, len as usize); + if let Err(_e) = (&mut *PLUG).poll(&mut buf) { + // TODO: Handle error maybe? + } + } + + #[no_mangle] + unsafe extern "C" fn plug_free() { + std::alloc::dealloc(PLUG as *mut u8, std::alloc::Layout::new::<$typ>()); + (&mut *PLUG).free(); + } + + }; +}