Files
signed/desktop/src/main.rs
T
reya b7e1ca7c86
Rust / build (macos-latest, stable) (push) Canceled after 0s
Rust / build (ubuntu-latest, stable) (push) Canceled after 0s
Rust / build (windows-latest, stable) (push) Canceled after 0s
feat: add si command line interface (#37)
Reviewed-on: #37
2026-11-30 00:34:44 +00:00

111 lines
3.6 KiB
Rust

use std::sync::Arc;
use gpui::*;
use gpui_platform::application;
use settings::SettingsStore;
use signed_app::AppRoot;
use ui::theme::{ActiveTheme as _, Theme};
actions!(signed, [Quit]);
/// Embeds app artwork and serves it plus the ui crate's icon set.
#[derive(rust_embed::RustEmbed)]
#[folder = "assets"]
#[exclude = "*.DS_Store"]
struct AppAssets;
impl AssetSource for AppAssets {
fn load(&self, path: &str) -> gpui::Result<Option<std::borrow::Cow<'static, [u8]>>> {
if let Some(name) = path.strip_prefix("icons/") {
return Ok(ui::Assets::get(name).map(|file| file.data));
}
Ok(Self::get(path).map(|file| file.data))
}
fn list(&self, path: &str) -> gpui::Result<Vec<SharedString>> {
let mut files: Vec<SharedString> = ui::Assets::iter()
.map(|name| SharedString::from(format!("icons/{name}")))
.filter(|file| file.starts_with(path))
.collect();
files.extend(
Self::iter()
.filter(|file| file.starts_with(path))
.map(SharedString::from),
);
Ok(files)
}
}
fn main() {
tracing_subscriber::fmt::init();
application()
.with_assets(AppAssets)
.with_http_client(Arc::new(reqwest_client::ReqwestClient::new()))
.run(move |cx| {
cx.bind_keys([
KeyBinding::new("cmd-q", Quit, None),
KeyBinding::new("ctrl-q", Quit, None),
]);
cx.on_action(|_: &Quit, cx| cx.quit());
cx.set_app_identity(paths::APP_ID, paths::APP_NAME);
ui::init(cx);
if let Err(error) = signed_state::init(cx) {
tracing::error!("failed to initialize application state: {error:#}");
cx.quit();
return;
}
metadata::init(cx);
let settings = SettingsStore::global(cx);
let appearance = settings.read(cx).settings().appearance;
AppRoot::apply_appearance_mode(appearance, cx);
let theme = cx.theme();
let bounds = Bounds::centered(None, size(px(1120.0), px(750.0)), cx);
let options = WindowOptions {
window_bounds: Some(WindowBounds::Windowed(bounds)),
window_min_size: Some(size(px(960.0), px(640.0))),
titlebar: Some(TitlebarOptions {
title: Some("Signed".into()),
appears_transparent: true,
traffic_light_position: Some(point(
px(12.0),
(theme.titlebar_height - px(16.0)) / 2.0,
)),
}),
app_owns_titlebar_drag: true,
window_background: theme.window_background,
app_id: Some("Signed".to_owned()),
..Default::default()
};
if let Err(error) = cx.open_window(options, |window, cx| {
Theme::sync_from_window(window, cx);
Theme::sync_window_rem_size(window, cx);
window
.observe_window_appearance(|window, cx| {
Theme::sync_from_window(window, cx);
Theme::sync_window_rem_size(window, cx);
cx.refresh_windows();
})
.detach();
AppRoot::mount(window, cx)
}) {
tracing::error!("failed to open window: {error}");
cx.quit();
return;
}
cx.activate(true);
});
}