diff --git a/.cargo/config.toml b/.cargo/config.toml index f4e8c00..c0509e6 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,2 @@ [build] -target = "wasm32-unknown-unknown" +#target = "wasm32-unknown-unknown" diff --git a/postsack-web/build_web.sh b/postsack-web/build_web.sh index f26a117..695af3b 100755 --- a/postsack-web/build_web.sh +++ b/postsack-web/build_web.sh @@ -16,7 +16,7 @@ export RUSTFLAGS=--cfg=web_sys_unstable_apis rm -f web_demo/${CRATE_NAME_SNAKE_CASE}_bg.wasm echo "Building rust…" -BUILD=debug +BUILD=release if [[ "$BUILD" == "debug" ]]; then cargo build -p ${CRATE_NAME} --lib --target wasm32-unknown-unknown else diff --git a/postsack/build_mac.sh b/postsack/build_mac.sh new file mode 100755 index 0000000..62ef41b --- /dev/null +++ b/postsack/build_mac.sh @@ -0,0 +1,29 @@ +#!/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" + diff --git a/icons/Icon.icns b/postsack/icons/Icon.icns similarity index 100% rename from icons/Icon.icns rename to postsack/icons/Icon.icns diff --git a/icons/Icon.iconset/icon-128.png b/postsack/icons/Icon.iconset/icon-128.png similarity index 100% rename from icons/Icon.iconset/icon-128.png rename to postsack/icons/Icon.iconset/icon-128.png diff --git a/icons/Icon.iconset/icon-128@2x.png b/postsack/icons/Icon.iconset/icon-128@2x.png similarity index 100% rename from icons/Icon.iconset/icon-128@2x.png rename to postsack/icons/Icon.iconset/icon-128@2x.png diff --git a/icons/Icon.iconset/icon-16.png b/postsack/icons/Icon.iconset/icon-16.png similarity index 100% rename from icons/Icon.iconset/icon-16.png rename to postsack/icons/Icon.iconset/icon-16.png diff --git a/icons/Icon.iconset/icon-16@2x.png b/postsack/icons/Icon.iconset/icon-16@2x.png similarity index 100% rename from icons/Icon.iconset/icon-16@2x.png rename to postsack/icons/Icon.iconset/icon-16@2x.png diff --git a/icons/Icon.iconset/icon-256.png b/postsack/icons/Icon.iconset/icon-256.png similarity index 100% rename from icons/Icon.iconset/icon-256.png rename to postsack/icons/Icon.iconset/icon-256.png diff --git a/icons/Icon.iconset/icon-256@2x.png b/postsack/icons/Icon.iconset/icon-256@2x.png similarity index 100% rename from icons/Icon.iconset/icon-256@2x.png rename to postsack/icons/Icon.iconset/icon-256@2x.png diff --git a/icons/Icon.iconset/icon-32.png b/postsack/icons/Icon.iconset/icon-32.png similarity index 100% rename from icons/Icon.iconset/icon-32.png rename to postsack/icons/Icon.iconset/icon-32.png diff --git a/icons/Icon.iconset/icon-32@2x.png b/postsack/icons/Icon.iconset/icon-32@2x.png similarity index 100% rename from icons/Icon.iconset/icon-32@2x.png rename to postsack/icons/Icon.iconset/icon-32@2x.png diff --git a/icons/Icon.iconset/icon-512.png b/postsack/icons/Icon.iconset/icon-512.png similarity index 100% rename from icons/Icon.iconset/icon-512.png rename to postsack/icons/Icon.iconset/icon-512.png diff --git a/icons/Icon.iconset/icon-512@2x.png b/postsack/icons/Icon.iconset/icon-512@2x.png similarity index 100% rename from icons/Icon.iconset/icon-512@2x.png rename to postsack/icons/Icon.iconset/icon-512@2x.png diff --git a/icons/make_icns.sh b/postsack/icons/make_icns.sh similarity index 100% rename from icons/make_icns.sh rename to postsack/icons/make_icns.sh diff --git a/ps-core/src/model/link.rs b/ps-core/src/model/link.rs index c926ed5..2b274ed 100644 --- a/ps-core/src/model/link.rs +++ b/ps-core/src/model/link.rs @@ -17,7 +17,7 @@ use eyre::Result; use serde_json::Value; use crate::database::{ - database_like::DatabaseQuery, + database_like::{DatabaseLike, DatabaseQuery}, query::Query, query_result::{QueryResult, QueryRow}, }; @@ -38,6 +38,7 @@ pub(super) type OutputReciever = Receiver>>; // FIXME: Instead of this wasm mess, two different link types? pub(super) struct Link { + #[cfg(target_arch = "wasm32")] database: Box, #[cfg(not(target_arch = "wasm32"))] @@ -128,7 +129,7 @@ impl Link { } #[cfg(not(target_arch = "wasm32"))] -pub(super) fn run( +pub(super) fn run( config: &Config, ) -> Result> { // Create a new database connection, just for reading diff --git a/ps-database/src/db.rs b/ps-database/src/db.rs index fe64dc4..aa33235 100644 --- a/ps-database/src/db.rs +++ b/ps-database/src/db.rs @@ -9,7 +9,7 @@ use super::sql::*; use super::{value_from_field, RowConversion}; use ps_core::{ crossbeam_channel::{unbounded, Sender}, - Config, DBMessage, DatabaseLike, EmailEntry, OtherQuery, Query, QueryResult, + Config, DBMessage, DatabaseLike, DatabaseQuery, EmailEntry, OtherQuery, Query, QueryResult, }; #[derive(Debug)] @@ -25,6 +25,43 @@ impl Clone for Database { } } +impl DatabaseQuery for Database { + fn query(&self, query: &Query) -> Result> { + use rusqlite::params_from_iter; + let c = match &self.connection { + Some(n) => n, + None => bail!("No connection to database available in query"), + }; + let (sql, values) = query.to_sql(); + let mut stmt = c.prepare(&sql)?; + let mut query_results = Vec::new(); + let mut converted = Vec::new(); + for value in values { + converted.push(super::conversion::json_to_value(&value)?); + } + + let p = params_from_iter(converted.iter()); + + let mut rows = stmt.query(p)?; + while let Some(row) = rows.next()? { + match query { + Query::Grouped { group_by, .. } => { + let result = QueryResult::grouped_from_row(group_by, row)?; + query_results.push(result); + } + Query::Normal { fields, .. } => { + let result = QueryResult::from_row(fields, row)?; + query_results.push(result); + } + Query::Other { + query: OtherQuery::All(field), + } => query_results.push(QueryResult::Other(value_from_field(field, row)?)), + } + } + Ok(query_results) + } +} + impl DatabaseLike for Database { /// Open database at path `Path`. fn new(path: impl AsRef) -> Result { @@ -72,41 +109,6 @@ impl DatabaseLike for Database { self.insert_config_fields(fields) } - fn query(&self, query: &Query) -> Result> { - use rusqlite::params_from_iter; - let c = match &self.connection { - Some(n) => n, - None => bail!("No connection to database available in query"), - }; - let (sql, values) = query.to_sql(); - let mut stmt = c.prepare(&sql)?; - let mut query_results = Vec::new(); - let mut converted = Vec::new(); - for value in values { - converted.push(super::conversion::json_to_value(&value)?); - } - - let p = params_from_iter(converted.iter()); - - let mut rows = stmt.query(p)?; - while let Some(row) = rows.next()? { - match query { - Query::Grouped { group_by, .. } => { - let result = QueryResult::grouped_from_row(group_by, row)?; - query_results.push(result); - } - Query::Normal { fields, .. } => { - let result = QueryResult::from_row(fields, row)?; - query_results.push(result); - } - Query::Other { - query: OtherQuery::All(field), - } => query_results.push(QueryResult::Other(value_from_field(field, row)?)), - } - } - Ok(query_results) - } - /// Begin the data import. /// This will consume the `Database`. A new one has to be opened /// afterwards in order to support multi-threading.