add unlock/exit buttons to home screen
This commit is contained in:
1 parent
b2a7e5759a
commit
3c06f7e536
3 files changed
+112
-6
No files matched your search
@@ -0,0 +1,28 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use gpui_kit::assets::{Assets, icon_assets};
|
||||
use gpui_kit::{AssetSource, Result, SharedString};
|
||||
|
||||
|
||||
// gpui-kit only embeds the icons its own components use, so anything else has to be listed here
|
||||
icon_assets!(CreddyIcons, [LogOut, ShieldCheck]);
|
||||
|
||||
/// Our extra icons, falling back to gpui-kit's defaults.
|
||||
pub struct CreddyAssets;
|
||||
|
||||
impl AssetSource for CreddyAssets {
|
||||
fn load(&self, path: &str) -> Result<Option<Cow<'static, [u8]>>> {
|
||||
match CreddyIcons.load(path)? {
|
||||
Some(bytes) => Ok(Some(bytes)),
|
||||
None => Assets.load(path),
|
||||
}
|
||||
}
|
||||
|
||||
fn list(&self, path: &str) -> Result<Vec<SharedString>> {
|
||||
let mut paths = Assets.list(path)?;
|
||||
paths.extend(CreddyIcons.list(path)?);
|
||||
paths.sort();
|
||||
paths.dedup();
|
||||
Ok(paths)
|
||||
}
|
||||
}
|
||||
+21
-1
@@ -4,6 +4,7 @@ use gpui_kit::{
|
||||
};
|
||||
use gpui_omarchy::ActiveTheme;
|
||||
|
||||
mod assets;
|
||||
mod components;
|
||||
mod config;
|
||||
mod db;
|
||||
@@ -68,7 +69,7 @@ fn main() {
|
||||
|
||||
// Icons are read through the asset source, so register the bundle.
|
||||
gpui_kit::application()
|
||||
.with_assets(gpui_kit::assets::Assets)
|
||||
.with_assets(assets::CreddyAssets)
|
||||
.run(|app| {
|
||||
launch(app, app_config, app_session);
|
||||
app.activate(true);
|
||||
@@ -204,4 +205,23 @@ mod tests {
|
||||
assert!(is_unlocked(cx));
|
||||
assert_eq!(cx.read(|cx| cx.global::<AppConfig>().rehide_ms), 5000);
|
||||
}
|
||||
|
||||
#[gpui_kit::test]
|
||||
fn test_lock(cx: &mut TestAppContext) {
|
||||
let env = TestEnv::new().unwrap();
|
||||
env.db().unwrap();
|
||||
let window = open_app(&env, cx);
|
||||
fill(window, "passphrase", TEST_PASSPHRASE, cx);
|
||||
click(window, "submit", cx);
|
||||
assert!(is_unlocked(cx));
|
||||
|
||||
click(window, "lock", cx);
|
||||
|
||||
assert!(cx.read(|cx| matches!(cx.global::<AppSession>(), AppSession::Locked)));
|
||||
// The unlock screen should be a new one, not the old one with the passphrase still in it.
|
||||
// The masked input doesn't expose its value, so check by submitting it as-is.
|
||||
click(window, "submit", cx);
|
||||
assert_eq!(error_message(window, cx).as_deref(), Some("Passphrase is empty."));
|
||||
assert!(!is_unlocked(cx));
|
||||
}
|
||||
}
|
||||
+63
-5
@@ -1,13 +1,71 @@
|
||||
use gpui_kit::{div, Render, Window, Context, IntoElement, Styled, ParentElement};
|
||||
use gpui_kit::base::Button;
|
||||
use gpui_kit::{
|
||||
App, Context, FontWeight, Hsla, InteractiveElement, IntoElement, ParentElement, Render,
|
||||
StatefulInteractiveElement, Styled, Window, div, rems,
|
||||
};
|
||||
use gpui_omarchy::{ActiveTheme, IconName, focus_scope, icon};
|
||||
|
||||
use crate::session::AppSession;
|
||||
|
||||
|
||||
pub struct HomeScreen {}
|
||||
|
||||
impl Render for HomeScreen {
|
||||
fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
|
||||
div()
|
||||
fn render(&mut self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let t = cx.omarchy();
|
||||
let lock = nav_tile("lock", IconName::ShieldCheck, "Lock", "Lock Creddy.", t.warning, cx)
|
||||
.on_click(|_, _, cx| cx.set_global(AppSession::Locked));
|
||||
let exit = nav_tile("exit", IconName::LogOut, "Exit", "Close Creddy.", t.accent, cx)
|
||||
.on_click(|_, _, cx| cx.quit());
|
||||
|
||||
focus_scope("home")
|
||||
.size_full()
|
||||
.flex()
|
||||
.justify_center()
|
||||
.flex_col()
|
||||
.items_center()
|
||||
.child("Creddy is unlocked")
|
||||
.p(rems(0.5))
|
||||
.child(
|
||||
div()
|
||||
.text_size(rems(1.875))
|
||||
.font_weight(FontWeight::BOLD)
|
||||
.child("Creddy"),
|
||||
)
|
||||
.child(
|
||||
// fill the rest of the window so the tiles sit in the middle of it
|
||||
div()
|
||||
.flex_1()
|
||||
.flex()
|
||||
.items_center()
|
||||
.gap(rems(1.5))
|
||||
.child(lock)
|
||||
.child(exit),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// A big square-ish button with an icon, a title, and a short description.
|
||||
fn nav_tile(
|
||||
id: &'static str,
|
||||
icon_name: IconName,
|
||||
title: &'static str,
|
||||
description: &'static str,
|
||||
color: Hsla,
|
||||
cx: &App,
|
||||
) -> Button {
|
||||
let t = cx.omarchy();
|
||||
Button::new(id)
|
||||
.accessibility_label(title)
|
||||
.flex_col()
|
||||
.justify_start()
|
||||
.gap(rems(1.))
|
||||
.w(rems(14.))
|
||||
.p(rems(1.))
|
||||
.border_1()
|
||||
.border_color(color)
|
||||
.hover(|s| s.bg(t.hover_fill()))
|
||||
.focus_visible(|s| s.bg(t.hover_fill()))
|
||||
.active(|s| s.bg(t.pressed_fill()))
|
||||
.child(icon(icon_name).size(rems(3.)).text_color(color))
|
||||
.child(div().text_size(rems(1.125)).font_weight(FontWeight::BOLD).child(title))
|
||||
.child(div().text_size(rems(0.875)).text_center().child(description))
|
||||
}
|
||||
Reference in new issue
Block a user