aboutsummaryrefslogtreecommitdiff
path: root/src-tauri/src/util.rs
diff options
context:
space:
mode:
authorGeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com>2023-10-13 13:21:06 +0200
committerGitHub <noreply@github.com>2023-10-13 13:21:06 +0200
commitb3b558dbab5ac41a64f36d36aac81f0b996101b0 (patch)
tree985666659cb5d3e8a14012ce07b07eafdf2f5ce5 /src-tauri/src/util.rs
parent97d4773d5ee55cf6a9081475f2bc3011b23e1037 (diff)
downloadFlightCore-b3b558dbab5ac41a64f36d36aac81f0b996101b0.tar.gz
FlightCore-b3b558dbab5ac41a64f36d36aac81f0b996101b0.zip
refactor: Move relevant functions to util module (#623)
* 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
Diffstat (limited to 'src-tauri/src/util.rs')
-rw-r--r--src-tauri/src/util.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/src-tauri/src/util.rs b/src-tauri/src/util.rs
index b21b2208..274cf488 100644
--- a/src-tauri/src/util.rs
+++ b/src-tauri/src/util.rs
@@ -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}");