From 7e5e2263b654f5e124a5c2004535be1d7c4be4c0 Mon Sep 17 00:00:00 2001 From: kabir-afk Date: Wed, 19 Jun 2024 18:35:30 +0530 Subject: [PATCH 1/3] revert : keeping the old approach for Firefox --- popup/popup.js | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/popup/popup.js b/popup/popup.js index bf32158..ab2a96e 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -382,10 +382,21 @@ var browser = (browserType === 'firefox') ? browser : (browserType === 'chrome') ui = new UI(); ui.switchPanel( 'loaded' ); } - chrome.runtime.onMessage.addListener((message, sender) => { - console.log(sender); - if (message.state === "ready") { - ui = new UI(); - } + if (browserType === "chrome") { + chrome.runtime.onMessage.addListener((message, sender) => { + if (message.state === "ready") { + ui = new UI(); + } }); + } else { + let state = _backgroundPage.state; + function waitWhileLoading() { + if (state === "ready") { + ui = new UI(); + } else { + setTimeout(waitWhileLoading, 100); + } + } + waitWhileLoading(); + } })(); From 9ca292736a5f9a18aa5ce93cd8e70019f72cf5d2 Mon Sep 17 00:00:00 2001 From: kabir-afk Date: Thu, 20 Jun 2024 00:04:12 +0530 Subject: [PATCH 2/3] chore : removed log messages --- sw.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sw.js b/sw.js index 8260491..a71ac8d 100644 --- a/sw.js +++ b/sw.js @@ -773,7 +773,7 @@ const WAIT_ALARM = 'waitWhileLoading'; async function createAlarm() { await chrome.alarms.create(WAIT_ALARM, { periodInMinutes: 1 / 60 // by specifying it as fraction we can run the ⏰ in every 1 second - },()=>console.log('⏰ running inside createAlarm()',new Date().getSeconds())); + }); } chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { @@ -788,9 +788,7 @@ chrome.alarms.onAlarm.addListener((alarm)=>{ if (alarm.name === WAIT_ALARM) { if (state === 'ready') { chrome.runtime.sendMessage({state:'ready'}); - chrome.alarms.clear(WAIT_ALARM,()=>{ - console.log('⏰ stopped at ',new Date().getSeconds()); - }); + chrome.alarms.clear(WAIT_ALARM); } } }) \ No newline at end of file From 6f4a994caa7846d53d93250bcbce4dfffb0f5e59 Mon Sep 17 00:00:00 2001 From: kabir <123084434+kabir-afk@users.noreply.github.com> Date: Thu, 20 Jun 2024 00:07:20 +0530 Subject: [PATCH 3/3] feat : adding alarms API (#97) * chore:added alarms permission * feat : added alarm functionality * refactor: Initialize UI with respect to alarms API * style:better readabiity * style : better readabiity * revert : keeping the old approach for Firefox * revert : keeping the old approach for Firefox * chore : removed log messages --- manifest.json | 2 +- popup/popup.js | 28 +++++++++++++++++----------- sw.js | 21 ++++++++++++++++++--- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/manifest.json b/manifest.json index 81797bd..46a9f54 100644 --- a/manifest.json +++ b/manifest.json @@ -17,7 +17,7 @@ "storage", "webRequest", "webRequestBlocking", - "offscreen" + "alarms" ], "content_scripts": [ { diff --git a/popup/popup.js b/popup/popup.js index f3224e0..ab2a96e 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -382,15 +382,21 @@ var browser = (browserType === 'firefox') ? browser : (browserType === 'chrome') ui = new UI(); ui.switchPanel( 'loaded' ); } - - let state = _backgroundPage.state; - function waitWhileLoading() { - if (state === 'ready' ) { - ui = new UI(); - } else { - setTimeout( waitWhileLoading, 100 ); - } - } - waitWhileLoading() - + if (browserType === "chrome") { + chrome.runtime.onMessage.addListener((message, sender) => { + if (message.state === "ready") { + ui = new UI(); + } + }); + } else { + let state = _backgroundPage.state; + function waitWhileLoading() { + if (state === "ready") { + ui = new UI(); + } else { + setTimeout(waitWhileLoading, 100); + } + } + waitWhileLoading(); + } })(); diff --git a/sw.js b/sw.js index 335bc3a..a71ac8d 100644 --- a/sw.js +++ b/sw.js @@ -769,11 +769,26 @@ async function setState(value) { // Run it main(); +const WAIT_ALARM = 'waitWhileLoading'; +async function createAlarm() { + await chrome.alarms.create(WAIT_ALARM, { + periodInMinutes: 1 / 60 // by specifying it as fraction we can run the ⏰ in every 1 second + }); +} + chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { if (message.command === "getBackground") { - // persisted the state inside chrome.storage.local but will get to that later - console.log(state); const extensionData = {state,params,uiLanguages,records,signLanguages}; sendResponse(extensionData); + createAlarm(); } -}); \ No newline at end of file +}); + +chrome.alarms.onAlarm.addListener((alarm)=>{ + if (alarm.name === WAIT_ALARM) { + if (state === 'ready') { + chrome.runtime.sendMessage({state:'ready'}); + chrome.alarms.clear(WAIT_ALARM); + } + } +}) \ No newline at end of file