moved generated,spacetime into it's own package + many other things

This commit is contained in:
Sebastian Moser
2026-05-17 14:23:34 +02:00
parent 2907d7e236
commit d1ddb405c8
49 changed files with 610 additions and 499 deletions

View File

@@ -5,10 +5,21 @@ use clap::{Arg, Command};
use rusqlite::{params, Connection};
use serde_json::{json, Value};
use mize::{mize_err, mize_part, Mize, MizeError, MizePart, MizeResult};
use dioxus::prelude::*;
use mize::{mize_err, mize_part, Mize, MizeError, MizePart, MizePartCreate, MizeResult};
use crate::cli::CliPart;
use crate::habitica::Habitica;
use crate::SpacetimePart;
use generated::spacetime::{
activitiesQueryTableAccess, next_action, remove_activity, task_partQueryTableAccess,
update_activity, update_upcoming, Action, ActivitiesTableAccess, Activity, DbConnection,
TaskPart, TaskPartTableAccess,
};
use spacetimedb_sdk::{
credentials, DbContext, Error, Event, Identity, Status, SubscriptionHandle, Table,
TableWithPrimaryKey,
};
mod dashboard;
@@ -24,6 +35,7 @@ impl MizePart for C2vi {
mize.new_opt("c2vi.local_storage_path");
}
}
impl MizePartCreate for C2vi {}
impl C2vi {
fn with_db<F, R>(&self, f: F) -> MizeResult<R>
@@ -42,12 +54,67 @@ impl C2vi {
}
pub fn c2vi(mize: &mut Mize) -> MizeResult<()> {
#[cfg(feature = "client")]
c2vi_client(mize)?;
#[cfg(feature = "desktop")]
if mize
.get_config("c2vi.dash.enable")?
.as_bool()
.unwrap_or(false)
{
// refresh the credentials every 23h
// as this is basically running as a daemon
use crate::auth::client::ClientAuth;
let mut auth = mize.get_part_native::<ClientAuth>("auth")?;
auth.refresh()?;
auth.start_refresh_thread()?;
drop(auth);
launch_c2vi_dashboard(mize);
}
Ok(())
}
#[cfg(feature = "desktop")]
pub fn launch_c2vi_dashboard(mize: &mut Mize) {
use dioxus::desktop::{muda::Menu, Config, WindowBuilder};
let mize_clone = mize.clone();
LaunchBuilder::new()
.with_context_provider(move || Box::new(mize_clone.clone()))
.with_cfg(desktop! {
Config::new().with_window(WindowBuilder::new().with_decorations(false).with_title("PPC"))
})
.launch(c2vi_dash_main);
}
pub fn c2vi_dash_main() -> Element {
let mut current = use_signal_sync(|| "".to_string());
use_effect(move || {
let mut mize = use_context::<Mize>();
let mut spacetime = mize.get_part_native::<SpacetimePart>("spacetime").unwrap();
let con = spacetime.con();
con.subscription_builder()
.on_applied(move |ctx| {
let data = ctx.db.task_part().identity().find(&ctx.identity()).unwrap();
current.set(data.current.name.clone());
})
.add_query(|q| q.from.task_part())
.subscribe();
con.db
.task_part()
.on_update(move |_, old: &TaskPart, new: &TaskPart| {
current.set(new.current.name.clone());
});
});
rsx! {
div {
style: "text-align: center; padding: 2rem; font-size: 50px;",
p {
"{current}"
}
}
}
}
pub fn c2vi_client(mize: &mut Mize) -> MizeResult<()> {
//let storage_path = mize.get_config("c2vi.local_storage_path")?.as_
let storage_path = "/home/me/work/app-data/ppc";
@@ -97,7 +164,7 @@ fn setup_tables(conn: &Connection) -> MizeResult<()> {
fn register_subcommands(cli: &mut CliPart) {
cli.subcommand(
Command::new("c2vi-dash").about("Run the c2vi dashboard gui"),
|_matches, mut mize| Ok(dioxus::launch(dashboard::main)),
|_matches, mut _mize| Ok(dioxus::launch(dashboard::main)),
);
cli.subcommand(
Command::new("bed").about("Command to run when c2vi goes to bed"),