Too lazy to make propper edit but i changed the

polling system to a message one so we can have
more ways we can interract with plugins
(reload/ reset/ on click events)
This commit is contained in:
2024-06-26 04:00:44 +03:00
parent 9f53240807
commit 026a68364b
33 changed files with 694 additions and 271 deletions

View File

@@ -1,6 +1,6 @@
use std::fmt::Write;
use chrono::prelude::*;
use dim_sdk::{plugin_info, Context, DimPlugin};
use dim_sdk::{plugin_info, Context, DimPlugin, Result};
plugin_info!(
Plug, // Your main global structs name that implements `DimPlugin`
@@ -11,27 +11,31 @@ plugin_info!(
#[derive(Debug, Clone)]
struct Plug {
ctx: Context
}
impl Plug {
pub fn new() -> Self {
Self {
}
}
}
impl DimPlugin for Plug {
fn init(&mut self, _ctx: Context) {}
fn poll(&mut self, f: &mut dim_sdk::CBuffer) -> dim_sdk::Result<()> {
let local: DateTime<Local> = Local::now();
let formatted_time = local.format("%H:%M (%Y-%m-%d)").to_string();
log::info!("Hello from clocky :3");
write!(f, "Time: {}", formatted_time)?;
fn init(ctx: Context) -> Result<Self> {
Ok(Self {
ctx
})
}
fn on_message(&mut self, msg: dim_sdk::Message) -> Result<()> {
self.ctx.buf.reset();
match msg.name.as_str() {
"poll" => {
let local: DateTime<Local> = Local::now();
let formatted_time = local.format("%H:%M (%Y-%m-%d)").to_string();
write!(self.ctx, "Time: {}", formatted_time)?;
}
_ => ()
}
Ok(())
}
fn pre_reload(&mut self) {}
fn post_reload(&mut self) {}
fn free(&mut self) {}
fn pre_reload(&mut self) -> Result<()> { Ok(()) }
fn post_reload(&mut self) -> Result<()> { Ok(()) }
fn free(&mut self) -> Result<()> { Ok(()) }
}