Prompt sync after migration

This commit is contained in:
thePR0M3TH3AN
2025-08-04 09:05:32 -04:00
parent 30da26f086
commit 6d110679c5
2 changed files with 37 additions and 9 deletions

View File

@@ -1158,7 +1158,7 @@ class PasswordManager:
migrated = False
try:
_, migrated = self.vault.load_index(return_migration_flag=True)
self.vault.load_index(return_migration_flag=True)
except RuntimeError as exc:
print(colored(str(exc), "red"))
sys.exit(1)
@@ -1222,8 +1222,29 @@ class PasswordManager:
delta_since=self.delta_since or None,
)
if migrated and not self.offline_mode:
self.start_background_vault_sync()
if getattr(self.encryption_manager, "last_migration_performed", False):
print(colored("Local database migration successful.", "green"))
self.encryption_manager.last_migration_performed = False
if not self.offline_mode and confirm_action(
"Do you want to sync the migrated profile to Nostr now?"
):
result = self.sync_vault()
if result:
print(
colored(
"Profile synchronized to Nostr successfully.",
"green",
)
)
else:
print(colored("Error: Failed to sync profile to Nostr.", "red"))
elif not self.offline_mode:
print(
colored(
"You can sync the migrated profile later from the main menu.",
"yellow",
)
)
logger.debug("Managers re-initialized for the new fingerprint.")

View File

@@ -105,13 +105,16 @@ def test_migration_triggers_sync(monkeypatch, tmp_path: Path):
pm.bip85 = SimpleNamespace()
calls = {"sync": 0}
pm.start_background_vault_sync = lambda *a, **k: calls.__setitem__(
"sync", calls["sync"] + 1
)
pm.sync_vault = lambda *a, **k: calls.__setitem__("sync", calls["sync"] + 1) or {
"manifest_id": "m",
"chunk_ids": [],
"delta_ids": [],
}
monkeypatch.setattr(
"seedpass.core.manager.NostrClient", lambda *a, **k: SimpleNamespace()
)
monkeypatch.setattr("seedpass.core.manager.confirm_action", lambda *_a, **_k: True)
pm.initialize_managers()
assert calls["sync"] == 1
@@ -186,9 +189,13 @@ def test_legacy_index_reinit_triggers_sync_once(monkeypatch, tmp_path: Path):
)
calls = {"sync": 0}
pm.start_background_vault_sync = lambda *a, **k: calls.__setitem__(
"sync", calls["sync"] + 1
)
pm.sync_vault = lambda *a, **k: calls.__setitem__("sync", calls["sync"] + 1) or {
"manifest_id": "m",
"chunk_ids": [],
"delta_ids": [],
}
monkeypatch.setattr("seedpass.core.manager.confirm_action", lambda *_a, **_k: True)
pm.initialize_managers()
pm.initialize_managers()