Skip to content

Commit

Permalink
add option in settings to automatically keep games updated
Browse files Browse the repository at this point in the history
  • Loading branch information
trippjoe committed Dec 31, 2024
1 parent 755cf61 commit 5742eb4
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src-tauri/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,26 @@ pub async fn set_bypass_requirements(
Ok(())
}

#[tauri::command]
pub async fn get_auto_update_games(
config: tauri::State<'_, tokio::sync::Mutex<LauncherConfig>>,
) -> Result<bool, CommandError> {
let config_lock = config.lock().await;
Ok(config_lock.auto_update_games)
}

#[tauri::command]
pub async fn set_auto_update_games(
config: tauri::State<'_, tokio::sync::Mutex<LauncherConfig>>,
value: bool,
) -> Result<(), CommandError> {
let mut config_lock = config.lock().await;
config_lock.set_auto_update_games(value).map_err(|_| {
CommandError::Configuration("Unable to persist bypass requirements change".to_owned())
})?;
Ok(())
}

#[tauri::command]
pub async fn get_check_for_latest_mod_version(
config: tauri::State<'_, tokio::sync::Mutex<LauncherConfig>>,
Expand Down
8 changes: 8 additions & 0 deletions src-tauri/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ pub struct LauncherConfig {
pub decompiler_settings: Option<DecompilerSettings>,
pub check_for_latest_mod_version: Option<bool>,
pub proceed_after_successful_operation: Option<bool>,
pub auto_update_games: bool,
}

fn default_version() -> Option<String> {
Expand Down Expand Up @@ -226,6 +227,7 @@ impl LauncherConfig {
decompiler_settings: Some(DecompilerSettings::default()),
check_for_latest_mod_version: Some(true),
proceed_after_successful_operation: Some(true),
auto_update_games: false,
}
}

Expand Down Expand Up @@ -460,6 +462,12 @@ impl LauncherConfig {
Ok(())
}

pub fn set_auto_update_games(&mut self, value: bool) -> Result<(), ConfigError> {
self.auto_update_games = value;
self.save_config()?;
Ok(())
}

pub fn set_check_for_latest_mod_version(
&mut self,
check_for_latest_mod_version: bool,
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ fn main() {
commands::config::reset_to_defaults,
commands::config::save_active_version_change,
commands::config::set_bypass_requirements,
commands::config::set_auto_update_games,
commands::config::get_auto_update_games,
commands::config::set_enabled_texture_packs,
commands::config::set_install_directory,
commands::config::set_locale,
Expand Down
1 change: 1 addition & 0 deletions src/components/games/job/GameJob.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
progressTracker.proceed();
await finalizeInstallation(getInternalName(activeGame));
progressTracker.proceed();
location.reload();
}
async function setupTexturePacks() {
Expand Down
11 changes: 10 additions & 1 deletion src/components/games/setup/GameUpdate.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<script lang="ts">
import type { SupportedGame } from "$lib/constants";
import { isMinimumVCCRuntimeInstalled } from "$lib/rpc/config";
import {
getAutoUpdateGames,
isMinimumVCCRuntimeInstalled,
} from "$lib/rpc/config";
import { VersionStore } from "$lib/stores/VersionStore";
import { type } from "@tauri-apps/api/os";
import { Button, Card } from "flowbite-svelte";
Expand All @@ -22,6 +25,12 @@
const isVCCInstalled = await isMinimumVCCRuntimeInstalled();
displayVCCWarning = !isVCCInstalled;
}
let shouldAutoUpdate = await getAutoUpdateGames();
if (shouldAutoUpdate) {
dispatch("job", {
type: "updateGame",
});
}
});
</script>

