Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ jobs:
pkg-config \
build-essential

- name: IPC types drift check
run: bun run check:ipc-types

- name: TypeScript typecheck
run: bun run typecheck

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"release:major": "./scripts/release.sh major",
"sync-versions": "bun run scripts/sync-versions.ts",
"sync-versions:check": "bun run scripts/sync-versions.ts --check",
"generate:ipc-types": "cargo run --manifest-path src-tauri/Cargo.toml --bin generate_ipc_types && bunx biome format --write src/common/generated/ipc-types.ts",
"check:ipc-types": "bun run generate:ipc-types && git diff --exit-code -- src/common/generated/ipc-types.ts",
"typecheck": "tsc --noEmit",
"check": "biome check .",
"lint": "biome lint --write",
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "1.3.0"
description = "Claudometer - Tray-first macOS + Linux app to monitor Claude web usage limits."
authors = ["Softaworks"]
edition = "2021"
default-run = "claudometer"

[lib]
name = "claudometer_lib"
Expand All @@ -29,6 +30,7 @@ thiserror = "2"
time = { version = "0.3", features = ["formatting", "macros"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread", "sync", "time", "process", "io-util"] }
urlencoding = "2"
ts-rs = "11.1"

[target.'cfg(target_os = "macos")'.dependencies]
objc2 = "0.6"
Expand Down
12 changes: 8 additions & 4 deletions src-tauri/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use crate::claude::ClaudeApiClient;
use crate::codex::CodexApiClient;
use crate::commands::{self, AppState, RefreshBus, SecretManager};
use crate::commands;
use crate::refresh;
use crate::settings::SettingsStore;
use crate::state::{
AppState, DebugOverride, RefreshBus, SecretManager, KEYRING_USER_CLAUDE_SESSION_KEY,
};
use crate::tray::{self, TrayUi};
use std::collections::HashMap;
use tauri::Manager;
Expand Down Expand Up @@ -173,15 +177,15 @@ pub fn run() {

let state = AppState {
settings: settings.clone(),
claude_session_key: SecretManager::new(commands::KEYRING_USER_CLAUDE_SESSION_KEY),
claude_session_key: SecretManager::new(KEYRING_USER_CLAUDE_SESSION_KEY),
claude: std::sync::Arc::new(claude),
codex: std::sync::Arc::new(codex),
organizations: std::sync::Arc::new(tokio::sync::Mutex::new(vec![])),
orgs_cache: std::sync::Arc::new(tokio::sync::Mutex::new(None)),
latest_snapshot: std::sync::Arc::new(tokio::sync::Mutex::new(None)),
reset_baseline_by_org: std::sync::Arc::new(tokio::sync::Mutex::new(HashMap::new())),
debug_override: std::sync::Arc::new(tokio::sync::Mutex::new(
crate::commands::DebugOverride::default(),
DebugOverride::default(),
)),
tray: tray.clone(),
refresh: refresh.clone(),
Expand All @@ -192,7 +196,7 @@ pub fn run() {
state.track_codex_enabled(),
None,
);
commands::spawn_refresh_loop(app_handle.clone(), state.clone(), rx);
refresh::spawn_refresh_loop(app_handle.clone(), state.clone(), rx);

if settings.get_bool(crate::settings::KEY_CHECK_UPDATES_ON_STARTUP, true) {
crate::updater::check_for_updates_background(app_handle.clone());
Expand Down
59 changes: 59 additions & 0 deletions src-tauri/src/bin/generate_ipc_types.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use std::fs;
use std::path::PathBuf;
use ts_rs::TS;

fn write_decl<T: TS>(out: &mut String) {
let mut decl = T::decl();
let trimmed = decl.trim_start();
if trimmed.starts_with("type ") {
decl = decl.replacen("type ", "export type ", 1);
} else if trimmed.starts_with("interface ") {
decl = decl.replacen("interface ", "export interface ", 1);
} else if trimmed.starts_with("enum ") {
decl = decl.replacen("enum ", "export enum ", 1);
}
out.push_str(&decl);
if !out.ends_with('\n') {
out.push('\n');
}
out.push('\n');
}

fn main() {
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let repo_root = manifest_dir
.parent()
.expect("src-tauri must have a parent directory");
let out_path = repo_root.join("src/common/generated/ipc-types.ts");

if let Some(parent) = out_path.parent() {
fs::create_dir_all(parent).expect("create generated output directory");
}

let mut out = String::new();
out.push_str("// @generated\n");
out.push_str("// This file is generated by `cargo run --manifest-path src-tauri/Cargo.toml --bin generate_ipc_types`.\n");
out.push_str("// Do not edit manually.\n\n");

write_decl::<claudometer_lib::types::UsageStatus>(&mut out);
write_decl::<claudometer_lib::types::UsageSource>(&mut out);
write_decl::<claudometer_lib::types::CodexUsageSource>(&mut out);

write_decl::<claudometer_lib::types::ClaudeModelUsage>(&mut out);
write_decl::<claudometer_lib::types::ClaudeUsageSnapshot>(&mut out);
write_decl::<claudometer_lib::types::CodexUsageSnapshot>(&mut out);
write_decl::<claudometer_lib::types::UsageSnapshotBundle>(&mut out);

write_decl::<claudometer_lib::types::ClaudeOrganization>(&mut out);
write_decl::<claudometer_lib::types::SettingsState>(&mut out);
write_decl::<claudometer_lib::types::SaveSettingsPayload>(&mut out);

write_decl::<claudometer_lib::types::IpcErrorCode>(&mut out);
write_decl::<claudometer_lib::types::IpcError>(&mut out);

// Export the generic result envelope used by IPC responses.
write_decl::<claudometer_lib::types::IpcResult<()>>(&mut out);

fs::write(&out_path, out).expect("write generated file");
println!("Wrote {}", out_path.display());
}
Loading