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

@@ -10,3 +10,4 @@ crate-type=["cdylib"]
[dependencies]
dim_sdk = {path="../../sdk/rust/dim_sdk"}
lazy_static = "1.4.0"
log = "0.4.21"

View File

@@ -1,5 +1,5 @@
use std::fmt::Write;
use dim_sdk::{plugin_info, Context, DimPlugin};
use dim_sdk::{plugin_info, Context, DimPlugin, Message, Result};
plugin_info!(
Plug, // Your main global structs name that implements `DimPlugin`
@@ -10,37 +10,45 @@ plugin_info!(
#[derive(Debug, Clone)]
struct Plug {
ctx: Context,
counter: usize,
}
impl Plug {
pub fn new() -> Self {
Self {
counter: 0
}
}
}
impl DimPlugin for Plug {
fn init(&mut self, _ctx: Context) {
fn init(ctx: Context) -> dim_sdk::Result<Self> {
// Initialise data, this will run once, it will not run again after reload
// log::info!("hewo from rust :3");
Ok(Self {
ctx,
counter: 0
})
}
fn poll(&mut self, f: &mut dim_sdk::CBuffer) -> dim_sdk::Result<()> {
// Write to buffer the text you want to display, keep this short
write!(f, "Hello from rust! ({})", self.counter)?;
self.counter += 1;
fn on_message(&mut self, msg: Message) -> dim_sdk::Result<()> {
self.ctx.buf.reset();
match msg.name.as_str() {
"poll" => {
// Write to buffer the text you want to display, keep this short
write!(self.ctx, "Hello from rust! ({})", self.counter)?;
self.counter += 1;
}
_ => ()
}
Ok(())
}
fn pre_reload(&mut self) {
fn pre_reload(&mut self) -> Result<()> {
// Do stuff before reload, probably save important things because theres a good chance
// (especially on rust) that if you change the data layout it will die
Ok(())
}
fn post_reload(&mut self) {
fn post_reload(&mut self) -> Result<()>{
// Do stuff after reloading plugin, state a.k.a this struct has the same data, will crash
// if the data layout changed
Ok(())
}
fn free(&mut self) {
fn free(&mut self) -> Result<()> {
// Yout probably dont need this but its for freeing things before the plugin gets unloaded
Ok(())
}
}