-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(desktop-notifications): new service worker module, bugfixes and …
…refactorings Encapsulated service worker logic into an own JS module. There are numerous bugfixes in regard to the display of notifications in the major browsers. Important: The notifications currently won't work in WebKit based browsers like Safari, as the notification toggle logic which requires a user interaction has not been added yet.
- Loading branch information
Showing
23 changed files
with
1,940 additions
and
293 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 |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
!.git* | ||
!.github | ||
!.phpcs.xml | ||
/dist/serviceworker/node_modules/ |
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,35 @@ | ||
### Prerequisites | ||
```shell | ||
# 1. NODE VERSION MANAGER | ||
# make sure to install the latest (lts) version of NodeJS | ||
# the easiest way of doing so is by using the n manager (https://github.com/tj/n) | ||
# and its installer (https://github.com/mklement0/n-install) | ||
curl -L https://bit.ly/n-install | bash | ||
n install lts | ||
# after a directory change to .../icinga-notifications-web/dist/serviceworker | ||
npm update && npm install | ||
|
||
# 2. PHPSTORM SETTINGS | ||
# open the TypeScript configuration in PhpStorm: | ||
# File | Settings | Languages & Frameworks | TypeScript | ||
# or via link: jetbrains://PhpStorm/settings?name=Languages+%26+Frameworks--TypeScript | ||
# set the node interpreter to these settings: | ||
# Node interpreter: ~/n/bin/node (or the equivalent path of the 'n' manager installation) | ||
# Options: --target ES6 | ||
``` | ||
|
||
### Build | ||
```shell | ||
# the generated files are placed under ./build/{*.js|*.js.map} | ||
|
||
# development | ||
npm run build | ||
# production | ||
npm run build-prod | ||
``` | ||
|
||
### Serve local test server | ||
```shell | ||
# remove the -o if you don't want to open the default browser automatically | ||
http-server ./example -p 9216 -c-1 -o | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,17 @@ | ||
import {build} from 'esbuild'; | ||
|
||
build({ | ||
entryPoints: ['source/icinga-notifications-worker.ts'], | ||
outdir: 'build', | ||
bundle: true, | ||
sourcemap: true, | ||
minify: true, | ||
splitting: false, | ||
format: 'iife', | ||
define: { global: 'globalThis' }, | ||
target: ['chrome58', 'firefox57', 'safari11', 'edge16'], | ||
globalName: 'icinga.notifications.worker', | ||
legalComments: 'none', | ||
logLevel: 'debug' | ||
}) | ||
.catch((process) => process.exit(1)); |
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,17 @@ | ||
import {build} from 'esbuild'; | ||
|
||
build({ | ||
entryPoints: ['source/icinga-notifications-worker.ts'], | ||
outdir: 'build', | ||
bundle: true, | ||
sourcemap: true, | ||
minify: false, | ||
splitting: false, | ||
format: 'iife', | ||
define: { global: 'globalThis' }, | ||
target: ['chrome58', 'firefox57', 'safari11', 'edge16'], | ||
globalName: 'icinga.notifications.worker', | ||
legalComments: 'none', | ||
logLevel: 'debug' | ||
}) | ||
.catch((process) => process.exit(1)); |
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 @@ | ||
../build/icinga-notifications-worker.js |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,48 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>IcingaNotificationsWorker :: Test</title> | ||
</head> | ||
<body> | ||
<main> | ||
<p>Test123</p> | ||
</main> | ||
<script> | ||
try { | ||
navigator.serviceWorker.register( | ||
'/icinga-notifications-worker.js', | ||
{ | ||
scope: '/', | ||
type: 'classic' | ||
} | ||
).then((registration) => { | ||
if (registration.installing) { | ||
console.log("Service worker is installing."); | ||
} else if (registration.waiting) { | ||
console.log("Service worker has been installed and is waiting to be run."); | ||
} else if (registration.active) { | ||
console.log("Service worker has been activated."); | ||
setTimeout(() => { | ||
let es = new EventSource('/icingaweb2/notifications/daemon'); | ||
}); | ||
} | ||
|
||
if (navigator.serviceWorker.controller === null) { | ||
/** | ||
* hard refresh detected. This causes the browser to not forward fetch requests to | ||
* service workers. Reloading the site fixes this. | ||
*/ | ||
setTimeout(() => { | ||
console.log("Hard refresh detected. Reloading page to fix the service workers."); | ||
location.reload(); | ||
}, 1000); | ||
return; | ||
} | ||
}); | ||
} catch (error) { | ||
console.error(`Service worker failed to register: ${error}`); | ||
} | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.