-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #160 from dvishal485/main
test notif worker
- Loading branch information
Showing
6 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# This is a basic workflow to help you get started with Actions | ||
|
||
name: Deploy on push | ||
|
||
# Controls when the workflow will run | ||
on: | ||
# Triggers the workflow on push or pull request events but only for the "main" branch | ||
push: | ||
branches: [ "dev" ] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
# This workflow contains a single job called "build" | ||
build: | ||
# The type of runner that the job will run on | ||
runs-on: self-hosted | ||
|
||
# Steps represent a sequence of tasks that will be executed as part of the job | ||
steps: | ||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Get to work dir | ||
run: cd $GITHUB_WORKSPACE | ||
|
||
- name: Install dependencies | ||
run: npm i | ||
|
||
- name: Run build task | ||
run: npm run build | ||
|
||
- name: Deploy to web | ||
run: rsync -avz --delete dist/ ~/nix_frontend_dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
self.addEventListener("activate", async () => { | ||
// This will be called only once when the service worker is activated. | ||
console.log("Hello from service worker"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
export class Notification { | ||
static notify = window.Notification; | ||
|
||
public static isPermissionGranted() { | ||
if (!Notification.isSupported()) { | ||
throw new Error("Notification API is not supported"); | ||
} | ||
return Notification.notify.permission === "granted"; | ||
} | ||
|
||
public static async requestPermission() { | ||
if (!Notification.isSupported()) { | ||
throw new Error("Notification API is not supported"); | ||
} | ||
const permission = await Notification.notify.requestPermission(); | ||
console.log("Notification API permission", permission); | ||
return permission; | ||
} | ||
|
||
public static constructNotification( | ||
title: string, | ||
options: NotificationOptions, | ||
) { | ||
return new Notification.notify(title, options); | ||
} | ||
|
||
public static isSupported() { | ||
return Notification.notify !== undefined; | ||
} | ||
|
||
public static async displayNotification( | ||
title: string, | ||
options: NotificationOptions, | ||
) { | ||
const permission = await Notification.requestPermission(); | ||
if (permission === "granted") { | ||
Notification.constructNotification(title, options); | ||
} else { | ||
console.error("Permission denied"); | ||
} | ||
} | ||
} | ||
|
||
export class BgService { | ||
static bg = window.navigator; | ||
|
||
public static isSupported() { | ||
return BgService.bg !== undefined; | ||
} | ||
|
||
public static async registerServiceWorker(swPath: string) { | ||
const registration = await BgService.bg.serviceWorker.register(swPath); | ||
console.log("Service worker registered", registration); | ||
return registration; | ||
} | ||
|
||
public static async unregisterServiceWorker() { | ||
const registrations = await BgService.bg.serviceWorker.getRegistrations(); | ||
registrations.forEach((registration) => registration.unregister()); | ||
} | ||
|
||
public static async getRegistration() { | ||
const registration = await BgService.bg.serviceWorker.getRegistration(); | ||
return registration; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,8 @@ | |
} | ||
}, | ||
"include": [ | ||
"src" | ||
"src", | ||
"public/notification-service.js" | ||
], | ||
"references": [ | ||
{ | ||
|