Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,7 @@
"close": "Close"
},
"vault": {
"updateAvailable": "{{app}} {{version}} is available",
"library": "Library",
"switchLibrary": "Open another library",
"createTitle": "Protect this library",
Expand Down
1 change: 1 addition & 0 deletions crates/i18n/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,7 @@
"close": "Fermer"
},
"vault": {
"updateAvailable": "{{app}} {{version}} est disponible",
"library": "Bibliothèque",
"switchLibrary": "Ouvrir une autre bibliothèque",
"createTitle": "Protéger cette bibliothèque",
Expand Down
16 changes: 14 additions & 2 deletions crates/ui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,16 +371,26 @@ impl eframe::App for DevNotesApp {
}
} else {
let mut asked = Vec::new();
gate::show(
let updates = &self.state.updates;
let offer = updates.offered().map(|update| gate::Offer {
version: &update.version,
status: updates.status(),
percent: updates.progress(),
});
let install = gate::show(
ui,
&self.state.gate,
&mut self.state.gate_view,
language,
(language, offer),
&mut asked,
);
for action in asked {
actions.push(Action::Gate(action));
}
if install {
let asked = crate::banners::update_prompt::Ask::Install;
actions.push(Action::Menu(crate::titlebar::Action::Update(asked)));
}
}
});
if self.state.gate.is_open() {
Expand Down Expand Up @@ -438,6 +448,8 @@ mod area_switch_tests;
#[cfg(test)]
mod library_panel_tests;

#[cfg(test)]
mod gate_update_tests;
#[cfg(test)]
mod rail_toggle_tests;
#[cfg(test)]
Expand Down
21 changes: 21 additions & 0 deletions crates/ui/src/app/captures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2085,3 +2085,24 @@ fn a_wrapped_list_selected_whole() {
settle(&mut harness);
capture(&mut harness, "note-menu");
}

#[test]
fn an_update_found_at_the_gate() {
use crate::services::updates::UpdateState;
use crate::services::updates::fake::FakeUpdater;
let profile = tempfile::tempdir().unwrap();
let mut creating = launch(profile.path());
type_into(&mut creating, "vault-passphrase", PASSPHRASE);
type_into(&mut creating, "vault-confirmation", PASSPHRASE);
click(&mut creating, "vault-submit");
settle(&mut creating);
crate::testing::close_library(&creating.state().backend);
drop(creating);

let mut harness = launch(profile.path());
harness.state_mut().state.updates = UpdateState::with(FakeUpdater::offering("1.2.2"));
let app = harness.state_mut();
app.state.updates.check(&app.backend, true);
settle(&mut harness);
capture(&mut harness, "gate-update");
}
100 changes: 100 additions & 0 deletions crates/ui/src/app/gate_update_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//! An update found while the passphrase is asked: said on the unlock card, never a dialog
//! taking the keys from the field.

use std::path::Path;
use std::sync::Arc;

use egui_kittest::Harness;
use egui_kittest::kittest::{NodeT, Queryable};

use super::DevNotesApp;
use super::tests::{click, open_library, present, settle, startup};
use crate::services::updates::UpdateState;
use crate::services::updates::fake::FakeUpdater;

/// A library made, then the window launched again over it: the unlock card, the launch's
/// check answered by `fake` while it is shown.
fn at_the_gate(directory: &Path, fake: Arc<FakeUpdater>) -> Harness<'static, DevNotesApp> {
let first = open_library(directory);
crate::testing::close_library(first.state().backend());
drop(first);
let startup = startup(directory);
let mut harness = Harness::builder()
.with_size(egui::vec2(1100.0, 720.0))
.build_eframe(|cc| DevNotesApp::new(cc, startup).unwrap());
harness
.ctx
.set_missing_glyph_policy(egui::epaint::text::MissingGlyphPolicy::Tofu);
settle(&mut harness);
harness.state_mut().state.updates = UpdateState::with(fake);
let app = harness.state_mut();
app.state.updates.check(&app.backend, true);
settle(&mut harness);
harness
}

fn focused(harness: &Harness<'_, DevNotesApp>) -> Option<String> {
let node = harness.query_by(|node| node.is_focused() && node.author_id().is_some())?;
node.accesskit_node().author_id().map(str::to_owned)
}

#[test]
fn an_update_found_at_the_gate_is_said_on_the_card_and_the_field_keeps_the_keys() {
let directory = tempfile::tempdir().unwrap();
let mut harness = at_the_gate(directory.path(), FakeUpdater::offering("0.26.0"));

assert!(!harness.state().state().gate.is_open());
assert!(
!present(&harness, "update-prompt"),
"no dialog over the field"
);
assert!(present(&harness, "gate-update"));
assert_eq!(focused(&harness).as_deref(), Some("vault-passphrase"));

harness
.get_by(|node| node.author_id() == Some("vault-passphrase"))
.type_text(crate::testing::PASSPHRASE);
harness.key_press(egui::Key::Enter);
settle(&mut harness);

assert!(
harness.state().state().gate.is_open(),
"Enter still unlocks"
);
assert!(!present(&harness, "update-prompt"), "nor once unlocked");
click(&mut harness, "about-open");
let entry = harness.get_by(|node| node.author_id() == Some("about-check-updates"));
let label = entry.accesskit_node().label().unwrap_or_default();
assert!(label.contains("0.26.0"), "{label}");
}

