diff options
author | GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> | 2022-10-19 15:40:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-19 15:40:22 +0200 |
commit | 6365220063527735fca0134f0649b97d82525990 (patch) | |
tree | 822d28793cdb757507e9d30a66f1cc56cc852f35 | |
parent | 4e55dce30214a426c8621c565f525303b43fbf7f (diff) | |
download | FlightCore-6365220063527735fca0134f0649b97d82525990.tar.gz FlightCore-6365220063527735fca0134f0649b97d82525990.zip |
refactor: Use `Result<>` return type for Linux checks (#21)
* refactor: Use result return type for Linux checks
* refactor: Store min required ldd version in const
This way we only need to update a single variable in case min required
version changes.
-rw-r--r-- | src-tauri/src/lib.rs | 18 | ||||
-rw-r--r-- | src-tauri/src/main.rs | 11 | ||||
-rw-r--r-- | src-vue/src/views/DeveloperView.vue | 32 |
3 files changed, 36 insertions, 25 deletions
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 6a44514d..c2007130 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -46,17 +46,25 @@ pub fn check_mod_version_number(path_to_mod_folder: String) -> Result<String, an // for now tho it only checks `ldd --version` // - salmon -pub fn linux_checks_librs() -> bool { - let mut linux_compatible: bool = true; // a variable that starts true and will be set to false if any of the checks arent met +pub fn linux_checks_librs() -> Result<(), String> { + // Perform various checks in terms of Linux compatibility + // Return early with error message if a check fails // check `ldd --version` to see if glibc is up to date for northstar proton + let min_required_ldd_version = 2.33; let lddv = linux::check_glibc_v(); - if lddv < 2.33 { linux_compatible = false }; + if lddv < min_required_ldd_version { + return Err(format!( + "GLIBC is not version {} or greater", + min_required_ldd_version + ) + .to_string()); + }; - return linux_compatible; + // All checks passed + Ok(()) } - /// Attempts to find the game install location pub fn find_game_install_location() -> Result<GameInstall, anyhow::Error> { // Attempt parsing Steam library directly diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index a33f836c..411e75c9 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -120,12 +120,13 @@ fn is_debug_mode() -> bool { #[tauri::command] /// Returns true if linux compatible -fn linux_checks() -> bool { - if get_host_os() == "windows" { - false - } else { - linux_checks_librs() +fn linux_checks() -> Result<(), String> { + // Early return if Windows + if get_host_os() == "windows" { + return Err("Not available on Windows".to_string()); } + + linux_checks_librs() } #[tauri::command] diff --git a/src-vue/src/views/DeveloperView.vue b/src-vue/src/views/DeveloperView.vue index 80390432..e1f9eb7c 100644 --- a/src-vue/src/views/DeveloperView.vue +++ b/src-vue/src/views/DeveloperView.vue @@ -50,22 +50,24 @@ export default defineComponent({ }); }, async checkLinuxCompatibility() { - let LinuxCompatible = await invoke("linux_checks"); - if (!LinuxCompatible) { - ElNotification({ - title: 'Not linux compatible', - message: 'GLIBC is not version 2.33 or greater', - type: 'error', - position: 'bottom-right' - }); - } else { - ElNotification({ - title: 'Linux compatible', - message: 'No error reported', - type: 'success', - position: 'bottom-right' + await invoke("linux_checks") + .then(() => { + ElNotification({ + title: 'Linux compatible', + message: 'All checks passed', + type: 'success', + position: 'bottom-right' + }); + }) + .catch((error) => { + ElNotification({ + title: 'Not linux compatible', + message: error, + type: 'error', + position: 'bottom-right' + }); + console.error(error); }); - } }, async toggleReleaseCandidate() { // Flip between RELEASE and RELEASE_CANDIDATE |