unknown: move away from tauri events for updating the header

For whatever reason, these triggered in dev but not in release builds.

However, I already made a global store for managing the versions, so events aren't really needed -- but this may be a problem in the future
This commit is contained in:
Tyler Wilding 2023-03-05 15:16:47 -05:00
parent c58b24af50
commit 93941a5cb3
No known key found for this signature in database
GPG key ID: 77CB07796494137E
9 changed files with 51 additions and 80 deletions

View file

@ -172,7 +172,6 @@ pub async fn get_installed_version_folder(
#[tauri::command]
pub async fn save_active_version_change(
config: tauri::State<'_, tokio::sync::Mutex<LauncherConfig>>,
app_handle: tauri::AppHandle,
version_folder: String,
new_active_version: String,
) -> Result<(), CommandError> {
@ -185,7 +184,6 @@ pub async fn save_active_version_change(
config_lock
.set_active_version(new_active_version)
.map_err(|_| CommandError::Configuration(format!("Unable to persist active version change")))?;
app_handle.emit_all("toolingVersionChanged", {})?;
Ok(())
}

View file

@ -1,5 +1,6 @@
<script lang="ts">
import type { SupportedGame } from "$lib/constants";
import { VersionStore } from "$lib/stores/VersionStore";
import { Button, Card } from "flowbite-svelte";
import { createEventDispatcher } from "svelte";
@ -9,8 +10,6 @@
export let installedVersion: String;
export let installedVersionFolder: String;
export let activeVersion: String;
export let activeVersionFolder: String;
</script>
<div class="flex flex-col h-full justify-center items-center">
@ -31,8 +30,8 @@
...but you currently have selected
</p>
<ul class="list-disc list-inside mb-5">
<li>Version: <strong>{activeVersion}</strong></li>
<li>Type: <strong>{activeVersionFolder}</strong></li>
<li>Version: <strong>{$VersionStore.activeVersionName}</strong></li>
<li>Type: <strong>{$VersionStore.activeVersionName}</strong></li>
</ul>
<p class="mb-3">
You can either update the game to this new version (no save data will be

View file

@ -1,7 +1,7 @@
<script lang="ts">
import { appWindow } from "@tauri-apps/api/window";
import logo from "$assets/images/icon.png";
import { onMount } from "svelte";
import { onDestroy, onMount } from "svelte";
import { getVersion } from "@tauri-apps/api/app";
import { Link } from "svelte-navigator";
import Icon from "@iconify/svelte";
@ -14,17 +14,16 @@
listDownloadedVersions,
} from "$lib/rpc/versions";
import { getLatestOfficialRelease } from "$lib/utils/github";
import { listen } from "@tauri-apps/api/event";
import { VersionStore } from "$lib/stores/VersionStore";
let launcherVerison = null;
let toolingVersion = null;
let toolingVersionType = null;
onMount(async () => {
// Get current versions
launcherVerison = `v${await getVersion()}`;
toolingVersion = await getActiveVersion();
toolingVersionType = await getActiveVersionFolder();
$VersionStore.activeVersionType = await getActiveVersionFolder();
$VersionStore.activeVersionName = await getActiveVersion();
// Check for a launcher update
// I think it won't work unless the updater is in the configuration, which of course has other issues
@ -50,21 +49,13 @@
}
await checkIfLatestVersionInstalled();
const unlistenInstalled = await listen(
"toolingVersionChanged",
async (event) => {
toolingVersion = await getActiveVersion();
toolingVersionType = await getActiveVersionFolder();
}
);
});
async function checkIfLatestVersionInstalled() {
// Check for an update to the tooling (right now, only if it's official)
if (toolingVersionType === "official") {
if ($VersionStore.activeVersionType === "official") {
const latestToolingVersion = await getLatestOfficialRelease();
if (toolingVersion !== latestToolingVersion.version) {
if ($VersionStore.activeVersionName !== latestToolingVersion.version) {
// Check that we havn't already downloaded it
let alreadyHaveRelease = false;
const downloadedOfficialVersions = await listDownloadedVersions(
@ -108,10 +99,12 @@
{launcherVerison === null ? "not set!" : launcherVerison}
</p>
<p class="font-mono text-sm">
{toolingVersion === null ? "not set!" : toolingVersion}
{#if toolingVersionType === "unofficial"}
{$VersionStore.activeVersionName === null
? "not set!"
: $VersionStore.activeVersionName}
{#if $VersionStore.activeVersionType === "unofficial"}
(unf)
{:else if toolingVersionType === "devel"}
{:else if $VersionStore.activeVersionType === "devel"}
(dev)
{/if}
</p>

View file

@ -2,23 +2,23 @@ import type { VersionFolders } from "$lib/rpc/versions";
import { writable } from "svelte/store";
export interface VersionStoreSelectedInfo {
official: string | undefined;
unofficial: string | undefined;
devel: string | undefined;
official: string | null;
unofficial: string | null;
devel: string | null;
}
export interface VersionStoreIFace {
activeVersionType: VersionFolders;
activeVersionName: string | undefined;
activeVersionName: string | null;
selectedVersions: VersionStoreSelectedInfo;
}
export const VersionStore = writable<VersionStoreIFace>({
activeVersionType: undefined,
activeVersionName: undefined,
activeVersionType: null,
activeVersionName: null,
selectedVersions: {
official: undefined,
unofficial: undefined,
devel: undefined,
official: null,
unofficial: null,
devel: null,
},
});

View file

@ -14,7 +14,7 @@
import GameUpdate from "../components/games/setup/GameUpdate.svelte";
import { getActiveVersion, getActiveVersionFolder } from "$lib/rpc/versions";
import GameToolsNotSet from "../components/games/GameToolsNotSet.svelte";
import { listen } from "@tauri-apps/api/event";
import { VersionStore } from "$lib/stores/VersionStore";
const params = useParams();
let activeGame = SupportedGame.Jak1;
@ -25,10 +25,7 @@
let installedVersion;
let installedVersionFolder;
let activeVersion;
let activeVersionFolder;
let toolingNotSet = false;
let versionMismatchDetected = false;
onMount(async () => {
@ -45,42 +42,28 @@
// First off, check that they've downloaded and have a jak-project release set
// TODO - and that it's still downloaded
activeVersion = await getActiveVersion();
activeVersionFolder = await getActiveVersionFolder();
if (activeVersion === null || activeVersionFolder === null) {
toolingNotSet = true;
} else {
// First obvious thing to check -- is the game installed at all
gameInstalled = await isGameInstalled(getInternalName(activeGame));
$VersionStore.activeVersionType = await getActiveVersionFolder();
$VersionStore.activeVersionName = await getActiveVersion();
// Next step, check if there is a version mismatch
// - they installed the game before with a different version than what they currently have selected
// - prompt them to either reinstall OR go and select their previous version
if (gameInstalled) {
installedVersion = await getInstalledVersion(
getInternalName(activeGame)
);
installedVersionFolder = await getInstalledVersionFolder(
getInternalName(activeGame)
);
if (
installedVersion !== activeVersion ||
installedVersionFolder !== activeVersionFolder
) {
versionMismatchDetected = true;
}
// First obvious thing to check -- is the game installed at all
gameInstalled = await isGameInstalled(getInternalName(activeGame));
// Next step, check if there is a version mismatch
// - they installed the game before with a different version than what they currently have selected
// - prompt them to either reinstall OR go and select their previous version
if (gameInstalled) {
installedVersion = await getInstalledVersion(getInternalName(activeGame));
installedVersionFolder = await getInstalledVersionFolder(
getInternalName(activeGame)
);
if (
installedVersion !== $VersionStore.activeVersionName ||
installedVersionFolder !== $VersionStore.activeVersionType
) {
versionMismatchDetected = true;
}
}
const unlistenInstalled = await listen(
"toolingVersionChanged",
async (event) => {
activeVersion = await getActiveVersion();
activeVersionFolder = await getActiveVersionFolder();
toolingNotSet = activeVersion === null || activeVersionFolder === null;
}
);
componentLoaded = true;
});
@ -106,7 +89,7 @@
<div class="flex flex-col h-full justify-center items-center">
<Spinner color="yellow" size={"12"} />
</div>
{:else if toolingNotSet}
{:else if $VersionStore.activeVersionName === null || $VersionStore.activeVersionType === null}
<GameToolsNotSet />
{:else if !gameInstalled}
<GameSetup {activeGame} on:change={updateGameState} />
@ -121,8 +104,6 @@
{activeGame}
{installedVersion}
{installedVersionFolder}
{activeVersion}
{activeVersionFolder}
on:job={runGameJob}
/>
{:else}

View file

@ -56,8 +56,8 @@
// TODO if save was successful
$VersionStore.activeVersionType = "devel";
$VersionStore.activeVersionName = $VersionStore.selectedVersions.devel;
$VersionStore.selectedVersions.official = undefined;
$VersionStore.selectedVersions.unofficial = undefined;
$VersionStore.selectedVersions.official = null;
$VersionStore.selectedVersions.unofficial = null;
}
async function onOpenVersionFolder(evt: any) {

View file

@ -91,8 +91,8 @@
// TODO if save was successful
$VersionStore.activeVersionType = "official";
$VersionStore.activeVersionName = $VersionStore.selectedVersions.official;
$VersionStore.selectedVersions.unofficial = undefined;
$VersionStore.selectedVersions.devel = undefined;
$VersionStore.selectedVersions.unofficial = null;
$VersionStore.selectedVersions.devel = null;
}
async function openOfficialVersionFolder(evt) {

View file

@ -58,8 +58,8 @@
// TODO if save was successful
$VersionStore.activeVersionType = "unofficial";
$VersionStore.activeVersionName = $VersionStore.selectedVersions.unofficial;
$VersionStore.selectedVersions.official = undefined;
$VersionStore.selectedVersions.devel = undefined;
$VersionStore.selectedVersions.official = null;
$VersionStore.selectedVersions.devel = null;
}
async function onOpenVersionFolder(evt: any) {

View file

@ -36,7 +36,7 @@
function changesPending(versionStore: VersionStoreIFace): boolean {
return (
versionStore.selectedVersions[releaseType] !== undefined &&
versionStore.selectedVersions[releaseType] !== null &&
versionStore.selectedVersions[releaseType] !== "" &&
versionStore.selectedVersions[releaseType] !==
versionStore.activeVersionName