Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement welcome and help screens for better onboarding #51

Merged
merged 2 commits into from
Jun 26, 2023
Merged
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
275 changes: 275 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ data = { version = "0.1.0", path = "data" }

chrono = { version = "0.4", features = ['serde'] }
fern = "0.6.1"
iced = { version = "0.9", features = ["tokio", "lazy", "advanced"] }
iced = { version = "0.9", features = ["tokio", "lazy", "advanced", "image"] }
log = "0.4.16"
palette = "=0.7.2"
thiserror = "1.0.30"
Expand Down
Binary file modified assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 24 additions & 15 deletions data/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fs::File;
use std::fs::{self, File};
use std::io::BufReader;
use std::path::PathBuf;

Expand All @@ -8,6 +8,8 @@ use thiserror::Error;
use crate::palette::Palette;
use crate::{environment, pane, server};

const CONFIG_TEMPLATE: &[u8] = include_bytes!("../../config.yaml");

#[derive(Debug, Clone, Default, Deserialize)]
pub struct Config {
#[serde(default)]
Expand All @@ -19,38 +21,45 @@ pub struct Config {
}

impl Config {
pub fn config_dir() -> Result<PathBuf, Error> {
let dir = environment::config_dir()
.ok_or(Error::DirectoryNotFound)?
.join("halloy");
pub fn config_dir() -> PathBuf {
let dir = environment::config_dir().join("halloy");

if !dir.exists() {
std::fs::create_dir(dir.as_path()).map_err(|_| Error::DirectoryCreation)?;
std::fs::create_dir(dir.as_path())
.expect("expected permissions to create config folder");
}

Ok(dir)
dir
}

fn path() -> Result<PathBuf, Error> {
Ok(Self::config_dir()?.join("config.yaml"))
fn path() -> PathBuf {
Self::config_dir().join("config.yaml")
}

pub fn load() -> Result<Self, Error> {
let path = Self::path()?;
let path = Self::path();
let file = File::open(path).map_err(|e| Error::Read(e.to_string()))?;

serde_yaml::from_reader(BufReader::new(file)).map_err(|e| Error::Parse(e.to_string()))
}

pub fn create_template_config() {
// Checks if a config file is there
let config_file = Self::path();
if config_file.exists() {
return;
}

// Create template configuration file.
let config_template_file = Self::config_dir().join("config.template.yaml");
let _ = fs::write(config_template_file, CONFIG_TEMPLATE);
}
}

#[derive(Debug, Error, Clone)]
pub enum Error {
#[error("config directory could not be found")]
DirectoryNotFound,
#[error("config directory could not be created")]
DirectoryCreation,
#[error("config could not be read: {0}")]
Read(String),
#[error("config could not be parsed: {0}")]
#[error("{0}")]
Parse(String),
}
6 changes: 4 additions & 2 deletions data/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub fn formatted_version() -> String {
format!("{}{hash}", VERSION)
}

pub(crate) fn config_dir() -> Option<PathBuf> {
pub(crate) fn config_dir() -> PathBuf {
// HOST_* checked first for flatpak
#[cfg(target_os = "linux")]
{
Expand All @@ -21,11 +21,12 @@ pub(crate) fn config_dir() -> Option<PathBuf> {
.map(PathBuf::from)
.filter(|p| is_absolute(p))
.or_else(dirs_next::config_dir)
.expect("expected valid config dir")
}

#[cfg(not(target_os = "linux"))]
{
dirs_next::config_dir()
dirs_next::config_dir().expect("expected valid config dir")
}
}

Expand All @@ -46,6 +47,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
7 changes: 2 additions & 5 deletions src/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use data::{buffer, config, history};
use data::{buffer, history};
use iced::Command;

use self::channel::Channel;
Expand Down Expand Up @@ -89,12 +89,9 @@ impl Buffer {
history: &'a history::Manager,
settings: &'a buffer::Settings,
is_focused: bool,
load_config_error: &'a Option<config::Error>,
) -> Element<'a, Message> {
match self {
Buffer::Empty(state) => {
empty::view(state, clients, load_config_error).map(Message::Empty)
}
Buffer::Empty(state) => empty::view(state).map(Message::Empty),
Buffer::Channel(state) => {
let status = clients.status(&state.server);

Expand Down
58 changes: 7 additions & 51 deletions src/buffer/empty.rs
Original file line number Diff line number Diff line change
@@ -1,55 +1,21 @@
use core::fmt;

use data::{config, 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,
// TODO: Make error a separate screen so we don't
// have to pass this all the way down
load_config_error: &'a Option<config::Error>,
) -> 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 = load_config_error
.as_ref()
.map(|error| text(error.to_string()).style(theme::Text::Error));
let title = if is_empty {
text("please create or edit config.yaml in the directory below")
} else {
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_maybe(error)
.push(title)
.push(vertical_space(14))
.push_maybe(action)
.push(text("⟵ select buffer"))
.align_items(iced::Alignment::Center);

container(content)
Expand All @@ -64,17 +30,7 @@ pub fn view<'a>(
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
2 changes: 1 addition & 1 deletion src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub const MONO: Font = Font {
..Font::with_name("Iosevka Term")
};

pub const _MONO_BOLD: Font = Font {
pub const MONO_BOLD: Font = Font {
monospaced: true,
weight: font::Weight::Bold,
..Font::with_name("Iosevka Term")
Expand Down
5 changes: 5 additions & 0 deletions src/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ use crate::{font, theme};

// Based off https://github.com/iced-rs/iced_aw/blob/main/src/graphics/icons/bootstrap.rs

pub fn error<'a>() -> Text<'a> {
to_text('\u{f33a}')
}

pub fn globe<'a>() -> Text<'a> {
to_text('\u{f3ef}')
}
Expand Down Expand Up @@ -40,6 +44,7 @@ pub fn people<'a>() -> Text<'a> {

fn to_text<'a>(unicode: char) -> Text<'a> {
text(unicode.to_string())
.style(theme::Text::Primary)
.line_height(LineHeight::Relative(1.1))
.size(theme::ICON_SIZE)
.font(font::ICON)
Expand Down
Loading