fix: update on mobile

This commit is contained in:
Andras Bacsai 2022-11-11 10:38:30 +01:00
parent 75af551435
commit fe7390bd4d
2 changed files with 14 additions and 6 deletions
apps/ui/src/lib

@ -1,7 +1,14 @@
<script lang="ts"> <script lang="ts">
import { dev } from '$app/env'; import { dev } from '$app/env';
import { get, post } from '$lib/api'; import { get, post } from '$lib/api';
import { addToast, appSession, features, updateLoading, isUpdateAvailable } from '$lib/store'; import {
addToast,
appSession,
features,
updateLoading,
isUpdateAvailable,
latestVersion
} from '$lib/store';
import { asyncSleep, errorNotification } from '$lib/common'; import { asyncSleep, errorNotification } from '$lib/common';
import { onMount } from 'svelte'; import { onMount } from 'svelte';
import Tooltip from './Tooltip.svelte'; import Tooltip from './Tooltip.svelte';
@ -11,17 +18,17 @@
loading: false, loading: false,
success: null success: null
}; };
let latestVersion = 'latest';
async function update() { async function update() {
updateStatus.loading = true; updateStatus.loading = true;
try { try {
if (dev) { if (dev) {
localStorage.setItem('lastVersion', $appSession.version); localStorage.setItem('lastVersion', $appSession.version);
await asyncSleep(1000); await asyncSleep(1000);
updateStatus.loading = false;
return window.location.reload(); return window.location.reload();
} else { } else {
localStorage.setItem('lastVersion', $appSession.version); localStorage.setItem('lastVersion', $appSession.version);
await post(`/update`, { type: 'update', latestVersion }); await post(`/update`, { type: 'update', latestVersion: $latestVersion });
addToast({ addToast({
message: 'Update completed.<br><br>Waiting for the new version to start...', message: 'Update completed.<br><br>Waiting for the new version to start...',
type: 'success' type: 'success'
@ -64,7 +71,7 @@
$updateLoading = true; $updateLoading = true;
const data = await get(`/update`); const data = await get(`/update`);
if (overrideVersion || data?.isUpdateAvailable) { if (overrideVersion || data?.isUpdateAvailable) {
latestVersion = overrideVersion || data.latestVersion; $latestVersion = overrideVersion || data.latestVersion;
if (overrideVersion) { if (overrideVersion) {
$isUpdateAvailable = true; $isUpdateAvailable = true;
} else { } else {
@ -93,7 +100,7 @@
{#if updateStatus.loading} {#if updateStatus.loading}
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
class="lds-heart h-8 w-8" class="lds-heart h-8 w-8 mx-auto"
viewBox="0 0 24 24" viewBox="0 0 24 24"
stroke-width="1.5" stroke-width="1.5"
stroke="currentColor" stroke="currentColor"
@ -110,7 +117,7 @@
<div class="flex items-center justify-center space-x-2"> <div class="flex items-center justify-center space-x-2">
<svg <svg
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"
class="h-8 w-8" class="h-8 w-8 mx-auto"
viewBox="0 0 24 24" viewBox="0 0 24 24"
stroke-width="1.5" stroke-width="1.5"
stroke="currentColor" stroke="currentColor"

@ -32,6 +32,7 @@ interface AddToast {
} }
export const updateLoading: Writable<boolean> = writable(false); export const updateLoading: Writable<boolean> = writable(false);
export const isUpdateAvailable: Writable<boolean> = writable(false); export const isUpdateAvailable: Writable<boolean> = writable(false);
export const latestVersion: Writable<string> = writable('latest');
export const search: any = writable('') export const search: any = writable('')
export const loginEmail: Writable<string | undefined> = writable() export const loginEmail: Writable<string | undefined> = writable()
export const appSession: Writable<AppSession> = writable({ export const appSession: Writable<AppSession> = writable({