Skip to content

Commit

Permalink
GH-93: Fix build issues on Android AArch64 builds
Browse files Browse the repository at this point in the history
  • Loading branch information
SetZero committed Apr 28, 2024
1 parent 2965380 commit 33ddd2a
Show file tree
Hide file tree
Showing 21 changed files with 213 additions and 64 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
"@mui/material": "^5.12.0",
"@mui/styles": "^5.12.0",
"@reduxjs/toolkit": "^1.9.5",
"@rollup/rollup-linux-x64-gnu": "^4.17.0",
"@tauri-apps/api": "^2.0.0",
"@tauri-apps/plugin-dialog": "^2.0.0-beta.2",
"@tauri-apps/plugin-os": "^2.0.0-beta.2",
"@types/dompurify": "^3.0.1",
"@types/lodash": "^4.14.202",
"@types/marked": "^5.0.0",
"@types/quill": "^2.0.10",
"@types/react-color": "^3.0.6",
"@types/tinycolor2": "^1.4.3",
"@use-gesture/react": "^10.3.1",
"dayjs": "^1.11.7",
"dompurify": "^3.0.2",
"fuse.js": "^6.6.2",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[build]
target = "x86_64-pc-windows-msvc"
target = "x86_64-unknown-linux-gnu"

[target]
16 changes: 11 additions & 5 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ async-trait = "0.1.68"
tracing = "0.1"
tracing-subscriber = {version = "0.3", features = ["env-filter"] }
base64 = "0.22.0"
openssl = "0.10.52"
os_info = "3"
rodio = "0.17.1"
directories = "5.0.1"
Expand All @@ -47,17 +46,25 @@ symphonia = "0.5.3"
mime_guess = "2.0.4"
uuid = "1.7.0"
tauri-plugin-dialog = "2.0.0-beta.4"
image = {version = "0.25.1", features = ["gif", "png"], default-features = false } # zune jpeg is broken in android builds
audiopus_sys = { git = "F:/Dokumente/projekte/rust/audiopus_sys", branch = "0.0.6" }
audiopus_sys = { git = "file:///mnt/f/Dokumente/projekte/rust/audiopus_sys", branch = "0.0.9" }
opus = "0.3.0"
oboe = { version = "0.6.1", features = [ "java-interface", "shared-stdcxx" ] } # Android
tauri-plugin-os = "2.0.0-beta.3"

[dev-dependencies]
tempfile = "3.5.0"
mockall = "0.12.1"
tokio-test = "0.4.2"
xshell = "0.2.3"

[target.'cfg(all(target_os = "windows", target_os = "linux", target_os = "macos"))'.dependencies]
image = "0.25.1"
openssl = "0.10.52"

[target.'cfg(target_os = "android")'.dependencies]
oboe = { version = "0.6.1", features = [ "java-interface", "shared-stdcxx" ] } # Android
image = {version = "0.25.1", features = ["gif", "png"], default-features = false} # zune jpeg is broken in android builds
openssl = { version = "0.10", features = ["vendored"] }

[features]
# by default Tauri runs in production mode
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
Expand All @@ -66,7 +73,6 @@ default = ["custom-protocol"]
# DO NOT remove this
custom-protocol = ["tauri/custom-protocol"]


[profile.release]
debug = 1

Expand Down
12 changes: 9 additions & 3 deletions src-tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,15 @@ fn main() -> io::Result<()> {
});
}

let mumble_proto_str = mumble_proto.to_str().expect("Failed to convert path to string");
let mumble_udp_proto_str = mumble_udp_proto.to_str().expect("Failed to convert path to string");
let fancy_proto_str = fancy_proto.to_str().expect("Failed to convert path to string");
let mumble_proto_str = mumble_proto
.to_str()
.expect("Failed to convert path to string");
let mumble_udp_proto_str = mumble_udp_proto
.to_str()
.expect("Failed to convert path to string");
let fancy_proto_str = fancy_proto
.to_str()
.expect("Failed to convert path to string");

