Skip to content
Open
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
34 changes: 11 additions & 23 deletions apps/desktop/src/plugin_host/runtime/trust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
//! SHA-256 is remembered, and a changed plugin asks again. Built-ins and `--plugin-dir` don't ask.
//! What the user chose is the plugin's record in the app's database (`super::boot::save_record`).

use rune::{El, TextStyle, Tx, col, el, row, spacer, text};
use rune::{El, Tx, row, spacer, text};

use crate::App;
use crate::palette::Pal;
use crate::plugin_host::{Life, Trust, TrustEvent, step_trust};
use crate::view::{UI, UI_MED};
use crate::view::UI;
use opencode_ui::widgets::{self, DialogKind, DialogSize, Fit, button};
use rune_kit::ButtonVariant;
use opencode_ui::palette::kit;

/// The plugin whose prompt shows now: the first waiting one the user hasn't put off.
fn shown(app: &App) -> Option<usize> {
Expand All @@ -19,22 +22,11 @@ pub fn dialog(s: &App, p: &Pal, cx: &rune::Cx<App>) -> Vec<El> {
let Some(i) = shown(s) else { return Vec::new() };
let plugin = &s.plugins.list[i];
let (id, name) = (plugin.manifest.id.clone(), plugin.manifest.name.clone());
let button = |key: &str, label: &str, ink: rune::Color, fill: Option<rune::Color>| {
let mut b = row().key(key.to_owned()).role("button").label(label.to_owned()).h(28.0).px(12.0).radius(6.0).center().hover(p.hover);
if let Some(f) = fill {
b = b.fill(f).hover(f.alpha(0.9));
}
b.child(text(label.to_owned()).font(UI_MED).color(ink))
};
let mut card = col()
let mut card = widgets::dialog_card(p, DialogKind::Form)
.key("plugin-trust-card")
.padding(20.0)
.gap(6.0)
.radius(12.0)
.fill(p.bg_base)
.box_shadow(Pal::ring_out(p.ring))
.shadow(8.0, 32.0, p.shadow_far)
.child(text(format!("Enable plugin \"{name}\"?")).font(TextStyle::new(15.0, 600.0).lh(24.0)).color(p.text))
.child(text(format!("Enable plugin \"{name}\"?")).font(opencode_ui::dialog::TITLE).color(p.text))
.child(text(format!("{name} {} can read and change your files, run programs and reach the network. Only enable plugins you trust.", plugin.manifest.version)).font(UI).color(p.muted).wrap());
if let Some(d) = plugin.manifest.description.as_ref().filter(|d| !d.is_empty()) {
card = card.child(text(d.clone()).font(UI).color(p.muted).wrap().mt(6.0));
Expand All @@ -51,19 +43,15 @@ pub fn dialog(s: &App, p: &Pal, cx: &rune::Cx<App>) -> Vec<El> {
.gap(8.0)
.mt(14.0)
.child(spacer())
.child(button("plugin-trust-later", "Not now", p.text, None).on_press_tx(move |s: &mut App, tx: &mut Tx| answer(s, &later, TrustEvent::Later, tx)))
.child(button("plugin-trust-enable", "Enable", p.on_fill, Some(p.bg_accent)).on_press_tx(move |s: &mut App, tx: &mut Tx| answer(s, &ok, TrustEvent::Accept, tx))),
.child(button("Not now", ButtonVariant::Ghost).on_press_tx(move |s: &mut App, tx: &mut Tx| answer(s, &later, TrustEvent::Later, tx)).build(kit(p)).key("plugin-trust-later").autofocus())
.child(button("Enable", ButtonVariant::Contrast).on_press_tx(move |s: &mut App, tx: &mut Tx| answer(s, &ok, TrustEvent::Accept, tx)).build(kit(p)).key("plugin-trust-enable")),
);
// No Desktop counterpart: a confirmation, so the normal size.
let card = crate::widgets::sized(card, crate::widgets::DialogSize::Normal, crate::widgets::Fit::Content, crate::widgets::dialog_window(cx, *s.zoom));
vec![
el().key("plugin-trust-scrim").absolute(0.0, 0.0).w_full().h_full().fill(p.dim),
el().key("plugin-trust-modal").absolute(0.0, 0.0).w_full().h_full().center().child(card).raise(),
]
widgets::sized_modal("plugin-trust", p, DialogSize::Normal, Fit::Content, widgets::dialog_window(cx, *s.zoom), card)
}

fn answer(app: &mut App, id: &str, event: TrustEvent, tx: &mut Tx) {
tx.instant();
tx.animated();
if let Some(i) = app.plugins.find(id) {
step_trust(app, i, event);
}
Expand Down
12 changes: 11 additions & 1 deletion apps/desktop/src/stories/shell/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ fn toast_start(s: &mut App, tx: &mut Play<App>) {
s.finish_stream();
crate::status_toast::dismiss(s);
tx.instant();
if *s.fixture_run.variant == 2 {
tx.after(0.5, |s, tx| {
tx.animated();
crate::status_toast::show(s, crate::status_toast::Entry::new(
"This HTML file is outside this session's workspace and cannot open in the browser pane.",
None, true,
), None);
});
return;
}
if *s.fixture_run.variant == 1 {
tx.after(0.5, |s, _| {
crate::status_toast::show(s, crate::status_toast::Entry::new("Export saved", Some("Ready to share".into()), false), Some(3.0));
Expand All @@ -103,5 +113,5 @@ fn toast_start(s: &mut App, tx: &mut Play<App>) {

rune_register::register!(crate::stories::STORY_LIST: Story = [
Story::session("Popover/Menus", KEYS).knobs(&[motion::GROUP]).variants(VARIANTS),
Story::session("Components/Toast", TOAST_KEYS).variants(&[("Single", 0), ("Expiry stack", 1)]),
Story::session("Components/Toast", TOAST_KEYS).variants(&[("Single", 0), ("Expiry stack", 1), ("Long warning", 2)]),
]);
21 changes: 7 additions & 14 deletions apps/desktop/src/surfaces/automations/delete_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Delete automation confirmation dialog (packages/app/src/automations/route.tsx:confirmDelete).

use opencode_i18n::t;
use opencode_ui::palette::{Elevate as _, Pal, flat, kit};
use opencode_ui::palette::{Pal, kit};
use opencode_ui::widgets::{BODY, DialogSize, Fit, button, dialog_window, sized_modal};
use rune::{Color, Cx, El, TextStyle, Tx, col, row, spacer, text};
use rune::{Cx, El, TextStyle, Tx, col, row, spacer, text};
use rune_kit::ButtonVariant;

use crate::App;
Expand All @@ -19,28 +19,21 @@ pub fn view(s: &App, p: &Pal, cx: &Cx<App>) -> Vec<El> {
let (key, server, id, name) = (key.clone(), server.clone(), id.clone(), name.clone());
let k = kit(p);
let cancel = button(t!("common.cancel"), ButtonVariant::Ghost)
.on_press_tx(|s: &mut App, tx: &mut Tx| { super::cancel_delete(s, tx); })
.on_press_tx(|s: &mut App, tx: &mut Tx| { super::cancel_delete(s, tx); tx.animated(); })
.build(k)
.key("auto-delete-cancel")
.autofocus();
let delete = button(t!("automations.delete.button"), ButtonVariant::Danger)
.on_press_tx(move |s: &mut App, tx: &mut Tx| super::confirm_delete(s, &key, &server, &id, tx))
.on_press_tx(move |s: &mut App, tx: &mut Tx| { super::confirm_delete(s, &key, &server, &id, tx); tx.animated(); })
.build(k)
.key("auto-delete-confirm");
let delete = if p.dark && p.theme == 0 {
delete.fill(flat(Color::WHITE.alpha(0.06), p.layer1))
} else {
delete
};
let card = col()
let delete = opencode_ui::widgets::danger_surface(p, delete);
let card = opencode_ui::widgets::dialog_card(p, opencode_ui::widgets::DialogKind::Form)
.key("auto-delete-card")
.role("dialog")
.label_static(t!("automations.delete.title"))
.radius(6.0)
.fill(p.layer1)
.elevate(p.overlay)
.clip_soft(0.0)
.modal_tx(true, |s: &mut App, tx: &mut Tx| { super::cancel_delete(s, tx); })
.modal_tx(true, |s: &mut App, tx: &mut Tx| { super::cancel_delete(s, tx); tx.animated(); })
.child(
col()
.key("auto-delete-header")
Expand Down
19 changes: 6 additions & 13 deletions apps/desktop/src/workspace/system/deep_links/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
//! (`packages/app/src/shell/deep-links/{deep-links.tsx,prompt-preview.ts}`, `opencode#65803`, `#67170`).

use opencode_i18n::t;
use opencode_ui::palette::{Elevate as _, Pal, kit};
use opencode_ui::widgets::{BODY, DialogSize, Fit, button, dialog_window, sized};
use opencode_ui::palette::{Pal, kit};
use opencode_ui::widgets::{BODY, DialogSize, Fit, button, dialog_window};
use rune::{Cx, Direction, El, Key, KeyEvent, TextStyle, Tx, col, el, row, spacer, text};
use rune_kit::ButtonVariant;

Expand All @@ -21,7 +21,7 @@ pub(crate) fn asking(s: &App) -> bool {

/// Accepts the active deep-link confirmation attempt.
pub(crate) fn accept(s: &mut App, attempt: u64, tx: &mut Tx) {
tx.instant();
tx.animated();
let ready = ready_servers(s);
let effects = s
.services
Expand All @@ -36,7 +36,7 @@ pub(crate) fn accept(s: &mut App, attempt: u64, tx: &mut Tx) {

/// Declines the active deep-link confirmation attempt.
pub(crate) fn decline(s: &mut App, attempt: u64, tx: &mut Tx) {
tx.instant();
tx.animated();
let effects = s.services.deep_links.step(DeepLinkEvent::Declined { attempt }, |_| false);
let _ = run(s, effects, tx);
if asking(s) {
Expand Down Expand Up @@ -122,13 +122,10 @@ pub(crate) fn dialog(s: &App, p: &Pal, cx: &Cx<App>) -> Vec<El> {
.py(2.0)
.fill(p.text.alpha(0.08))
.child(text(dir).font(FOLDER_CODE).color(p.text).dir(Direction::Ltr).wrap());
let card = col()
let card = opencode_ui::widgets::dialog_card(p, opencode_ui::widgets::DialogKind::Form)
.key("deep-link-card")
.role("dialog")
.label(title.clone())
.radius(6.0)
.fill(p.layer1)
.elevate(p.overlay)
.clip_soft(0.0)
.modal_tx(true, move |s: &mut App, tx: &mut Tx| decline(s, attempt, tx))
.child(
Expand Down Expand Up @@ -176,11 +173,7 @@ pub(crate) fn dialog(s: &App, p: &Pal, cx: &Cx<App>) -> Vec<El> {
.child(text(t!("deepLink.open.warning")).font(BODY).color(p.muted).wrap().w_full()),
)
.child(row().key("deep-link-footer").w_full().padding(16.0).gap(8.0).child(spacer()).child(cancel).child(open_btn));
let card = sized(card, DialogSize::Normal, Fit::Content, dialog_window(cx, *s.zoom));
vec![
el().key("deep-link-scrim").absolute(0.0, 0.0).w_full().h_full().fill(p.scrim),
el().key("deep-link-modal").absolute(0.0, 0.0).w_full().h_full().center().child(card).raise(),
]
opencode_ui::widgets::sized_modal("deep-link", p, DialogSize::Normal, Fit::Content, dialog_window(cx, *s.zoom), card)
}

fn folder_name(dir: &str) -> String {
Expand Down
14 changes: 14 additions & 0 deletions crates/opencode-ui/src/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,17 @@ impl DialogSize {
((win_h - self.height(win_h)) / 2.0).max(0.0)
}
}

/// Dialog presence: a small centred scale with its scrim. Rune reduces this to a short
/// opacity fade when Reduce Motion is enabled (no travel or scale).
pub fn transition() -> rune::Transition {
rune::Transition::scale(0.96).springs(rune::SpringPair::new(rune::Spring::new(0.2, 0.0), rune::Spring::new(0.15, 0.0)))
}

/// The backdrop uses the card's timing without scaling the window-sized scrim.
pub fn scrim_transition() -> rune::Transition {
rune::Transition::opacity().springs(transition().springs)
}

/// Shared dialog heading: the calibrated medium Inter face.
pub const TITLE: rune::TextStyle = rune::TextStyle::new(15.0, 530.0).lh(20.0).tracking(-0.13);
4 changes: 2 additions & 2 deletions crates/opencode-ui/src/toast/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Toast notifications at the window's bottom-right, matching OpenCode Desktop's `Toast.Region`
//! (`packages/ui/src/feedback/toast/toast.tsx`, `toast.css`), with instant entrance and a
//! downward exit on expiry. Explicit keyboard and button dismissals remain immediate.
//! (`packages/ui/src/feedback/toast/toast.tsx`, `toast.css`), with an upward entrance and a
//! downward fade on expiry or explicit close-button dismissal. Rune respects Reduce Motion.
//!
//! Toasts stack as Sonner stacks them (`rune_kit::ToastStack`): the newest in front, up to two
//! more peeking behind it; hovering the stack spreads them out, and while hovered or while the
Expand Down
23 changes: 14 additions & 9 deletions crates/opencode-ui/src/toast/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use rune::{Anim, Color, Edge, El, Icon, Shadow, Spring, SpringPair, TextStyle, Transition, Tx, col, el, icon, row, spacer, text};
use rune_kit::{ToastEntry, ToastEvent};
use crate::focus::FocusExt as _;
use crate::palette::{Elevate as _, Pal};

use super::state::{dismiss_id, stack_key, step};
Expand All @@ -13,10 +14,10 @@ const TITLE: TextStyle = TextStyle::new(13.0, 530.0).lh(20.0).tracking(-0.04);
const DESC: TextStyle = TextStyle::new(13.0, 440.0).lh(20.0).tracking(-0.04);

// `packages/ui/src/feedback/toast/toast.css` keeps removal and stack movement animated.
// Keep the instant entrance; a timed dismissal travels down on a short zero-bounce spring.
fn exit_transition() -> Transition {
Transition::asymmetric(Transition::none(), Transition::move_edge(Edge::Bottom))
.springs(SpringPair { enter: Spring::NONE, exit: Spring::new(0.25, 0.0) })
// Enter and leave from the lower edge; Rune reduces travel to a fade under Reduce Motion.
fn presence_transition() -> Transition {
Transition::move_edge(Edge::Bottom).combined(Transition::opacity())
.springs(SpringPair { enter: Spring::new(0.3, 0.0), exit: Spring::new(0.25, 0.0) })
}

/// Sonner's close glyph, which `toast.css` draws at 16 px: two strokes 6 to 18 across 24, 1.5
Expand Down Expand Up @@ -54,7 +55,7 @@ pub fn view<S: ToastHost>(s: &S, p: &Pal) -> Option<El> {
let mut stack = el()
.key(STACK)
// When the last toast leaves, its parent carries the exit instead of the card.
.transition(exit_transition())
.transition(presence_transition())
.role("region")
.label("Notifications alt+T")
.w(w)
Expand All @@ -81,7 +82,7 @@ pub fn view<S: ToastHost>(s: &S, p: &Pal) -> Option<El> {
let (pulse, scale_motion) = s.toast().pulse.of(e.id).unwrap_or((1.0, MOVE));
stack = stack.child(
card.offset(0.0, -at.lift)
.transition(exit_transition())
.transition(presence_transition())
.offset_motion(MOVE)
.scale(at.scale * pulse)
.scale_motion(scale_motion)
Expand Down Expand Up @@ -165,13 +166,14 @@ fn card<S: ToastHost>(s: &S, p: &Pal, entry: &Entry<S::CustomAction>, content_sh
.center()
.hover(p.hover)
.press(p.pressed)
.focus_inset(p)
.hover_group()
.hover_motion(INSTANT, INSTANT)
.on_press_tx(move |s: &mut S, tx: &mut Tx| {
tx.instant();
dismiss_id(s, id);
// `ToastOptions.onDismiss`: the person closed it.
s.on_dismissed(id, tx);
tx.animated();
})
// `icon-muted` at rest, `icon-base` under the pointer.
.child(icon(&CLOSE, 16.0).color(p.icon_muted))
Expand All @@ -185,7 +187,7 @@ fn card<S: ToastHost>(s: &S, p: &Pal, entry: &Entry<S::CustomAction>, content_sh
// difference: official stacks every action under the content).
let one_line = entry.description.is_none() && entry.quote.is_none() && entry.next.is_none() && entry.buttons.is_empty();
if one_line && action_btn.is_some() {
let title = text(entry.title.clone()).key("toast-title").font(TITLE).color(p.text).truncate().grow(1.0).shrink().min_w(0.0);
let title = text(entry.title.clone()).key("toast-title").font(TITLE).color(p.text).help_when_truncated(entry.title.clone()).truncate().grow(1.0).shrink().min_w(0.0);
let body = row()
.key("toast-head")
.w_full()
Expand All @@ -200,13 +202,14 @@ fn card<S: ToastHost>(s: &S, p: &Pal, entry: &Entry<S::CustomAction>, content_sh
return frame::<S>(p, entry, body).py(8.0).pl(14.0).pr(8.0);
}

// Unlike toast.css's single-line title, a warning must keep its complete explanation.
let mut content = col()
.key("toast-content")
.grow(1.0)
.shrink()
.min_w(0.0)
.gap(4.0)
.child(text(entry.title.clone()).key("toast-title").font(TITLE).color(p.text).truncate().w_full())
.child(text(entry.title.clone()).key("toast-title").font(TITLE).color(p.text).wrap().w_full())
.children(entry.description.as_ref().map(|desc| text(desc.clone()).key("toast-description").font(DESC).color(p.muted).wrap().w_full()))
// The server's words, set apart by a rule as a quotation is, in the text colour: theirs.
.children(entry.quote.as_ref().map(|q| {
Expand Down Expand Up @@ -275,6 +278,7 @@ fn action_button<S: ToastHost>(s: &S, p: &Pal, id: u64, action: &ToastAction<S::
.elevate(neutral_lift(p))
.hover(p.hover)
.press(p.pressed)
.focus_inset(p)
.hover_motion(INSTANT, INSTANT)
.on_press_tx(move |s: &mut S, tx: &mut Tx| match action.clone() {
ToastAction::Reveal(_, path) => {
Expand All @@ -300,6 +304,7 @@ fn extra_button<S: ToastHost>(p: &Pal, id: u64, i: usize, button: &ToastButton<S
styled
.hover(p.hover)
.press(p.pressed)
.focus_inset(p)
.hover_motion(INSTANT, INSTANT)
.on_press_tx(move |s: &mut S, tx: &mut Tx| {
tx.instant();
Expand Down
49 changes: 32 additions & 17 deletions crates/opencode-ui/src/widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! MCP status dot.

use rune::{Color, El, Icon, TextStyle, Transition, col, el, icon, row, text};
use rune_kit::{Badge, Button, ButtonVariant, Loader};
use rune_kit::{Badge, Button, ButtonVariant};
use rune_theme_opencode::provider_icons;
use crate::palette::{Elevate as _, Pal, kit};

Expand Down Expand Up @@ -50,7 +50,7 @@ pub fn status_row(p: &Pal, key: &str, label: &str) -> El {
.label(label.to_owned())
.gap(8.0)
.center_y()
.child(Loader::new().size(16.0).build(kit(p)))
.child(crate::style::busy_glyph(kit(p), 16.0))
.child(text(label.to_owned()).font(BODY).color(p.muted))
}

Expand Down Expand Up @@ -125,27 +125,42 @@ pub fn sized_modal(key: &str, p: &Pal, size: DialogSize, fit: Fit, win: [f32; 2]
modal(key, p, sized(card, size, fit, win), kept.then(|| size.top(win[1])))
}

/// A dialog's scrim and its centring layer (the dialog element's `.modal` / `.modal_tx` handles
/// outside presses).
/// Dialog content uses one corner geometry; searchable lists keep their base surface
/// (packages/ui/src/overlays/dialog/dialog.css).
#[derive(Clone, Copy)]
pub enum DialogKind { Form, List }

pub fn dialog_card(p: &Pal, kind: DialogKind) -> El {
let fill = match kind { DialogKind::Form => p.layer1, DialogKind::List => p.bg_base };
col().role("dialog").radius(12.0).fill(fill).elevate(p.overlay)
.motion(rune::Spring::NONE)
}

/// A destructive button keeps semantic warning ink on a tinted surface in every theme.
/// Deliberately stronger than button.css's neutral danger fill, which loses its warning at rest.
pub fn danger_surface(p: &Pal, button: El) -> El {
button.fill(crate::palette::flat(p.danger_bg, p.layer1))
}

/// A dialog's scrim and centring layer; the card's modal callback handles outside presses.
pub fn modal(key: &str, p: &Pal, dialog: El, top: Option<f32>) -> Vec<El> {
let scrim = el().key(format!("{key}-scrim")).absolute(0.0, 0.0).w_full().h_full().fill(p.scrim).transition(Transition::none());
let mut layer = col().key(format!("{key}-modal")).absolute(0.0, 0.0).w_full().h_full().items_center().transition(Transition::none());
layer = match top {
Some(t) => layer.pt(t),
None => layer.center(),
let scrim = el().key(format!("{key}-scrim")).absolute(0.0, 0.0).w_full().h_full().fill(p.scrim).transition(crate::dialog::scrim_transition()).enter_in_instant();
let layer = col().key(format!("{key}-modal")).w_full().items_center().transition(crate::dialog::transition()).enter_in_instant();
// Presence belongs to the parent: Rune's rides_parent suppresses child presence tracks.
// Anchored layers hug the card so the scale origin stays at the dialog's centre.
let layer = match top {
Some(t) => layer.absolute(0.0, t),
None => layer.absolute(0.0, 0.0).h_full().center(),
};
vec![scrim, layer.child(dialog).raise()]
vec![scrim, layer.child(dialog.transition(Transition::none())).raise()]
}

/// A status dot's colour (`.mcp-status-dot`, `.session-service-dot`): Desktop's v1
/// `icon-success-base`, `icon-critical-base` and `icon-warning-base`, or a chosen theme's v2
/// state colours; faint otherwise.
/// MCP and session service status colours, using the active theme's semantic tokens.
pub fn status_ink(p: &Pal, status: &str) -> Color {
let v1 = |light: &str, dark: &str, or: Color| if p.theme == 0 { rune::color::hex(if p.dark { dark } else { light }).unwrap_or(or) } else { or };
match status {
"connected" | "active" => v1("#0abe00", "#089b00", p.success),
"failed" => v1("#fa3012", "#cb321c", p.danger),
"needs_auth" => p.v1_icon_warning,
"connected" | "active" => p.success,
"failed" => p.danger,
"needs_auth" => p.warning,
_ => p.icon_faint,
}
}
Expand Down
Loading
Loading