Skip to content

Commit

Permalink
test: sw
Browse files Browse the repository at this point in the history
  • Loading branch information
freeshineit committed May 31, 2024
1 parent 4b8a4f6 commit 5f0b34b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
35 changes: 18 additions & 17 deletions docs/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,36 @@
</head>

<body>
<h3>Hello 这是一个可以安装到桌面的网页</h3>
<h3 onclick="showNotification()">Hello 这是一个可以安装到桌面的网页</h3>
<div id="installContainer">
用谷歌浏览器打开,看一下地址栏后面有一个安装的图标,安装一下试试吧
</div>
</body>
<script>
// 检测浏览器是否支持SW
if (navigator.serviceWorker != null) {

function showNotification() {
Notification.requestPermission().then((result) => {
if (result === "granted") {
navigator.serviceWorker.ready.then((registration) => {
registration.showNotification("Vibration Sample", {
body: "Buzz! Buzz!",
icon: "./logo.png",
vibrate: [200, 100, 200, 100, 200, 100, 200],
tag: "vibration-sample",
});
});
}
});
}

navigator.serviceWorker.register('./sw.js')
.then(function (registartion) {
console.log('支持sw:', registartion.scope)
showNotification()
})

// function showNotification() {
Notification.requestPermission().then((result) => {
if (result === "granted") {
navigator.serviceWorker.ready.then((registration) => {
registration.showNotification("Vibration Sample", {
body: "Buzz! Buzz!",
icon: "../images/touch/chrome-touch-icon-192x192.png",
vibrate: [200, 100, 200, 100, 200, 100, 200],
tag: "vibration-sample",
});
});
}
});
// }


} else {
console.log('不支持SW:')
}
Expand Down
Binary file added docs/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/sw.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5f0b34b

Please sign in to comment.