Expand Down
30 changes: 30 additions & 0 deletions src/components/header/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import { checkUpdate } from "@tauri-apps/api/updater";
import { isInDebugMode } from "$lib/utils/common";
import {
downloadOfficialVersion,
getActiveVersion,
getActiveVersionFolder,
listDownloadedVersions,
Expand All @@ -19,9 +20,29 @@
import { exceptionLog, infoLog } from "$lib/rpc/logging";
import { _ } from "svelte-i18n";
import { toastStore } from "$lib/stores/ToastStore";
import { getAutoUpdateGames, saveActiveVersionChange } from "$lib/rpc/config";
let launcherVerison = null;
async function downloadLatestVersion(version: string, url: String) {
await downloadOfficialVersion(version, url);
$UpdateStore.selectedTooling.updateAvailable = false;
$VersionStore.selectedVersions.official = version;
await saveOfficialVersionChange();
}
async function saveOfficialVersionChange() {
const success = await saveActiveVersionChange(
"official",
$VersionStore.selectedVersions.official,
);
if (success) {
$VersionStore.activeVersionType = "official";
$VersionStore.activeVersionName = $VersionStore.selectedVersions.official;
toastStore.makeToast($_("toasts_savedToolingVersion"), "info");
}
}
onMount(async () => {
// Get current versions
launcherVerison = `v${await getVersion()}`;
Expand Down Expand Up @@ -90,6 +111,15 @@
}
}
if (!alreadyHaveRelease) {
let shouldAutoUpdate = await getAutoUpdateGames();
if (shouldAutoUpdate) {
await downloadLatestVersion(
latestToolingVersion.version,
latestToolingVersion.downloadUrl,
);
location.reload(); // TODO! this is hacky, when i refactor this will be done automatically
}
$UpdateStore.selectedTooling = {
updateAvailable: true,
versionNumber: latestToolingVersion.version,
Expand Down
8 changes: 8 additions & 0 deletions src/lib/rpc/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ export async function setLocale(localeId: string): Promise<void> {
);
}

export async function setAutoUpdateGames(value: boolean): Promise<void> {
return await invoke_rpc("set_auto_update_games", { value }, () => {});
}

export async function getAutoUpdateGames(): Promise<boolean> {
return await invoke_rpc("get_auto_update_games", {}, () => false);
}

export async function setBypassRequirements(bypass: boolean): Promise<void> {
return await invoke_rpc("set_bypass_requirements", { bypass }, () => {});
}
Expand Down
15 changes: 15 additions & 0 deletions src/routes/settings/General.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
getLocale,
localeSpecificFontAvailableForDownload,
resetLauncherSettingsToDefaults,
setAutoUpdateGames,
getAutoUpdateGames,
setBypassRequirements,
setInstallationDirectory,
setLocale,
Expand All @@ -27,15 +29,19 @@
import { downloadFile } from "$lib/rpc/download";
import { appDataDir, join } from "@tauri-apps/api/path";
import { folderPrompt } from "$lib/utils/file-dialogs";
import { writable } from "svelte/store";
let currentInstallationDirectory = "";
let currentLocale;
let availableLocales = [];
let currentBypassRequirementsVal = false;
let keepGamesUpdated = writable(false);
let localeFontForDownload: Locale | undefined = undefined;
let localeFontDownloading = false;
onMount(async () => {
let autoUpdateGames = await getAutoUpdateGames();
keepGamesUpdated.set(autoUpdateGames);
currentInstallationDirectory = await getInstallationDirectory();
for (const locale of AVAILABLE_LOCALES) {
availableLocales = [
Expand Down Expand Up @@ -143,6 +149,15 @@
>
</div>
<div>
<Toggle
color="orange"
checked={$keepGamesUpdated}
on:change={async () => {
$keepGamesUpdated = !$keepGamesUpdated;
await setAutoUpdateGames($keepGamesUpdated);
}}
class="mb-2">Automatically keep games updated (experimental)</Toggle
>
<Toggle
checked={currentBypassRequirementsVal}
color="orange"
Expand Down

0 comments on commit 5742eb4

Please sign in to comment.