Skip to content
New issue

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

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

Already on GitHub? # to your account

ネットワークエラーの場合は定期処理をスキップする #7

Merged
merged 1 commit into from
Feb 18, 2019
Merged
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
15 changes: 14 additions & 1 deletion js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,24 @@ chrome.runtime.onInstalled.addListener(() => {
chrome.alarms.create('alerm', { periodInMinutes: 5 });
});

chrome.alarms.onAlarm.addListener(function() {
chrome.alarms.onAlarm.addListener(async () => {
if (!KTR.credential.valid()) {
return
}

// 接続できない場合は何もしない
const connectable = await fetch(KTR.service.url(), {
method: 'GET',
cache: 'no-store',
credentials: 'include'
})
.then(() => true)
.catch(() => false);

if (!connectable) {
return
}

const manifest = chrome.runtime.getManifest();
const notificationId = Math.floor(Math.random() * 9007199254740992) + 1;

Expand Down