diff --git a/Cargo.lock b/Cargo.lock index ec2e2e8..ce3a4b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5433,6 +5433,7 @@ name = "scope" version = "0.1.0" dependencies = [ "chrono", + "dirs 5.0.1", "dotenv", "env_logger", "gpui", @@ -5443,6 +5444,8 @@ dependencies = [ "scope-backend-discord", "scope-chat", "scope-util", + "serde", + "serde_json", "tokio", "ui", ] @@ -5627,9 +5630,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.132" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" +checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" dependencies = [ "indexmap 2.6.0", "itoa 1.0.11", diff --git a/Cargo.toml b/Cargo.toml index 0d86827..df62c14 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,6 @@ [workspace] resolver = "2" -members = [ - "src/ui" -] +members = ["src/ui"] [workspace.dependencies] -chrono = "0.4.38" \ No newline at end of file +chrono = "0.4.38" diff --git a/src/ui/Cargo.toml b/src/ui/Cargo.toml index 924cc19..b848762 100644 --- a/src/ui/Cargo.toml +++ b/src/ui/Cargo.toml @@ -29,6 +29,9 @@ log = "0.4.22" random-string = "1.1.0" rust-embed = "8.5.0" chrono.workspace = true +serde = "1.0.215" +dirs = "5.0.1" +serde_json = "1.0.133" [features] default = ["gpui/x11"] diff --git a/src/ui/src/main.rs b/src/ui/src/main.rs index 4282e3b..be96d62 100644 --- a/src/ui/src/main.rs +++ b/src/ui/src/main.rs @@ -1,8 +1,9 @@ pub mod actions; -pub mod app; pub mod app_state; pub mod channel; pub mod menu; +pub mod settings; +pub mod surfaces; use std::sync::Arc; @@ -67,17 +68,30 @@ async fn main() { cx.set_global(theme); cx.refresh(); - let opts = WindowOptions { - window_decorations: Some(WindowDecorations::Client), - window_min_size: Some(size(Pixels(800.0), Pixels(600.0))), - titlebar: Some(TitlebarOptions { - appears_transparent: true, - title: Some(SharedString::new_static("scope")), - ..Default::default() - }), - ..Default::default() - }; - - cx.open_window(opts, |cx| cx.new_view(crate::app::App::new)).unwrap(); + let settings = settings::load_or_init_settings_on_disk(); + + match settings.token { + Some(token) => { + let opts = WindowOptions { + window_decorations: Some(WindowDecorations::Client), + window_min_size: Some(size(Pixels(800.0), Pixels(600.0))), + titlebar: Some(TitlebarOptions { + appears_transparent: true, + title: Some(SharedString::new_static("scope")), + ..Default::default() + }), + ..Default::default() + }; + + cx.open_window(opts, |cx| cx.new_view(crate::surfaces::app::App::new)).unwrap(); + } + + None => { + cx.open_window(WindowOptions::default(), |cx| { + cx.new_view(|cx| crate::surfaces::welcome::Welcome::new(cx)) + }) + .unwrap(); + } + } }); } diff --git a/src/ui/src/settings/mod.rs b/src/ui/src/settings/mod.rs new file mode 100644 index 0000000..272186c --- /dev/null +++ b/src/ui/src/settings/mod.rs @@ -0,0 +1,36 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Serialize, Deserialize)] +pub struct Settings { + pub token: Option, +} + +impl Settings { + pub fn new() -> Self { + Self { token: None } + } +} + +pub fn get_full_settings_file_path() -> String { + let home = dirs::home_dir().expect("Could not determine home directory"); + let path = home.join(".scopeclient/settings.json"); + path.to_str().unwrap().to_string() +} + +pub fn load_or_init_settings_on_disk() -> Settings { + let path = get_full_settings_file_path(); + + if let Ok(file) = std::fs::read_to_string(&path) { + if let Ok(settings) = serde_json::from_str(&file) { + return settings; + } + } + + let settings = Settings::new(); + let settings_json = serde_json::to_string(&settings).unwrap(); + + std::fs::create_dir_all(path.rsplitn(2, '/').last().unwrap()).unwrap(); + std::fs::write(&path, settings_json).unwrap(); + + settings +} diff --git a/src/ui/src/surfaces/README.md b/src/ui/src/surfaces/README.md new file mode 100644 index 0000000..3c9af18 --- /dev/null +++ b/src/ui/src/surfaces/README.md @@ -0,0 +1 @@ +Probably a poorly named folder. This is the renderers for each window. Right now that's the welcome/setup window, and the main application window. diff --git a/src/ui/src/app.rs b/src/ui/src/surfaces/app.rs similarity index 94% rename from src/ui/src/app.rs rename to src/ui/src/surfaces/app.rs index 54449bb..8856a03 100644 --- a/src/ui/src/app.rs +++ b/src/ui/src/surfaces/app.rs @@ -11,7 +11,7 @@ pub struct App { impl App { pub fn new(ctx: &mut ViewContext<'_, Self>) -> App { let token = dotenv::var("DISCORD_TOKEN").expect("Must provide DISCORD_TOKEN in .env"); - let demo_channel_id = dotenv::var("DEMO_CHANNEL_ID").expect("Must provide DEMO_CHANNEL_ID in .env"); + let demo_channel_id = dotenv::var("DEMO_CHANNEL_ID").unwrap_or("1306357873437179944".into()); let mut context = ctx.to_async(); diff --git a/src/ui/src/surfaces/mod.rs b/src/ui/src/surfaces/mod.rs new file mode 100644 index 0000000..6f7a022 --- /dev/null +++ b/src/ui/src/surfaces/mod.rs @@ -0,0 +1,2 @@ +pub mod app; +pub mod welcome; diff --git a/src/ui/src/surfaces/welcome.rs b/src/ui/src/surfaces/welcome.rs new file mode 100644 index 0000000..7f0722f --- /dev/null +++ b/src/ui/src/surfaces/welcome.rs @@ -0,0 +1,16 @@ +use components::theme::ActiveTheme; +use gpui::{div, ParentElement, Render, Styled, ViewContext}; + +pub struct Welcome {} + +impl Welcome { + pub fn new(ctx: &mut ViewContext<'_, Self>) -> Welcome { + Welcome {} + } +} + +impl Render for Welcome { + fn render(&mut self, cx: &mut gpui::ViewContext) -> impl gpui::IntoElement { + div().bg(cx.theme().background).w_full().h_full().flex().flex_col().child(div().child("cool")) + } +}