Added small cfgs for wasm32 to make it compile

pull/8/head
Benedikt Terhechte 3 years ago
parent 9a3f4fb47a
commit 73043bd655

@ -12,7 +12,7 @@ tracing-subscriber = "0.3.0"
regex = "1.5.3"
flate2 = "1.0.22"
once_cell = "1.8.0"
chrono = "0.4.19"
chrono = {version = "0.4.19", features = ["wasmbind"]}
serde_json = "1.0.70"
serde = { version = "1.0.131", features = ["derive"]}
crossbeam-channel = "0.5.1"
@ -20,14 +20,12 @@ rsql_builder = "0.1.2"
treemap = "0.3.2"
strum = "0.23.0"
strum_macros = "0.23.0"
lru = { version = "0.7.0", optional = true }
shellexpand = "2.1.0"
rand = "0.8.4"
lru = { version = "0.7.0"}
[target."cfg(target_arch = \"wasm32\")".dependencies]
# https://docs.rs/getrandom/latest/getrandom/#webassembly-support
getrandom = { version = "0.2", features = ["js"] }
[features]
default = ["lru"]
[target."cfg(not(target_arch = \"wasm32\"))".dependencies]
shellexpand = "2.1.0"

@ -11,6 +11,7 @@ pub use database::query_result::{QueryResult, QueryRow};
pub use types::{Config, EmailEntry, EmailMeta, FormatType};
pub use crossbeam_channel;
pub use eyre;
pub use importer::{Importerlike, Message, MessageReceiver, MessageSender};
// Tracing