#[test]
fn install_now_from_the_gate_downloads_the_update() {
let directory = tempfile::tempdir().unwrap();
let fake = FakeUpdater::offering("0.26.0");
let mut harness = at_the_gate(directory.path(), Arc::clone(&fake));

click(&mut harness, "gate-update-install");
settle(&mut harness);

assert!(
harness.state().state().quitting,
"downloaded, it leaves for the installer"
);
eframe::App::on_exit(harness.state_mut());
assert!(*fake.relaunched.lock().unwrap());
}

#[test]
fn an_update_silenced_is_not_said_at_the_gate() {
let directory = tempfile::tempdir().unwrap();
let mut harness = at_the_gate(directory.path(), Arc::new(FakeUpdater::default()));
harness.state_mut().state.settings.update_notifications = false;
harness.state_mut().state.updates = UpdateState::with(FakeUpdater::offering("0.26.0"));
let app = harness.state_mut();
app.state.updates.check(&app.backend, true);
settle(&mut harness);

assert!(!present(&harness, "gate-update"));
assert!(!present(&harness, "update-prompt"));
}
7 changes: 7 additions & 0 deletions crates/ui/src/app/update_prompt_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,10 @@ fn an_update_known_is_named_by_its_entry_drawn_clear_of_the_next() {
click(&mut harness, "about-check-updates");
assert!(present(&harness, "update-prompt"), "the offer reopened");
}

#[test]
fn an_update_found_with_the_library_open_still_opens_its_dialog() {
let directory = tempfile::tempdir().unwrap();
let harness = launched(directory.path(), FakeUpdater::offering("0.26.0"));
assert!(present(&harness, "update-prompt"));
}
2 changes: 1 addition & 1 deletion crates/ui/src/banners/update_prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub(crate) fn show(
view: &mut UpdateView,
actions: &mut Actions,
) {
let Some(update) = state.updates.offered() else {
let Some(update) = state.updates.offered().filter(|_| state.gate.is_open()) else {
return;
};
let cross = i18n::translate(state.language, i18n::keys::dialog::CLOSE, &[]);
Expand Down
62 changes: 59 additions & 3 deletions crates/ui/src/gate/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,28 @@ use i18n::{Key, Language, Message, keys};

use super::passphrase::PassphraseField;
use super::{Action, Gate, GateView};
use crate::services::updates::Status;
use crate::theme::palette;
use crate::widgets::{self, Button, ChoiceMenu, Kind};
use engine::app_info::METADATA;

/// The whole window while the library is not open.
/// An update found while the library is closed, as the caller knows it.
pub struct Offer<'a> {
pub version: &'a str,
pub status: Status,
pub percent: Option<u32>,
}

/// The whole window while the library is not open. `true` when the update offered is to be
/// installed: the gate only says it.
pub fn show(
ui: &mut Ui,
gate: &Gate,
view: &mut GateView,
language: Language,
(language, offer): (Language, Option<Offer<'_>>),
actions: &mut Vec<Action>,
) {
) -> bool {
let mut install = false;
let p = palette(ui.ctx());
let tr = |key: Key| i18n::translate(language, key, &[]);
let height_id = ui.scope_id().with("gate-height");
Expand Down Expand Up @@ -63,10 +74,55 @@ pub fn show(
} else {
form(ui, gate, view, language, actions);
}
if let Some(offer) = &offer {
install = update_line(ui, offer, language);
}
});
});
ui.data_mut(|data| data.insert_temp(height_id, shown.response.rect.height()));
});
install
}

