mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2025-09-08 07:18:47 +00:00
Merge pull request #506 from PR0M3TH3AN/codex/modify-passwordmanager-to-support-quick-unlock
Enable background sync when quick unlock
This commit is contained in:
@@ -530,7 +530,13 @@ class PasswordManager:
|
|||||||
# Initialize BIP85 and other managers
|
# Initialize BIP85 and other managers
|
||||||
self.initialize_bip85()
|
self.initialize_bip85()
|
||||||
self.initialize_managers()
|
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"))
|
print(colored(f"Switched to seed profile {selected_fingerprint}.", "green"))
|
||||||
|
|
||||||
# Re-initialize NostrClient with the new fingerprint
|
# Re-initialize NostrClient with the new fingerprint
|
||||||
@@ -603,7 +609,13 @@ class PasswordManager:
|
|||||||
self.initialize_managers()
|
self.initialize_managers()
|
||||||
self.locked = False
|
self.locked = False
|
||||||
self.update_activity()
|
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:
|
def handle_existing_seed(self) -> None:
|
||||||
"""
|
"""
|
||||||
@@ -775,7 +787,13 @@ class PasswordManager:
|
|||||||
|
|
||||||
self.initialize_bip85()
|
self.initialize_bip85()
|
||||||
self.initialize_managers()
|
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
|
return fingerprint # Return the generated or added fingerprint
|
||||||
except BaseException:
|
except BaseException:
|
||||||
# Clean up partial profile on failure or interruption
|
# Clean up partial profile on failure or interruption
|
||||||
@@ -930,7 +948,13 @@ class PasswordManager:
|
|||||||
|
|
||||||
self.initialize_bip85()
|
self.initialize_bip85()
|
||||||
self.initialize_managers()
|
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:
|
except Exception as e:
|
||||||
logging.error(f"Failed to encrypt and save parent seed: {e}", exc_info=True)
|
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"))
|
print(colored(f"Error: Failed to encrypt and save parent seed: {e}", "red"))
|
||||||
|
@@ -6,6 +6,7 @@ import sys
|
|||||||
sys.path.append(str(Path(__file__).resolve().parents[1]))
|
sys.path.append(str(Path(__file__).resolve().parents[1]))
|
||||||
|
|
||||||
from password_manager.manager import PasswordManager
|
from password_manager.manager import PasswordManager
|
||||||
|
from password_manager import manager as manager_module
|
||||||
|
|
||||||
|
|
||||||
def test_unlock_triggers_sync(monkeypatch, tmp_path):
|
def test_unlock_triggers_sync(monkeypatch, tmp_path):
|
||||||
@@ -26,3 +27,30 @@ def test_unlock_triggers_sync(monkeypatch, tmp_path):
|
|||||||
time.sleep(0.05)
|
time.sleep(0.05)
|
||||||
|
|
||||||
assert called["sync"]
|
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"]
|
||||||
|
Reference in New Issue
Block a user