diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-12-08 18:55:17 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-12-08 18:55:17 +0100 |
commit | da8e93414399157e1dd66f527c7466a1e7218807 (patch) | |
tree | 61fe96501952d9965bb077d57a5257b519ffc7e8 | |
parent | cd93da65aa447d3bf4ec53fbad040e77305b38c3 (diff) | |
parent | 7863d21153afd293226c9889610379ab94b0b6f6 (diff) |
Merge branch 'iced-gui'
-rw-r--r-- | Cargo.toml | 54 | ||||
-rw-r--r-- | cli/Cargo.toml | 49 | ||||
-rw-r--r-- | cli/src/cli.rs (renamed from src/cli.rs) | 7 | ||||
-rw-r--r-- | cli/src/main.rs | 28 | ||||
-rw-r--r-- | cli/src/profile.rs (renamed from src/commands/profile.rs) | 4 | ||||
-rw-r--r-- | gui/Cargo.toml | 46 | ||||
-rw-r--r-- | gui/src/app.rs | 185 | ||||
-rw-r--r-- | gui/src/cli.rs | 19 | ||||
-rw-r--r-- | gui/src/main.rs | 22 | ||||
-rw-r--r-- | lib/Cargo.toml | 63 | ||||
-rw-r--r-- | lib/src/cid.rs (renamed from src/cid.rs) | 0 | ||||
-rw-r--r-- | lib/src/client.rs (renamed from src/client.rs) | 0 | ||||
-rw-r--r-- | lib/src/config.rs (renamed from src/config.rs) | 0 | ||||
-rw-r--r-- | lib/src/consts.rs (renamed from src/consts.rs) | 0 | ||||
-rw-r--r-- | lib/src/ipfs_client.rs (renamed from src/ipfs_client.rs) | 0 | ||||
-rw-r--r-- | lib/src/lib.rs | 6 | ||||
-rw-r--r-- | lib/src/profile/mod.rs (renamed from src/profile/mod.rs) | 7 | ||||
-rw-r--r-- | lib/src/profile/state.rs (renamed from src/profile/state.rs) | 0 | ||||
-rw-r--r-- | lib/src/types/datetime.rs (renamed from src/types/datetime.rs) | 0 | ||||
-rw-r--r-- | lib/src/types/mod.rs (renamed from src/types/mod.rs) | 0 | ||||
-rw-r--r-- | lib/src/types/node.rs (renamed from src/types/node.rs) | 0 | ||||
-rw-r--r-- | lib/src/types/payload.rs (renamed from src/types/payload.rs) | 0 | ||||
-rw-r--r-- | shell.nix | 28 | ||||
-rw-r--r-- | src/commands/mod.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 24 |
25 files changed, 463 insertions, 81 deletions
@@ -1,48 +1,6 @@ -[package] -name = "distrox" -version = "0.1.0" -authors = ["Matthias Beyer <mail@beyermatthias.de>"] - -description = "Distributed network build on IPFS" - -keywords = ["social", "network", "ipfs", "distributed"] -readme = "README.md" -license = "GPL-2.0" - -documentation = "https://docs.rs/distrox" -repository = "https://github.com/matthiasbeyer/distrox" -homepage = "http://github.com/matthiasbeyer/distrox" - -edition = "2018" - -[dependencies] -anyhow = "1" -async-trait = "0.1" -chrono = { version = "0.4", features = ["serde"] } -cid = "0.5" -clap = "3.0.0-beta.5" -daglib = { git = "https://git.sr.ht/~matthiasbeyer/daglib", branch = "master" } -env_logger = "0.8" -futures = "0.3" -log = "0.4" -tokio = { version = "1", features = ["full", "rt", "macros"] } -mime = "0.3" -rand_core = { version = "0.6", features = ["getrandom"] } -rand_os = "0.2" -ed25519-dalek = "*" -http = "0.2" -serde = "1" -serde_json = "1" -getset = "0.1" -xdg = "2.4" -libp2p = "0.39.1" -tracing = "0.1" -ctrlc = "3.2" - -[dependencies.ipfs] -git = "https://github.com/rs-ipfs/rust-ipfs/" -rev = "ad3ab49b4d9236363969b0f74f14aabc7c906b3b" - - -[dev-dependencies] -multibase = "0.8" +[workspace] +members = [ + "cli", + "gui", + "lib", +] diff --git a/cli/Cargo.toml b/cli/Cargo.toml new file mode 100644 index 0000000..e558c19 --- /dev/null +++ b/cli/Cargo.toml @@ -0,0 +1,49 @@ +[package] +name = "distrox-cli" +version = "0.1.0" +authors = ["Matthias Beyer <mail@beyermatthias.de>"] + +description = "Distributed network build on IPFS, CLI frontend" + +keywords = ["social", "network", "ipfs", "distributed"] +readme = "README.md" +license = "GPL-2.0" + +documentation = "https://docs.rs/distrox" +repository = "https://github.com/matthiasbeyer/distrox" +homepage = "http://github.com/matthiasbeyer/distrox" + +edition = "2018" + +[dependencies] +anyhow = "1" +async-trait = "0.1" +chrono = { version = "0.4", features = ["serde"] } +cid = "0.5" +clap = "3.0.0-beta.5" +daglib = { git = "https://git.sr.ht/~matthiasbeyer/daglib", branch = "master" } +env_logger = "0.8" +futures = "0.3" +log = "0.4" +tokio = { version = "1", features = ["full", "rt", "macros"] } +mime = "0.3" +rand_core = { version = "0.6", features = ["getrandom"] } +rand_os = "0.2" +ed25519-dalek = "*" +http = "0.2" +serde = "1" +serde_json = "1" +getset = "0.1" +xdg = "2.4" +tracing = "0.1" +ctrlc = "3.2" + +[dependencies.ipfs] +git = "https://github.com/rs-ipfs/rust-ipfs/" +rev = "ad3ab49b4d9236363969b0f74f14aabc7c906b3b" + +[dependencies.distrox-lib] +path = "../lib" + +[dev-dependencies] +multibase = "0.8" diff --git a/src/cli.rs b/cli/src/cli.rs index 8e912e0..3f74128 100644 --- a/src/cli.rs +++ b/cli/src/cli.rs @@ -9,7 +9,6 @@ pub fn app<'a>() -> App<'a> { .version(crate_version!()) .about("Distributed social network") - .subcommand(App::new("profile") .author(crate_authors!()) .version(crate_version!()) @@ -51,4 +50,10 @@ pub fn app<'a>() -> App<'a> { ) ) ) + + .subcommand(App::new("gui") + .author(crate_authors!()) + .version(crate_version!()) + .about("Start the distrox gui") + ) } diff --git a/cli/src/main.rs b/cli/src/main.rs new file mode 100644 index 0000000..c4050ac --- /dev/null +++ b/cli/src/main.rs @@ -0,0 +1,28 @@ +use anyhow::Result; + +mod cli; +mod profile; + +#[tokio::main] +async fn main() -> Result<()> { + let _ = env_logger::try_init()?; + let matches = crate::cli::app().get_matches(); + + match matches.subcommand() { + Some(("profile", matches)) => crate::profile::profile(matches).await, + Some(("gui", _)) => { + unimplemented!() + }, + Some((other, _)) => { + log::error!("No subcommand {} implemented", other); + Ok(()) + }, + + _ => { + log::error!("Don't know what to do"); + Ok(()) + }, + } +} + + diff --git a/src/commands/profile.rs b/cli/src/profile.rs index 853984f..0eb8b75 100644 --- a/src/commands/profile.rs +++ b/cli/src/profile.rs @@ -6,8 +6,8 @@ use anyhow::Context; use anyhow::Result; use clap::ArgMatches; -use crate::config::Config; -use crate::profile::Profile; +use distrox_lib::config::Config; +use distrox_lib::profile::Profile; pub async fn profile(matches: &ArgMatches) -> Result<()> { match matches.subcommand() { diff --git a/gui/Cargo.toml b/gui/Cargo.toml new file mode 100644 index 0000000..274f8ed --- /dev/null +++ b/gui/Cargo.toml @@ -0,0 +1,46 @@ +[package] +name = "distrox-gui" +version = "0.1.0" +authors = ["Matthias Beyer <mail@beyermatthias.de>"] + +description = "Distributed network build on IPFS, GUI frontend" + +keywords = ["social", "network", "ipfs", "distributed"] +readme = "README.md" +license = "GPL-2.0" + +documentation = "https://docs.rs/distrox" +repository = "https://github.com/matthiasbeyer/distrox" +homepage = "http://github.com/matthiasbeyer/distrox" + +edition = "2018" + +[dependencies] +anyhow = "1" +chrono = { version = "0.4", features = ["serde"] } +cid = "0.5" +clap = "3.0.0-beta.5" +env_logger = "0.8" +futures = "0.3" +log = "0.4" +getset = "0.1" +xdg = "2.4" +tracing = "0.1" +ctrlc = "3.2" + +[dependencies.ipfs] +git = "https://github.com/rs-ipfs/rust-ipfs/" +rev = "ad3ab49b4d9236363969b0f74f14aabc7c906b3b" + +[dependencies.iced] +git = "https://github.com/iced-rs/iced" +rev = "6f3a608717e08330187871516b1ab54a9a2192a3" +default-features = false +features = ["glow", "tokio", "debug"] + +[dependencies.distrox-lib] +path = "../lib" + +[dev-dependencies] +multibase = "0.8" + diff --git a/gui/src/app.rs b/gui/src/app.rs new file mode 100644 index 0000000..d60f7b8 --- /dev/null +++ b/gui/src/app.rs @@ -0,0 +1,185 @@ +use std::sync::Arc; + +use anyhow::Result; +use iced::Application; +use iced::Column; +use iced::Container; +use iced::Length; +use iced::Scrollable; +use iced::TextInput; +use iced::scrollable; +use iced::text_input; + +use distrox_lib::profile::Profile; +use distrox_lib::config::Config; + +#[derive(Debug)] +enum Distrox { + Loading, + Loaded(State), + FailedToStart, +} + +#[derive(Debug)] +struct State { + profile: Arc<Profile>, + + scroll: scrollable::State, + input: text_input::State, + input_value: String, +} + +#[derive(Debug, Clone)] +enum Message { + Loaded(Arc<Profile>), + FailedToLoad, + + InputChanged(String), + CreatePost, + + PostCreated(cid::Cid), + PostCreationFailed(String), +} + +impl Application for Distrox { + type Executor = iced::executor::Default; // tokio + type Message = Message; + type Flags = String; + + fn new(name: String) -> (Self, iced::Command<Self::Message>) { + ( + Distrox::Loading, + iced::Command::perform(async move { + match Profile::new_inmemory(Config::default(), &name).await { + Err(_) => Message::FailedToLoad, + Ok(instance) => { + Message::Loaded(Arc::new(instance)) + } + } + }, |m: Message| -> Message { m }) + ) + } + + fn title(&self) -> String { + String::from("distrox") + } + + fn update(&mut self, message: Self::Message) -> iced::Command<Self::Message> { + match self { + Distrox::Loading => { + match message { + Message::Loaded(profile) => { + let state = State { + profile, + scroll: scrollable::State::default(), + input: text_input::State::default(), + input_value: String::default(), + }; + *self = Distrox::Loaded(state); + } + + Message::FailedToLoad => { + log::error!("Failed to load"); + *self = Distrox::FailedToStart; + } + + _ => {} + + } + } + + Distrox::Loaded(state) => { + match message { + Message::InputChanged(input) => { + state.input_value = input; + } + + Message::CreatePost => { + if !state.input_value.is_empty() { + let profile = state.profile.clone(); + let input = state.input_value.clone(); + iced::Command::perform(async move { + profile.client().post_text_blob(input).await + }, + |res| match res { + Ok(cid) => Message::PostCreated(cid), + Err(e) => Message::PostCreationFailed(e.to_string()) + }); + } + } + + _ => {} + } + } + + Distrox::FailedToStart => { + unimplemented!() + } + } + iced::Command::none() + } + + fn view(&mut self) -> iced::Element<Self::Message> { + match self { + Distrox::Loading => { + let text = iced::Text::new("Loading"); + + let content = Column::new() + .max_width(800) + .spacing(20) + .push(text); + + Container::new(content) + .width(Length::Fill) + .center_x() + .into() + } + + Distrox::Loaded(state) => { + let input = TextInput::new( + &mut state.input, + "What do you want to tell the world?", + &mut state.input_value, + Message::InputChanged, + ) + .padding(15) + .size(30) + .on_submit(Message::CreatePost); + + let content = Column::new() + .max_width(800) + .spacing(20) + .push(input); + + Scrollable::new(&mut state.scroll) + .padding(40) + .push( + Container::new(content).width(Length::Fill).center_x(), + ) + .into() + } + + Distrox::FailedToStart => { + unimplemented!() + } + } + } + +} + +pub fn run(name: String) -> Result<()> { + let settings = iced::Settings { + window: iced::window::Settings { + resizable: true, + decorations: true, + transparent: false, + always_on_top: false, + ..iced::window::Settings::default() + }, + flags: name, + exit_on_close_request: true, + ..iced::Settings::default() + }; + + Distrox::run(settings).map_err(anyhow::Error::from) +} diff --git a/gui/src/cli.rs b/gui/src/cli.rs new file mode 100644 index 0000000..bf81b45 --- /dev/null +++ b/gui/src/cli.rs @@ -0,0 +1,19 @@ +use clap::crate_authors; +use clap::crate_version; +use clap::App; +use clap::Arg; + +pub fn app<'a>() -> App<'a> { + App::new("distrox-gui") + .author(crate_authors!()) + .version(crate_version!()) + .about("Distributed social network, GUI frontend") + + .arg(Arg::new("name") + .index(1) + .takes_value(true) + .value_name("NAME") + .about("Profile to load the GUI for") + ) +} + diff --git a/gui/src/main.rs b/gui/src/main.rs new file mode 100644 index 0000000..32d6d61 --- /dev/null +++ b/gui/src/main.rs @@ -0,0 +1,22 @@ +use anyhow::Result; + +mod app; +mod cli; + +fn main() -> Result<()> { + let _ = env_logger::try_init()?; + let matches = crate::cli::app().get_matches(); + + match matches.subcommand() { + None => { + let name = matches.value_of("name").map(String::from).unwrap(); // safe by clap + crate::app::run(name) + }, + Some((other, _)) => { + log::error!("No subcommand {} implemented", other); + Ok(()) + }, + } +} + + diff --git a/lib/Cargo.toml b/lib/Cargo.toml new file mode 100644 index 0000000..a8a90fa --- /dev/null +++ b/lib/Cargo.toml @@ -0,0 +1,63 @@ +[package] +name = "distrox-lib" +version = "0.1.0" +authors = ["Matthias Beyer <mail@beyermatthias.de>"] + +description = "Distributed network build on IPFS" + +keywords = ["social", "network", "ipfs", "distributed"] +readme = "README.md" +license = "GPL-2.0" + +documentation = "https://docs.rs/distrox" +repository = "https://github.com/matthiasbeyer/distrox" +homepage = "http://github.com/matthiasbeyer/distrox" + +edition = "2018" + +[dependencies] +anyhow = "1" +async-trait = "0.1" +chrono = { version = "0.4", features = ["serde"] } +cid = "0.5" +clap = "3.0.0-beta.5" +daglib = { git = "https://git.sr.ht/~matthiasbeyer/daglib", branch = "master" } +env_logger = "0.8" +futures = "0.3" +log = "0.4" +tokio = { version = "1", features = ["full", "rt", "macros"] } +mime = "0.3" +rand_core = { version = "0.6", features = ["getrandom"] } +rand_os = "0.2" +ed25519-dalek = "*" +http = "0.2" +serde = "1" +serde_json = "1" +getset = "0.1" +xdg = "2.4" +tracing = "0.1" +ctrlc = "3.2" + +[dependencies.libp2p] +version = "0.39.1" +default-features = false +features = [ + "dns-tokio", + "floodsub", + "gossipsub", + "identify", + "kad", + "mdns", + "mplex", + "noise", + "ping", + "tcp-tokio", + "yamux" +] + +[dependencies.ipfs] +git = "https://github.com/rs-ipfs/rust-ipfs/" +rev = "ad3ab49b4d9236363969b0f74f14aabc7c906b3b" + +[dev-dependencies] +multibase = "0.8" diff --git a/src/cid.rs b/lib/src/cid.rs index 2957cc5..2957cc5 100644 --- a/src/cid.rs +++ b/lib/src/cid.rs diff --git a/src/client.rs b/lib/src/client.rs index da8ad94..da8ad94 100644 --- a/src/client.rs +++ b/lib/src/client.rs diff --git a/src/config.rs b/lib/src/config.rs index 0d25e78..0d25e78 100644 --- a/src/config.rs +++ b/lib/src/config.rs diff --git a/src/consts.rs b/lib/src/consts.rs index 79ff2f5..79ff2f5 100644 --- a/src/consts.rs +++ b/lib/src/consts.rs diff --git a/src/ipfs_client.rs b/lib/src/ipfs_client.rs index 964b22c..964b22c 100644 --- a/src/ipfs_client.rs +++ b/lib/src/ipfs_client.rs diff --git a/lib/src/lib.rs b/lib/src/lib.rs new file mode 100644 index 0000000..759ea14 --- /dev/null +++ b/lib/src/lib.rs @@ -0,0 +1,6 @@ +pub mod client; +pub mod config; +pub mod consts; +pub mod ipfs_client; +pub mod profile; +pub mod types; diff --git a/src/profile/mod.rs b/lib/src/profile/mod.rs index 56b4ac9..db3c593 100644 --- a/src/profile/mod.rs +++ b/lib/src/profile/mod.rs @@ -11,9 +11,11 @@ use crate::ipfs_client::IpfsClient; mod state; use state::*; -#[derive(Debug)] +#[derive(Debug, getset::Getters)] pub struct Profile { state: ProfileState, + + #[getset(get = "pub")] client: Client, } @@ -41,8 +43,7 @@ impl Profile { Self::new(ipfs, config, name.to_string(), keypair).await } - #[cfg(test)] - async fn new_inmemory(config: Config, name: &str) -> Result<Self> { + pub async fn new_inmemory(config: Config, name: &str) -> Result<Self> { let mut opts = ipfs::IpfsOptions::inmemory_with_generated_keys(); opts.mdns = true; let keypair = opts.keypair.clone(); diff --git a/src/profile/state.rs b/lib/src/profile/state.rs index 4075b52..4075b52 100644 --- a/src/profile/state.rs +++ b/lib/src/profile/state.rs diff --git a/src/types/datetime.rs b/lib/src/types/datetime.rs index 00d739a..00d739a 100644 --- a/src/types/datetime.rs +++ b/lib/src/types/datetime.rs diff --git a/src/types/mod.rs b/lib/src/types/mod.rs index 7382f16..7382f16 100644 --- a/src/types/mod.rs +++ b/lib/src/types/mod.rs diff --git a/src/types/node.rs b/lib/src/types/node.rs index eb5679b..eb5679b 100644 --- a/src/types/node.rs +++ b/lib/src/types/node.rs diff --git a/src/types/payload.rs b/lib/src/types/payload.rs index a11b215..a11b215 100644 --- a/src/types/payload.rs +++ b/lib/src/types/payload.rs @@ -22,11 +22,37 @@ let pkgconfig which zlib + + freetype + expat + ]; + xorgPackages = with pkgs.xorg; [ + libXcursor + libXfont2 + # libXpm + # libXtst + # libxshmfence + # libXft + libXrandr + libXext + # libXinerama + # libXrender + # libXxf86misc + # libxcb + libX11 + # libXcomposite + libXfont + libXi + # libXt + # libxkbfile + + pkgs.libGL ]; in pkgs.mkShell rec { - buildInputs = env ++ dependencies; + buildInputs = env ++ dependencies ++ xorgPackages; LIBCLANG_PATH = "${pkgs.llvmPackages.libclang}/lib"; PROTOC = "${pkgs.protobuf}/bin/protoc"; + LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath xorgPackages; } diff --git a/src/commands/mod.rs b/src/commands/mod.rs deleted file mode 100644 index 5569bcb..0000000 --- a/src/commands/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -mod profile; -pub use profile::profile; diff --git a/src/main.rs b/src/main.rs deleted file mode 100644 index 257847c..0000000 --- a/src/main.rs +++ /dev/null @@ -1,24 +0,0 @@ -use anyhow::Result; - -pub mod cli; -pub mod client; -mod commands; -pub mod config; -pub mod consts; -pub mod ipfs_client; -pub mod profile; -pub mod types; - -#[tokio::main] -async fn main() -> Result<()> { - let _ = env_logger::try_init()?; - let matches = crate::cli::app().get_matches(); - - match matches.subcommand() { - Some(("profile", matches)) => crate::commands::profile(matches).await, - _ => unimplemented!() - } - - -} - |