diff --git a/data/src/environment.rs b/data/src/environment.rs index fa27a2dc3..a95f40a2b 100644 --- a/data/src/environment.rs +++ b/data/src/environment.rs @@ -46,6 +46,7 @@ pub(crate) fn data_dir() -> Option { } } +#[allow(dead_code)] fn is_absolute(path: &Path) -> bool { path.is_absolute() } diff --git a/data/src/message.rs b/data/src/message.rs index 098acfb6c..5790948d2 100644 --- a/data/src/message.rs +++ b/data/src/message.rs @@ -358,9 +358,8 @@ pub(crate) mod broadcast { //! Generate messages that can be broadcast into every buffer use chrono::Utc; - use crate::user::Nick; - use super::{Direction, Message, Sender, Source}; + use crate::user::Nick; fn expand( channels: impl IntoIterator, diff --git a/data/src/stream.rs b/data/src/stream.rs index 2c0fbed99..d89a6af37 100644 --- a/data/src/stream.rs +++ b/data/src/stream.rs @@ -2,8 +2,7 @@ use std::time::Duration; use futures::channel::mpsc; use futures::never::Never; -use futures::stream; -use futures::{SinkExt, StreamExt}; +use futures::{stream, SinkExt, StreamExt}; use irc::proto::Capability; use tokio::time::{self, Instant, Interval}; diff --git a/src/buffer.rs b/src/buffer.rs index 8cea15002..00393596e 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -91,7 +91,7 @@ impl Buffer { is_focused: bool, ) -> Element<'a, Message> { match self { - Buffer::Empty(state) => empty::view(state, clients).map(Message::Empty), + Buffer::Empty(state) => empty::view(state).map(Message::Empty), Buffer::Channel(state) => { let status = clients.status(&state.server); diff --git a/src/buffer/empty.rs b/src/buffer/empty.rs index f1756bf07..5c535ac7d 100644 --- a/src/buffer/empty.rs +++ b/src/buffer/empty.rs @@ -1,41 +1,21 @@ use core::fmt; -use data::Config; -use iced::widget::{button, column, container, text, vertical_space}; +use iced::widget::{column, container, text}; use iced::{alignment, Length}; -use crate::theme; -use crate::widget::{Collection, Element}; +use crate::widget::Element; #[derive(Debug, Clone)] -pub enum Message { - ConfigurationDirectoryPressed, -} +pub enum Message {} #[derive(Debug, Clone)] pub enum Event {} -pub fn view<'a>(_state: &Empty, clients: &data::client::Map) -> Element<'a, Message> { - let is_empty = clients.get_channels().is_empty(); - let config_dir = is_empty - .then(|| { - Config::config_dir() - .map(|path| String::from(path.to_string_lossy())) - .ok() - }) - .flatten(); - - let error = text("you had me at Halloy"); +pub fn view<'a>(_state: &Empty) -> Element<'a, Message> { + // TODO: Consider if we can completetly remove this buffer. - let action = config_dir.map(|path| { - button(text(path)) - .on_press(Message::ConfigurationDirectoryPressed) - .style(theme::Button::Default) - }); let content = column![] - .push(error) - .push(vertical_space(14)) - .push_maybe(action) + .push(text("⟵ select buffer")) .align_items(iced::Alignment::Center); container(content) @@ -50,17 +30,7 @@ pub fn view<'a>(_state: &Empty, clients: &data::client::Map) -> Element<'a, Mess pub struct Empty {} impl Empty { - pub fn update(&mut self, message: Message) -> Option { - match message { - Message::ConfigurationDirectoryPressed => { - let Ok(config) = Config::config_dir() else { - return None - }; - - let _ = open::that(config); - } - } - + pub fn update(&mut self, _message: Message) -> Option { None } } diff --git a/src/main.rs b/src/main.rs index 28519a540..954715cc3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,11 +15,11 @@ use std::env; use data::config::{self, Config}; use iced::widget::container; use iced::{executor, Application, Command, Length, Subscription}; +use screen::{dashboard, help, welcome}; use self::event::{events, Event}; pub use self::theme::Theme; use self::widget::Element; -use screen::{dashboard, help, welcome}; pub fn main() -> iced::Result { let mut args = env::args(); @@ -227,7 +227,17 @@ impl Application for Halloy { return Command::none(); }; - let _ = welcome.update(message); + if let Some(event) = welcome.update(message) { + match event { + welcome::Event::RefreshConfiguration => { + let (halloy, command) = Halloy::load_from_configuration(); + *self = halloy; + + return command; + } + } + } + Command::none() } Message::Stream(update) => match update { diff --git a/src/screen/welcome.rs b/src/screen/welcome.rs index 47abb447d..e0a9a4e24 100644 --- a/src/screen/welcome.rs +++ b/src/screen/welcome.rs @@ -1,6 +1,4 @@ -use std::path::PathBuf; - -use data::{config, Config}; +use data::Config; use iced::widget::{button, column, container, image, row, text, vertical_space}; use iced::{alignment, Length}; @@ -18,19 +16,34 @@ pub enum Event { RefreshConfiguration, } -#[derive(Debug, Clone)] -pub struct Welcome {} +#[derive(Debug, Default, Clone)] +pub struct Welcome; impl Welcome { pub fn new() -> Self { - Welcome {} + Welcome::default() } - pub fn update(&mut self, _message: Message) -> Option { - None + pub fn update(&mut self, message: Message) -> Option { + match message { + Message::RefreshConfiguration => Some(Event::RefreshConfiguration), + Message::OpenConfigurationDirectory => { + let Ok(config) = Config::config_dir() else { + return None + }; + + let _ = open::that(config); + + None + } + } } pub fn view<'a>(&self) -> Element<'a, Message> { + let config_dir = Config::config_dir() + .map(|path| String::from(path.to_string_lossy())) + .expect("welcome screen expects valid config dir"); + let config_button = Config::config_dir().ok().map(|_| { button( container(text("Open Directory")) @@ -58,8 +71,34 @@ impl Welcome { .push(text("Welcome to Halloy!").font(font::MONO_BOLD)) .push(vertical_space(4)) .push(text( - "To get started, please create a configuration file. You can find help to create the configuration file on the website: halloy.squidowl.org", + "No configuration file found. Please follow the steps below to proceed", )) + .push(vertical_space(8)) + .push( + column![] + .push(row![ + text("1. ").style(theme::Text::Accent), + text("Go to "), + text(config_dir).style(theme::Text::Info) + ]) + .push(row![ + text("2. ").style(theme::Text::Accent), + text("Create a "), + text("config.yml").style(theme::Text::Info), + text(" file, which will serve as your configuration file"), + ]) + .push(row![ + text("3. ").style(theme::Text::Accent), + text("Customize the file with your preferred servers, settings, and theme") + ]) + .push(row![ + text("4. ").style(theme::Text::Accent), + text("For help and assistance, please visit "), + text("github.com/squidowl/halloy").style(theme::Text::Info), + ]) + .spacing(2) + .align_items(iced::Alignment::Start), + ) .push(vertical_space(10)) .push( row![] @@ -70,7 +109,7 @@ impl Welcome { ) .align_items(iced::Alignment::Center); - container(container(content).width(450)) + container(container(content).width(475)) .align_x(alignment::Horizontal::Center) .align_y(alignment::Vertical::Center) .width(Length::Fill) diff --git a/src/stream.rs b/src/stream.rs index f06054b7d..c666e5ed8 100644 --- a/src/stream.rs +++ b/src/stream.rs @@ -1,8 +1,6 @@ use data::server; -use iced::subscription; -use iced::Subscription; - pub use data::stream::{self, *}; +use iced::{subscription, Subscription}; pub fn run(entry: server::Entry) -> Subscription { // Channel messages are batched every 50ms so channel size 10 ~= 500ms which diff --git a/src/theme.rs b/src/theme.rs index 6d2817b51..033f284ad 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -154,6 +154,7 @@ pub enum Text { Alpha04, Action, Accent, + Info, Server, Error, Nickname(Option), @@ -177,6 +178,9 @@ impl text::StyleSheet for Theme { Text::Accent => text::Appearance { color: Some(self.colors.accent.base), }, + Text::Info => text::Appearance { + color: Some(self.colors.info.base), + }, Text::Error => text::Appearance { color: Some(self.colors.error.base), },