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
1 change: 1 addition & 0 deletions apps/desktop-tauri/src-tauri/permissions/commands.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ commands.allow = [
"get_launch_block_reason",
"get_work_area_rect",
"play_notification_sound",
"send_test_notification",
"open_external_url",
"reanchor_tray_panel",
"quit_app",
Expand Down
27 changes: 16 additions & 11 deletions apps/desktop-tauri/src-tauri/src/capacity_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,11 @@ fn inactive_windows(snapshot: &ProviderUsageSnapshot) -> HashMap<String, String>
.collect()
}

fn ignored_capacity_window(snapshot: &ProviderUsageSnapshot, id: &str, title: &str) -> bool {
pub(crate) fn ignored_capacity_window(
snapshot: &ProviderUsageSnapshot,
id: &str,
title: &str,
) -> bool {
if snapshot.provider_id != "cursor" {
return false;
}
Expand All @@ -535,7 +539,7 @@ fn ignored_capacity_window(snapshot: &ProviderUsageSnapshot, id: &str, title: &s
|| identity.contains("ondemand")
}

fn semantic_inactive_window_id(provider_id: &str, id: &str, title: &str) -> String {
pub(crate) fn semantic_inactive_window_id(provider_id: &str, id: &str, title: &str) -> String {
let title_id = normalize_window_id(title);
if let Some(core_id) = core_window_id(&title_id) {
return core_id.to_string();
Expand Down Expand Up @@ -592,7 +596,7 @@ fn to_observed_window(label: &str, window: &RateWindowSnapshot) -> Option<Observ
})
}

fn semantic_window_id(label: &str, window_minutes: Option<u32>) -> String {
pub(crate) fn semantic_window_id(label: &str, window_minutes: Option<u32>) -> String {
let normalized = normalize_window_id(label);
if matches!(
normalized.as_str(),
Expand Down Expand Up @@ -624,15 +628,15 @@ fn normalize_window_id(value: &str) -> String {
.to_string()
}

fn observation_scope(snapshot: &ProviderUsageSnapshot) -> String {
let identity = snapshot
.account_email
.as_deref()
.or(snapshot.account_organization.as_deref())
.unwrap_or("anonymous");
pub(crate) fn observation_scope(snapshot: &ProviderUsageSnapshot) -> String {
// Scope by BOTH account identifiers, not either/or: the same email can
// belong to different organizations (e.g. a personal vs a business
// workspace) with distinct limits, and those must never share a baseline.
let email = snapshot.account_email.as_deref().unwrap_or("");
let organization = snapshot.account_organization.as_deref().unwrap_or("");
let raw = format!(
"{}|{}|{}",
snapshot.provider_id, snapshot.source_label, identity
"{}|{}|{}|{}",
snapshot.provider_id, snapshot.source_label, email, organization
);
format!("{}:{:016x}", snapshot.provider_id, fnv1a64(raw.as_bytes()))
}
Expand Down Expand Up @@ -729,6 +733,7 @@ mod tests {
id: id.into(),
title: title.into(),
description: "Not currently limited".into(),
state: "notEnforced".into(),
});
snapshot
}
Expand Down
6 changes: 6 additions & 0 deletions apps/desktop-tauri/src-tauri/src/commands/bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ pub struct InactiveRateWindowSnapshot {
pub id: String,
pub title: String,
pub description: String,
/// "notEnforced" (provider reported no active limit) or "unavailable" (the
/// window dropped out of an otherwise-successful response).
pub state: String,
}

#[derive(Debug, Clone, Serialize)]
Expand Down Expand Up @@ -275,6 +278,7 @@ impl ProviderUsageSnapshot {
id: window.id.clone(),
title: window.title.clone(),
description: window.description.clone(),
state: window.state.as_str().to_string(),
})
.collect(),
promo_signals: usage
Expand Down Expand Up @@ -557,6 +561,7 @@ pub struct SettingsSnapshot {
float_bar_style: String,
taskbar_widget_open_on_hover: bool,
float_bar_density: String,
float_bar_information_mode: String,
float_bar_contrast: String,
float_bar_click_through: bool,
float_bar_provider_ids: Vec<String>,
Expand Down Expand Up @@ -657,6 +662,7 @@ impl From<Settings> for SettingsSnapshot {
float_bar_style: settings.float_bar_style,
taskbar_widget_open_on_hover: settings.taskbar_widget_open_on_hover,
float_bar_density: settings.float_bar_density,
float_bar_information_mode: settings.float_bar_information_mode,
float_bar_contrast,
float_bar_click_through: settings.float_bar_click_through,
float_bar_provider_ids: settings.float_bar_provider_ids,
Expand Down
12 changes: 11 additions & 1 deletion apps/desktop-tauri/src-tauri/src/commands/providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,18 @@ async fn refresh_provider(app: tauri::AppHandle, id: ProviderId, ctx: FetchConte

let state = app.state::<Mutex<AppState>>();
let (snapshot, capacity_events, notifications_armed) = if let Ok(mut guard) = state.lock() {
let snapshot = preserve_last_good_transient_failure(&mut guard, id, snapshot);
let mut snapshot = preserve_last_good_transient_failure(&mut guard, id, snapshot);
// Detect resets/lifts against the real response first, so the synthetic
// `unavailable` rows added next are never mistaken for a lifted window.
let capacity_events = guard.capacity_event_observer.observe(&snapshot);
let unavailable = guard.enforcement_tracker.annotate(&mut snapshot);
if !unavailable.is_empty() {
tracing::debug!(
provider = %snapshot.provider_id,
windows = ?unavailable,
"windows dropped out of a successful response; marked unavailable"
);
}
let notifications_armed = guard.notification_manager.notifications_are_armed();
upsert_provider_cache(&mut guard.provider_cache, snapshot.clone());
(snapshot, capacity_events, notifications_armed)
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop-tauri/src-tauri/src/commands/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub struct SettingsUpdate {
pub float_bar_style: Option<String>,
pub taskbar_widget_open_on_hover: Option<bool>,
pub float_bar_density: Option<String>,
pub float_bar_information_mode: Option<String>,
pub float_bar_contrast: Option<String>,
pub float_bar_click_through: Option<bool>,
pub float_bar_provider_ids: Option<Vec<String>>,
Expand Down Expand Up @@ -283,6 +284,7 @@ impl SettingsUpdate {
style: self.float_bar_style.clone(),
open_on_hover: self.taskbar_widget_open_on_hover,
density: self.float_bar_density.clone(),
information_mode: self.float_bar_information_mode.clone(),
contrast: self.float_bar_contrast.clone(),
click_through: self.float_bar_click_through,
provider_ids: self.float_bar_provider_ids.clone(),
Expand Down
8 changes: 8 additions & 0 deletions apps/desktop-tauri/src-tauri/src/commands/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,14 @@ pub fn play_notification_sound() -> Result<(), String> {
Ok(())
}

/// Show a real Windows toast on demand so the user can confirm notifications
/// are delivered on their machine. Runs the full toast pipeline synchronously
/// and surfaces any failure back to the Settings button.
#[tauri::command]
pub fn send_test_notification() -> Result<(), String> {
codexbar::notifications::send_test_notification()
}

/// Reposition the flyout window so its bottom-right corner stays anchored to
/// the system-tray area. Called from the frontend after dynamic resize.
///
Expand Down
Loading
Loading