mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-05-27 02:22:23 +02:00
refactor: cleanup
This commit is contained in:
@@ -1582,7 +1582,10 @@ impl BrowserRunner {
|
||||
}
|
||||
|
||||
if profile.password_protected {
|
||||
crate::profile::password::complete_after_quit(profile);
|
||||
// Await the re-encryption so the queued sync (released later by
|
||||
// `mark_profile_stopped` in `kill_browser`) sees fresh ciphertext on
|
||||
// disk instead of the previous snapshot.
|
||||
crate::profile::password::complete_after_quit_and_wait(profile).await;
|
||||
} else if profile.ephemeral {
|
||||
crate::ephemeral_dirs::remove_ephemeral_dir(&profile.id.to_string());
|
||||
}
|
||||
@@ -1924,7 +1927,10 @@ impl BrowserRunner {
|
||||
}
|
||||
|
||||
if profile.password_protected {
|
||||
crate::profile::password::complete_after_quit(profile);
|
||||
// Await the re-encryption so the queued sync (released later by
|
||||
// `mark_profile_stopped` in `kill_browser`) sees fresh ciphertext on
|
||||
// disk instead of the previous snapshot.
|
||||
crate::profile::password::complete_after_quit_and_wait(profile).await;
|
||||
} else if profile.ephemeral {
|
||||
crate::ephemeral_dirs::remove_ephemeral_dir(&profile.id.to_string());
|
||||
}
|
||||
|
||||
+13
-7
@@ -1822,6 +1822,19 @@ pub fn run() {
|
||||
);
|
||||
}
|
||||
|
||||
// Re-encrypt password-protected profiles when the browser
|
||||
// exits naturally (user closing the window) — the explicit
|
||||
// kill path in browser_runner.rs handles app-driven stops.
|
||||
// Must run BEFORE `mark_profile_stopped` because that
|
||||
// releases any queued sync run, and a sync that picks up
|
||||
// the on-disk dir before re-encryption finishes uploads
|
||||
// the previous snapshot (issue: encrypted profiles not
|
||||
// syncing fresh data).
|
||||
if !is_running && profile.password_protected {
|
||||
crate::profile::password::complete_after_quit_and_wait(&profile)
|
||||
.await;
|
||||
}
|
||||
|
||||
// Notify sync scheduler of running state changes
|
||||
if let Some(scheduler) = sync::get_global_scheduler() {
|
||||
if is_running {
|
||||
@@ -1832,13 +1845,6 @@ pub fn run() {
|
||||
}
|
||||
}
|
||||
|
||||
// Re-encrypt password-protected profiles when the browser
|
||||
// exits naturally (user closing the window) — the explicit
|
||||
// kill path in browser_runner.rs handles app-driven stops.
|
||||
if !is_running && profile.password_protected {
|
||||
crate::profile::password::complete_after_quit(&profile);
|
||||
}
|
||||
|
||||
last_running_states.insert(profile_id, is_running);
|
||||
} else {
|
||||
// Update the state even if unchanged to ensure we have it tracked
|
||||
|
||||
@@ -637,22 +637,31 @@ pub fn complete_after_quit_blocking(
|
||||
result
|
||||
}
|
||||
|
||||
/// Async re-encrypt of a password-protected profile's ephemeral dir back to
|
||||
/// disk, called after the browser process exits. Optionally purges the
|
||||
/// ephemeral dir + cached key based on the global setting.
|
||||
pub fn complete_after_quit(profile: &crate::profile::BrowserProfile) {
|
||||
/// Re-encrypt a password-protected profile's ephemeral dir back to the
|
||||
/// on-disk encrypted dir after the browser process exits. Optionally purges
|
||||
/// the ephemeral dir + cached key based on the global setting. Returns the
|
||||
/// number of files re-encrypted (`None` when nothing to do or the profile
|
||||
/// isn't protected).
|
||||
///
|
||||
/// Callers that release a queued sync run after a browser quit MUST await
|
||||
/// this future — releasing sync while re-encryption is still in-flight
|
||||
/// uploads the stale on-disk snapshot and leaves the fresh ciphertext
|
||||
/// orphaned until the next scheduler tick.
|
||||
pub async fn complete_after_quit_and_wait(
|
||||
profile: &crate::profile::BrowserProfile,
|
||||
) -> Option<usize> {
|
||||
if !profile.password_protected {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
let keep_decrypted = read_keep_decrypted_setting();
|
||||
let profile = profile.clone();
|
||||
|
||||
tauri::async_runtime::spawn(async move {
|
||||
let _ = tokio::task::spawn_blocking(move || {
|
||||
complete_after_quit_blocking(&profile, keep_decrypted);
|
||||
tokio::task::spawn_blocking(move || complete_after_quit_blocking(&profile, keep_decrypted))
|
||||
.await
|
||||
.unwrap_or_else(|e| {
|
||||
log::error!("complete_after_quit_and_wait join error: {e}");
|
||||
None
|
||||
})
|
||||
.await;
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user