Compare commits
2 Commits
main
...
In-Progres
| Author | SHA1 | Date | |
|---|---|---|---|
| b99015fc1b | |||
| b53d67acb7 |
136
Cargo.lock
generated
136
Cargo.lock
generated
@@ -227,7 +227,7 @@ dependencies = [
|
||||
"clipboard-win",
|
||||
"image",
|
||||
"log",
|
||||
"objc2 0.6.1",
|
||||
"objc2 0.6.4",
|
||||
"objc2-app-kit 0.3.1",
|
||||
"objc2-core-foundation",
|
||||
"objc2-core-graphics",
|
||||
@@ -288,6 +288,17 @@ dependencies = [
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-fs"
|
||||
version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8034a681df4aed8b8edbd7fbe472401ecf009251c8b40556b304567052e294c5"
|
||||
dependencies = [
|
||||
"async-lock",
|
||||
"blocking",
|
||||
"futures-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-io"
|
||||
version = "2.4.1"
|
||||
@@ -318,6 +329,17 @@ dependencies = [
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-net"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b948000fad4873c1c9339d60f2623323a0cfd3816e5181033c6a5cb68b2accf7"
|
||||
dependencies = [
|
||||
"async-io",
|
||||
"blocking",
|
||||
"futures-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "async-process"
|
||||
version = "2.3.1"
|
||||
@@ -490,6 +512,15 @@ dependencies = [
|
||||
"objc2 0.5.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "block2"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5"
|
||||
dependencies = [
|
||||
"objc2 0.6.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "blocking"
|
||||
version = "1.6.2"
|
||||
@@ -511,7 +542,9 @@ dependencies = [
|
||||
"egui",
|
||||
"env_logger",
|
||||
"log",
|
||||
"rfd",
|
||||
"serde",
|
||||
"smol",
|
||||
"tinytemplate",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
@@ -752,7 +785,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec"
|
||||
dependencies = [
|
||||
"bitflags 2.9.4",
|
||||
"objc2 0.6.1",
|
||||
"block2 0.6.2",
|
||||
"libc",
|
||||
"objc2 0.6.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1252,7 +1287,7 @@ dependencies = [
|
||||
"glutin_glx_sys",
|
||||
"glutin_wgl_sys",
|
||||
"libloading",
|
||||
"objc2 0.6.1",
|
||||
"objc2 0.6.4",
|
||||
"objc2-app-kit 0.3.1",
|
||||
"objc2-core-foundation",
|
||||
"objc2-foundation 0.3.1",
|
||||
@@ -1810,9 +1845,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "objc2"
|
||||
version = "0.6.1"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "88c6597e14493ab2e44ce58f2fdecf095a51f12ca57bec060a11c57332520551"
|
||||
checksum = "3a12a8ed07aefc768292f076dc3ac8c48f3781c8f2d5851dd3d98950e8c5a89f"
|
||||
dependencies = [
|
||||
"objc2-encode",
|
||||
]
|
||||
@@ -1824,7 +1859,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e4e89ad9e3d7d297152b17d39ed92cd50ca8063a89a9fa569046d41568891eff"
|
||||
dependencies = [
|
||||
"bitflags 2.9.4",
|
||||
"block2",
|
||||
"block2 0.5.1",
|
||||
"libc",
|
||||
"objc2 0.5.2",
|
||||
"objc2-core-data",
|
||||
@@ -1840,7 +1875,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6f29f568bec459b0ddff777cec4fe3fd8666d82d5a40ebd0ff7e66134f89bcc"
|
||||
dependencies = [
|
||||
"bitflags 2.9.4",
|
||||
"objc2 0.6.1",
|
||||
"block2 0.6.2",
|
||||
"objc2 0.6.4",
|
||||
"objc2-core-foundation",
|
||||
"objc2-core-graphics",
|
||||
"objc2-foundation 0.3.1",
|
||||
@@ -1853,7 +1889,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "74dd3b56391c7a0596a295029734d3c1c5e7e510a4cb30245f8221ccea96b009"
|
||||
dependencies = [
|
||||
"bitflags 2.9.4",
|
||||
"block2",
|
||||
"block2 0.5.1",
|
||||
"objc2 0.5.2",
|
||||
"objc2-core-location",
|
||||
"objc2-foundation 0.2.2",
|
||||
@@ -1865,7 +1901,7 @@ version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a5ff520e9c33812fd374d8deecef01d4a840e7b41862d849513de77e44aa4889"
|
||||
dependencies = [
|
||||
"block2",
|
||||
"block2 0.5.1",
|
||||
"objc2 0.5.2",
|
||||
"objc2-foundation 0.2.2",
|
||||
]
|
||||
@@ -1877,7 +1913,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "617fbf49e071c178c0b24c080767db52958f716d9eabdf0890523aeae54773ef"
|
||||
dependencies = [
|
||||
"bitflags 2.9.4",
|
||||
"block2",
|
||||
"block2 0.5.1",
|
||||
"objc2 0.5.2",
|
||||
"objc2-foundation 0.2.2",
|
||||
]
|
||||
@@ -1890,7 +1926,7 @@ checksum = "1c10c2894a6fed806ade6027bcd50662746363a9589d3ec9d9bef30a4e4bc166"
|
||||
dependencies = [
|
||||
"bitflags 2.9.4",
|
||||
"dispatch2",
|
||||
"objc2 0.6.1",
|
||||
"objc2 0.6.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -1901,7 +1937,7 @@ checksum = "989c6c68c13021b5c2d6b71456ebb0f9dc78d752e86a98da7c716f4f9470f5a4"
|
||||
dependencies = [
|
||||
"bitflags 2.9.4",
|
||||
"dispatch2",
|
||||
"objc2 0.6.1",
|
||||
"objc2 0.6.4",
|
||||
"objc2-core-foundation",
|
||||
"objc2-io-surface",
|
||||
]
|
||||
@@ -1912,7 +1948,7 @@ version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "55260963a527c99f1819c4f8e3b47fe04f9650694ef348ffd2227e8196d34c80"
|
||||
dependencies = [
|
||||
"block2",
|
||||
"block2 0.5.1",
|
||||
"objc2 0.5.2",
|
||||
"objc2-foundation 0.2.2",
|
||||
"objc2-metal",
|
||||
@@ -1924,7 +1960,7 @@ version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "000cfee34e683244f284252ee206a27953279d370e309649dc3ee317b37e5781"
|
||||
dependencies = [
|
||||
"block2",
|
||||
"block2 0.5.1",
|
||||
"objc2 0.5.2",
|
||||
"objc2-contacts",
|
||||
"objc2-foundation 0.2.2",
|
||||
@@ -1943,7 +1979,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ee638a5da3799329310ad4cfa62fbf045d5f56e3ef5ba4149e7452dcf89d5a8"
|
||||
dependencies = [
|
||||
"bitflags 2.9.4",
|
||||
"block2",
|
||||
"block2 0.5.1",
|
||||
"dispatch",
|
||||
"libc",
|
||||
"objc2 0.5.2",
|
||||
@@ -1956,7 +1992,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "900831247d2fe1a09a683278e5384cfb8c80c79fe6b166f9d14bfdde0ea1b03c"
|
||||
dependencies = [
|
||||
"bitflags 2.9.4",
|
||||
"objc2 0.6.1",
|
||||
"objc2 0.6.4",
|
||||
"objc2-core-foundation",
|
||||
]
|
||||
|
||||
@@ -1967,7 +2003,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7282e9ac92529fa3457ce90ebb15f4ecbc383e8338060960760fa2cf75420c3c"
|
||||
dependencies = [
|
||||
"bitflags 2.9.4",
|
||||
"objc2 0.6.1",
|
||||
"objc2 0.6.4",
|
||||
"objc2-core-foundation",
|
||||
]
|
||||
|
||||
@@ -1977,7 +2013,7 @@ version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1a1ae721c5e35be65f01a03b6d2ac13a54cb4fa70d8a5da293d7b0020261398"
|
||||
dependencies = [
|
||||
"block2",
|
||||
"block2 0.5.1",
|
||||
"objc2 0.5.2",
|
||||
"objc2-app-kit 0.2.2",
|
||||
"objc2-foundation 0.2.2",
|
||||
@@ -1990,7 +2026,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd0cba1276f6023976a406a14ffa85e1fdd19df6b0f737b063b95f6c8c7aadd6"
|
||||
dependencies = [
|
||||
"bitflags 2.9.4",
|
||||
"block2",
|
||||
"block2 0.5.1",
|
||||
"objc2 0.5.2",
|
||||
"objc2-foundation 0.2.2",
|
||||
]
|
||||
@@ -2002,7 +2038,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e42bee7bff906b14b167da2bac5efe6b6a07e6f7c0a21a7308d40c960242dc7a"
|
||||
dependencies = [
|
||||
"bitflags 2.9.4",
|
||||
"block2",
|
||||
"block2 0.5.1",
|
||||
"objc2 0.5.2",
|
||||
"objc2-foundation 0.2.2",
|
||||
"objc2-metal",
|
||||
@@ -2025,7 +2061,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b8bb46798b20cd6b91cbd113524c490f1686f4c4e8f49502431415f3512e2b6f"
|
||||
dependencies = [
|
||||
"bitflags 2.9.4",
|
||||
"block2",
|
||||
"block2 0.5.1",
|
||||
"objc2 0.5.2",
|
||||
"objc2-cloud-kit",
|
||||
"objc2-core-data",
|
||||
@@ -2045,7 +2081,7 @@ version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44fa5f9748dbfe1ca6c0b79ad20725a11eca7c2218bceb4b005cb1be26273bfe"
|
||||
dependencies = [
|
||||
"block2",
|
||||
"block2 0.5.1",
|
||||
"objc2 0.5.2",
|
||||
"objc2-foundation 0.2.2",
|
||||
]
|
||||
@@ -2057,7 +2093,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76cfcbf642358e8689af64cee815d139339f3ed8ad05103ed5eaf73db8d84cb3"
|
||||
dependencies = [
|
||||
"bitflags 2.9.4",
|
||||
"block2",
|
||||
"block2 0.5.1",
|
||||
"objc2 0.5.2",
|
||||
"objc2-core-location",
|
||||
"objc2-foundation 0.2.2",
|
||||
@@ -2215,6 +2251,12 @@ dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pollster"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3"
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.11.1"
|
||||
@@ -2356,6 +2398,33 @@ version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19b30a45b0cd0bcca8037f3d0dc3421eaf95327a17cad11964fb8179b4fc4832"
|
||||
|
||||
[[package]]
|
||||
name = "rfd"
|
||||
version = "0.17.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "20dafead71c16a34e1ff357ddefc8afc11e7d51d6d2b9fbd07eaa48e3e540220"
|
||||
dependencies = [
|
||||
"block2 0.6.2",
|
||||
"dispatch2",
|
||||
"js-sys",
|
||||
"libc",
|
||||
"log",
|
||||
"objc2 0.6.4",
|
||||
"objc2-app-kit 0.3.1",
|
||||
"objc2-core-foundation",
|
||||
"objc2-foundation 0.3.1",
|
||||
"percent-encoding",
|
||||
"pollster",
|
||||
"raw-window-handle",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"web-sys",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ron"
|
||||
version = "0.11.0"
|
||||
@@ -2566,6 +2635,23 @@ dependencies = [
|
||||
"wayland-backend",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smol"
|
||||
version = "2.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a33bd3e260892199c3ccfc487c88b2da2265080acb316cd920da72fdfd7c599f"
|
||||
dependencies = [
|
||||
"async-channel",
|
||||
"async-executor",
|
||||
"async-fs",
|
||||
"async-io",
|
||||
"async-lock",
|
||||
"async-net",
|
||||
"async-process",
|
||||
"blocking",
|
||||
"futures-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smol_str"
|
||||
version = "0.2.2"
|
||||
@@ -3043,7 +3129,7 @@ dependencies = [
|
||||
"jni",
|
||||
"log",
|
||||
"ndk-context",
|
||||
"objc2 0.6.1",
|
||||
"objc2 0.6.4",
|
||||
"objc2-foundation 0.3.1",
|
||||
"url",
|
||||
"web-sys",
|
||||
@@ -3596,7 +3682,7 @@ dependencies = [
|
||||
"android-activity",
|
||||
"atomic-waker",
|
||||
"bitflags 2.9.4",
|
||||
"block2",
|
||||
"block2 0.5.1",
|
||||
"bytemuck",
|
||||
"calloop",
|
||||
"cfg_aliases",
|
||||
|
||||
@@ -26,10 +26,12 @@ log = "0.4.27"
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
|
||||
tinytemplate = "1.2.1"
|
||||
rfd = "0.17.2"
|
||||
|
||||
# native:
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
env_logger = "0.11.8"
|
||||
smol = "2.0.2"
|
||||
|
||||
# web:
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
|
||||
136
src/app.rs
136
src/app.rs
@@ -1,6 +1,18 @@
|
||||
use std::fs::DirEntry;
|
||||
use std::sync::mpsc;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use tinytemplate;
|
||||
use crate::templates::{self, Template};
|
||||
|
||||
use egui::{Align, Layout};
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use wasm_bindgen_futures;
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use web_sys;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use smol;
|
||||
|
||||
use tinytemplate::TinyTemplate;
|
||||
|
||||
/// We derive Deserialize/Serialize so we can persist app state on shutdown.
|
||||
#[derive(serde::Deserialize, serde::Serialize)]
|
||||
@@ -14,8 +26,20 @@ pub struct TemplateApp {
|
||||
|
||||
#[serde(skip)] // This how you opt-out of serialization of a field
|
||||
value: f32,
|
||||
|
||||
templates: HashMap<String, Template>,
|
||||
active_template: String,
|
||||
|
||||
#[serde(skip)]
|
||||
templates: Vec<DirEntry>,
|
||||
preview_text: String,
|
||||
|
||||
#[serde(skip)]
|
||||
messaging: (mpsc::Sender<Message>, mpsc::Receiver<Message>),
|
||||
}
|
||||
|
||||
pub enum Message {
|
||||
AddTemplate(Template),
|
||||
|
||||
}
|
||||
|
||||
impl Default for TemplateApp {
|
||||
@@ -25,7 +49,10 @@ impl Default for TemplateApp {
|
||||
init: false,
|
||||
label: "Hello World!".to_owned(),
|
||||
value: 2.7,
|
||||
templates: Vec::new(),
|
||||
templates: HashMap::new(),
|
||||
active_template: "Select a template".to_string(),
|
||||
preview_text: "No File Selected".to_string(),
|
||||
messaging: mpsc::channel(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,6 +71,7 @@ impl TemplateApp {
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
impl eframe::App for TemplateApp {
|
||||
@@ -57,12 +85,19 @@ impl eframe::App for TemplateApp {
|
||||
// Put your widgets into a `SidePanel`, `TopBottomPanel`, `CentralPanel`, `Window` or `Area`.
|
||||
// For inspiration and more examples, go to https://emilk.github.io/egui
|
||||
|
||||
let is_web = cfg!(target_arch = "wasm32");
|
||||
|
||||
for i in self.messaging.1.try_iter() {
|
||||
match i {
|
||||
Message::AddTemplate(t) => add_template(&mut self.templates, t.name.clone(), t),
|
||||
}
|
||||
}
|
||||
|
||||
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
|
||||
// The top panel is often a good place for a menu bar:
|
||||
|
||||
egui::MenuBar::new().ui(ui, |ui| {
|
||||
// NOTE: no File->Quit on web pages!
|
||||
let is_web = cfg!(target_arch = "wasm32");
|
||||
if !is_web {
|
||||
ui.menu_button("File", |ui| {
|
||||
if ui.button("Quit").clicked() {
|
||||
@@ -75,8 +110,17 @@ impl eframe::App for TemplateApp {
|
||||
});
|
||||
});
|
||||
|
||||
egui::TopBottomPanel::bottom("bottom_panel").show(ctx, |ui| {
|
||||
ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| {
|
||||
powered_by_egui_and_eframe(ui);
|
||||
egui::warn_if_debug_build(ui);
|
||||
});
|
||||
});
|
||||
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
// The central panel the region left after adding TopPanel's and SidePanel's
|
||||
egui::containers::Sides::new().show(ui, |ui|{
|
||||
ui.with_layout(Layout::top_down(Align::LEFT), |ui| {
|
||||
ui.heading("eframe template");
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
@@ -84,21 +128,47 @@ impl eframe::App for TemplateApp {
|
||||
ui.text_edit_singleline(&mut self.label);
|
||||
});
|
||||
|
||||
ui.add(egui::Slider::new(&mut self.value, 0.0..=10.0).text("value"));
|
||||
if ui.button("Increment").clicked() {
|
||||
if ui.button("test").clicked() {
|
||||
self.value += 1.0;
|
||||
}
|
||||
|
||||
if ui.button("rfd").clicked() {
|
||||
test_async(self.messaging.0.clone());
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
if self.templates.is_empty() {
|
||||
|
||||
}
|
||||
|
||||
egui::containers::ComboBox::from_label("Select a template")
|
||||
.selected_text(self.active_template.clone())
|
||||
.show_ui(ui, |x| {
|
||||
for (name, _) in self.templates.iter() {
|
||||
x.selectable_value(&mut self.active_template, name.clone(), name.clone());
|
||||
}
|
||||
});
|
||||
|
||||
ui.separator();
|
||||
|
||||
ui.add(egui::github_link_file!(
|
||||
"https://github.com/emilk/eframe_template/blob/main/",
|
||||
"Source code."
|
||||
));
|
||||
|
||||
ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| {
|
||||
powered_by_egui_and_eframe(ui);
|
||||
egui::warn_if_debug_build(ui);
|
||||
});
|
||||
}, |ui| {
|
||||
let selected = match self.templates.get(&self.active_template.clone()) {
|
||||
Some(t) => {
|
||||
let text = t.text_files.iter().next();
|
||||
match text {
|
||||
Some(t) => t.1.clone(),
|
||||
None => "No File Selected".to_string(),
|
||||
}
|
||||
},
|
||||
None => "No File Selected".to_string()
|
||||
};
|
||||
ui.label(selected);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -117,3 +187,47 @@ fn powered_by_egui_and_eframe(ui: &mut egui::Ui) {
|
||||
ui.label(".");
|
||||
});
|
||||
}
|
||||
|
||||
fn test_async(test: mpsc::Sender<Message>) {
|
||||
// Spawn dialog on main thread
|
||||
let task = rfd::AsyncFileDialog::new().pick_file();
|
||||
|
||||
// Await somewhere else
|
||||
execute(async move {
|
||||
|
||||
let file = task.await;
|
||||
|
||||
if let Some(file) = file {
|
||||
// If you care about wasm support you just read() the file
|
||||
let name = file.file_name();
|
||||
let output = file.read().await;
|
||||
|
||||
let string_data = match String::from_utf8(output) {
|
||||
Ok(t) => t,
|
||||
Err(e) => e.to_string(),
|
||||
};
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
web_sys::console::log_1(&string_data.clone().into());
|
||||
|
||||
let _ = test.send(Message::AddTemplate(Template::new(string_data)));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn execute<F: Future<Output = ()> + Send + 'static>(f: F) {
|
||||
std::thread::spawn(move || smol::block_on(f));
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn execute<F: Future<Output = ()> + 'static>(f: F) {
|
||||
web_sys::console::log_1(&"Async Start".into());
|
||||
wasm_bindgen_futures::spawn_local(f);
|
||||
web_sys::console::log_1(&"Async End".into());
|
||||
}
|
||||
|
||||
|
||||
fn add_template(map: &mut HashMap<String, Template>, label: String, template: Template) {
|
||||
map.insert(label, template);
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
#![warn(clippy::all, rust_2018_idioms)]
|
||||
|
||||
mod app;
|
||||
mod templates;
|
||||
|
||||
pub use app::TemplateApp;
|
||||
|
||||
52
src/templates.rs
Normal file
52
src/templates.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use std::hash::Hash;
|
||||
|
||||
|
||||
|
||||
#[derive(serde::Serialize, serde::Deserialize, Eq)]
|
||||
#[serde(default)]
|
||||
pub struct Template {
|
||||
pub name: String,
|
||||
pub text_files: Vec<(String, String)>,
|
||||
pub images: Vec<(String, Vec<u8>)>,
|
||||
pub config: String,
|
||||
}
|
||||
|
||||
impl Template {
|
||||
pub fn new(name: String) -> Self {
|
||||
Self {
|
||||
name,
|
||||
text_files: Vec::new(),
|
||||
images: Vec::new(),
|
||||
config: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Template {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: "New_Template".to_string(),
|
||||
text_files: Vec::new(),
|
||||
images: Vec::new(),
|
||||
config: String::new() }
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Template {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.name == other.name
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq<String> for Template {
|
||||
fn eq(&self, other: &String) -> bool {
|
||||
&self.name == other
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for Template {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.name.hash(state);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user