@ -141,6 +141,11 @@ impl Config {
) -> eyre::Result<Self> {
// If we don't have a database path, we use a temporary folder.
let persistent = db.is_some();
#[cfg(target_arch = "wasm32")]
let database_path = PathBuf::new();
#[cfg(not(target_arch = "wasm32"))]
let database_path = match db {
Some(n) => n.as_ref().to_path_buf(),
None => {

@ -9,7 +9,7 @@ thiserror = "1.0.29"
tracing = "0.1.29"
tracing-subscriber = "0.3.0"
rusqlite = {version = "0.26.1", features = ["chrono", "trace", "serde_json", "bundled"]}
chrono = "0.4.19"
chrono = {version = "0.4.19", features = ["wasmbind"]}
serde_json = "1.0.70"
serde = { version = "1.0.130", features = ["derive"]}
rsql_builder = "0.1.2"

@ -15,8 +15,7 @@ crossbeam-channel = "0.5.1"
eframe = "0.15.0"
num-format = "0.4.0"
rand = "0.8.4"
image = { version = "0.23", default-features = false, features = ["png"] }
chrono = "0.4.19"
chrono = {version = "0.4.19", features = ["wasmbind"]}
ps-core = { path = "../ps-core" }
[target."cfg(target_os = \"macos\")".dependencies.cocoa]
@ -28,6 +27,7 @@ version = "0.2.7"
ps-importer = { path = "../ps-importer" }
shellexpand = "2.1.0"
tinyfiledialogs = "3.0"
image = { version = "0.23", default-features = false, features = ["png"] }
[target."cfg(target_arch = \"wasm32\")".dependencies]
# https://docs.rs/getrandom/latest/getrandom/#webassembly-support

@ -19,6 +19,7 @@ pub struct PostsackApp<Database: DatabaseLike> {
}
impl<Database: DatabaseLike> PostsackApp<Database> {
#[cfg(not(target_arch = "wasm32"))]
pub fn new() -> Self {
let state = StateUI::new();
PostsackApp {
@ -28,6 +29,17 @@ impl<Database: DatabaseLike> PostsackApp<Database> {
_database: PhantomData,
}
}
#[cfg(target_arch = "wasm32")]
pub fn new(config: ps_core::Config, total: usize) -> Self {
let state = StateUI::new::<Database>(config, total);
PostsackApp {
state,
platform_custom_setup: false,
textures: None,
_database: PhantomData,
}
}
}
impl<Database: DatabaseLike> App for PostsackApp<Database> {

@ -76,6 +76,10 @@ impl ImporterUI {
// Could not figure out how to build this properly
// with dynamic dispatch. (to abstract away the match)
// Will try again when I'm online.
// On Wasm, we just do nothing. Wasm is just a demo and
// the importer will never be run.
#[cfg(not(target_arch = "wasm32"))]
let handle = match config.format {
FormatType::AppleMail => {
let importer = ps_importer::applemail_importer(config);
@ -91,6 +95,9 @@ impl ImporterUI {
}
};
#[cfg(target_arch = "wasm32")]
let handle = std::thread::spawn(|| Ok(()));
Ok(Self {
config: cloned_config,
adapter,

@ -104,10 +104,16 @@ impl StateUI {
}
impl StateUI {
#[cfg(not(target_arch = "wasm32"))]
pub fn new() -> StateUI {
StateUI::Startup(startup::StartupUI::default())
}
#[cfg(target_arch = "wasm32")]
pub fn new<Database: DatabaseLike>(config: Config, total: usize) -> StateUI {
StateUI::Main(main::MainUI::new::<Database>(config, total).unwrap())
}
pub fn create_database<Database: DatabaseLike>(
&self,
database_path: Option<PathBuf>,

@ -155,7 +155,8 @@ impl StartupUI {
self.open_email_folder_dialog()
}
if self.format == FormatType::AppleMail && ui.button("or Mail.app default folder").clicked(){
self.email_folder = ps_importer::default_path(&self.format);
self.set_default_path();
}
});
ui.end_row();
@ -243,6 +244,14 @@ impl StartupUI {
response.response
}
#[cfg(not(target_arch = "wasm32"))]
fn set_default_path(&mut self) {
self.email_folder = ps_importer::default_path(&self.format);
}
#[cfg(target_arch = "wasm32")]
fn set_default_path(&mut self) {}
}
impl StartupUI {
@ -300,6 +309,10 @@ impl StartupUI {
self.format = selected;
}
#[cfg(target_arch = "wasm32")]
fn open_email_folder_dialog(&mut self) {}
#[cfg(not(target_arch = "wasm32"))]
fn open_email_folder_dialog(&mut self) {
let fallback = shellexpand::tilde("~/");
let default_path = ps_importer::default_path(&self.format)
@ -320,6 +333,10 @@ impl StartupUI {
self.email_folder = Some(path);
}
#[cfg(target_arch = "wasm32")]
fn save_database_dialog(&mut self) {}
#[cfg(not(target_arch = "wasm32"))]
fn save_database_dialog(&mut self) {
let default_path = "~/Desktop/";
@ -342,6 +359,12 @@ impl StartupUI {
self.database_path = Some(path)
}
#[cfg(target_arch = "wasm32")]
fn open_database_dialog(&mut self) -> Option<PathBuf> {
None
}
#[cfg(not(target_arch = "wasm32"))]
fn open_database_dialog(&mut self) -> Option<PathBuf> {
let default_path = "~/Desktop/";

@ -15,6 +15,12 @@ mod linux;
#[cfg(target_os = "linux")]
pub use linux::{initial_update, navigation_button};
#[cfg(target_arch = "wasm32")]
mod web;
#[cfg(target_arch = "wasm32")]
pub use web::{initial_update, navigation_button};
#[cfg(target_os = "macos")]
mod macos;
@ -63,6 +69,9 @@ pub fn setup(ctx: &egui::CtxRef, theme: Theme) {
#[cfg(target_os = "macos")]
use macos as module;
#[cfg(target_arch = "wasm32")]
use web as module;
INSTANCE
.set(module::platform_colors(theme))
.expect("Could not setup colors");

@ -0,0 +1,48 @@
#![cfg(target_arch = "wasm32")]
use eframe::egui::{self, Color32};
use eyre::Result;
use super::{PlatformColors, Theme};
pub fn platform_colors(theme: Theme) -> PlatformColors {
// From Google images, Windows 11
match theme {
Theme::Light => PlatformColors {
is_light: true,
animation_background: Color32::from_rgb(248, 246, 249),
window_background: Color32::from_rgb(241, 243, 246),
content_background: Color32::from_rgb(251, 251, 253),
text_primary: Color32::from_gray(0),
text_secondary: Color32::from_gray(30),
line1: Color32::from_gray(0),
line2: Color32::from_gray(30),
line3: Color32::from_gray(60),
line4: Color32::from_gray(90),
},
Theme::Dark => PlatformColors {
is_light: false,
animation_background: Color32::from_gray(60),
window_background: Color32::from_rgb(32, 32, 32),
content_background: Color32::from_rgb(34, 32, 40),
text_primary: Color32::from_gray(255),
text_secondary: Color32::from_gray(200),
line1: Color32::from_gray(255),
line2: Color32::from_gray(210),
line3: Color32::from_gray(190),
line4: Color32::from_gray(120),
},
}
}
/// This is called from `App::setup`
pub fn setup(ctx: &egui::CtxRef) {}
/// This is called once from `App::update` on the first run.
pub fn initial_update(ctx: &egui::CtxRef) -> Result<()> {
Ok(())
}
pub fn navigation_button(title: &str) -> egui::Button {
egui::Button::new(title)
}

@ -7,6 +7,8 @@
//! necessary on macOS and I'd rather not load it on Windows or Linux systems.
use eframe::{self, egui, epi};
#[cfg(target_os = "macos")]
use image;
/// Pre-loaded textures
@ -37,6 +39,7 @@ impl Textures {
/// Load the permission image
// via: https://github.com/emilk/egui/blob/master/eframe/examples/image.rs
#[allow(unused)]
#[cfg(target_os = "macos")]
fn install_missing_permission_image(
image_data: &[u8],
frame: &mut epi::Frame<'_>,

Loading…
Cancel
Save