Skip to content
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

added option in settings to automatically remove previous versions after installing latest #650

Merged
merged 8 commits into from
Jan 5, 2025
4 changes: 3 additions & 1 deletion src/assets/translations/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@
"settings_tabs_decompiler": "Decompiler",
"settings_tabs_general": "General",
"settings_tabs_versions": "Versions",
"settings_general_keep_updated": "Automatically keep games updated (experimental)",
"settings_general_uninstall_old": "Automatically uninstall old versions",
"settings_versions_header": "Configure your active tooling version",
"settings_versions_icon_downloadVersion_altText": "download version",
"settings_versions_icon_githubRelease_altText": "github release notes",
Expand Down Expand Up @@ -222,4 +224,4 @@
"toasts_unableToRetrieveModDownloadURL": "Unable to retrieve mod download URL",
"toasts_githubRateLimit": "Unable to hit GitHub's API, you are rate-limited",
"toasts_githubUnexpectedError": "Unexpected error when hitting GitHub's API"
}
}
3 changes: 3 additions & 0 deletions src/components/header/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
downloadOfficialVersion,
getActiveVersion,
listDownloadedVersions,
removeOldVersions,
} from "$lib/rpc/versions";
import { getLatestOfficialRelease } from "$lib/utils/github";
import { VersionStore } from "$lib/stores/VersionStore";
Expand Down Expand Up @@ -103,6 +104,8 @@
latestToolingVersion.version,
latestToolingVersion.downloadUrl,
);
await removeOldVersions();

location.reload(); // TODO! this is hacky, when i refactor this will be done automatically
}

Expand Down
18 changes: 18 additions & 0 deletions src/lib/rpc/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,24 @@ export async function getAutoUpdateGames(): Promise<boolean> {
);
}

export async function setAutoUninstallOldVersions(
value: boolean,
): Promise<void> {
return await invoke_rpc(
"update_setting_value",
{ key: "delete_previous_versions", val: value },
() => {},
);
}

export async function getAutoUninstallOldVersions(): Promise<boolean> {
return await invoke_rpc(
"get_setting_value",
{ key: "delete_previous_versions" },
() => false,
);
}

export async function setBypassRequirements(bypass: boolean): Promise<void> {
return await invoke_rpc(
"update_setting_value",
Expand Down
18 changes: 18 additions & 0 deletions src/lib/rpc/versions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getLatestOfficialRelease } from "$lib/utils/github";
import { getAutoUninstallOldVersions } from "./config";
import { invoke_rpc } from "./rpc";

export async function listDownloadedVersions(): Promise<string[]> {
Expand Down Expand Up @@ -31,6 +33,22 @@ export async function removeVersion(version: String): Promise<boolean> {
);
}

export async function removeOldVersions(): Promise<boolean> {
let shouldRemove = await getAutoUninstallOldVersions();
if (shouldRemove) {
let downloadedVersions = await listDownloadedVersions();
let latestRelease = await getLatestOfficialRelease();
downloadedVersions = downloadedVersions.filter(
(v) => v !== latestRelease?.version,
);
downloadedVersions.forEach((v) => {
removeVersion(v);
});
return false;
}
return false;
}

export async function openVersionFolder() {
return await invoke_rpc(
"go_to_version_folder",
Expand Down
31 changes: 25 additions & 6 deletions src/routes/settings/General.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
setBypassRequirements,
setInstallationDirectory,
setLocale,
setAutoUninstallOldVersions,
getAutoUninstallOldVersions,
} from "$lib/rpc/config";
import { getActiveVersion } from "$lib/rpc/versions";
import { VersionStore } from "$lib/stores/VersionStore";
Expand All @@ -36,12 +38,14 @@
let availableLocales = [];
let currentBypassRequirementsVal = false;
let keepGamesUpdated = writable(false);
let uninstallOldVersions = writable(false);
let localeFontForDownload: Locale | undefined = undefined;
let localeFontDownloading = false;
let initialized = false;

onMount(async () => {
let autoUpdateGames = await getAutoUpdateGames();
keepGamesUpdated.set(autoUpdateGames);
keepGamesUpdated.set(await getAutoUpdateGames());
uninstallOldVersions.set(await getAutoUninstallOldVersions());
currentInstallationDirectory = await getInstallationDirectory();
for (const locale of AVAILABLE_LOCALES) {
availableLocales = [
Expand All @@ -58,7 +62,16 @@
localeFontForDownload =
await localeSpecificFontAvailableForDownload($currentLocale);
}
initialized = true;
});

$: if (initialized) {
setAutoUpdateGames($keepGamesUpdated);
}

$: if (initialized) {
setAutoUninstallOldVersions($uninstallOldVersions);
}
</script>

<div class="flex flex-col gap-5 mt-2">
Expand Down Expand Up @@ -150,13 +163,19 @@
<div>
<Toggle
color="orange"
checked={$keepGamesUpdated}
bind:checked={$keepGamesUpdated}
on:change={async () => {
$keepGamesUpdated = !$keepGamesUpdated;
await setAutoUpdateGames($keepGamesUpdated);
$uninstallOldVersions = false;
}}
class="mb-2">Automatically keep games updated (experimental)</Toggle
class="mb-2">{$_("settings_general_keep_updated")}</Toggle
>
{#if $keepGamesUpdated}
<Toggle
color="orange"
bind:checked={$uninstallOldVersions}
class="ml-14 mb-2">{$_("settings_general_uninstall_old")}</Toggle
>
{/if}
<Toggle
checked={currentBypassRequirementsVal}
color="orange"
Expand Down
1 change: 1 addition & 0 deletions src/routes/settings/versions/OfficialVersions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
event.detail.version,
event.detail.downloadUrl,
);
$VersionStore.activeVersionName = event.detail.version;
// Then mark it as downloaded
for (const release of releases) {
if (release.version === event.detail.version) {
Expand Down
3 changes: 2 additions & 1 deletion src/routes/settings/versions/VersionList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import { _ } from "svelte-i18n";
import { getActiveVersion } from "$lib/rpc/versions";
import { writable } from "svelte/store";
import { VersionStore } from "$lib/stores/VersionStore";

export let description: string;
export let releaseList: ReleaseInfo[];
Expand Down Expand Up @@ -107,7 +108,7 @@
<TableBodyCell class="px-6 py-2 whitespace-nowrap font-medium">
{#if release.isDownloaded}
<Radio
bind:group={$activeVersion}
bind:group={$VersionStore.activeVersionName}
value={release.version}
on:change={() =>
dispatch("versionChange", { version: release.version })}
Expand Down
Loading