From e2eddb7189eab03186b617568c6da7adf31b3f3a Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Mon, 28 Sep 2026 15:47:09 -0300 Subject: [PATCH] desktop: add reset bunker to the app detail screen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Port the Android "Reset Bunker" (EditConfigurationScreen): the app detail screen gains a reset button that regenerates the app's local key and secret (new UUID secret, fresh local key, marked disconnected), keeps the permission rules, deletes the old record with its history, and refreshes filters — invalidating the old pairing so the app must reconnect with the new connection string, which the connection string section then shows. A confirm dialog explains the consequence before anything is replaced (Android resets directly); like Android, the screen returns to the Applications list afterwards. The reset_bunker label reuses the translations bundled from the Android strings; the confirm message is translated in all 14 locales. --- .../desktop/ui/ApplicationDetailScreen.kt | 93 +++++++++++++++++++ .../src/main/resources/i18n/strings_de.xml | 3 + .../src/main/resources/i18n/strings_en.xml | 3 + .../src/main/resources/i18n/strings_es.xml | 3 + .../src/main/resources/i18n/strings_fr.xml | 3 + .../src/main/resources/i18n/strings_in.xml | 3 + .../src/main/resources/i18n/strings_it.xml | 3 + .../src/main/resources/i18n/strings_ja.xml | 3 + .../src/main/resources/i18n/strings_ko.xml | 3 + .../src/main/resources/i18n/strings_pt-BR.xml | 3 + .../src/main/resources/i18n/strings_ru.xml | 3 + .../src/main/resources/i18n/strings_th.xml | 3 + .../src/main/resources/i18n/strings_tr.xml | 3 + .../src/main/resources/i18n/strings_vi.xml | 3 + .../src/main/resources/i18n/strings_zh.xml | 3 + 15 files changed, 135 insertions(+) diff --git a/desktop/src/main/kotlin/com/greenart7c3/nostrsigner/desktop/ui/ApplicationDetailScreen.kt b/desktop/src/main/kotlin/com/greenart7c3/nostrsigner/desktop/ui/ApplicationDetailScreen.kt index 10e901ec..34effc95 100644 --- a/desktop/src/main/kotlin/com/greenart7c3/nostrsigner/desktop/ui/ApplicationDetailScreen.kt +++ b/desktop/src/main/kotlin/com/greenart7c3/nostrsigner/desktop/ui/ApplicationDetailScreen.kt @@ -30,20 +30,28 @@ import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalClipboardManager +import androidx.compose.ui.text.AnnotatedString +import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import com.greenart7c3.nostrsigner.desktop.core.AmberDesktop import com.greenart7c3.nostrsigner.desktop.core.AppPermissionRecord +import com.greenart7c3.nostrsigner.desktop.core.AppWithPermissions import com.greenart7c3.nostrsigner.desktop.core.DesktopAccount import com.greenart7c3.nostrsigner.desktop.core.RememberType import com.greenart7c3.nostrsigner.desktop.core.SignerDescriptions import com.greenart7c3.nostrsigner.desktop.core.Strings +import com.greenart7c3.nostrsigner.desktop.core.generateBunkerPrivKey +import com.greenart7c3.nostrsigner.desktop.core.localPubKeyFromPrivKey import com.greenart7c3.nostrsigner.desktop.core.toShortenHex import java.text.DateFormat import java.util.Date +import java.util.UUID import kotlinx.coroutines.launch @Composable @@ -56,6 +64,7 @@ fun ApplicationDetailScreen( val apps by store.apps.collectAsState() val history by store.history.collectAsState() val language by Strings.currentLanguage.collectAsState() + val scope = rememberCoroutineScope() val app = apps.firstOrNull { it.app.key == appKey } var tab by remember { mutableStateOf(0) } @@ -114,6 +123,90 @@ fun ApplicationDetailScreen( ) Spacer(Modifier.height(8.dp)) + // Mirrors the Android app-detail connection string (EditPermission): + // the bunker:// URI the client app can re-paste to reconnect. + val connectionPubKey = if (app.app.localKey.isNotEmpty()) { + localPubKeyFromPrivKey(app.app.localKey) + } else { + account.hexKey + } + val bunkerUri = remember(connectionPubKey, app.app.relays, app.app.useSecret, app.app.secret) { + val relayParams = app.app.relays.joinToString(separator = "&") { "relay=$it" } + val localSecret = if (app.app.useSecret) "&secret=${app.app.secret}" else "" + "bunker://$connectionPubKey?$relayParams$localSecret" + } + val clipboard = LocalClipboardManager.current + Spacer(Modifier.height(16.dp)) + Text(Strings.get("d_connection_string", language), style = MaterialTheme.typography.titleSmall) + Spacer(Modifier.height(4.dp)) + Text( + bunkerUri, + style = MaterialTheme.typography.bodySmall, + fontFamily = FontFamily.Monospace, + modifier = Modifier + .fillMaxWidth() + .border(BorderStroke(1.dp, MaterialTheme.colorScheme.outlineVariant), RoundedCornerShape(8.dp)) + .padding(8.dp), + ) + AmberTextButton( + text = Strings.get("copy", language).trim(), + onClick = { + clipboard.setText(AnnotatedString(bunkerUri)) + Toaster.toast(Strings.get("d_connection_string_copied", language)) + }, + ) + Spacer(Modifier.height(12.dp)) + + // Mirrors the Android "Reset Bunker" (EditConfigurationScreen): a new + // key and secret invalidate the old pairing; permission rules stay. + var showResetBunker by remember { mutableStateOf(false) } + if (showResetBunker) { + AlertDialog( + onDismissRequest = { showResetBunker = false }, + title = { Text(Strings.get("reset_bunker", language)) }, + text = { Text(Strings.get("d_reset_bunker_message", language)) }, + confirmButton = { + AmberTextButton( + text = Strings.get("reset_bunker", language), + onClick = { + showResetBunker = false + val oldKey = app.app.key + val newSecret = UUID.randomUUID().toString() + store.upsert( + AppWithPermissions( + app = app.app.copy( + key = newSecret, + isConnected = false, + secret = newSecret, + useSecret = true, + localKey = generateBunkerPrivKey(), + ), + permissions = app.permissions, + ), + ) + store.delete(oldKey) + scope.launch { + AmberDesktop.engine.updateFilter() + AmberDesktop.client.connect() + } + Toaster.toast(Strings.get("d_saved", language)) + }, + ) + }, + dismissButton = { + AmberTextButton( + text = Strings.get("cancel", language), + onClick = { showResetBunker = false }, + ) + }, + ) + } + AmberOutlinedButton( + text = Strings.get("reset_bunker", language), + onClick = { showResetBunker = true }, + ) + Spacer(Modifier.height(12.dp)) + var showRemoveAll by remember { mutableStateOf(false) } if (showRemoveAll) { AlertDialog( diff --git a/desktop/src/main/resources/i18n/strings_de.xml b/desktop/src/main/resources/i18n/strings_de.xml index 67a92653..f3e39f7d 100644 --- a/desktop/src/main/resources/i18n/strings_de.xml +++ b/desktop/src/main/resources/i18n/strings_de.xml @@ -52,6 +52,7 @@ Berechtigungen Anwendung löschen Bunker zurücksetzen + Dadurch werden ein neuer Schlüssel und ein neues Secret für diese App erzeugt. Die Berechtigungsregeln bleiben erhalten, aber die App muss sich mit dem neuen Verbindungs-String neu verbinden. In Zwischenablage kopieren Noch nichts zu genehmigen Warum nicht deine Lieblings-Nostr-App ein wenig erkunden? @@ -810,6 +811,8 @@ Seed-Wörter Anzeigen nsec kopieren + Verbindungs-String + In die Zwischenablage kopiert Geheimer Schlüssel kopiert. Leere deine Zwischenablage nach dem Einfügen! Verschlüsselte Sicherung (ncryptsec) Passwort diff --git a/desktop/src/main/resources/i18n/strings_en.xml b/desktop/src/main/resources/i18n/strings_en.xml index 3b5d0c24..ae8dc226 100644 --- a/desktop/src/main/resources/i18n/strings_en.xml +++ b/desktop/src/main/resources/i18n/strings_en.xml @@ -77,6 +77,7 @@ Permissions Delete Application Reset Bunker + This generates a new key and secret for this app. Its permission rules are kept, but the app must reconnect with the new connection string. Copy to clipboard Nothing to approve yet Why not explore your favorite nostr app a bit? @@ -821,6 +822,8 @@ Seed words Show Copy nsec + Connection string + Copied to clipboard Secret key copied. Clear your clipboard after pasting it! Encrypted backup (ncryptsec) Password diff --git a/desktop/src/main/resources/i18n/strings_es.xml b/desktop/src/main/resources/i18n/strings_es.xml index 9141827d..a5a3cdcb 100644 --- a/desktop/src/main/resources/i18n/strings_es.xml +++ b/desktop/src/main/resources/i18n/strings_es.xml @@ -54,6 +54,7 @@ Permisos Eliminar aplicación Restablecer Bunker + Esto genera una nueva clave y un nuevo secreto para esta aplicación. Sus reglas de permisos se conservan, pero la aplicación deberá reconectarse con la nueva cadena de conexión. Copiar al portapapeles Nada que aprobar aún ¿Por qué no explorar un poco tu app favorita de nostr? @@ -813,6 +814,8 @@ Palabras semilla Mostrar Copiar nsec + Cadena de conexión + Copiado al portapapeles Clave secreta copiada. ¡Borra el portapapeles después de pegarla! Copia de seguridad cifrada (ncryptsec) Contraseña diff --git a/desktop/src/main/resources/i18n/strings_fr.xml b/desktop/src/main/resources/i18n/strings_fr.xml index 894e0195..519784cd 100644 --- a/desktop/src/main/resources/i18n/strings_fr.xml +++ b/desktop/src/main/resources/i18n/strings_fr.xml @@ -52,6 +52,7 @@ Autorisations Supprimer l\'application Réinitialiser le Bunker + Cette action génère une nouvelle clé et un nouveau secret pour cette application. Ses règles d'autorisation sont conservées, mais l'application devra se reconnecter avec la nouvelle chaîne de connexion. Copier dans le presse-papiers Rien à approuver pour l\'instant Pourquoi ne pas explorer un peu votre application Nostr préférée ? @@ -810,6 +811,8 @@ Mots de récupération Afficher Copier la nsec + Chaîne de connexion + Copié dans le presse-papiers Clé secrète copiée. Videz votre presse-papiers après l'avoir collée ! Sauvegarde chiffrée (ncryptsec) Mot de passe diff --git a/desktop/src/main/resources/i18n/strings_in.xml b/desktop/src/main/resources/i18n/strings_in.xml index e58ce04b..d95462f0 100644 --- a/desktop/src/main/resources/i18n/strings_in.xml +++ b/desktop/src/main/resources/i18n/strings_in.xml @@ -54,6 +54,7 @@ Izin Hapus Aplikasi Atur Ulang Bunker + Ini menghasilkan kunci dan rahasia baru untuk aplikasi ini. Aturan izinnya dipertahankan, tetapi aplikasi harus tersambung kembali dengan string koneksi yang baru. Salin ke clipboard Belum ada yang perlu disetujui Mengapa tidak menjelajahi aplikasi nostr favorit Anda sebentar? @@ -813,6 +814,8 @@ Kata benih Tampilkan Salin nsec + String koneksi + Disalin ke papan klip Kunci rahasia disalin. Bersihkan papan klip setelah menempelkannya! Cadangan terenkripsi (ncryptsec) Kata sandi diff --git a/desktop/src/main/resources/i18n/strings_it.xml b/desktop/src/main/resources/i18n/strings_it.xml index 69bcf238..f4411c2b 100644 --- a/desktop/src/main/resources/i18n/strings_it.xml +++ b/desktop/src/main/resources/i18n/strings_it.xml @@ -54,6 +54,7 @@ Permessi Elimina applicazione Reimposta Bunker + Questo genera una nuova chiave e un nuovo segreto per questa app. Le regole di permesso vengono conservate, ma l'app deve riconnettersi con la nuova stringa di connessione. Copia negli appunti Niente da approvare per ora Perché non esplori un po\' la tua app Nostr preferita? @@ -813,6 +814,8 @@ Seed words Mostra Copia nsec + Stringa di connessione + Copiato negli appunti Chiave segreta copiata. Svuota gli appunti dopo averla incollata! Backup cifrato (ncryptsec) Password diff --git a/desktop/src/main/resources/i18n/strings_ja.xml b/desktop/src/main/resources/i18n/strings_ja.xml index c3cf0371..77793868 100644 --- a/desktop/src/main/resources/i18n/strings_ja.xml +++ b/desktop/src/main/resources/i18n/strings_ja.xml @@ -45,6 +45,7 @@ 権限 アプリケーションを削除 Bunker をリセット + このアプリの新しい鍵とシークレットを生成します。権限ルールは保持されますが、アプリは新しい接続文字列で再接続する必要があります。 クリップボードにコピー まだ承認するものはありません お気に入りの Nostr アプリを少し探索してみませんか? @@ -789,6 +790,8 @@ シードワード 表示 nsec をコピー + 接続文字列 + クリップボードにコピーしました 秘密鍵をコピーしました。貼り付けた後はクリップボードを消去してください! 暗号化バックアップ (ncryptsec) パスワード diff --git a/desktop/src/main/resources/i18n/strings_ko.xml b/desktop/src/main/resources/i18n/strings_ko.xml index b5f7e4d2..91607c5a 100644 --- a/desktop/src/main/resources/i18n/strings_ko.xml +++ b/desktop/src/main/resources/i18n/strings_ko.xml @@ -54,6 +54,7 @@ 권한 애플리케이션 삭제 Bunker 초기화 + 이 앱의 새 키와 시크릿을 생성합니다. 권한 규칙은 유지되지만 앱은 새 연결 문자열로 다시 연결해야 합니다. 클립보드에 복사 아직 승인할 항목이 없습니다 즐겨 사용하는 Nostr 앱을 조금 더 탐색해 보세요. @@ -813,6 +814,8 @@ 시드 단어 표시 nsec 복사 + 연결 문자열 + 클립보드에 복사되었습니다 비밀 키가 복사되었습니다. 붙여넣은 후 클립보드를 지우세요! 암호화된 백업 (ncryptsec) 비밀번호 diff --git a/desktop/src/main/resources/i18n/strings_pt-BR.xml b/desktop/src/main/resources/i18n/strings_pt-BR.xml index c33a73b9..41798ba4 100644 --- a/desktop/src/main/resources/i18n/strings_pt-BR.xml +++ b/desktop/src/main/resources/i18n/strings_pt-BR.xml @@ -50,6 +50,7 @@ Permissões Excluir aplicativo Redefinir Bunker + Isso gera uma nova chave e um novo segredo para este aplicativo. As regras de permissão são mantidas, mas o aplicativo precisa reconectar com a nova string de conexão. Copiar para área de transferência Nada para aprovar ainda Por que não explorar um pouco seu aplicativo nostr favorito? @@ -808,6 +809,8 @@ Palavras-semente Mostrar Copiar nsec + String de conexão + Copiado para a área de transferência Chave secreta copiada. Limpe sua área de transferência depois de colá-la! Backup criptografado (ncryptsec) Senha diff --git a/desktop/src/main/resources/i18n/strings_ru.xml b/desktop/src/main/resources/i18n/strings_ru.xml index 4aedb9f3..a0ce206b 100644 --- a/desktop/src/main/resources/i18n/strings_ru.xml +++ b/desktop/src/main/resources/i18n/strings_ru.xml @@ -54,6 +54,7 @@ Разрешения Удалить приложение Сбросить Bunker + Будут созданы новый ключ и секрет для этого приложения. Правила разрешений сохранятся, но приложению потребуется переподключиться с новой строкой подключения. Копировать в буфер обмена Пока нечего подтверждать Почему бы немного не изучить ваше любимое Nostr-приложение? @@ -813,6 +814,8 @@ Сид-слова Показать Копировать nsec + Строка подключения + Скопировано в буфер обмена Секретный ключ скопирован. Очистите буфер обмена после вставки! Зашифрованная резервная копия (ncryptsec) Пароль diff --git a/desktop/src/main/resources/i18n/strings_th.xml b/desktop/src/main/resources/i18n/strings_th.xml index 7d30039e..ca2880c5 100644 --- a/desktop/src/main/resources/i18n/strings_th.xml +++ b/desktop/src/main/resources/i18n/strings_th.xml @@ -45,6 +45,7 @@ สิทธิ์ ลบแอปพลิเคชัน รีเซ็ต Bunker + การกระทำนี้จะสร้างกุญแจและรหัสลับใหม่ให้แอปนี้ กฎการอนุญาตจะยังคงอยู่ แต่แอปจะต้องเชื่อมต่อใหม่ด้วยสตริงการเชื่อมต่อใหม่ คัดลอกไปยังคลิปบอร์ด ยังไม่มีรายการที่ต้องอนุมัติ ลองสำรวจแอป Nostr ที่คุณชื่นชอบสักหน่อยดีไหม? @@ -789,6 +790,8 @@ คำกู้คืน แสดง คัดลอก nsec + สตริงการเชื่อมต่อ + คัดลอกไปยังคลิปบอร์ดแล้ว คัดลอกกุญแจลับแล้ว ล้างคลิปบอร์ดของคุณหลังจากวางเสร็จ! ข้อมูลสำรองที่เข้ารหัส (ncryptsec) รหัสผ่าน diff --git a/desktop/src/main/resources/i18n/strings_tr.xml b/desktop/src/main/resources/i18n/strings_tr.xml index c27ca87b..2346c881 100644 --- a/desktop/src/main/resources/i18n/strings_tr.xml +++ b/desktop/src/main/resources/i18n/strings_tr.xml @@ -52,6 +52,7 @@ İzinler Uygulamayı Sil Bunker\'ı Sıfırla + Bu, uygulama için yeni bir anahtar ve gizli anahtar oluşturur. İzin kuralları korunur ancak uygulamanın yeni bağlantı dizesiyle yeniden bağlanması gerekir. Panoya kopyala Henüz onaylanacak bir şey yok Neden favori Nostr uygulamanızı biraz keşfetmiyorsunuz? @@ -809,6 +810,8 @@ Tohum kelimeleri Göster nsec'i kopyala + Bağlantı dizesi + Panoya kopyalandı Gizli anahtar kopyalandı. Yapıştırdıktan sonra panonuzu temizleyin! Şifreli yedek (ncryptsec) Parola diff --git a/desktop/src/main/resources/i18n/strings_vi.xml b/desktop/src/main/resources/i18n/strings_vi.xml index 59d0bbfa..9fedbbe8 100644 --- a/desktop/src/main/resources/i18n/strings_vi.xml +++ b/desktop/src/main/resources/i18n/strings_vi.xml @@ -45,6 +45,7 @@ Quyền Xóa Ứng Dụng Đặt lại Bunker + Thao tác này sẽ tạo khóa và bí mật mới cho ứng dụng này. Các quy tắc quyền được giữ nguyên, nhưng ứng dụng phải kết nối lại bằng chuỗi kết nối mới. Sao chép vào khay nhớ tạm Chưa có gì để phê duyệt Tại sao không khám phá ứng dụng Nostr yêu thích của bạn một chút? @@ -789,6 +790,8 @@ Các từ khôi phục Hiện Sao chép nsec + Chuỗi kết nối + Đã sao chép vào bộ nhớ tạm Đã sao chép khóa bí mật. Hãy xóa bộ nhớ tạm sau khi dán! Bản sao lưu đã mã hóa (ncryptsec) Mật khẩu diff --git a/desktop/src/main/resources/i18n/strings_zh.xml b/desktop/src/main/resources/i18n/strings_zh.xml index a0f38b96..f6196a3c 100644 --- a/desktop/src/main/resources/i18n/strings_zh.xml +++ b/desktop/src/main/resources/i18n/strings_zh.xml @@ -50,6 +50,7 @@ 权限 删除应用 重置 Bunker + 将为该应用生成新的密钥和秘密。权限规则会保留,但该应用需要使用新的连接字符串重新连接。 复制到剪贴板 暂无批复请求 为什么不去探索一下你喜欢的 Nostr 应用呢? @@ -794,6 +795,8 @@ 助记词 显示 复制 nsec + 连接字符串 + 已复制到剪贴板 私钥已复制。粘贴后请清除剪贴板! 加密备份(ncryptsec) 密码