From 467cad7e2418d92692ef4419bb1500c6e1552fb8 Mon Sep 17 00:00:00 2001 From: Andor Kesselman Date: Wed, 8 May 2024 20:26:52 +0530 Subject: [PATCH] fix next config and updated timer --- next.config.js | 4 ---- src/components/timer/index.tsx | 35 ++++++++++------------------- src/components/workers/WakeLock.tsx | 1 - 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/next.config.js b/next.config.js index 55d9fa6..f9f58dc 100644 --- a/next.config.js +++ b/next.config.js @@ -32,10 +32,6 @@ const nextConfig = { }, ]; }, - pwa: { - runtimeCaching, - buildExcludes: [/middleware-manifest.json$/, "/app-build-manifest.json$/"], - }, webpack: (config, { isServer }) => { const registerJs = path.join( path.dirname(require.resolve("next-pwa")), diff --git a/src/components/timer/index.tsx b/src/components/timer/index.tsx index d82bec2..0fe391e 100644 --- a/src/components/timer/index.tsx +++ b/src/components/timer/index.tsx @@ -29,19 +29,6 @@ class Timer { this._intervalId = null; this._timeStarted = 0; this._targetTime = 0; - // Start a background sync to update timer state - } - - async sendTimerMessage() { - if ("serviceWorker" in navigator && "SyncManager" in window) { - const registration = await navigator.serviceWorker.ready; - try { - // @ts-ignore - await registration.sync.register("timer-sync"); - } catch { - console.log("Background Sync could not be registered!"); - } - } } get totalTime() { @@ -64,13 +51,17 @@ class Timer { return this._finished; } + computeTargetTime(from: Date, n: number) { + this._targetTime = from + n; // Set the target time by adding n milliseconds to the current time. + } + play() { if (!this._isPlaying && this._remainingTime > 0) { this._isPlaying = true; - this.setTime(this._remainingTime); + const now = Date.now(); + this._startTime = now; + this.computeTargetTime(this._startTime, this._remainingTime); this._intervalId = setInterval(() => { - console.log("playing now", this._isPlaying, this._timerId); - // this.sendTimerMessage(); if (this._remainingTime > 0) { const currentTime = Date.now(); this._remainingTime = this._targetTime - currentTime; @@ -116,13 +107,11 @@ class Timer { } setTime(n: number) { - // this.reset(); - const now = Date.now(); // Current time in milliseconds. - this._totalTime = n; - this._timeStarted = now; - this._targetTime = now + n; // Set the target time by adding n milliseconds to the current time. - const currentTime = Date.now(); // Get the current time again, if needed. - this._remainingTime = this._targetTime - currentTime; // Calculate remaining time. + this._remainingTime = n; + const now = Date.now(); + + this._startTime = now; + this.computeTargetTime(this._startTime, this._remainingTime); } setFinished() { diff --git a/src/components/workers/WakeLock.tsx b/src/components/workers/WakeLock.tsx index 07962aa..3fe62f8 100644 --- a/src/components/workers/WakeLock.tsx +++ b/src/components/workers/WakeLock.tsx @@ -10,7 +10,6 @@ const WakeLock: React.FC = () => { newWakeLock.addEventListener("release", () => { console.log("Wake Lock was released"); }); - console.log("Wake Lock is active"); setWakeLock(newWakeLock); } catch (err: any) {