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
31 changes: 30 additions & 1 deletion src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,35 @@ fn secret_delete(key: String) -> Result<(), String> {
}
}

/// Save a newly generated recovery key as a text file in the user's Downloads folder (never
/// overwriting an existing file) and return its path. The file is readable by the user only.
#[tauri::command]
fn save_recovery_key(app: tauri::AppHandle, contents: String) -> Result<String, String> {
use std::io::Write;
use tauri::Manager;
let dir = app.path().download_dir().map_err(|e| e.to_string())?;
for n in 0..100 {
let name = if n == 0 { "murmrchat-recovery-key.txt".to_string() } else { format!("murmrchat-recovery-key-{n}.txt") };
let path = dir.join(name);
let mut opts = std::fs::OpenOptions::new();
opts.write(true).create_new(true);
#[cfg(unix)]
{
use std::os::unix::fs::OpenOptionsExt;
opts.mode(0o600);
}
match opts.open(&path) {
Ok(mut f) => {
f.write_all(contents.as_bytes()).map_err(|e| e.to_string())?;
return Ok(path.to_string_lossy().into_owned());
}
Err(e) if e.kind() == std::io::ErrorKind::AlreadyExists => continue,
Err(e) => return Err(e.to_string()),
}
}
Err("Could not find a free file name in Downloads".into())
}

/// Write a diagnostic line from the web UI to stderr (CSP violations, uncaught errors).
/// The packaged app has no visible devtools console, so this is how problems surface.
#[tauri::command]
Expand Down Expand Up @@ -172,7 +201,7 @@ pub fn run() {
.plugin(tauri_plugin_window_state::Builder::new().build())
.plugin(tauri_plugin_notification::init())
.plugin(tauri_plugin_opener::init())
.invoke_handler(tauri::generate_handler![secret_get, secret_set, secret_delete, frontend_log, set_unread])
.invoke_handler(tauri::generate_handler![secret_get, secret_set, secret_delete, save_recovery_key, frontend_log, set_unread])
.build(tauri::generate_context!())
.expect("error while building tauri application")
.run(|app, event| {
Expand Down
8 changes: 8 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ pre code { background: none; padding: 0; }
.modal { width: 480px; max-width: calc(100% - 32px); background: var(--bg); border-radius: 8px; padding: 24px; box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 8px; font-size: 18px; color: var(--text-strong); }
.modal textarea { width: 100%; margin-top: 12px; padding: 10px; border: 1px solid var(--border); border-radius: 4px; background: var(--bg); font-family: ui-monospace, Menlo, monospace; resize: vertical; }
.enc-status { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 12px 0; font-size: 14px; }
.enc-status dt { color: var(--muted); }
.enc-status dd { margin: 0; font-weight: 600; }
.enc-status dd.ok { color: var(--text-strong); }
.enc-status dd.warn { color: var(--danger); }
.recovery-key { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 16px; line-height: 1.6; word-spacing: 4px; padding: 12px 14px; margin-top: 12px; background: var(--bg-soft); border-radius: 6px; color: var(--text-strong); user-select: all; overflow-wrap: anywhere; }
.enc-note { margin-top: 8px; overflow-wrap: anywhere; }
.enc-check { display: flex; align-items: center; gap: 8px; margin-top: 16px; font-weight: 600; font-size: 13px; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(128, 128, 128, 0.35); border-radius: 4px; }
Expand Down
Loading
Loading