From fa70fa2ecf9d6bd2068a41b6f69f21b5b04132a0 Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Tue, 12 Nov 2019 14:56:57 -0800 Subject: [PATCH] Track last use via heartbeat instead of by last startup --- js/background.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/js/background.js b/js/background.js index 3599d95074..e5798ceb37 100644 --- a/js/background.js +++ b/js/background.js @@ -360,13 +360,18 @@ await storage.put('indexeddb-delete-needed', true); } - const currentStartup = Date.now(); - const lastStartup = storage.get('lastStartup'); - await storage.put('lastStartup', currentStartup); + const now = Date.now(); + const lastHeartbeat = storage.get('lastHeartbeat'); + await storage.put('lastStartup', Date.now()); + const THIRTY_DAYS = 30 * 24 * 60 * 60 * 1000; - if (lastStartup > 0 && currentStartup - lastStartup > THIRTY_DAYS) { + if (lastHeartbeat > 0 && now - lastHeartbeat > THIRTY_DAYS) { await unlinkAndDisconnect(); + } else { + storage.put('lastHeartbeat', Date.now()); + const TWELVE_HOURS = 12 * 60 * 60 * 1000; + setInterval(() => storage.put('lastHeartbeat', Date.now()), TWELVE_HOURS); } const currentVersion = window.getVersion();