Skip to content

Commit 4e03230

Browse files
refactor: Make all functions async (#35)
This way none of them are run on main thread and as such if a function panics, it will only crash that specific thread allowing the rest of the application to survive. The only exception is `force_panic()` as its purpose is hard crashing the application. From the frontend side of things, `invoke()` is already async, so no frontend changes are needed.
1 parent d2ab94e commit 4e03230

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src-tauri/src/main.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn main() {
9797

9898
#[tauri::command]
9999
/// Wrapper for `find_game_install_location` as tauri doesn't allow passing `Result<>` types to front-end
100-
fn find_game_install_location_caller() -> Result<GameInstall, String> {
100+
async fn find_game_install_location_caller() -> Result<GameInstall, String> {
101101
match find_game_install_location() {
102102
Ok(game_install) => Ok(game_install),
103103
Err(err) => {
@@ -109,19 +109,20 @@ fn find_game_install_location_caller() -> Result<GameInstall, String> {
109109

110110
#[tauri::command]
111111
/// This function's only use is to force a `panic!()`
112+
// This must NOT be async to ensure crashing whole application.
112113
fn force_panic() {
113114
panic!("Force panicked!");
114115
}
115116

116117
#[tauri::command]
117118
/// Returns true if built in debug mode
118-
fn is_debug_mode() -> bool {
119+
async fn is_debug_mode() -> bool {
119120
return cfg!(debug_assertions);
120121
}
121122

122123
#[tauri::command]
123124
/// Returns true if linux compatible
124-
fn linux_checks() -> Result<(), String> {
125+
async fn linux_checks() -> Result<(), String> {
125126
// Early return if Windows
126127
if get_host_os() == "windows" {
127128
return Err("Not available on Windows".to_string());
@@ -132,7 +133,7 @@ fn linux_checks() -> Result<(), String> {
132133

133134
#[tauri::command]
134135
/// Returns the current version number as a string
135-
fn get_flightcore_version_number() -> String {
136+
async fn get_flightcore_version_number() -> String {
136137
let version = env!("CARGO_PKG_VERSION");
137138
if cfg!(debug_assertions) {
138139
// Debugging enabled
@@ -144,7 +145,7 @@ fn get_flightcore_version_number() -> String {
144145
}
145146

146147
#[tauri::command]
147-
fn get_northstar_version_number_caller(game_path: String) -> String {
148+
async fn get_northstar_version_number_caller(game_path: String) -> String {
148149
match get_northstar_version_number(game_path) {
149150
Ok(version_number) => version_number,
150151
Err(err) => {
@@ -207,13 +208,13 @@ async fn check_is_northstar_outdated(
207208
/// Checks if installed FlightCore version is up-to-date
208209
/// false -> FlightCore install is up-to-date
209210
/// true -> FlightCore install is outdated
210-
fn check_is_flightcore_outdated_caller() -> Result<bool, String> {
211+
async fn check_is_flightcore_outdated_caller() -> Result<bool, String> {
211212
check_is_flightcore_outdated()
212213
}
213214

214215
#[tauri::command]
215216
/// Checks if is valid Titanfall2 install based on certain conditions
216-
fn verify_install_location(game_path: String) -> bool {
217+
async fn verify_install_location(game_path: String) -> bool {
217218
match check_is_valid_game_path(&game_path) {
218219
Ok(()) => true,
219220
Err(err) => {
@@ -225,7 +226,7 @@ fn verify_install_location(game_path: String) -> bool {
225226

226227
#[tauri::command]
227228
/// Returns identifier of host OS FlightCore is running on
228-
fn get_host_os_caller() -> String {
229+
async fn get_host_os_caller() -> String {
229230
get_host_os()
230231
}
231232

@@ -265,28 +266,28 @@ async fn update_northstar_caller(
265266

266267
#[tauri::command]
267268
/// Launches Northstar
268-
fn launch_northstar_caller(game_install: GameInstall) -> Result<String, String> {
269+
async fn launch_northstar_caller(game_install: GameInstall) -> Result<String, String> {
269270
launch_northstar(game_install)
270271
}
271272

272273
#[tauri::command]
273274
/// Get list of Northstar logs
274-
fn get_log_list_caller(game_install: GameInstall) -> Result<Vec<std::path::PathBuf>, String> {
275+
async fn get_log_list_caller(game_install: GameInstall) -> Result<Vec<std::path::PathBuf>, String> {
275276
get_log_list(game_install)
276277
}
277278

278279
#[tauri::command]
279-
fn verify_game_files_caller(game_install: GameInstall) -> Result<String, String> {
280+
async fn verify_game_files_caller(game_install: GameInstall) -> Result<String, String> {
280281
verify_game_files(game_install)
281282
}
282283

283284
#[tauri::command]
284-
fn get_enabled_mods_caller(game_install: GameInstall) -> Result<serde_json::value::Value, String> {
285+
async fn get_enabled_mods_caller(game_install: GameInstall) -> Result<serde_json::value::Value, String> {
285286
get_enabled_mods(game_install)
286287
}
287288

288289
#[tauri::command]
289-
fn set_mod_enabled_status_caller(
290+
async fn set_mod_enabled_status_caller(
290291
game_install: GameInstall,
291292
mod_name: String,
292293
is_enabled: bool,
@@ -295,7 +296,7 @@ fn set_mod_enabled_status_caller(
295296
}
296297

297298
#[tauri::command]
298-
fn disable_all_but_core_caller(game_install: GameInstall) -> Result<(), String> {
299+
async fn disable_all_but_core_caller(game_install: GameInstall) -> Result<(), String> {
299300
disable_all_but_core(game_install)
300301
}
301302

0 commit comments

Comments
 (0)