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
15 changes: 15 additions & 0 deletions src-tauri/Cargo.lock

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

5 changes: 4 additions & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ tauri-plugin-opener = "2"
tauri-plugin-process = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = { version = "1", features = ["io-util", "process", "rt", "sync", "time"] }
tokio = { version = "1", features = ["io-util", "process", "rt", "sync", "time", "macros"] }
uuid = { version = "1", features = ["v4"] }
tauri-plugin-dialog = "2"
git2 = "0.20.3"
fix-path-env = { git = "https://github.com/tauri-apps/fix-path-env-rs" }
ignore = "0.4.25"
portable-pty = "0.8"
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
sha2 = "0.10"
hex = "0.4"

[target."cfg(not(any(target_os = \"android\", target_os = \"ios\")))".dependencies]
tauri-plugin-updater = "2"
34 changes: 30 additions & 4 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ use tauri::{Manager, WebviewUrl, WebviewWindowBuilder};
mod backend;
mod codex;
mod event_sink;
#[cfg(desktop)]
mod telegram;
#[cfg(mobile)]
mod telegram_stub;
#[cfg(mobile)]
use telegram_stub as telegram;
mod git;
mod prompts;
mod settings;
Expand All @@ -24,7 +30,7 @@ pub fn run() {
}
}

tauri::Builder::default()
let app = tauri::Builder::default()
.enable_macos_default_menu(false)
.menu(|handle| {
let app_name = handle.package_info().name.clone();
Expand Down Expand Up @@ -127,6 +133,7 @@ pub fn run() {
.setup(|app| {
let state = state::AppState::load(&app.handle());
app.manage(state);
telegram::start_telegram_poller(app.handle().clone());
#[cfg(desktop)]
app.handle()
.plugin(tauri_plugin_updater::Builder::new().build())?;
Expand Down Expand Up @@ -171,8 +178,27 @@ pub fn run() {
terminal::terminal_open,
terminal::terminal_write,
terminal::terminal_resize,
terminal::terminal_close
terminal::terminal_close,
telegram::telegram_bot_status
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
.build(tauri::generate_context!())
.expect("error while building tauri application");

#[cfg(desktop)]
let exit_notified = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
#[cfg(desktop)]
let exit_notified_for_run = exit_notified.clone();

app.run(move |app_handle, event| {
#[cfg(desktop)]
if matches!(event, tauri::RunEvent::ExitRequested { .. }) {
use std::sync::atomic::Ordering;
if !exit_notified_for_run.swap(true, Ordering::SeqCst) {
let handle = app_handle.clone();
tauri::async_runtime::spawn(async move {
telegram::notify_app_exit(handle).await;
});
}
}
});
}
35 changes: 32 additions & 3 deletions src-tauri/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,42 @@ pub(crate) async fn get_app_settings(state: State<'_, AppState>) -> Result<AppSe
Ok(settings.clone())
}

fn merge_settings(current: &AppSettings, incoming: &AppSettings) -> AppSettings {
let mut merged = incoming.clone();

// Preserve generated secrets if a stale client sends empty values.
if merged.telegram_pairing_secret.trim().is_empty() {
merged.telegram_pairing_secret = current.telegram_pairing_secret.clone();
}

// Linking happens out-of-band (via Telegram). Make this additive so a stale UI
// snapshot can't wipe the allowlist.
if !current.telegram_allowed_user_ids.is_empty() {
let mut ids = current.telegram_allowed_user_ids.clone();
for id in &incoming.telegram_allowed_user_ids {
if !ids.contains(id) {
ids.push(*id);
}
}
merged.telegram_allowed_user_ids = ids;
}

// Default chat id is learned during linking; don't lose it if the UI sends null.
if merged.telegram_default_chat_id.is_none() {
merged.telegram_default_chat_id = current.telegram_default_chat_id;
}

merged
}

#[tauri::command]
pub(crate) async fn update_app_settings(
settings: AppSettings,
state: State<'_, AppState>,
) -> Result<AppSettings, String> {
write_settings(&state.settings_path, &settings)?;
let mut current = state.app_settings.lock().await;
*current = settings.clone();
Ok(settings)
let merged = merge_settings(&current, &settings);
write_settings(&state.settings_path, &merged)?;
*current = merged.clone();
Ok(merged)
}
15 changes: 13 additions & 2 deletions src-tauri/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use std::sync::Arc;

use tauri::{AppHandle, Manager};
use tokio::sync::Mutex;
use uuid::Uuid;

use crate::storage::{read_settings, read_workspaces};
use crate::storage::{read_settings, read_workspaces, write_settings};
use crate::types::{AppSettings, WorkspaceEntry};

pub(crate) struct AppState {
Expand All @@ -16,6 +17,9 @@ pub(crate) struct AppState {
pub(crate) storage_path: PathBuf,
pub(crate) settings_path: PathBuf,
pub(crate) app_settings: Mutex<AppSettings>,
#[cfg(desktop)]
pub(crate) telegram_tx:
Mutex<Option<tokio::sync::mpsc::UnboundedSender<crate::telegram::TelegramEvent>>>,
}

impl AppState {
Expand All @@ -27,14 +31,21 @@ impl AppState {
let storage_path = data_dir.join("workspaces.json");
let settings_path = data_dir.join("settings.json");
let workspaces = read_workspaces(&storage_path).unwrap_or_default();
let app_settings = read_settings(&settings_path).unwrap_or_default();
let mut app_settings = read_settings(&settings_path).unwrap_or_default();

if app_settings.telegram_pairing_secret.trim().is_empty() {
app_settings.telegram_pairing_secret = Uuid::new_v4().to_string();
let _ = write_settings(&settings_path, &app_settings);
}
Self {
workspaces: Mutex::new(workspaces),
sessions: Mutex::new(HashMap::new()),
terminal_sessions: Mutex::new(HashMap::new()),
storage_path,
settings_path,
app_settings: Mutex::new(app_settings),
#[cfg(desktop)]
telegram_tx: Mutex::new(None),
}
}
}
Loading