OSDN Git Service

fix: save lock time in background
authorj <coffce404@gmail.com>
Thu, 25 Feb 2021 06:26:25 +0000 (14:26 +0800)
committerj <coffce404@gmail.com>
Thu, 25 Feb 2021 06:26:25 +0000 (14:26 +0800)
src/background.js
src/models/lock.js
src/views/lock.vue

index 9896c57..7069b43 100644 (file)
@@ -14,6 +14,7 @@ import { BTM, camelize } from './utils/constants'
 import account from "@/models/account";
 
 let prompt = null;
+let lockTime = null;
 
 export default class Background {
   constructor() {
@@ -350,4 +351,7 @@ export default class Background {
 
 }
 
+window.setLockTime = (time) => lockTime = time || Date.now();
+window.getLockTime = () => lockTime;
+
 new Background()
index 1b20554..0526b57 100644 (file)
@@ -1,9 +1,9 @@
-const STORGE_KEY = 'LOCK_TIME'
-let lockTime = localStorage.getItem(STORGE_KEY)
+const backgroundPage = chrome.extension.getBackgroundPage()
+let lockTime = backgroundPage.getLockTime()
 
 export function updateLockTime () {
-  lockTime = Date.now()
-  localStorage.setItem('LOCK_TIME', lockTime)
+  lockTime = Date.now();
+  backgroundPage.setLockTime(lockTime)
 }
 export function isNeedLock () {
   const oneHour = 1000 * 60 * 60
index 2c20248..4eab4f8 100644 (file)
@@ -29,7 +29,6 @@ import { store } from '@/store/store'
 import { toast } from '@/components/toast'
 import account from "@/models/account"
 import { updateLockTime } from '@/models/lock'
-import { log } from 'util'
 
 export default {
   data () {
@@ -56,7 +55,7 @@ export default {
       
       // success
       updateLockTime()
-      this.$router.replace({ name: this.$route.query.to })
+      this.$router.replace({ name: this.$route.query.to || 'home' })
     }
   }
 };