Skip to content

Commit

Permalink
Update the DioxusDesktop configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
photino committed Oct 15, 2023
1 parent c27da31 commit 09b505f
Show file tree
Hide file tree
Showing 16 changed files with 339 additions and 204 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ Cargo.lock
# Uploads
**/uploads/*

# Builds
**/dist/*

# SQLite data
**/*.db
24 changes: 24 additions & 0 deletions examples/dioxus-desktop/Dioxus.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[application]
name = "DataCube"
default_platform = "desktop"
out_dir = "dist"
asset_dir = "public"

[web.app]
title = "DataCube"

[web.watcher]
reload_html = true
watch_path = ["src", "public"]
index_on_404 = true

[web.resource]
style = [
"./css/bulma.min.css",
"./css/custom.css",
]
script = []

[web.resource.dev]
style = []
script = []
9 changes: 8 additions & 1 deletion examples/dioxus-desktop/config/config.dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ uploads = "local/uploads"

[window]
title = "DataCube"
theme = "Light"
theme = "Dark"
transparent = false

[desktop]
icon = "public/favicon.ico"
stylesheets = [
"public/css/bulma.min.css",
"public/css/custom.css",
]

[database]
namespace = "dc"
max-rows = 10000
Expand Down
8 changes: 8 additions & 0 deletions examples/dioxus-desktop/config/config.prod.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ uploads = "local/uploads"
[window]
title = "DataCube"
theme = "Dark"
transparent = false

[desktop]
icon = "public/favicon.ico"
stylesheets = [
"public/css/bulma.min.css",
"public/css/custom.css",
]

[database]
type = "sqlite"
Expand Down
Binary file added examples/dioxus-desktop/icons/icon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions examples/dioxus-desktop/public/css/bulma.min.css

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions examples/dioxus-desktop/public/css/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
html {
overflow-y: auto !important;
}
Binary file added examples/dioxus-desktop/public/favicon.ico
Binary file not shown.
40 changes: 4 additions & 36 deletions examples/dioxus-desktop/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,12 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Index</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DataCube</title>
<link rel="icon" type="image/x-icon" href="public/favicon.ico">
<link rel="stylesheet" href="public/css/bulma.min.css">
<link rel="stylesheet" href="public/css/custom.css">
</head>
<body>
<h3>Congratulations, you have booted your application successfully!</h3>
<script>
// SSE
const sse = new EventSource('/sse?topic=message');
sse.addEventListener('message', (event) => {
console.dir(event);
});
window.addEventListener('beforeunload', (event) => {
console.log('close');
sse.close();
});

// WebSocket
const socket = new WebSocket('ws://localhost:6080/websocket');
socket.addEventListener('open', (event) => {
const data = {
specversion: '1.0',
type: 'smartscreen:sn-container:click',
id: 'f024794d020d48088fc9d40afe0d60c0',
source: 'http://localhost:6080/index.html',
data: {
id: 'index:sn-container-2',
name: 'sn-container',
width: 10,
height: 3,
left: 1,
top: 0.75,
},
};
socket.send(JSON.stringify(data));
});
socket.addEventListener('message', (event) => {
console.dir(event);
});
</script>
</body>
</html>
15 changes: 0 additions & 15 deletions examples/dioxus-desktop/public/upload.html

This file was deleted.

41 changes: 36 additions & 5 deletions examples/dioxus-desktop/src/view/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,42 @@ use dioxus_router::prelude::*;

