refactor(multi-account): remove legacy migration code
Migration from single-account files didn't work reliably. Removed migrateFromLegacyFiles() and migrateAndLoadAccounts(). Account list now populated only via saveCurrentAccount/saveBunkerAccount when user logs in — no automatic migration from old format. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -663,8 +663,8 @@ fun App(
|
||||
subscriptionsCoordinator.start()
|
||||
|
||||
scope.launch(Dispatchers.IO) {
|
||||
// Migrate legacy single-account files and load account list
|
||||
accountManager.migrateAndLoadAccounts()
|
||||
// Load account list from encrypted storage
|
||||
accountManager.refreshAccountListOnStartup()
|
||||
|
||||
if (accountManager.hasBunkerAccount()) {
|
||||
// Show connecting UI while dedicated NIP-46 client connects
|
||||
|
||||
+1
-2
@@ -713,8 +713,7 @@ class AccountManager internal constructor(
|
||||
disconnectNip46Client()
|
||||
}
|
||||
|
||||
suspend fun migrateAndLoadAccounts() {
|
||||
accountStorage.migrateFromLegacyFiles(this)
|
||||
suspend fun refreshAccountListOnStartup() {
|
||||
refreshAccountList()
|
||||
}
|
||||
|
||||
|
||||
-49
@@ -92,55 +92,6 @@ class DesktopAccountStorage(
|
||||
writeMetadata(metadata.copy(activeNpub = npub))
|
||||
}
|
||||
|
||||
// --- Migration from single-account files ---
|
||||
|
||||
suspend fun migrateFromLegacyFiles(accountManager: AccountManager): Boolean {
|
||||
val prefsFile = File(amethystDir, "last_account.txt")
|
||||
val bunkerFile = File(amethystDir, "bunker_uri.txt")
|
||||
|
||||
if (!prefsFile.exists() && !bunkerFile.exists()) return false
|
||||
if (getAccountsFile().exists()) return false // already migrated
|
||||
|
||||
val npub =
|
||||
prefsFile
|
||||
.takeIf { it.exists() }
|
||||
?.readText()
|
||||
?.trim()
|
||||
?.takeIf { it.isNotEmpty() }
|
||||
?: return false
|
||||
|
||||
val bunkerUri =
|
||||
bunkerFile
|
||||
.takeIf { it.exists() }
|
||||
?.readText()
|
||||
?.trim()
|
||||
?.takeIf { it.isNotEmpty() }
|
||||
|
||||
val signerType =
|
||||
if (bunkerUri != null) {
|
||||
SignerType.Remote(bunkerUri)
|
||||
} else {
|
||||
val hasPrivKey = secureStorage.hasPrivateKey(npub)
|
||||
if (hasPrivKey) SignerType.Internal else SignerType.ViewOnly
|
||||
}
|
||||
|
||||
val info = AccountInfo(npub = npub, signerType = signerType)
|
||||
val metadata = AccountMetadata(accounts = listOf(AccountInfoDto.from(info)), activeNpub = npub)
|
||||
writeMetadata(metadata)
|
||||
|
||||
// Verify migration by reading back
|
||||
val verified = readMetadata()
|
||||
if (verified.accounts.any { it.npub == npub }) {
|
||||
// Migration verified — rename old files
|
||||
prefsFile.renameTo(File(amethystDir, "last_account.txt.bak"))
|
||||
bunkerFile.takeIf { it.exists() }?.renameTo(File(amethystDir, "bunker_uri.txt.bak"))
|
||||
Log.d("DesktopAccountStorage", "Migrated legacy account: $npub")
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// --- Encrypted file I/O ---
|
||||
|
||||
private suspend fun readMetadata(): AccountMetadata {
|
||||
|
||||
Reference in New Issue
Block a user