check for update feature
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const CACHE_VERSION = 'nexus-timer-cache-v9';
|
||||
const CACHE_VERSION = 'nexus-timer-cache-v10';
|
||||
const APP_SHELL_URLS = [
|
||||
// '/', // Let NetworkFirst handle '/'
|
||||
'/manifest.json',
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
<template>
|
||||
<div class="flex-grow flex flex-col p-4 md:p-6 lg:p-8 items-center dark:bg-gray-800 text-gray-700 dark:text-gray-200">
|
||||
<header class="w-full max-w-2xl mb-2 text-center"> <!-- Reduced mb for tighter spacing -->
|
||||
<header class="w-full max-w-2xl mb-2 text-center">
|
||||
<h1 class="text-3xl font-bold text-blue-600 dark:text-blue-400 mb-1">About Nexus Timer</h1>
|
||||
<!-- Build Time Information -->
|
||||
<p class="text-xs text-gray-500 dark:text-gray-400 mb-4">
|
||||
Build: <span class="font-mono">{{ buildTime }}</span>
|
||||
<div class="flex items-center justify-center space-x-2 text-xs text-gray-500 dark:text-gray-400 mb-4">
|
||||
<span>Build: <span class="font-mono">{{ buildTime }}</span></span>
|
||||
<button
|
||||
v-if="canCheckForUpdate"
|
||||
@click="checkForUpdates"
|
||||
class="text-blue-500 hover:text-blue-700 dark:hover:text-blue-300 underline text-xs"
|
||||
:disabled="checkingForUpdate"
|
||||
>
|
||||
{{ checkingForUpdate ? 'Checking...' : 'Check for Update' }}
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="updateStatusMessage" class="text-sm mt-1" :class="updateError ? 'text-red-500' : 'text-green-500'">
|
||||
{{ updateStatusMessage }}
|
||||
</p>
|
||||
</header>
|
||||
|
||||
@@ -26,7 +36,7 @@
|
||||
<li>Audio feedback for timer events.</li>
|
||||
<li>Light/Dark theme options.</li>
|
||||
<li>Persistent storage of game state.</li>
|
||||
<li>Screen Wake Lock to keep screen on during active gameplay.</li> <!-- Added Wake Lock to features -->
|
||||
<li>Screen Wake Lock to keep screen on during active gameplay.</li>
|
||||
</ul>
|
||||
|
||||
<h2 class="text-xl font-semibold mt-6 mb-2">Source Code</h2>
|
||||
@@ -47,22 +57,76 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue'; // Import ref
|
||||
import { ref, computed } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useStore } from 'vuex';
|
||||
|
||||
const router = useRouter();
|
||||
const store = useStore();
|
||||
|
||||
// --- Build Time Placeholder ---
|
||||
// This value will be replaced by your Git pre-commit hook.
|
||||
// The hook should search for the string "__BUILD_TIME__" (including quotes if you prefer)
|
||||
// and replace it with the actual build timestamp.
|
||||
// For display, we'll use a ref.
|
||||
const buildTime = ref("2025-05-09 17:40:26");
|
||||
// If your hook replaces the entire line `const buildTime = ref("2025-05-09 17:10:59");`
|
||||
// with `const buildTime = ref("YYYY-MM-DD HH:MM:SS");`, that's also fine.
|
||||
// Or, if it replaces only the string content: `const buildTime = ref("Actual Build Time");`
|
||||
const buildTime = ref("2025-05-09 20:58:36");
|
||||
|
||||
// --- PWA Update Check Logic ---
|
||||
const canCheckForUpdate = ref('serviceWorker' in navigator);
|
||||
const checkingForUpdate = ref(false);
|
||||
const updateStatusMessage = ref('');
|
||||
const updateError = ref(false);
|
||||
|
||||
const checkForUpdates = async () => {
|
||||
if (!('serviceWorker' in navigator)) {
|
||||
updateStatusMessage.value = 'Service Worker API not supported.';
|
||||
updateError.value = true;
|
||||
return;
|
||||
}
|
||||
|
||||
checkingForUpdate.value = true;
|
||||
updateStatusMessage.value = 'Checking for updates...';
|
||||
updateError.value = false;
|
||||
|
||||
try {
|
||||
const registration = await navigator.serviceWorker.getRegistration();
|
||||
if (!registration) {
|
||||
updateStatusMessage.value = 'No active service worker found. Try reloading.';
|
||||
updateError.value = true;
|
||||
checkingForUpdate.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// This attempts to update the service worker.
|
||||
// If a new version is found, it will be installed in the background.
|
||||
// The update bar logic in App.vue will handle prompting the user to refresh.
|
||||
await registration.update();
|
||||
|
||||
// Check if an update was found and is now waiting
|
||||
// This needs a small delay for the update process to potentially complete
|
||||
setTimeout(() => {
|
||||
const newWorker = registration.waiting;
|
||||
if (newWorker) {
|
||||
updateStatusMessage.value = 'A new version has been downloaded! Refresh prompt will appear soon or on next load.';
|
||||
updateError.value = false;
|
||||
// You could also trigger the App.vue update bar logic directly if needed
|
||||
// e.g., by emitting an event or calling a global function/store action.
|
||||
// For now, relying on App.vue's existing SW listeners.
|
||||
} else if (registration.active && registration.installing) {
|
||||
updateStatusMessage.value = 'New version is installing...';
|
||||
updateError.value = false;
|
||||
}
|
||||
else {
|
||||
updateStatusMessage.value = 'You are on the latest version.';
|
||||
updateError.value = false;
|
||||
}
|
||||
checkingForUpdate.value = false;
|
||||
}, 2000); // Give some time for SW update process
|
||||
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error checking for PWA updates:', error);
|
||||
updateStatusMessage.value = 'Error checking for updates. See console.';
|
||||
updateError.value = true;
|
||||
checkingForUpdate.value = false;
|
||||
}
|
||||
};
|
||||
// --- End PWA Update Check Logic ---
|
||||
|
||||
const goBack = () => {
|
||||
if (store.getters.players && store.getters.players.length >= 2) {
|
||||
@@ -72,7 +136,3 @@ const goBack = () => {
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* Tailwind's typography plugin 'prose' handles most styling */
|
||||
</style>
|
||||
@@ -1,7 +1,7 @@
|
||||
[Unit]
|
||||
Description=nexus-timer (virt-nexus-timer)
|
||||
Requires=docker.service
|
||||
After=docker.service
|
||||
After=network.target docker.service
|
||||
DefaultDependencies=no
|
||||
|
||||
[Service]
|
||||
@@ -13,7 +13,6 @@ ExecStartPre=-/usr/bin/env sh -c '/usr/bin/env docker rm virt-nexus-timer 2>/dev
|
||||
ExecStart=/usr/bin/env docker run \
|
||||
--rm \
|
||||
--name=virt-nexus-timer \
|
||||
--log-driver=none \
|
||||
--network=traefik \
|
||||
--label-file /virt/nexus-timer/labels \
|
||||
virt-nexus-timer
|
||||
|
||||
Reference in New Issue
Block a user