Skip to content
Closed
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
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@tanstack/react-virtual": "^3.13.18",
"@tauri-apps/api": "^2",
"@tauri-apps/plugin-dialog": "^2",
"@tauri-apps/plugin-notification": "^2.3.3",
"@tauri-apps/plugin-opener": "^2",
"@tauri-apps/plugin-process": "^2.3.1",
"@tauri-apps/plugin-updater": "^2.9.0",
Expand Down
70 changes: 69 additions & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tauri-build = { version = "2", features = [] }
tauri = { version = "2", features = ["macos-private-api"] }
tauri-plugin-opener = "2"
tauri-plugin-process = "2"
tauri-plugin-notification = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = { version = "1", features = ["fs", "net", "io-util", "process", "rt", "sync", "time"] }
Expand All @@ -40,3 +41,6 @@ chrono = { version = "0.4", features = ["clock"] }

[target."cfg(not(any(target_os = \"android\", target_os = \"ios\")))".dependencies]
tauri-plugin-updater = "2"

[target."cfg(target_os = \"macos\")".dependencies]
mac-notification-sys = "0.6"
3 changes: 2 additions & 1 deletion src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dialog:default",
"process:default",
"updater:default",
"core:window:allow-start-dragging"
"core:window:allow-start-dragging",
"notification:default"
]
}
4 changes: 4 additions & 0 deletions src-tauri/src/bin/codex_monitor_daemon.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#[path = "../backend/mod.rs"]
#[allow(dead_code)]
mod backend;
#[path = "../codex_config.rs"]
mod codex_config;
#[path = "../storage.rs"]
mod storage;
#[path = "../types.rs"]
#[allow(dead_code)]
mod types;

use serde_json::{json, Map, Value};
Expand Down Expand Up @@ -35,6 +37,7 @@ struct DaemonEventSink {
tx: broadcast::Sender<DaemonEvent>,
}

#[allow(dead_code)]
#[derive(Clone)]
enum DaemonEvent {
AppServer(AppServerEvent),
Expand Down Expand Up @@ -1060,6 +1063,7 @@ fn parse_optional_u32(value: &Value, key: &str) -> Option<u32> {
}
}

#[allow(dead_code)]
fn parse_optional_bool(value: &Value, key: &str) -> Option<bool> {
match value {
Value::Object(map) => map.get(key).and_then(|value| value.as_bool()),
Expand Down
3 changes: 3 additions & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod event_sink;
mod git;
mod git_utils;
mod local_usage;
mod notifications;
mod prompts;
mod settings;
mod state;
Expand Down Expand Up @@ -216,6 +217,7 @@ pub fn run() {
.plugin(tauri_plugin_opener::init())
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_process::init())
.plugin(tauri_plugin_notification::init())
.invoke_handler(tauri::generate_handler![
settings::get_app_settings,
settings::update_app_settings,
Expand Down Expand Up @@ -266,6 +268,7 @@ pub fn run() {
prompts::prompts_move,
prompts::prompts_workspace_dir,
prompts::prompts_global_dir,
notifications::send_native_notification,
terminal::terminal_open,
terminal::terminal_write,
terminal::terminal_resize,
Expand Down
104 changes: 104 additions & 0 deletions src-tauri/src/notifications.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
use serde::{Deserialize, Serialize};
use std::sync::atomic::{AtomicBool, Ordering};
use tauri::{AppHandle, Emitter, Manager};

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NativeNotificationPayload {
pub title: String,
pub body: Option<String>,
pub workspace_id: String,
pub thread_id: Option<String>,
pub kind: String,
}

#[derive(Debug, Serialize, Clone)]
#[serde(rename_all = "camelCase")]
struct NotificationClickEvent {
workspace_id: String,
thread_id: Option<String>,
kind: String,
}

#[cfg(target_os = "macos")]
static WAITING_FOR_CLICK: AtomicBool = AtomicBool::new(false);

#[cfg(target_os = "macos")]
fn emit_notification_click(app: &AppHandle, payload: NotificationClickEvent) {
if let Some(window) = app.get_webview_window("main") {
let _ = window.show();
let _ = window.set_focus();
}
let _ = app.emit("notification-clicked", payload);
}

#[cfg(target_os = "macos")]
fn resolve_bundle_id(app: &AppHandle) -> String {
if tauri::is_dev() {
"com.apple.Terminal".to_string()
} else {
app.config().identifier.clone()
}
}

#[cfg(target_os = "macos")]
#[tauri::command]
pub async fn send_native_notification(
app: AppHandle,
payload: NativeNotificationPayload,
) -> Result<bool, String> {
if WAITING_FOR_CLICK
.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst)
.is_err()
{
return Ok(false);
}
let app_handle = app.clone();

tauri::async_runtime::spawn_blocking(move || {
let title = payload.title;
let body = payload.body.unwrap_or_default();
let workspace_id = payload.workspace_id;
let thread_id = payload.thread_id;
let kind = payload.kind;

let mut notification = mac_notification_sys::Notification::new();
notification.title(&title);
notification.message(&body);
notification.wait_for_click(true);

let bundle_id = resolve_bundle_id(&app_handle);
let _ = mac_notification_sys::set_application(&bundle_id);

match notification.send() {
Ok(response) => match response {
mac_notification_sys::NotificationResponse::Click
| mac_notification_sys::NotificationResponse::ActionButton(_)
| mac_notification_sys::NotificationResponse::Reply(_) => {
emit_notification_click(
&app_handle,
NotificationClickEvent {
workspace_id,
thread_id,
kind,
},
);
}
_ => {}
},
Err(_) => {}
}
WAITING_FOR_CLICK.store(false, Ordering::SeqCst);
});

Ok(true)
}

#[cfg(not(target_os = "macos"))]
#[tauri::command]
pub async fn send_native_notification(
_app: AppHandle,
_payload: NativeNotificationPayload,
) -> Result<bool, String> {
Ok(false)
}
11 changes: 11 additions & 0 deletions src-tauri/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ pub(crate) struct AppSettings {
rename = "notificationSoundsEnabled"
)]
pub(crate) notification_sounds_enabled: bool,
#[serde(
default = "default_notification_push_enabled",
rename = "notificationPushEnabled"
)]
pub(crate) notification_push_enabled: bool,
#[serde(
default = "default_experimental_collab_enabled",
rename = "experimentalCollabEnabled"
Expand Down Expand Up @@ -339,6 +344,10 @@ fn default_notification_sounds_enabled() -> bool {
true
}

fn default_notification_push_enabled() -> bool {
true
}

fn default_experimental_collab_enabled() -> bool {
false
}
Expand Down Expand Up @@ -382,6 +391,7 @@ impl Default for AppSettings {
last_composer_reasoning_effort: None,
ui_scale: 1.0,
notification_sounds_enabled: true,
notification_push_enabled: true,
experimental_collab_enabled: false,
experimental_steer_enabled: false,
experimental_unified_exec_enabled: false,
Expand Down Expand Up @@ -422,6 +432,7 @@ mod tests {
assert!(settings.last_composer_reasoning_effort.is_none());
assert!((settings.ui_scale - 1.0).abs() < f64::EPSILON);
assert!(settings.notification_sounds_enabled);
assert!(settings.notification_push_enabled);
assert!(!settings.experimental_steer_enabled);
assert!(!settings.dictation_enabled);
assert_eq!(settings.dictation_model_id, "base");
Expand Down
Loading