diff --git a/.drone.yml b/.drone.yml index c6f4492..555e80b 100644 --- a/.drone.yml +++ b/.drone.yml @@ -26,6 +26,7 @@ steps: - cargo install cargo-deb - cargo deb -v -p cli -o target/debian/jm.deb - cargo deb -v -p tokencracker -o target/debian/jmtoken.deb + - cargo deb -v -p gui -o target/debian/jmg.deb - name: publish image: plugins/gitea-release @@ -38,10 +39,13 @@ steps: files: - target/release/jm - target/release/jmtoken + - target/release/jmg - target/x86_64-pc-windows-gnu/release/jm.exe - target/x86_64-pc-windows-gnu/release/jmtoken.exe + - target/x86_64-pc-windows-gnu/release/jmg.exe - target/debian/jm.deb - target/debian/jmtoken.deb + - target/debian/jmg.deb when: event: tag depends_on: diff --git a/Cargo.toml b/Cargo.toml index c5417f6..d552ed0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [workspace] members = [ - "tokencracker", "cli", + "gui", "jm_client_core", + "tokencracker", ] diff --git a/cli/Cargo.toml b/cli/Cargo.toml index a51a497..8891358 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -29,4 +29,5 @@ term-table = "1.3.0" term_size = "0.3.2" tokio = { version = "0.2.23", features = ["macros", "fs", "process"] } url = "2.2.0" +reqwest = { version = "0.10", features = ["stream"] } diff --git a/gui/Cargo.toml b/gui/Cargo.toml new file mode 100644 index 0000000..5efcc67 --- /dev/null +++ b/gui/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "gui" +version = "0.1.0" +authors = ["LordMZTE "] +edition = "2018" + +[package.metadata.deb] +name = "jensmemes-gui" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[[bin]] +name = "jmg" +path = "src/main.rs" + +[dependencies] +anyhow = "1.0.40" +druid = "0.7.0" +jm_client_core = { path = "../jm_client_core" } +tokio = { version = "0.2.23", features = ["macros"] } +reqwest = "0.10" diff --git a/gui/src/main.rs b/gui/src/main.rs new file mode 100644 index 0000000..3ae6f38 --- /dev/null +++ b/gui/src/main.rs @@ -0,0 +1,80 @@ +use std::{cmp::Ordering, sync::Arc}; + +use crate::util::EqData; +use druid::{ + widget::{Flex, Label, List, Scroll}, + AppLauncher, + Color, + Data, + Lens, + Widget, + WidgetExt, + WindowDesc, +}; +use jm_client_core::api::Meme; +use reqwest::Client; + +pub(crate) mod util; + +const LIST_COLS: &[(&str, f64)] = &[("Link", 1000.), ("User", 50.)]; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + let http = Client::new(); + let mut memes = jm_client_core::util::api::memes(&http, None, None) + .await? + .iter() + .map(|m| EqData(m.clone())) + .collect::>(); + + memes.sort_by(|a, b| { + if let Ok((a, b)) = + a.0.file_name() + .and_then(|a| b.0.file_name().map(|b| (a, b))) + { + a.cmp(b) + } else { + Ordering::Equal + } + }); + + let main_gui = WindowDesc::new(build_root_widget).title("JensMemes GUI"); + + AppLauncher::with_window(main_gui).launch(State { + memes: Arc::new(memes), + })?; + + Ok(()) +} + +#[derive(Debug, Clone, Data, Lens)] +pub struct State { + pub memes: Arc>>, +} + +fn build_root_widget() -> impl Widget { + Scroll::new( + Flex::column() + .with_child( + Flex::row() + .with_child(Label::new(LIST_COLS[0].0).fix_width(LIST_COLS[0].1)) + .with_child(Label::new(LIST_COLS[1].0).fix_width(LIST_COLS[1].1)) + .background(Color::grey8(0x33)), + ) + .with_child( + List::new(|| { + Flex::row() + .with_child( + Label::dynamic(|d: &EqData, _| d.0.link.clone()) + .fix_width(LIST_COLS[0].1), + ) + .with_child( + Label::dynamic(|d: &EqData, _| d.0.user.clone()) + .fix_width(LIST_COLS[1].1), + ) + }) + .lens(State::memes), + ), + ) + .padding(5.) +} diff --git a/gui/src/util.rs b/gui/src/util.rs new file mode 100644 index 0000000..2466756 --- /dev/null +++ b/gui/src/util.rs @@ -0,0 +1,10 @@ +use druid::Data; + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct EqData(pub T); + +impl Data for EqData { + fn same(&self, other: &Self) -> bool { + self == other + } +} diff --git a/jm_client_core/Cargo.toml b/jm_client_core/Cargo.toml index 3072552..40038b6 100644 --- a/jm_client_core/Cargo.toml +++ b/jm_client_core/Cargo.toml @@ -16,5 +16,5 @@ reqwest = "0.10.9" serde = { version = "1.0.117", features = ["derive"] } serde_json = "1.0.60" thiserror = "1.0.23" -tokio = { version = "0.2.23", features = ["macros", "fs", "process"] } +tokio = { version = "0.2.23", features = ["macros", "fs"] } url = "2.2.0"