Skip to content

Commit

Permalink
GH-93: Initial Android Support Changes + Tauri 2.0 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
SetZero committed Apr 21, 2024
1 parent 6c9abd9 commit 2965380
Show file tree
Hide file tree
Showing 41 changed files with 601 additions and 352 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,6 @@ dist-ssr
src-tauri/data
src-tauri/src/proto/Mumble.proto
src-tauri/src/proto/MumbleUDP.proto
src-tauri/gen
src-tauri/gen

out/
6 changes: 6 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# .yarnrc.yml
supportedArchitectures:
os:
- "current"
- "linux"
- "win32"
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "module",
"license": "MIT",
"scripts": {
"dev": "vite",
"dev": "vite --host",
"build": "tsc && vite build",
"preview": "vite preview"
},
Expand All @@ -17,7 +17,8 @@
"@mui/material": "^5.12.0",
"@mui/styles": "^5.12.0",
"@reduxjs/toolkit": "^1.9.5",
"@tauri-apps/api": "^1.2.0",
"@tauri-apps/api": "^2.0.0",
"@tauri-apps/plugin-dialog": "^2.0.0-beta.2",
"@types/dompurify": "^3.0.1",
"@types/lodash": "^4.14.202",
"@types/marked": "^5.0.0",
Expand Down Expand Up @@ -46,14 +47,14 @@
"react-router-dom": "^6.10.0",
"socket.io": "^4.7.4",
"socket.io-client": "^4.7.4",
"tauri-plugin-store-api": "https://github.com/tauri-apps/tauri-plugin-store#v1",
"tauri-plugin-store-api": "https://github.com/tauri-apps/tauri-plugin-store#v2",
"tinycolor2": "^1.6.0"
},
"devDependencies": {
"@types/react": "^18.0.28",
"@types/react-dom": "^18.0.11",
"@vitejs/plugin-react": "^3.1.0",
"typescript": "^4.9.3",
"vite": "^4.2.0"
"vite": "^5.2.10"
}
}
4 changes: 4 additions & 0 deletions src-tauri/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[build]
target = "x86_64-pc-windows-msvc"

[target]
33 changes: 20 additions & 13 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
name = "app"
version = "0.2.2"
description = "Fancy Mumble"
authors = ["you"]
authors = ["SetZero"]
license = "MIT"
repository = ""
default-run = "app"
edition = "2021"
rust-version = "1.59"
rust-version = "1.77"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[build-dependencies]
tauri-build = { version = "1.4.0", features = [] }
tauri-build = { version = "2.0.0-beta", features = [] }
prost-build = "0.12.3"
reqwest = { version = "0.11", features = ["cookies"] }
reqwest = { version = "0.12", features = ["cookies"] }
sha2 = "0.10.6"
tokio = { version = "1", features = ["full"] }
patch = "0.7.0"

[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.5.4", features = [ "path-all", "dialog-open", "global-shortcut-all", "shell-open", "updater", "window-close", "window-hide", "window-maximize", "window-minimize", "window-start-dragging", "window-unmaximize", "window-unminimize"] }
tauri = { version = "2.0.0-beta", features = [] }
futures = "0.3.4"
tokio = { version = "1", features = ["full"] }
tokio-native-tls = "0.3.1"
Expand All @@ -31,23 +31,26 @@ byteorder = "1.4.3"
async-trait = "0.1.68"
tracing = "0.1"
tracing-subscriber = {version = "0.3", features = ["env-filter"] }
base64 = "0.21.0"
base64 = "0.22.0"
openssl = "0.10.52"
os_info = "3"
opus = "0.3.0"
rodio = "0.17.1"
image = "0.24.6"
directories = "5.0.1"
num-traits = "0.2"
brotli = "3.3.4"
brotli = "5.0.0"
webbrowser = "0.8.10"
reqwest = "0.11"
scraper = "0.18.1"
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v1" }
reqwest = "0.12"
scraper = "0.19"
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
tauri-plugin-store = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
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" }
opus = "0.3.0"
oboe = { version = "0.6.1", features = [ "java-interface", "shared-stdcxx" ] } # Android

[dev-dependencies]
tempfile = "3.5.0"
Expand All @@ -63,6 +66,7 @@ default = ["custom-protocol"]
# DO NOT remove this
custom-protocol = ["tauri/custom-protocol"]


[profile.release]
debug = 1

Expand All @@ -73,3 +77,6 @@ codegen-units = 1

[rust]
debuginfo-level = 1

[lib]
crate-type = ["staticlib", "cdylib", "rlib"]
15 changes: 10 additions & 5 deletions src-tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ async fn download_file(
}

fn main() -> io::Result<()> {
let mumble_proto = Path::new("src/proto/Mumble.proto");
let mumble_udp_proto = Path::new("src/proto/MumbleUDP.proto");
let mumble_proto = Path::new("../out/proto/Mumble.proto");
let mumble_udp_proto = Path::new("../out/proto/MumbleUDP.proto");
let fancy_proto = Path::new("src/proto/Fancy.proto");
let patch_file = Path::new("src/proto/Mumble.proto.patch");

let mumble_proto_bytes = read_file_as_bytes(mumble_proto).unwrap_or_default();
Expand Down Expand Up @@ -116,9 +117,13 @@ fn main() -> io::Result<()> {
});
}

prost_build::compile_protos(&["src/proto/Mumble.proto"], &["src/"])?;
prost_build::compile_protos(&["src/proto/MumbleUDP.proto"], &["src/"])?;
prost_build::compile_protos(&["src/proto/Fancy.proto"], &["src/"])?;
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"])?;
prost_build::compile_protos(&[fancy_proto_str], &["src/"])?;
tauri_build::build();

