mirror of https://github.com/terhechte/postsack
Add postsack-web target for wasm
This includes everything required to build a wasm target. It also separates the egui initialization into the separate postsack target for nativepull/8/head
parent
8ee485f7a7
commit
047552a20a
@ -0,0 +1,3 @@
|
|||||||
|
/target
|
||||||
|
target
|
||||||
|
.DS_Store
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,16 @@
|
|||||||
|
[package]
|
||||||
|
name = "postsack-web"
|
||||||
|
version = "0.2.0"
|
||||||
|
edition = "2021"
|
||||||
|
description = "Provides a high level visual overview of swaths of email"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
ps-gui = { path = "../ps-gui" }
|
||||||
|
ps-core = { path = "../ps-core" }
|
||||||
|
wasm-bindgen = "*"
|
||||||
|
console_error_panic_hook = "0.1.7"
|
@ -0,0 +1,60 @@
|
|||||||
|
use std::path::Path;
|
||||||
|
use std::thread::JoinHandle;
|
||||||
|
|
||||||
|
use ps_core::{
|
||||||
|
crossbeam_channel::Sender,
|
||||||
|
eyre::{bail, Result},
|
||||||
|
Config, DBMessage, DatabaseLike, DatabaseQuery, Field, Query, QueryResult, ValueField,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct FakeDatabase {}
|
||||||
|
|
||||||
|
impl FakeDatabase {
|
||||||
|
pub fn total_item_count() -> usize {
|
||||||
|
33
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Clone for FakeDatabase {
|
||||||
|
fn clone(&self) -> Self {
|
||||||
|
FakeDatabase {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DatabaseQuery for FakeDatabase {
|
||||||
|
fn query(&self, query: &Query) -> Result<Vec<QueryResult>> {
|
||||||
|
Ok((0..50)
|
||||||
|
.map(|e| QueryResult::Grouped {
|
||||||
|
count: e as usize + 30,
|
||||||
|
value: ValueField::usize(&Field::Month, e as usize),
|
||||||
|
})
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DatabaseLike for FakeDatabase {
|
||||||
|
fn new(path: impl AsRef<Path>) -> Result<Self>
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
|
Ok(FakeDatabase {})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn config(path: impl AsRef<Path>) -> Result<Config>
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
|
bail!("Na")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn total_mails(&self) -> Result<usize> {
|
||||||
|
Ok(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn import(self) -> (Sender<DBMessage>, JoinHandle<Result<usize>>) {
|
||||||
|
panic!()
|
||||||
|
}
|
||||||
|
fn save_config(&self, config: Config) -> Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
use ps_core::{Config, FormatType};
|
||||||
|
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
use ps_gui::{eframe, PostsackApp};
|
||||||
|
|
||||||
|
mod database;
|
||||||
|
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
use console_error_panic_hook;
|
||||||
|
|
||||||
|
/// Call this once from the HTML.
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn start(canvas_id: &str) -> Result<(), eframe::wasm_bindgen::JsValue> {
|
||||||
|
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
|
||||||
|
|
||||||
|
use database::FakeDatabase;
|
||||||
|
|
||||||
|
let format = FormatType::AppleMail;
|
||||||
|
let config = Config::new(None, "", vec!["test@gmail.com".to_owned()], format).unwrap();
|
||||||
|
|
||||||
|
let app = PostsackApp::<database::FakeDatabase>::new(config, FakeDatabase::total_item_count());
|
||||||
|
eframe::start_web(canvas_id, Box::new(app))
|
||||||
|
}
|
@ -1,8 +1,10 @@
|
|||||||
use ps_database::Database;
|
use ps_database::Database;
|
||||||
|
use ps_gui::{eframe, PostsackApp};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
ps_core::setup_tracing();
|
ps_core::setup_tracing();
|
||||||
|
|
||||||
ps_gui::run_ui::<Database>();
|
let options = eframe::NativeOptions::default();
|
||||||
|
eframe::run_native(Box::new(PostsackApp::<Database>::new()), options);
|
||||||
}
|
}
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
rm -rf target/release/bundle/osx/Postsack.app
|
|
||||||
|
|
||||||
# Build for x86 and ARM
|
|
||||||
cargo build --release --target=aarch64-apple-darwin
|
|
||||||
cargo build --release --target=x86_64-apple-darwin
|
|
||||||
|
|
||||||
# Combine into a fat binary
|
|
||||||
|
|
||||||
lipo -create target/aarch64-apple-darwin/release/postsack target/x86_64-apple-darwin/release/postsack -output postsack
|
|
||||||
|
|
||||||
# Perform Cargo bundle to create a macOS Bundle
|
|
||||||
|
|
||||||
cargo bundle --release
|
|
||||||
|
|
||||||
# Override bundle binary with the fat one
|
|
||||||
# Also: We want to have `Postsack` capitalized on macOS, so we rename
|
|
||||||
|
|
||||||
rm target/release/bundle/osx/Postsack.app/Contents/MacOS/postsack
|
|
||||||
|
|
||||||
mv ./postsack target/release/bundle/osx/Postsack.app/Contents/MacOS/
|
|
||||||
|
|
||||||
# Tell the Info.plist or binary is capitalized
|
|
||||||
|
|
||||||
/usr/libexec/PlistBuddy -c "Set :CFBundleExecutable Postsack" "target/release/bundle/osx/Postsack.app/Contents/Info.plist"
|
|
||||||
|
|
Loading…
Reference in New Issue