Skip to content

Commit

Permalink
fix next config and updated timer
Browse files Browse the repository at this point in the history
  • Loading branch information
andorsk committed May 8, 2024
1 parent e05d702 commit 467cad7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 deletions.
4 changes: 0 additions & 4 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")),
Expand Down
35 changes: 12 additions & 23 deletions src/components/timer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 0 additions & 1 deletion src/components/workers/WakeLock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 467cad7

Please sign in to comment.