diff --git a/manifest.json b/manifest.json index 20915c4..c73240d 100644 --- a/manifest.json +++ b/manifest.json @@ -9,6 +9,8 @@ "default_popup": "index.html" }, "permissions": [ + "notifications", + "alarms", "https://*/*" ] } diff --git a/src/assets/logo.jpg b/src/assets/logo.jpg new file mode 100644 index 0000000..1b09c1a Binary files /dev/null and b/src/assets/logo.jpg differ diff --git a/src/pages/Index.vue b/src/pages/Index.vue index 4db741d..7a4ba81 100644 --- a/src/pages/Index.vue +++ b/src/pages/Index.vue @@ -99,9 +99,29 @@ export default { if ([-1, 5].indexOf(this.todayIndex) > -1) { return '신나는 주말!'; } - if (lecture.start.isValid()) { return `${lecture.start.format('HH:mm')} ~ ${lecture.end.format('HH:mm')}`; } + if (lecture.start.isValid()) { + this.createAlarm(lecture) + return `${lecture.start.format('HH:mm')} ~ ${lecture.end.format('HH:mm')}`; + } return (lecture.idx) ? '오늘도 수고했어!' : '오늘도 화이팅!'; }, + + createNotification(period, minute) { + chrome.notifications.clear('dimicigan'); + chrome.notifications.create('dimicigan', { + iconUrl: './src/assets/logo.jpg', + type: 'basic', + title: `수업 시간 ${minute}분 전`, + message: `${period}교시 수업 시작까지 ${minute}분 남았어요!`, + }); + }, + + createAlarm(lecture) { + chrome.alarms.create('dimicigan', {when: lecture.start.subtract(5, 'minutes').valueOf()}); + chrome.alarms.onAlarm.addListener(function( alarm ) { + this.createNotification(lecture.idx, 5) + }); + }, }, };