Start on the GTK client application

This commit is contained in:
Savanni D'Gerinel 2021-11-21 01:12:00 -05:00
parent 05f850b9c5
commit ff18c4a0e7
9 changed files with 2007 additions and 29 deletions

1826
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

6
Cargo.toml Normal file
View File

@ -0,0 +1,6 @@
[workspace]
members = [
"common",
"gtk",
"server",
]

16
gtk/Cargo.toml Normal file
View File

@ -0,0 +1,16 @@
[package]
name = "datasphere-gtk"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
gdk = "*"
gio = { version = "0.14", features = ["v2_62"] }
glib = "0.14"
gtk-sys = "*"
gtk = { version = "0.14", features = ["v3_24"] }
gtk-clib = { path = "../../gtk-clib/" }
thiserror = "1.0.20"

43
gtk/src/aplikajxo.rs Normal file
View File

@ -0,0 +1,43 @@
use crate::elementoj::RolulPaĝo;
use glib::{Receiver, Sender};
use gtk::prelude::*;
use gtk_clib::Elemento;
#[derive(Clone)]
pub enum Ago {}
pub struct Aplikaĵo {
sendilo: Sender<Ago>,
recivilo: Receiver<Ago>,
evoluiga: bool,
vintro: gtk::ApplicationWindow,
}
impl Aplikaĵo {
pub fn kreu(
app: &gtk::Application,
sendilo: Sender<Ago>,
recivilo: Receiver<Ago>,
evoluiga: bool,
) -> Self {
let vintro = gtk::ApplicationWindow::builder()
.application(app)
.title("Datasphere Kliento")
.build();
let paĝo = RolulPaĝo::kreu();
paĝo.show();
vintro.add(&paĝo.fenestraĵo());
vintro.show();
paĝo.show();
Self {
sendilo,
recivilo,
evoluiga,
vintro,
}
}
}

36
gtk/src/elementoj/mod.rs Normal file
View File

@ -0,0 +1,36 @@
use gtk::{self, prelude::*};
use gtk_clib::{Elemento, TekstEnigo};
pub struct RolulPaĝo {
fenestraĵo: gtk::Box,
tekst_enigo: TekstEnigo,
}
impl RolulPaĝo {
pub fn kreu() -> Self {
let fenestraĵo = gtk::Box::new(gtk::Orientation::Vertical, 0);
let tekst_enigo = TekstEnigo::kreu::<String>(
None,
Box::new(|_| String::from("")),
Box::new(|v| Ok(Some(v.to_string()))),
Box::new(|_| {}),
);
fenestraĵo.pack_start(&tekst_enigo.fenestraĵo(), false, false, 0);
Self {
fenestraĵo,
tekst_enigo,
}
}
pub fn show(&self) {
self.fenestraĵo.show();
}
}
impl Elemento for RolulPaĝo {
fn fenestraĵo(&self) -> gtk::Widget {
self.fenestraĵo.clone().upcast::<gtk::Widget>()
}
}

21
gtk/src/main.rs Normal file
View File

@ -0,0 +1,21 @@
// use gtk_clib::TekstEntro;
mod aplikajxo;
mod elementoj;
use aplikajxo::Aplikaĵo;
use gtk::{self, prelude::*};
fn main() {
let evoluiga = std::env::var("EVO").map_or_else(|_| false, |_| true);
let aplikaĵo = gtk::Application::new(
Some("com.luminescent-dreams.datasphere"),
Default::default(),
);
aplikaĵo.connect_activate(move |gtk_app| {
let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT);
Aplikaĵo::kreu(gtk_app, tx, rx, evoluiga);
});
aplikaĵo.run();
}

View File

@ -6,5 +6,6 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
orizentic = { path = "../../orizentic/" }
tokio = { version = "1", features = ["full"] }
warp = { version = "0.3.1" }

View File

@ -1,42 +1,64 @@
use orizentic::{OrizenticCtx, Secret, Username};
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use warp::Filter;
use std::sync::{Arc, RwLock};
use warp::{reject, Filter, Rejection};
fn gm_paths() -> impl Filter {
let base = warp::path("gm").and(warp::header("authentication"));
let character_sheet = base
.clone()
.and(warp::path!("character" / String))
.map(|auth: String, name| format!("name: {}", name));
let send_item = base
.clone()
.and(warp::path("send_item"))
.map(|auth| format!("send_item"));
let send_resource = base
.clone()
.and(warp::path("send_resource"))
.map(|auth| format!("send_resource"));
character_sheet.or(send_item).or(send_resource)
fn with_auth(
auth_ctx: Arc<RwLock<OrizenticCtx>>,
) -> impl Filter<Extract = (Username,), Error = Rejection> + Clone {
let auth_ctx = auth_ctx.clone();
warp::header("authentication").and_then({
let auth_ctx = auth_ctx.clone();
move |text| {
let auth_ctx = auth_ctx.clone();
async move {
match auth_ctx.read().unwrap().decode_and_validate_text(text) {
Ok(token) => Ok(token.claims.audience),
Err(_) => Err(reject()),
}
}
}
})
}
fn player_paths() -> impl Filter {
let base = warp::path("player").and(warp::header("authentication"));
let character_sheet = base
.and(warp::path!("character" / String))
.map(|authentication: String, name: String| format!("name: {}", name));
fn gm_routes(
auth_ctx: Arc<RwLock<OrizenticCtx>>,
) -> impl Filter<Extract = (), Error = Rejection> + Clone {
let base_route = with_auth(auth_ctx).and(warp::path("gm"));
character_sheet
let character_sheet = {
let auth_ctx = auth_ctx.clone();
with_auth(auth_ctx)
.and(warp::path!("gm" / "character" / String))
.map(|auth: Username, name| format!("name: {} {}", String::from(auth), name))
};
}
#[tokio::main]
pub async fn main() {
let hi = warp::path!("hello" / String)
.and(warp::header("user-agent"))
.map(|param: String, agent: String| format!("Saluton! {}, {}", param, agent));
let bye = warp::path!("goodbye").map(|| "Goodbye!");
let auth_ctx = Arc::new(RwLock::new(OrizenticCtx::new(
Secret(Vec::from("abcdefg".as_bytes())),
vec![],
)));
let server = warp::serve(hi.or(bye));
let send_item = {
let auth_ctx = auth_ctx.clone();
with_auth(auth_ctx)
.and(warp::path!("gm" / "send_item"))
.map(|auth: Username| format!("send_item: {}", String::from(auth)))
};
let send_resource = warp::header("authentication")
.and(warp::path!("gm" / "send_resource"))
.map(|auth: String| format!("send_resource"));
let pc_sheet = warp::header("authentication")
.and(warp::path!("player" / "character" / String))
.map(|authentication: String, name: String| format!("name: {}", name));
let filter = character_sheet.or(send_item).or(send_resource).or(pc_sheet);
let server = warp::serve(filter);
server
.run(SocketAddr::new(
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),

View File

@ -10,6 +10,13 @@ in pkgs.mkShell {
name = "datasphere";
nativeBuildInputs = [
pkgs.gnome.webkitgtk
pkgs.glib
pkgs.gtk3
pkgs.libpng
pkgs.openssl
pkgs.pkg-config
pkgs.wrapGAppsHook
rust
unstable.rust-analyzer
];