Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove notification #35

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions src/components/play/WorkoutNotificationToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,40 @@ function WorkoutNotificationToolbar() {
}
}, [timeLeft]);

const showNotification = (title: string, body: string) => {
const requestNotificationPermission = () => {
if ("Notification" in window) {
Notification.requestPermission().then(function (permission) {
alert("notification requested");
if (permission === "granted") {
alert("notification granted");
new Notification(title, { body });
Notification.requestPermission((result) => {
if (result === "granted") {
console.log("Acess granted! :)");
showServerTimeNotification();
} else if (result === "denied") {
console.log("Access denied :(");
} else {
console.error("Permission denied for Notification");
console.log("Request ignored :/");
}
});
}
};

function showServerTimeNotification() {
if ("serviceWorker" in navigator) {
navigator.serviceWorker.ready.then((registration) => {
console.log("sending notification");
setInterval(() => {
registration.showNotification("Server time", {
body: "Exercise",
});
console.log("done showing notification");
}, 30000);
});
}
}

// requestNotificationPermission();

useEffect(() => {
console.log("showing notification");
showNotification("Web Tabata Timer Workout ", "<div>adsf</div>");
//showNotification("Web Tabata Timer Workout ", "<div>adsf</div>");
}, [workoutState, workoutState.manager.timer]);

return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/workers/WakeLock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const WakeLock: React.FC = () => {

const requestWakeLock = async () => {
try {
console.log("requestign wakelock");
console.log("requesting wakelock");
const newWakeLock = await navigator.wakeLock.request("screen");
newWakeLock.addEventListener("release", () => {
console.log("Wake Lock was released");
Expand Down
Loading