forked from hokein/electron-sample-apps
-
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.
Merge pull request hokein#38 from hokein/service-worker
Add a service-worker demo.
- Loading branch information
Showing
7 changed files
with
62 additions
and
0 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,22 @@ | ||
<html> | ||
<body> | ||
<script> | ||
function log(message) { | ||
document.body.appendChild( | ||
document.createTextNode(message)); | ||
console.log.apply(console, arguments); | ||
} | ||
window.onerror = function(err) { | ||
log("Error", err); | ||
}; | ||
navigator.serviceWorker.register('service-worker.js', { | ||
scope: './' | ||
}).then(function(sw) { | ||
log("Registered!", sw); | ||
log("You should get a different response when you refresh the page."); | ||
}).catch(function(err) { | ||
log("Error", err); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
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,12 @@ | ||
const {app, BrowserWindow} = require('electron'); | ||
|
||
let mainWindow; | ||
|
||
app.on('ready', () => { | ||
mainWindow = new BrowserWindow({ | ||
height: 300, | ||
width: 400 | ||
}); | ||
|
||
mainWindow.loadURL('file://' + __dirname + '/index.html'); | ||
}); |
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,5 @@ | ||
{ | ||
"name": "service-worker-demo", | ||
"version": "1.0.1", | ||
"main": "main.js" | ||
} |
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,9 @@ | ||
# Service Worker Sample: Mock Response | ||
|
||
A sample demonstrates basic service worker registeration with file scheme, and | ||
the service worker's fetch handler. | ||
|
||
## Screenshot | ||
|
||
 | ||
 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,14 @@ | ||
console.log("Service worker startups."); | ||
|
||
self.addEventListener('install', function(event) { | ||
console.log("Service worker installed."); | ||
}); | ||
|
||
self.addEventListener('activate', function(event) { | ||
console.log("Service worker activated."); | ||
}); | ||
|
||
self.addEventListener('fetch', function(event) { | ||
console.log("Caught a fetch!"); | ||
event.respondWith(new Response("Hello world!")); | ||
}); |