Skip to content

Commit

Permalink
finished welcome and help
Browse files Browse the repository at this point in the history
  • Loading branch information
casperstorm committed Jun 26, 2023
1 parent c2a62e4 commit fc3406d
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 57 deletions.
1 change: 1 addition & 0 deletions data/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub(crate) fn data_dir() -> Option<PathBuf> {
}
}

#[allow(dead_code)]
fn is_absolute(path: &Path) -> bool {
path.is_absolute()
}
3 changes: 1 addition & 2 deletions data/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = String>,
Expand Down
3 changes: 1 addition & 2 deletions data/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
2 changes: 1 addition & 1 deletion src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
44 changes: 7 additions & 37 deletions src/buffer/empty.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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<Event> {
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<Event> {
None
}
}
Expand Down
14 changes: 12 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down
59 changes: 49 additions & 10 deletions src/screen/welcome.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -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<Event> {
None
pub fn update(&mut self, message: Message) -> Option<Event> {
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"))
Expand Down Expand Up @@ -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![]
Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions src/stream.rs
Original file line number Diff line number Diff line change
@@ -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<stream::Update> {
// Channel messages are batched every 50ms so channel size 10 ~= 500ms which
Expand Down
4 changes: 4 additions & 0 deletions src/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ pub enum Text {
Alpha04,
Action,
Accent,
Info,
Server,
Error,
Nickname(Option<String>),
Expand All @@ -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),
},
Expand Down

0 comments on commit fc3406d

Please sign in to comment.