feat: add bottom bar

This commit is contained in:
reya
2024-11-22 14:09:20 +07:00
parent 8bf497bdc7
commit f448508b31
11 changed files with 258 additions and 108 deletions
+43 -55
View File
@@ -1,37 +1,17 @@
use asset::Assets;
use client::NostrClient;
use components::theme::{Theme, ThemeColor, ThemeMode};
use gpui::*;
use http_client::anyhow;
use state::AppState;
use std::sync::Arc;
use views::app::AppView;
pub mod asset;
pub mod state;
pub mod utils;
pub mod views;
#[derive(rust_embed::RustEmbed)]
#[folder = "../../assets"]
struct Assets;
impl AssetSource for Assets {
fn load(&self, path: &str) -> Result<Option<std::borrow::Cow<'static, [u8]>>> {
Self::get(path)
.map(|f| Some(f.data))
.ok_or_else(|| anyhow!("could not find asset at path \"{}\"", path))
}
fn list(&self, path: &str) -> Result<Vec<SharedString>> {
Ok(Self::iter()
.filter_map(|p| {
if p.starts_with(path) {
Some(p.into())
} else {
None
}
})
.collect())
}
}
actions!(main_menu, [Quit]);
#[tokio::main]
async fn main() {
@@ -40,42 +20,50 @@ async fn main() {
// Initializ app state
let app_state = AppState::new();
App::new().with_assets(Assets).run(move |cx| {
// Initialize components
components::init(cx);
App::new()
.with_assets(Assets)
.with_http_client(Arc::new(reqwest_client::ReqwestClient::new()))
.run(move |cx| {
// Initialize components
components::init(cx);
// Set custom theme
let mut theme = Theme::from(ThemeColor::dark());
// TODO: support light mode
theme.mode = ThemeMode::Dark;
// TODO: adjust color set
// Set custom theme
let mut theme = Theme::from(ThemeColor::dark());
// TODO: support light mode
theme.mode = ThemeMode::Dark;
// TODO: adjust color set
// Set global theme
cx.set_global(theme);
// Set app state
cx.set_global(theme);
cx.set_global(nostr);
cx.set_global(app_state);
// Set nostr client as global state
cx.set_global(nostr);
cx.set_global(app_state);
// Set quit action
cx.on_action(quit);
// Rerender
cx.refresh();
// Rerender
cx.refresh();
// Set window size
let bounds = Bounds::centered(None, size(px(860.0), px(650.0)), cx);
// Set window size
let bounds = Bounds::centered(None, size(px(860.0), px(650.0)), cx);
cx.open_window(
WindowOptions {
window_bounds: Some(WindowBounds::Windowed(bounds)),
window_decorations: Some(WindowDecorations::Client),
titlebar: Some(TitlebarOptions {
title: Some(SharedString::new_static("coop")),
appears_transparent: true,
cx.open_window(
WindowOptions {
window_bounds: Some(WindowBounds::Windowed(bounds)),
window_decorations: Some(WindowDecorations::Client),
titlebar: Some(TitlebarOptions {
title: Some(SharedString::new_static("coop")),
appears_transparent: true,
..Default::default()
}),
..Default::default()
}),
..Default::default()
},
|cx| cx.new_view(AppView::new),
)
.unwrap();
});
},
|cx| cx.new_view(AppView::new),
)
.unwrap();
});
}
fn quit(_: &Quit, cx: &mut AppContext) {
cx.quit();
}