Ok(())
Expand Down
17 changes: 17 additions & 0 deletions src-tauri/capabilities/migrated.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"identifier": "migrated",
"description": "permissions that were migrated from v1",
"local": true,
"windows": [
"main"
],
"permissions": [
"path:default",
"event:default",
"window:default",
"app:default",
"resources:default",
"menu:default",
"tray:default"
]
}
22 changes: 16 additions & 6 deletions src-tauri/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ use crate::{
protocol::message_transmitter::MessageTransmitter,
utils::{audio::device_manager::AudioDeviceManager, constants::get_project_dirs},
};
use tauri::{AppHandle, State};
use tauri_plugin_window_state::{AppHandleExt, StateFlags};
use tauri::{AppHandle, Manager, State};
use tokio::sync::{
broadcast::{self, Receiver, Sender},
Mutex,
};
use tracing::{error, info, trace};
use tracing_subscriber::fmt::format;

use self::utils::settings::{
AudioOptions, AudioOutputSettings, AudioPreviewContainer, AudioUserState, Coordinates,
Expand All @@ -32,10 +32,12 @@ use image::{
imageops::{self, FilterType},
GenericImageView,
};
#[cfg(desktop)]
use tauri_plugin_window_state::{AppHandleExt, StateFlags};

pub struct ConnectionState {
pub connection: Mutex<Option<Connection>>,
pub window: Arc<Mutex<tauri::Window>>,
pub window: Arc<Mutex<tauri::WebviewWindow>>,
pub package_info: Mutex<tauri::PackageInfo>,
pub message_handler: Mutex<HashMap<String, Box<dyn Shutdown + Send>>>,
pub device_manager: Mutex<Option<AudioDeviceManager>>,
Expand Down Expand Up @@ -205,10 +207,9 @@ pub async fn crop_and_store_image(
zoom: f32,
crop: Coordinates,
rotation: i32,
app_handle: tauri::AppHandle
) -> Result<String, String> {
let project_dirs = get_project_dirs().ok_or("Unable to load project dir")?;

let data_dir = project_dirs.cache_dir();
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 @@ -354,6 +355,7 @@ pub async fn enable_audio_info(state: State<'_, ConnectionState>) -> Result<(),
Ok(())
}

#[cfg(desktop)]
#[allow(clippy::needless_pass_by_value)] // tauri command
#[tauri::command]
pub fn close_app(app: AppHandle) {
Expand All @@ -362,3 +364,11 @@ pub fn close_app(app: AppHandle) {
}
app.exit(0);
}

#[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())) {
error!("Failed to toggle dev tools: {:?}", e);
}
}
27 changes: 12 additions & 15 deletions src-tauri/src/commands/settings_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{
io::{Seek, SeekFrom, Write},
};

use tauri::Manager;
use tracing::{info, trace};

use crate::{
Expand All @@ -12,10 +13,9 @@ use crate::{

const SERVER_SETTINS_FILE: &str = "server.json";

pub fn get_settings_file(file_name: &str) -> Result<std::fs::File, String> {
let project_dirs = get_project_dirs().ok_or("Unable to load project dir")?;
let data_dir = project_dirs.config_dir();
std::fs::create_dir_all(data_dir).map_err(|e| format!("{e:?}"))?;
pub fn get_settings_file(file_name: &str, app: &tauri::AppHandle) -> Result<std::fs::File, String> {
let data_dir = app.path().app_config_dir().map_err(|e| format!("{e:?}"))?;
std::fs::create_dir_all(&data_dir).map_err(|e| format!("{e:?}"))?;
let settings_file = std::fs::OpenOptions::new()
.read(true)
.write(true)
Expand All @@ -32,9 +32,10 @@ pub fn save_server(
server_port: u16,
username: &str,
identity: Option<String>,
app_handle: tauri::AppHandle
) -> Result<(), String> {
info!("Saving server: {server_host}:{server_port}");
let mut server_file = get_settings_file(SERVER_SETTINS_FILE)?;
let mut server_file = get_settings_file(SERVER_SETTINS_FILE, &app_handle)?;

// read the json content using serde and append the new server
let mut server_list =
Expand Down Expand Up @@ -73,14 +74,13 @@ pub fn save_server(
}

#[tauri::command]
pub fn get_server_list() -> Result<Vec<Server>, String> {
pub fn get_server_list(app_handle: tauri::AppHandle) -> Result<Vec<Server>, String> {
info!("Getting server list");
let project_dirs = get_project_dirs().ok_or("Unable to load project dir")?;

let data_dir = project_dirs.config_dir();
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:?}"))?;
std::fs::create_dir_all(&data_dir).map_err(|e| format!("{e:?}"))?;

// open server.json or create it if it doesn't exist
let server_file = std::fs::OpenOptions::new()
Expand All @@ -100,14 +100,11 @@ pub fn get_server_list() -> Result<Vec<Server>, String> {
}

#[tauri::command]
pub fn get_identity_certs() -> Result<Vec<String>, String> {
let project_dirs = get_project_dirs()
.ok_or_else(|| CertificateError::new("Unable to load project dir"))
.map_err(|e| format!("{e:?}"))?;
let data_dir = project_dirs.data_dir();
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:?}"))?;

if !data_dir.exists() {
std::fs::create_dir_all(data_dir).map_err(|e| format!("{e:?}"))?;
std::fs::create_dir_all(&data_dir).map_err(|e| format!("{e:?}"))?;
}

let mut certs = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/src/commands/utils/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub struct AudioOutputSettings {
#[derive(Clone, Debug)]
pub struct AudioPreviewContainer {
pub enabled: bool,
pub window: Arc<Mutex<tauri::Window>>,
pub window: Arc<Mutex<tauri::WebviewWindow>>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
Expand Down
Loading

0 comments on commit 2965380

Please sign in to comment.