add passphrase dialog
This commit is contained in:
@@ -7,12 +7,14 @@ use gpui_component::{ActiveTheme, Root, StyledExt, TitleBar, h_flex, v_flex};
|
||||
use signed_state::{Backend, BackendEvent};
|
||||
|
||||
use crate::views::SidebarPanel;
|
||||
use crate::views::sidebar::passphrase_dialog;
|
||||
|
||||
/// Root view of the app: title bar, dock area, status bar.
|
||||
pub struct Workspace {
|
||||
dock: Entity<DockArea>,
|
||||
status: SharedString,
|
||||
_subscription: Subscription,
|
||||
_passphrase_subscription: Subscription,
|
||||
}
|
||||
|
||||
impl Workspace {
|
||||
@@ -59,10 +61,28 @@ impl Workspace {
|
||||
cx.notify();
|
||||
});
|
||||
|
||||
// Ask for the passphrase when the stored identity is NIP-49
|
||||
// encrypted. Subscribed via the window, since opening a dialog
|
||||
// needs one.
|
||||
let passphrase_subscription =
|
||||
window.subscribe(&backend, cx, |_backend, event, window, cx| {
|
||||
if matches!(event, BackendEvent::PassphraseRequired) {
|
||||
passphrase_dialog::open(window, cx);
|
||||
}
|
||||
});
|
||||
|
||||
// The event may have fired before this window existed (the backend
|
||||
// is initialized before the first window opens); fall back to the
|
||||
// backend state in that case.
|
||||
if backend.read(cx).passphrase_required() {
|
||||
passphrase_dialog::open(window, cx);
|
||||
}
|
||||
|
||||
Self {
|
||||
dock,
|
||||
status,
|
||||
_subscription: subscription,
|
||||
_passphrase_subscription: passphrase_subscription,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user