Skip to content

Use backend to verify existence of Resonite path #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion crates/tauri-app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ fn main() -> anyhow::Result<()> {
.build(),
)
.plugin(tauri_plugin_store::Builder::default().build())
.invoke_handler(tauri::generate_handler![show_window, load_manifest, install_version])
.invoke_handler(tauri::generate_handler![
show_window,
load_manifest,
install_version,
verify_resonite_path
])
.manage(Downloader::default())
.manage(ResoluteState::default())
.setup(|app| {
Expand Down Expand Up @@ -178,6 +183,14 @@ async fn install_version(app: AppHandle, rmod: ResoluteMod, version: ModVersion)
Ok(())
}

#[tauri::command]
async fn verify_resonite_path(app: AppHandle) -> Result<bool, String> {
let resonite_path: String = settings::require(&app, "resonitePath").map_err(|err| err.to_string())?;
tokio::fs::try_exists(resonite_path)
.await
.map_err(|err| err.to_string())
}

#[derive(Default)]
struct ResoluteState {
mods: Mutex<ResoluteModMap>,
Expand Down
10 changes: 5 additions & 5 deletions ui/src/components/pages/ModsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
onMounted,
onUnmounted,
} from 'vue';
import { exists as fsExists } from '@tauri-apps/api/fs';
import { invoke } from '@tauri-apps/api';
import { mdiRefresh } from '@mdi/js';

import useSettings from '../../settings';
Expand Down Expand Up @@ -87,15 +87,15 @@ onBeforeMount(checkIfResonitePathExists);
watch(settings.current, checkIfResonitePathExists);

/**
* Checks whether the Resonite path is configured and exists
* Checks whether the Resonite path is configured and exists via the backend
*/
async function checkIfResonitePathExists() {
if (!settings.current.resonitePath) {
resonitePathExists.value = null;
} else {
resonitePathExists.value = await fsExists(
settings.current.resonitePath,
).catch(() => false);
resonitePathExists.value = await invoke('verify_resonite_path').catch(
() => false,
);
}
}

Expand Down