Skip to content
Closed
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
7 changes: 5 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[workspace]
resolver = "2"
members = [
"src/ui"
]
members = ["src/ui"]

[workspace.dependencies]
chrono = "0.4.38"
chrono = "0.4.38"
3 changes: 3 additions & 0 deletions src/ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
40 changes: 27 additions & 13 deletions src/ui/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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();
}
}
});
}
36 changes: 36 additions & 0 deletions src/ui/src/settings/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
pub struct Settings {
pub token: Option<String>,
}

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
}
1 change: 1 addition & 0 deletions src/ui/src/surfaces/README.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion src/ui/src/app.rs → src/ui/src/surfaces/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 2 additions & 0 deletions src/ui/src/surfaces/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod app;
pub mod welcome;
16 changes: 16 additions & 0 deletions src/ui/src/surfaces/welcome.rs
Original file line number Diff line number Diff line change
@@ -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<Self>) -> impl gpui::IntoElement {
div().bg(cx.theme().background).w_full().h_full().flex().flex_col().child(div().child("cool"))
}
}
Loading