Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/kabir-afk/SignIt
Browse files Browse the repository at this point in the history
  • Loading branch information
kabir-afk committed Jun 19, 2024
2 parents 8c1e113 + 19a9db8 commit 839b281
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"storage",
"webRequest",
"webRequestBlocking",
"offscreen"
"alarms"
],
"content_scripts": [
{
Expand Down
13 changes: 4 additions & 9 deletions popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,10 @@ var browser = (browserType === 'firefox') ? browser : (browserType === 'chrome')
ui = new UI();
ui.switchPanel( 'loaded' );
}

let state = _backgroundPage.state;
function waitWhileLoading() {
if (state === 'ready' ) {
chrome.runtime.onMessage.addListener((message, sender) => {
console.log(sender);
if (message.state === "ready") {
ui = new UI();
} else {
setTimeout( waitWhileLoading, 100 );
}
}
waitWhileLoading()

});
})();
23 changes: 20 additions & 3 deletions sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,11 +769,28 @@ 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
},()=>console.log('⏰ running inside createAlarm()',new Date().getSeconds()));
}

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();
}
});
});

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());
});
}
}
})

0 comments on commit 839b281

Please sign in to comment.