|
@@ -222,39 +222,32 @@ export function hideBadge() {
|
|
|
|
|
|
export async function setMessageCount () {
|
|
|
const { accessToken: token = '', uid = '' } = await getChromeStorage('userInfo') || {}
|
|
|
- alarmFun();
|
|
|
if(token) {
|
|
|
getMessageInfo();
|
|
|
- // setInterval(() => {
|
|
|
- // getMessageInfo();
|
|
|
- // }, 10000);
|
|
|
- // 60000
|
|
|
+ createAlarm();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function alarmFun() {
|
|
|
- var count = 0;
|
|
|
- var alarmInfo = {
|
|
|
- //1分鐘之後開始(該值至少大於1)
|
|
|
+function createAlarm() {
|
|
|
+ let alarmInfo = {
|
|
|
+ //1分鐘之後開始(該值不能小於1)
|
|
|
delayInMinutes: 1,
|
|
|
//與上方等同的寫法是
|
|
|
- // when : Date.now() + 6000,
|
|
|
- //開始後每一分鐘執行一次(該值至少大於1)
|
|
|
+ // when : Date.now() + n,
|
|
|
+ //開始後每一分鐘執行一次(該值不能小于1)
|
|
|
periodInMinutes : 1
|
|
|
};
|
|
|
|
|
|
//每次加載就清空定時器
|
|
|
chrome.alarms.clearAll();
|
|
|
-
|
|
|
- //創造定時器
|
|
|
- chrome.alarms.create('testAlarm',alarmInfo);
|
|
|
- console.log("onAlarm-1",);
|
|
|
+
|
|
|
chrome.alarms.onAlarm.addListener(function(alarm) {
|
|
|
- //計算定時器觸發次數
|
|
|
- console.log("onAlarm-" , ++count, alarm);
|
|
|
-
|
|
|
+ console.log("onAlarm-", alarm);
|
|
|
getMessageInfo();
|
|
|
});
|
|
|
+
|
|
|
+ //創造定時器
|
|
|
+ chrome.alarms.create('denetChromeAlarm',alarmInfo);
|
|
|
}
|
|
|
|
|
|
export function getMessageInfo () {
|