diff --git a/package.json b/package.json
index bbe53a0..70a0ff7 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "tasgrid",
"private": true,
- "version": "0.0.0",
+ "version": "1.1.0",
"type": "module",
"scripts": {
"dev": "vite --host 0.0.0.0 --port 4001",
diff --git a/src/components/PwaUpdater.tsx b/src/components/PwaUpdater.tsx
index d86cae6..9734bb1 100644
--- a/src/components/PwaUpdater.tsx
+++ b/src/components/PwaUpdater.tsx
@@ -1,8 +1,10 @@
import { type Component, createEffect, onCleanup } from 'solid-js';
import { useRegisterSW } from 'virtual:pwa-register/solid';
+import { toast } from 'solid-sonner';
// We export a function so other parts of the app can manually trigger an update
let manualUpdateFn: (() => void) | undefined;
+let updateAndReloadFn: (() => void) | undefined;
export const forceServiceWorkerUpdate = () => {
if (manualUpdateFn) {
@@ -12,6 +14,15 @@ export const forceServiceWorkerUpdate = () => {
}
};
+export const updateAndReloadApp = () => {
+ if (updateAndReloadFn) {
+ updateAndReloadFn();
+ } else {
+ console.warn("PWA Updater not initialized yet; reloading directly.");
+ window.location.reload();
+ }
+};
+
export const PwaUpdater: Component = () => {
let registration: ServiceWorkerRegistration | undefined;
@@ -47,6 +58,33 @@ export const PwaUpdater: Component = () => {
registration.update();
}
};
+
+ updateAndReloadFn = () => {
+ if (needRefresh()) {
+ console.log('Update ready. Reloading now...');
+ updateServiceWorker(true);
+ return;
+ }
+
+ if (registration) {
+ console.log('Checking for updates before reload...');
+ registration.update();
+ }
+
+ const start = Date.now();
+ const timeoutMs = 5000;
+ const poll = window.setInterval(() => {
+ if (needRefresh()) {
+ console.log('Update found. Reloading with new SW...');
+ window.clearInterval(poll);
+ updateServiceWorker(true);
+ } else if (Date.now() - start > timeoutMs) {
+ console.log('No update detected quickly. Reloading now...');
+ window.clearInterval(poll);
+ toast.info("No update found");
+ }
+ }, 250);
+ };
});
createEffect(() => {
diff --git a/src/views/SettingsView.tsx b/src/views/SettingsView.tsx
index 8512be8..f5cc073 100644
--- a/src/views/SettingsView.tsx
+++ b/src/views/SettingsView.tsx
@@ -1088,20 +1088,50 @@ export const SettingsView: Component<{ setView?: (v: string) => void }> = (props
);
diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts
new file mode 100644
index 0000000..dbb4c62
--- /dev/null
+++ b/src/vite-env.d.ts
@@ -0,0 +1,3 @@
+///
+
+declare const __APP_VERSION__: string;
diff --git a/vite.config.ts b/vite.config.ts
index ba19fad..3a936d7 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -3,8 +3,16 @@ import solid from 'vite-plugin-solid'
import { VitePWA } from 'vite-plugin-pwa'
import tailwindcss from '@tailwindcss/vite'
import path from 'path'
+import { readFileSync } from 'fs'
+
+const packageJson = JSON.parse(
+ readFileSync(new URL('./package.json', import.meta.url), 'utf-8')
+);
export default defineConfig({
+ define: {
+ __APP_VERSION__: JSON.stringify(packageJson.version),
+ },
plugins: [
solid(),
tailwindcss(),
@@ -76,4 +84,4 @@ export default defineConfig({
"@": path.resolve(__dirname, "./src")
}
}
-})
\ No newline at end of file
+})