update
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run

This commit is contained in:
2026-11-19 10:37:22 +07:00
parent c7c1d0c741
commit 2a9d42a612
29 changed files with 532 additions and 425 deletions
+40 -19
View File
@@ -6,12 +6,11 @@ use gpui::{
use signed_state::Backend;
use ui::button::Button;
use ui::common::v_flex;
use ui::dialog::Dialog;
use ui::dialog::{Dialog, DialogHandle};
use ui::field::Field;
use ui::input::{Input, InputState, InputStateEvent};
use ui::theme::{ActiveTheme as _, TextRole, Typeset as _};
use crate::shared::dialogs::close_global;
use crate::shared::progress::{DialogProgress, error_row};
#[derive(Clone, Copy, Default, PartialEq, Eq)]
@@ -56,6 +55,7 @@ pub struct ImportState {
}
pub struct ImportDialog {
handle: DialogHandle,
secret_input: Entity<InputState>,
pass_input: Entity<InputState>,
repass_input: Entity<InputState>,
@@ -65,6 +65,7 @@ pub struct ImportDialog {
impl ImportDialog {
pub fn new(cx: &mut App) -> Entity<Self> {
let handle = DialogHandle::new(true);
let state = cx.new(|_| ImportState::default());
let secret_input = InputState::new(cx);
let pass_input = InputState::builder().password().build(cx);
@@ -78,15 +79,24 @@ impl ImportDialog {
let pass_input = pass_input.clone();
let repass_input = repass_input.clone();
let state = state.clone();
let handle = handle.clone();
subscriptions.push(cx.subscribe(input, move |_this, _input, event, cx| {
if matches!(event, InputStateEvent::Submitted) {
submit(&secret_input, &pass_input, &repass_input, &state, cx);
submit(
&secret_input,
&pass_input,
&repass_input,
&state,
&handle,
cx,
);
}
}));
}
Self {
handle,
secret_input,
pass_input,
repass_input,
@@ -110,15 +120,11 @@ impl Render for ImportDialog {
let action_pass = pass_input.clone();
let action_repass = repass_input.clone();
let action_close = self.handle.clone();
Dialog::new("import-dialog")
.open(true)
.handle(self.handle.clone())
.min_width(px(520.))
.on_change(|open, _, cx| {
if !open {
close_global(cx);
}
})
.title("Import identity")
.content(move |_window, cx| {
let state = state.read(cx);
@@ -181,13 +187,14 @@ impl Render for ImportDialog {
let pass = action_pass.clone();
let repass = action_repass.clone();
let state = action_state.clone();
let handle = action_close.clone();
let import: AnyElement = Button::new("import-identity")
.label(label)
.loading(busy)
.disabled(busy)
.on_click(move |_, _, cx| {
submit(&secret, &pass, &repass, &state, cx);
submit(&secret, &pass, &repass, &state, &handle, cx);
})
.into_any_element();
@@ -201,6 +208,7 @@ fn submit(
pass_input: &Entity<InputState>,
repass_input: &Entity<InputState>,
state: &Entity<ImportState>,
handle: &DialogHandle,
cx: &mut App,
) {
if state.read(cx).progress.busy {
@@ -208,14 +216,19 @@ fn submit(
}
match state.read(cx).stage {
Stage::Credential => start_import(secret_input, state, cx),
Stage::Encrypt => import_nsec(pass_input, repass_input, state, cx),
Stage::Decrypt => import_ncryptsec(pass_input, state, cx),
Stage::Credential => start_import(secret_input, state, handle, cx),
Stage::Encrypt => import_nsec(pass_input, repass_input, state, handle, cx),
Stage::Decrypt => import_ncryptsec(pass_input, state, handle, cx),
}
}
/// Parses the entered credential and either moves to the passphrase step or connects to a bunker.
fn start_import(secret_input: &Entity<InputState>, state: &Entity<ImportState>, cx: &mut App) {
fn start_import(
secret_input: &Entity<InputState>,
state: &Entity<ImportState>,
handle: &DialogHandle,
cx: &mut App,
) {
let credential = match Credential::parse(secret_input.read(cx).value()) {
Some(credential) => credential,
None => {
@@ -254,7 +267,7 @@ fn start_import(secret_input: &Entity<InputState>, state: &Entity<ImportState>,
let backend = Backend::global(cx);
let task = backend.update(cx, |backend, cx| backend.import_bunker(&uri, cx));
finish_import(task, state, cx);
finish_import(task, state, handle, cx);
}
}
}
@@ -264,6 +277,7 @@ fn import_nsec(
pass_input: &Entity<InputState>,
repass_input: &Entity<InputState>,
state: &Entity<ImportState>,
handle: &DialogHandle,
cx: &mut App,
) {
let backend = Backend::global(cx);
@@ -293,11 +307,16 @@ fn import_nsec(
});
let task = backend.update(cx, |backend, cx| backend.import_nsec(&nsec, &pass, cx));
finish_import(task, state, cx);
finish_import(task, state, handle, cx);
}
/// Decrypts the entered `ncryptsec` with the passphrase and signs in with it.
fn import_ncryptsec(pass_input: &Entity<InputState>, state: &Entity<ImportState>, cx: &mut App) {
fn import_ncryptsec(
pass_input: &Entity<InputState>,
state: &Entity<ImportState>,
handle: &DialogHandle,
cx: &mut App,
) {
let backend = Backend::global(cx);
let ncryptsec = state.read(cx).credential.clone();
let pass = pass_input.read(cx).value().to_string();
@@ -318,19 +337,21 @@ fn import_ncryptsec(pass_input: &Entity<InputState>, state: &Entity<ImportState>
let task = backend.update(cx, |backend, cx| {
backend.import_ncryptsec(&ncryptsec, &pass, cx)
});
finish_import(task, state, cx);
finish_import(task, state, handle, cx);
}
/// Runs the import task to completion, closing the dialog on success.
fn finish_import<T: 'static>(
task: Task<Result<T, anyhow::Error>>,
state: &Entity<ImportState>,
handle: &DialogHandle,
cx: &mut App,
) {
let state = state.clone();
let handle = handle.clone();
cx.spawn(async move |cx| match task.await {
Ok(_) => cx.update(close_global),
Ok(_) => cx.update(|cx| handle.close(cx)),
Err(error) => {
state.update(cx, |state, cx| {
state.progress.fail(error.to_string());