From 0928087751569148e7bbc1b351ed0eab0430dac5 Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Sat, 25 Feb 2023 20:55:54 +0100 Subject: refactor: Properly set cfg macro for OS conditional compilation (#186) * refactor: Properly set cfg macro for OS conditional compilation * docs: Add comment about MacOS --- src-tauri/src/lib.rs | 3 ++- src-tauri/src/main.rs | 14 ++++++++++---- src-tauri/src/platform_specific/mod.rs | 1 + 3 files changed, 13 insertions(+), 5 deletions(-) (limited to 'src-tauri/src') diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 5688512c..27019361 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -9,6 +9,7 @@ mod platform_specific; #[cfg(target_os = "windows")] use platform_specific::windows; +#[cfg(target_os = "linux")] use platform_specific::linux; use serde::{Deserialize, Serialize}; @@ -67,7 +68,7 @@ pub fn check_mod_version_number(path_to_mod_folder: String) -> Result Result<(), String> { // Perform various checks in terms of Linux compatibility // Return early with error message if a check fails diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 12fa477a..c0c8a186 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -142,12 +142,18 @@ async fn is_debug_mode() -> bool { #[tauri::command] /// Returns true if linux compatible async fn linux_checks() -> Result<(), String> { - // Early return if Windows - if get_host_os() == "windows" { - return Err("Not available on Windows".to_string()); + // Different behaviour depending on OS + // MacOS is missing as it is not a target + // in turn this means this application will not build on MacOS. + #[cfg(target_os = "windows")] + { + Err("Not available on Windows".to_string()) } - linux_checks_librs() + #[cfg(target_os = "linux")] + { + linux_checks_librs() + } } #[tauri::command] diff --git a/src-tauri/src/platform_specific/mod.rs b/src-tauri/src/platform_specific/mod.rs index ef45107e..84bd478a 100644 --- a/src-tauri/src/platform_specific/mod.rs +++ b/src-tauri/src/platform_specific/mod.rs @@ -1,4 +1,5 @@ #[cfg(target_os = "windows")] pub mod windows; +#[cfg(target_os = "linux")] pub mod linux; -- cgit v1.2.3