updated README and a bunch of other stuff

This commit is contained in:
Sebastian Moser
2026-11-04 20:24:14 +01:00
parent 6eedb1826a
commit 9707286375
46 changed files with 3725 additions and 172 deletions

View File

@@ -0,0 +1,19 @@
cargo-features = ["profile-rustflags"]
[package]
name = "mize-part-sci-timetrack"
version = "0.1.0"
edition = "2024"
[lib]
name = "mize_part_sci_timetrack"
crate-type = ["cdylib", "rlib"]
[dependencies]
mize = { workspace = true }
[profile.dev]
rustflags = ["-C", "prefer-dynamic", "-C", "link-args=-Wl,--export-dynamic"]
[profile.release]
rustflags = ["-C", "prefer-dynamic"]

View File

@@ -0,0 +1,73 @@
use mize::prelude::*;
pub struct CliPart {
id: MizeId,
}
impl MizePart for CliPart {
fn id(&self) -> MizeResult<MizeId> {
Ok(self.id.clone())
}
}
impl CliPart {
pub fn get(name: &str) -> MizeResult<CliPart> {
let mut mize = get_global_mize()?;
let part = mize.get_part(name)?;
Ok(CliPart { id: part.id()? })
}
pub fn set_command(&self, name: &str) -> MizeResult<()> {
let mut args = ItemData::new();
args.set_path("0", name.into_item_data())?;
dyn_call(self.id.clone(), "set_command", args)?;
Ok(())
}
pub fn subcommand<T: Fn(ArgMatches) -> MizeResult<()> + Send + Sync + 'static>(
&self,
subcmd: Command,
action: T,
) -> MizeResult<()> {
let mut subcmd_arg = ItemData::new();
subcmd_arg.set_path("_native", subcmd.native_id)?;
let action_arg = ItemData::fun(Box::new(move |args: ItemData| {
let matches = args.clone().get_path("0")?.native_take_from::<ArgMatches>()?;
action(matches)?;
Ok(ItemData::new())
}))?;
let mut args = ItemData::new();
args.set_path("0", subcmd_arg)?;
args.set_path("1", action_arg)?;
dyn_call(self.id.clone(), "subcommand", args)?;
Ok(())
}
}
pub struct Command {
native_id: u32,
}
pub struct ArgMatches {
native_id: u32,
}
impl FromItemData for ArgMatches {
fn from_itemdata(data: ItemData) -> MizeResult<Self> {
Ok(ArgMatches {
native_id: data.get_path("_native")?.value_u32()?,
})
}
}
impl Command {
pub fn new(name: &str) -> MizeResult<Command> {
let mut args = ItemData::new();
args.set_path("0", name.into_item_data())?;
let mut mize = get_global_mize()?;
let id = mize.id_new_dots("cli.Command")?;
let data = dyn_call(id, "new", args)?;
let native_id: u32 = data.get_path("_native")?.native_take()?;
Ok(Command { native_id })
}
}

View File

@@ -0,0 +1,65 @@
mod generated;
use generated::{ArgMatches, CliPart, Command};
use mize::prelude::*;
use mize::proto::MizeMessage;
fn ensure_default(rel: &str, default: ItemData) -> MizeResult<()> {
let mut mize = get_global_mize()?;
let cur = mize
.cur_eval_part()?
.ok_or_else(|| mize_err!("no cur_eval_part"))?;
let full = format!("{}.{}", cur.dot(), rel);
if mize.get_config(&full).is_ok() {
return Ok(());
}
let segs: Vec<&str> = rel.split('.').filter(|s| !s.is_empty()).collect();
let last = *segs.last().ok_or_else(|| mize_err!("empty opt path"))?;
let mut parent = cur.clone();
for seg in &segs[..segs.len() - 1] {
parent = parent.join(seg)?;
}
let original = Some(cur);
mize.set_cur_eval_part(Some(parent))?;
opt(last).default_val(default);
mize.set_cur_eval_part(original)?;
Ok(())
}
fn spacetime_unwired(_: ArgMatches) -> MizeResult<()> {
Err(mize_err!("spacetime SDK not wired yet"))
}
#[unsafe(no_mangle)]
pub extern "C" fn part_sci_timetrack() -> MizeResult<()> {
ensure_default("daily_notes_path", "".into_item_data())?;
ensure_default("profile", "c2vi".into_item_data())?;
let cli = CliPart::get("cli")?;
cli.set_command("sci")?;
for (name, alias) in [
("editActionList", "aal"),
("nextAction", "ne"),
("printCurrentAction", "cu"),
("listActions", "la"),
("listActivities", "lac"),
("editActivities", "eac"),
("timetrackExport", "te"),
] {
cli.subcommand(Command::new(name)?, spacetime_unwired)?;
cli.subcommand(Command::new(alias)?, spacetime_unwired)?;
}
let mut mize = get_global_mize()?;
mize.add_listener(
"timetrack.sub_current",
Box::new(|_msg: MizeMessage, _mize: &mut Mize| {
Err(mize_err!(
"spacetime SDK not wired yet (timetrack.sub_current)"
))
}),
)?;
Ok(())
}