Skip to content

Commit

Permalink
refactor: Move relevant functions to util module (#623)
Browse files Browse the repository at this point in the history
* refactor: Move to `get_flightcore_version_number` to util module

* refactor: Move to `open_repair_window` to util mod

* refactor: Move to `close_application` to util mod
  • Loading branch information
GeckoEidechse authored Oct 13, 2023
1 parent 97d4773 commit b3b558d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
51 changes: 4 additions & 47 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use serde::{Deserialize, Serialize};
use tauri::api::dialog::blocking::MessageDialogBuilder;
#[cfg(target_os = "windows")]
use tauri::api::dialog::{MessageDialogButtons, MessageDialogKind};
use tauri::{Manager, Runtime};
use tauri::Manager;
use tokio::time::sleep;
use ts_rs::TS;

Expand Down Expand Up @@ -119,7 +119,7 @@ fn main() {
.invoke_handler(tauri::generate_handler![
util::force_panic,
northstar::install::find_game_install_location,
get_flightcore_version_number,
util::get_flightcore_version_number,
northstar::get_northstar_version_number,
check_is_northstar_outdated,
repair_and_verify::verify_install_location,
Expand Down Expand Up @@ -147,15 +147,15 @@ fn main() {
platform_specific::install_northstar_proton_wrapper,
platform_specific::uninstall_northstar_proton_wrapper,
platform_specific::get_local_northstar_proton_wrapper_version,
open_repair_window,
util::open_repair_window,
thunderstore::query_thunderstore_packages_api,
github::get_list_of_tags,
github::compare_tags,
github::pull_requests::get_pull_requests_wrapper,
github::pull_requests::apply_launcher_pr,
github::pull_requests::apply_mods_pr,
github::pull_requests::get_launcher_download_link,
close_application,
util::close_application,
development::install_git_main,
get_available_northstar_versions,
northstar::profile::fetch_profiles,
Expand Down Expand Up @@ -194,19 +194,6 @@ fn main() {
};
}

/// Returns the current version number as a string
#[tauri::command]
async fn get_flightcore_version_number() -> String {
let version = env!("CARGO_PKG_VERSION");
if cfg!(debug_assertions) {
// Debugging enabled
format!("v{} (debug mode)", version)
} else {
// Debugging disabled
format!("v{}", version)
}
}

/// Helps with converting release candidate numbers which are different on Thunderstore
/// due to restrictions imposed by the platform
pub fn convert_release_candidate_number(version_number: String) -> String {
Expand Down Expand Up @@ -303,36 +290,6 @@ async fn clean_up_download_folder_wrapper(
}
}

/// Spawns repair window
#[tauri::command]
async fn open_repair_window(handle: tauri::AppHandle) -> Result<(), String> {
// Spawn new window
let repair_window = match tauri::WindowBuilder::new(
&handle,
"RepairWindow",
tauri::WindowUrl::App("/#/repair".into()),
)
.build()
{
Ok(res) => res,
Err(err) => return Err(err.to_string()),
};

// Set window title
match repair_window.set_title("FlightCore Repair Window") {
Ok(()) => (),
Err(err) => return Err(err.to_string()),
};
Ok(())
}

/// Closes all windows and exits application
#[tauri::command]
async fn close_application<R: Runtime>(app: tauri::AppHandle<R>) -> Result<(), String> {
app.exit(0); // Close application
Ok(())
}

/// Gets list of available Northstar versions from Thunderstore
#[tauri::command]
async fn get_available_northstar_versions() -> Result<Vec<NorthstarThunderstoreReleaseWrapper>, ()>
Expand Down
43 changes: 43 additions & 0 deletions src-tauri/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,49 @@ pub async fn is_debug_mode() -> bool {
cfg!(debug_assertions)
}

/// Returns the current version number as a string
#[tauri::command]
pub async fn get_flightcore_version_number() -> String {
let version = env!("CARGO_PKG_VERSION");
if cfg!(debug_assertions) {
// Debugging enabled
format!("v{} (debug mode)", version)
} else {
// Debugging disabled
format!("v{}", version)
}
}

/// Spawns repair window
#[tauri::command]
pub async fn open_repair_window(handle: tauri::AppHandle) -> Result<(), String> {
// Spawn new window
let repair_window = match tauri::WindowBuilder::new(
&handle,
"RepairWindow",
tauri::WindowUrl::App("/#/repair".into()),
)
.build()
{
Ok(res) => res,
Err(err) => return Err(err.to_string()),
};

// Set window title
match repair_window.set_title("FlightCore Repair Window") {
Ok(()) => (),
Err(err) => return Err(err.to_string()),
};
Ok(())
}

/// Closes all windows and exits application
#[tauri::command]
pub async fn close_application<R: tauri::Runtime>(app: tauri::AppHandle<R>) -> Result<(), String> {
app.exit(0); // Close application
Ok(())
}

/// Fetches `/client/servers` endpoint from master server
async fn fetch_server_list() -> Result<String, anyhow::Error> {
let url = format!("{MASTER_SERVER_URL}{SERVER_BROWSER_ENDPOINT}");
Expand Down

0 comments on commit b3b558d

Please sign in to comment.