Start on the GTK client application
This commit is contained in:
parent
05f850b9c5
commit
ff18c4a0e7
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,6 @@
|
||||||
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"common",
|
||||||
|
"gtk",
|
||||||
|
"server",
|
||||||
|
]
|
|
@ -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"
|
||||||
|
|
|
@ -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: >k::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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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>()
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
|
@ -6,5 +6,6 @@ edition = "2018"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
orizentic = { path = "../../orizentic/" }
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
warp = { version = "0.3.1" }
|
warp = { version = "0.3.1" }
|
||||||
|
|
|
@ -1,42 +1,64 @@
|
||||||
|
use orizentic::{OrizenticCtx, Secret, Username};
|
||||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||||
use warp::Filter;
|
use std::sync::{Arc, RwLock};
|
||||||
|
use warp::{reject, Filter, Rejection};
|
||||||
|
|
||||||
fn gm_paths() -> impl Filter {
|
fn with_auth(
|
||||||
let base = warp::path("gm").and(warp::header("authentication"));
|
auth_ctx: Arc<RwLock<OrizenticCtx>>,
|
||||||
|
) -> impl Filter<Extract = (Username,), Error = Rejection> + Clone {
|
||||||
let character_sheet = base
|
let auth_ctx = auth_ctx.clone();
|
||||||
.clone()
|
warp::header("authentication").and_then({
|
||||||
.and(warp::path!("character" / String))
|
let auth_ctx = auth_ctx.clone();
|
||||||
.map(|auth: String, name| format!("name: {}", name));
|
move |text| {
|
||||||
let send_item = base
|
let auth_ctx = auth_ctx.clone();
|
||||||
.clone()
|
async move {
|
||||||
.and(warp::path("send_item"))
|
match auth_ctx.read().unwrap().decode_and_validate_text(text) {
|
||||||
.map(|auth| format!("send_item"));
|
Ok(token) => Ok(token.claims.audience),
|
||||||
let send_resource = base
|
Err(_) => Err(reject()),
|
||||||
.clone()
|
}
|
||||||
.and(warp::path("send_resource"))
|
}
|
||||||
.map(|auth| format!("send_resource"));
|
}
|
||||||
|
})
|
||||||
character_sheet.or(send_item).or(send_resource)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn player_paths() -> impl Filter {
|
fn gm_routes(
|
||||||
let base = warp::path("player").and(warp::header("authentication"));
|
auth_ctx: Arc<RwLock<OrizenticCtx>>,
|
||||||
let character_sheet = base
|
) -> impl Filter<Extract = (), Error = Rejection> + Clone {
|
||||||
.and(warp::path!("character" / String))
|
let base_route = with_auth(auth_ctx).and(warp::path("gm"));
|
||||||
.map(|authentication: String, name: String| format!("name: {}", name));
|
|
||||||
|
|
||||||
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]
|
#[tokio::main]
|
||||||
pub async fn main() {
|
pub async fn main() {
|
||||||
let hi = warp::path!("hello" / String)
|
let auth_ctx = Arc::new(RwLock::new(OrizenticCtx::new(
|
||||||
.and(warp::header("user-agent"))
|
Secret(Vec::from("abcdefg".as_bytes())),
|
||||||
.map(|param: String, agent: String| format!("Saluton! {}, {}", param, agent));
|
vec![],
|
||||||
let bye = warp::path!("goodbye").map(|| "Goodbye!");
|
)));
|
||||||
|
|
||||||
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
|
server
|
||||||
.run(SocketAddr::new(
|
.run(SocketAddr::new(
|
||||||
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
|
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
|
||||||
|
|
|
@ -10,6 +10,13 @@ in pkgs.mkShell {
|
||||||
name = "datasphere";
|
name = "datasphere";
|
||||||
|
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
|
pkgs.gnome.webkitgtk
|
||||||
|
pkgs.glib
|
||||||
|
pkgs.gtk3
|
||||||
|
pkgs.libpng
|
||||||
|
pkgs.openssl
|
||||||
|
pkgs.pkg-config
|
||||||
|
pkgs.wrapGAppsHook
|
||||||
rust
|
rust
|
||||||
unstable.rust-analyzer
|
unstable.rust-analyzer
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue