Browse Source

feat: check api status

Ahmad Kholid 3 years ago
parent
commit
ef6adb6261
1 changed files with 11 additions and 1 deletions
  1. 11 1
      src/background/index.js

+ 11 - 1
src/background/index.js

@@ -2,6 +2,7 @@ import browser from 'webextension-polyfill';
 import dayjs from '@/lib/dayjs';
 import { MessageListener } from '@/utils/message';
 import { parseJSON, findTriggerBlock } from '@/utils/helper';
+import { fetchApi } from '@/utils/api';
 import getFile from '@/utils/getFile';
 import decryptFlow, { getWorkflowPass } from '@/utils/decryptFlow';
 import {
@@ -91,7 +92,6 @@ const workflow = {
       engine.resume(options.state);
     } else {
       engine.init();
-
       engine.on('destroyed', ({ id, status }) => {
         browser.permissions
           .contains({ permissions: ['notifications'] })
@@ -110,6 +110,16 @@ const workflow = {
             });
           });
       });
+
+      const lastCheckStatus = localStorage.getItem('check-status');
+      const isSameDay = dayjs().isSame(lastCheckStatus, 'day');
+      if (!isSameDay) {
+        fetchApi('/status')
+          .then((response) => response.json())
+          .then(() => {
+            localStorage.setItem('check-status', new Date());
+          });
+      }
     }
 
     return engine;