pub fn Wrapper(cx: Scope) -> Element {
render! {
header {
nav {
ul {
li { Link { to: Route::Home {}, "Home" } }
li { Link { to: Route::DatasetList {}, "Datasets" } }
nav {
class: "navbar is-link",
div {
class: "navbar-brand",
Link {
class: "navbar-item",
to: Route::Home {},
"DataCube"
}
}
div {
class: "navbar-menu is-active",
div {
class: "navbar-start",
Link {
class: "navbar-item",
to: Route::DatasetList {},
"Datasets",
}
}
div {
class: "navbar-end",
div {
class: "navbar-item",
div {
class: "buttons",
a {
class: "button",
"Sign up"
}
a {
class: "button is-primary",
strong { "Login in" }
}
}
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions zino-core/benches/sha256_sm3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub fn bench(c: &mut criterion::Criterion) {
let data = b"Hellow, world!";
let mut hasher = Sha256::new();
hasher.update(data);
hasher.finalize()
<[u8; 32]>::from(hasher.finalize())
})
});
c.bench_function("sm3_digest", |b| {
Expand All @@ -16,7 +16,7 @@ pub fn bench(c: &mut criterion::Criterion) {
let data = b"Hellow, world!";
let mut hasher = Sm3::new();
hasher.update(data);
hasher.finalize()
<[u8; 32]>::from(hasher.finalize())
})
});
c.bench_function("libsm_digest", |b| {
Expand Down
88 changes: 44 additions & 44 deletions zino-core/src/auth/jwt_claims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,50 @@ use std::{env, sync::LazyLock, time::Duration};
#[derive(Debug, Clone)]
pub struct JwtClaims<T = Map>(pub(crate) JWTClaims<T>);

impl<T: Default + Serialize + DeserializeOwned> JwtClaims<T> {
/// Creates a new instance.
pub fn new(subject: impl ToString) -> Self {
let mut claims = Claims::with_custom_claims(T::default(), (*DEFAULT_MAX_AGE).into());
claims.invalid_before = None;
claims.subject = Some(subject.to_string());
Self(claims)
}

/// Creates a new instance, expiring in `max-age`.
pub fn with_max_age(subject: impl ToString, max_age: Duration) -> Self {
let mut claims = Claims::with_custom_claims(T::default(), max_age.into());
claims.invalid_before = None;
claims.subject = Some(subject.to_string());
Self(claims)
}

/// Generates an access token signed with the shared secret access key.
pub fn refresh_token(&self) -> Result<String, Error> {
let mut claims = Claims::create((*DEFAULT_REFRESH_INTERVAL).into());
claims.invalid_before = self
.0
.expires_at
.map(|max_age| max_age - (*DEFAULT_TIME_TOLERANCE).into());
claims.subject = self.0.subject.as_ref().cloned();
JwtClaims::shared_key()
.authenticate(claims)
.map_err(|err| Error::new(err.to_string()))
}

/// Generates an access token signed with the shared secret access key.
#[inline]
pub fn access_token(self) -> Result<String, Error> {
self.sign_with(JwtClaims::shared_key())
}

/// Generates a signature with the secret access key.
#[inline]
pub fn sign_with<K: MACLike>(self, key: &K) -> Result<String, Error> {
key.authenticate(self.0)
.map_err(|err| Error::new(err.to_string()))
}
}

impl<T> JwtClaims<T> {
/// Sets the nonce.
#[inline]
Expand Down Expand Up @@ -77,50 +121,6 @@ impl<T> JwtClaims<T> {
}
}

impl<T: Default + Serialize + DeserializeOwned> JwtClaims<T> {
/// Creates a new instance.
pub fn new(subject: impl ToString) -> Self {
let mut claims = Claims::with_custom_claims(T::default(), (*DEFAULT_MAX_AGE).into());
claims.invalid_before = None;
claims.subject = Some(subject.to_string());
Self(claims)
}

/// Creates a new instance, expiring in `max-age`.
pub fn with_max_age(subject: impl ToString, max_age: Duration) -> Self {
let mut claims = Claims::with_custom_claims(T::default(), max_age.into());
claims.invalid_before = None;
claims.subject = Some(subject.to_string());
Self(claims)
}

/// Generates an access token signed with the shared secret access key.
pub fn refresh_token(&self) -> Result<String, Error> {
let mut claims = Claims::create((*DEFAULT_REFRESH_INTERVAL).into());
claims.invalid_before = self
.0
.expires_at
.map(|max_age| max_age - (*DEFAULT_TIME_TOLERANCE).into());
claims.subject = self.0.subject.as_ref().cloned();
JwtClaims::shared_key()
.authenticate(claims)
.map_err(|err| Error::new(err.to_string()))
}

/// Generates an access token signed with the shared secret access key.
#[inline]
pub fn access_token(self) -> Result<String, Error> {
self.sign_with(JwtClaims::shared_key())
}

/// Generates a signature with the secret access key.
#[inline]
pub fn sign_with<K: MACLike>(self, key: &K) -> Result<String, Error> {
key.authenticate(self.0)
.map_err(|err| Error::new(err.to_string()))
}
}

impl JwtClaims<Map> {
/// Adds a key-value pair to the custom data.
#[inline]
Expand Down
Loading

0 comments on commit 09b505f

Please sign in to comment.