prost_build::compile_protos(&[mumble_proto_str], &["../out"])?;
prost_build::compile_protos(&[mumble_udp_proto_str], &["../out"])?;
Expand Down
9 changes: 8 additions & 1 deletion src-tauri/capabilities/migrated.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
"app:default",
"resources:default",
"menu:default",
"tray:default"
"tray:default",
"os:default",
"os:default",
"os:allow-arch",
"os:allow-hostname",
"os:allow-os-type",
"os:allow-platform",
"store:allow-set"
]
}
16 changes: 12 additions & 4 deletions src-tauri/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub async fn connect_to_server(
username: String,
identity: Option<String>,
state: State<'_, ConnectionState>,
app_handle: tauri::AppHandle,
) -> Result<(), String> {
info!("Connecting to server: {server_host}:{server_port}, username: {username}, identity: {identity:?}");

Expand All @@ -89,6 +90,7 @@ pub async fn connect_to_server(
identity,
app_info,
settings_channel,
app_handle
));
if let Err(e) = connection.connect().await {
return Err(format!("{e:?}"));
Expand Down Expand Up @@ -207,9 +209,12 @@ pub async fn crop_and_store_image(
zoom: f32,
crop: Coordinates,
rotation: i32,
app_handle: tauri::AppHandle
app_handle: tauri::AppHandle,
) -> Result<String, String> {
let data_dir = app_handle.path().app_data_dir().map_err(|e| format!("{e:?}"))?;
let data_dir = app_handle
.path()
.app_data_dir()
.map_err(|e| format!("{e:?}"))?;
let path = Path::new(path);
let img = image::open(path).map_err(|e| e.to_string())?;

Expand Down Expand Up @@ -368,7 +373,10 @@ pub fn close_app(app: AppHandle) {
#[cfg(desktop)]
#[tauri::command]
pub fn dev_tools(app: AppHandle) {
if let Err(e) = app.get_webview_window("main").map_or_else(|| Err(()), |w| Ok(w.open_devtools())) {
if let Err(e) = app
.get_webview_window("main")
.map_or_else(|| Err(()), |w| Ok(w.open_devtools()))
{
error!("Failed to toggle dev tools: {:?}", e);
}
}
}
12 changes: 9 additions & 3 deletions src-tauri/src/commands/settings_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn save_server(
server_port: u16,
username: &str,
identity: Option<String>,
app_handle: tauri::AppHandle
app_handle: tauri::AppHandle,
) -> Result<(), String> {
info!("Saving server: {server_host}:{server_port}");
let mut server_file = get_settings_file(SERVER_SETTINS_FILE, &app_handle)?;
Expand Down Expand Up @@ -77,7 +77,10 @@ pub fn save_server(
pub fn get_server_list(app_handle: tauri::AppHandle) -> Result<Vec<Server>, String> {
info!("Getting server list");

let data_dir = app_handle.path().app_config_dir().map_err(|e| format!("{e:?}"))?;
let data_dir = app_handle
.path()
.app_config_dir()
.map_err(|e| format!("{e:?}"))?;

// create config dir if it doesn't exist
std::fs::create_dir_all(&data_dir).map_err(|e| format!("{e:?}"))?;
Expand All @@ -101,7 +104,10 @@ pub fn get_server_list(app_handle: tauri::AppHandle) -> Result<Vec<Server>, Stri

#[tauri::command]
pub fn get_identity_certs(app_handle: tauri::AppHandle) -> Result<Vec<String>, String> {
let data_dir = app_handle.path().app_data_dir().map_err(|e| format!("{e:?}"))?;
let data_dir = app_handle
.path()
.app_data_dir()
.map_err(|e| format!("{e:?}"))?;

if !data_dir.exists() {
std::fs::create_dir_all(&data_dir).map_err(|e| format!("{e:?}"))?;
Expand Down
7 changes: 6 additions & 1 deletion src-tauri/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use base64::Engine;
use std::collections::HashMap;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use tauri::PackageInfo;
use tauri::{Manager, PackageInfo};
use threads::{InputThread, MainThread, OutputThread, PingThread};
use tokio::net::TcpStream;
use tokio::sync::broadcast::{self, Receiver, Sender};
Expand Down Expand Up @@ -63,6 +63,8 @@ pub struct Connection {
package_info: PackageInfo,
stream_reader: Arc<Mutex<Option<StreamReader>>>,
settings_channel: Receiver<GlobalSettings>,

app_handle: tauri::AppHandle,
}

impl Connection {
Expand All @@ -73,6 +75,7 @@ impl Connection {
identity: Option<String>,
package_info: PackageInfo,
settings_channel: Receiver<GlobalSettings>,
app_handle: tauri::AppHandle,
) -> Self {
let (tx_in, _): (Sender<Vec<u8>>, Receiver<Vec<u8>>) = broadcast::channel(QUEUE_SIZE);
let (tx_out, _): (Sender<Vec<u8>>, Receiver<Vec<u8>>) = broadcast::channel(QUEUE_SIZE);
Expand All @@ -97,6 +100,7 @@ impl Connection {
message_channels: MessageChannels { message_channel },
stream_reader: Arc::new(Mutex::new(None)),
settings_channel,
app_handle,
}
}

Expand All @@ -109,6 +113,7 @@ impl Connection {
);

let mut certificate_store = CertificateBuilder::try_from(&self.server_data.identity)
.cert_path(self.app_handle.path().data_dir()?)
.load_or_generate_new(true)
.store_to_project_dir(true)
.build()?;
Expand Down
18 changes: 18 additions & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ use crate::commands::{
},
zip_cmd::{convert_to_base64, unzip_data_from_utf8, zip_data_to_utf8},
};
use commands::{web_cmd::CrawlerState, ConnectionState};
use std::{collections::HashMap, sync::Arc};
use tauri::Manager;
use tokio::sync::Mutex;

#[cfg(mobile)]
mod mobile;
Expand Down Expand Up @@ -50,7 +54,21 @@ impl AppBuilder {
let setup = self.setup;
tauri::Builder::default()
.plugin(tauri_plugin_store::Builder::default().build())
.plugin(tauri_plugin_os::init())
.setup(move |app| {
app.manage(ConnectionState {
connection: Mutex::new(None),
window: Arc::new(Mutex::new(
app.get_webview_window("main").expect("window not found"),
)),
package_info: Mutex::new(app.package_info().clone()),
message_handler: Mutex::new(HashMap::new()),
device_manager: Mutex::new(None),
settings_channel: Mutex::new(None),
});
app.manage(CrawlerState {
crawler: Mutex::new(None),
});
if let Some(setup) = setup {
(setup)(app)?;
}
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async fn main() {
init_logging();

tauri::Builder::default()
.plugin(tauri_plugin_os::init())
.plugin(tauri_plugin_window_state::Builder::default().build())
.plugin(tauri_plugin_store::Builder::default().build())
.setup(|app| {
Expand Down
30 changes: 15 additions & 15 deletions src-tauri/src/mobile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ use tracing_subscriber::{
};

fn init_logging() {
let format = fmt::format()
.with_level(true)
.with_target(false)
.with_thread_ids(false)
.with_thread_names(false)
.compact(); // use the `Compact` formatting style.
let format = fmt::format()
.with_level(true)
.with_target(false)
.with_thread_ids(false)
.with_thread_names(false)
.compact(); // use the `Compact` formatting style.

tracing_subscriber::fmt()
.with_max_level(Level::TRACE)
.event_format(format)
.with_env_filter(EnvFilter::from_default_env().add_directive(Level::INFO.into()))
.with_span_events(FmtSpan::CLOSE)
.init();
tracing_subscriber::fmt()
.with_max_level(Level::TRACE)
.event_format(format)
.with_env_filter(EnvFilter::from_default_env().add_directive(Level::INFO.into()))
.with_span_events(FmtSpan::CLOSE)
.init();
}

#[tauri::mobile_entry_point]
fn main() {
init_logging();
super::AppBuilder::new().run();
}
init_logging();
super::AppBuilder::new().run();
}
21 changes: 12 additions & 9 deletions src-tauri/src/utils/certificate_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct CertificateBuilder {
load_or_generate_new: bool,
store_to_project_dir: bool,
identity: Option<String>,
data_dir: PathBuf,
}

impl CertificateBuilder {
Expand All @@ -29,9 +30,15 @@ impl CertificateBuilder {
load_or_generate_new: false,
store_to_project_dir: false,
identity: identity.clone(),
data_dir: PathBuf::new(),
}
}

pub fn cert_path(mut self, path: PathBuf) -> Self {
self.data_dir = path;
self
}

pub const fn load_or_generate_new(mut self, load_or_generate_new: bool) -> Self {
self.load_or_generate_new = load_or_generate_new;
self
Expand All @@ -43,20 +50,16 @@ impl CertificateBuilder {
}

pub fn build(self) -> AnyError<CertificateStore> {
let project_dirs = get_project_dirs()
.ok_or_else(|| CertificateError::new("Unable to load project dir"))?;
let data_dir = project_dirs.data_dir();

if !data_dir.exists() {
std::fs::create_dir_all(data_dir)?;
if !self.data_dir.exists() {
std::fs::create_dir_all(&self.data_dir)?;
}

let certificate_path = data_dir.join(
let certificate_path = self.data_dir.join(
self.identity
.as_ref()
.map_or("certificate.pem".to_string(), |v| format!("cert_{v}.pem")),
);
let private_key_path = data_dir.join(
let private_key_path = self.data_dir.join(
self.identity
.as_ref()
.map_or("private_key.pem".to_string(), |v| {
Expand All @@ -70,7 +73,7 @@ impl CertificateBuilder {
if let Some(certificate_store) =
Self::read_certificates(&certificate_path, &private_key_path)
{
trace!("Certificate loaded from project dir: {data_dir:?}");
trace!("Certificate loaded from project dir: {:?}", self.data_dir);
return Ok(certificate_store);
}

Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"build": {
"beforeBuildCommand": "yarn run build",
"beforeDevCommand": "yarn run dev",
"devUrl": "http://localhost:5173",
"devUrl": "http://192.168.178.120:5173",
"frontendDist": "../dist"
},
"productName": "Fancy Mumble",
Expand Down
Loading

0 comments on commit 33ddd2a

Please sign in to comment.