Use background sync when quick unlock

This commit is contained in:
thePR0M3TH3AN
2025-07-13 15:27:24 -04:00
parent 540b33da0e
commit 8350504d00
2 changed files with 56 additions and 4 deletions

View File

@@ -530,7 +530,13 @@ class PasswordManager:
# Initialize BIP85 and other managers
self.initialize_bip85()
self.initialize_managers()
self.sync_index_from_nostr()
if (
getattr(self, "config_manager", None)
and self.config_manager.get_quick_unlock()
):
self.start_background_sync()
else:
self.sync_index_from_nostr()
print(colored(f"Switched to seed profile {selected_fingerprint}.", "green"))
# Re-initialize NostrClient with the new fingerprint
@@ -603,7 +609,13 @@ class PasswordManager:
self.initialize_managers()
self.locked = False
self.update_activity()
self.sync_index_from_nostr()
if (
getattr(self, "config_manager", None)
and self.config_manager.get_quick_unlock()
):
self.start_background_sync()
else:
self.sync_index_from_nostr()
def handle_existing_seed(self) -> None:
"""
@@ -775,7 +787,13 @@ class PasswordManager:
self.initialize_bip85()
self.initialize_managers()
self.sync_index_from_nostr()
if (
getattr(self, "config_manager", None)
and self.config_manager.get_quick_unlock()
):
self.start_background_sync()
else:
self.sync_index_from_nostr()
return fingerprint # Return the generated or added fingerprint
except BaseException:
# Clean up partial profile on failure or interruption
@@ -930,7 +948,13 @@ class PasswordManager:
self.initialize_bip85()
self.initialize_managers()
self.sync_index_from_nostr()
if (
getattr(self, "config_manager", None)
and self.config_manager.get_quick_unlock()
):
self.start_background_sync()
else:
self.sync_index_from_nostr()
except Exception as e:
logging.error(f"Failed to encrypt and save parent seed: {e}", exc_info=True)
print(colored(f"Error: Failed to encrypt and save parent seed: {e}", "red"))

View File

@@ -6,6 +6,7 @@ import sys
sys.path.append(str(Path(__file__).resolve().parents[1]))
from password_manager.manager import PasswordManager
from password_manager import manager as manager_module
def test_unlock_triggers_sync(monkeypatch, tmp_path):
@@ -26,3 +27,30 @@ def test_unlock_triggers_sync(monkeypatch, tmp_path):
time.sleep(0.05)
assert called["sync"]
def test_quick_unlock_background_sync(monkeypatch, tmp_path):
pm = PasswordManager.__new__(PasswordManager)
pm.profile_stack = [("rootfp", tmp_path, "seed")]
pm.config_manager = SimpleNamespace(get_quick_unlock=lambda: True)
monkeypatch.setattr(manager_module, "derive_index_key", lambda s: b"k")
monkeypatch.setattr(
manager_module, "EncryptionManager", lambda *a, **k: SimpleNamespace()
)
monkeypatch.setattr(manager_module, "Vault", lambda *a, **k: SimpleNamespace())
pm.initialize_bip85 = lambda: None
pm.initialize_managers = lambda: None
pm.update_activity = lambda: None
called = {"bg": False}
def fake_bg():
called["bg"] = True
pm.start_background_sync = fake_bg
pm.exit_managed_account()
assert called["bg"]