/// Under the form, at the card's bottom, in amber to be seen: the version found and « Install
/// now », then how far its download is. The field keeps the keys: nothing here asks for the focus.
fn update_line(ui: &mut Ui, offer: &Offer<'_>, language: Language) -> bool {
let p = palette(ui.ctx());
let said = match (offer.status, offer.percent) {
(Status::Installed, _) => Message::new(keys::update::RESTARTING)
.with("app", METADATA.name)
.text(language),
(Status::Installing, Some(percent)) => Message::new(keys::update::DOWNLOADING_PERCENT)
.with("percent", percent)
.text(language),
(Status::Installing, None) => i18n::translate(language, keys::update::DOWNLOADING, &[]),
_ => Message::new(keys::vault::UPDATE_AVAILABLE)
.with("app", METADATA.name)
.with("version", offer.version)
.text(language),
};
let top = ui.cursor().top();
ui.painter()
.hline(ui.max_rect().x_range(), top, Stroke::new(1.0, p.line_soft));
ui.add_space(gap::TIGHT);
// A row of the button's height: `horizontal` centres on egui's smaller default.
let row = Vec2::new(ui.available_width(), widgets::MIN_TARGET + gap::TIGHT);
ui.allocate_ui_with_layout(row, Layout::left_to_right(Align::Center), |ui| {
let shown = ui.label(small(&said, p.amber_text));
widgets::address(ui, &shown, "gate-update");
if offer.status != Status::Available {
return false;
}
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
let install = i18n::translate(language, keys::update::INSTALL, &[]);
Button::new(&install, "gate-update-install")
.kind(Kind::Accent)
.show(ui)
.clicked()
})
.inner
})
.inner
}

/// Which library the panel is about, above what it asks: several can be asked for here.
Expand Down
2 changes: 1 addition & 1 deletion crates/ui/src/gate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod draw;
pub mod passphrase;
pub mod prompt;

pub use draw::show;
pub use draw::{Offer, show};

use engine::error::{AppError, ErrorCode};
use engine::libraries::registry::Registry;
Expand Down
8 changes: 7 additions & 1 deletion crates/ui/src/gate/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ fn screen(backend: Backend, profile: tempfile::TempDir) -> Harness<'static, Scre
.gate
.update(&screen.backend, &mut screen.status, &mut screen.errors);
let mut asked = Vec::new();
show(ui, &screen.gate, &mut screen.view, Language::En, &mut asked);
show(
ui,
&screen.gate,
&mut screen.view,
(Language::En, None),
&mut asked,
);
for action in asked {
screen.gate.apply(action, &mut screen.view, &screen.backend);
}
Expand Down
7 changes: 7 additions & 0 deletions crates/ui/src/services/updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ impl UpdateState {
.filter(|_| self.status != Status::Installed)
}

/// The offer said on the unlock card and left unanswered: the menu keeps it, no dialog opens.
pub fn put_away(&mut self) {
if self.status == Status::Available {
self.status = Status::Idle;
}
}

/// The offer put away by « Later », shown again: no new check.
pub fn reopen(&mut self) {
if self.update.is_some() && self.status == Status::Idle {
Expand Down
6 changes: 5 additions & 1 deletion crates/ui/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,17 @@ impl AppState {
self.dialogs.begin_frame(ctx);
self.help.update();
self.updates.update(&self.settings, &mut self.errors);
let offered = self.updates.offered().is_some();
// The unlock card says the offer: no dialog takes the keys from the passphrase.
let offered = self.updates.offered().is_some() && self.gate.is_open();
let prompt = crate::banners::update_prompt::id();
self.dialogs.follow(ctx, Layer::Update, prompt, offered);
if self
.gate
.update(backend, &mut self.status, &mut self.errors)
{
if self.gate.is_open() {
self.updates.put_away();
}
self.reset_library_scope(ctx, backend);
}
if self.autostart.update(backend, &mut self.settings) {
Expand Down
5 changes: 3 additions & 2 deletions crates/ui/src/titlebar/about_menu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ pub(super) fn show(ui: &mut Ui, state: &AppState, view: &mut View, actions: &mut
if state.updates.has_pending() {
dot(ui, &anchor, state, "update-dot");
}
// The check keeps the menu open for its answer; an offer is answered in its own dialog.
if state.updates.offered().is_some() {
// The check keeps the menu open for its answer; an offer is answered in its own dialog, which
// the unlock card does without.
if state.updates.offered().is_some() && state.gate.is_open() {
Popup::close_id(ui.ctx(), Popup::default_response_id(&anchor));
}
let shown = Popup::menu(&anchor)
Expand Down
6 changes: 5 additions & 1 deletion docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -6221,7 +6221,11 @@ key can produce an installable update. It is the key the Tauri releases were sig
it back. ⚠️ Only the **silent** check at launch is silenced; the one asked from the menu always
answers.
- **The dot on the About menu** says « an update exists and is not installed », and outlives the
prompt it was raised with.
prompt it was raised with; the menu's entry then names the version and opens the offer again.
The menu says what a check found only when it was asked from it, and forgets it once closed.
- **No dialog over the passphrase.** While the unlock card is shown, the offer is a line at its
bottom with « Install now »: a dialog would take the keys from someone typing their phrase.
Unlocking with the offer unanswered puts it away (`put_away`): the dot and the entry keep it.
- **The notes the prompt shows** are the release's changelog section less what the user cannot see,
carried by `latest.json` (→ "The update prompt shows the release's notes").
- **The manifest** (`latest.json`, `scripts/latest-json.mjs`) carries the NSIS installer, the
Expand Down
Loading