1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00

Fix: To differentiate between which chrome alarm is triggered (#16360)

This commit is contained in:
Niranjana Binoy 2022-11-04 11:23:56 -04:00 committed by GitHub
parent c098c628cc
commit 39037684d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 26 deletions

View File

@ -191,11 +191,9 @@ export default class AppStateController extends EventEmitter {
const { timeoutMinutes } = this.store.getState(); const { timeoutMinutes } = this.store.getState();
if (this.timer) { if (this.timer) {
if (isManifestV3) {
chrome.alarms.clear(AUTO_LOCK_TIMEOUT_ALARM);
} else {
clearTimeout(this.timer); clearTimeout(this.timer);
} } else if (isManifestV3) {
chrome.alarms.clear(AUTO_LOCK_TIMEOUT_ALARM);
} }
if (!timeoutMinutes) { if (!timeoutMinutes) {
@ -207,17 +205,12 @@ export default class AppStateController extends EventEmitter {
delayInMinutes: timeoutMinutes, delayInMinutes: timeoutMinutes,
periodInMinutes: timeoutMinutes, periodInMinutes: timeoutMinutes,
}); });
chrome.alarms.onAlarm.addListener(() => { chrome.alarms.onAlarm.addListener((alarmInfo) => {
chrome.alarms.getAll((alarms) => { if (alarmInfo.name === AUTO_LOCK_TIMEOUT_ALARM) {
const hasAlarm = alarms.find(
(alarm) => alarm.name === AUTO_LOCK_TIMEOUT_ALARM,
);
if (hasAlarm) {
this.onInactiveTimeout(); this.onInactiveTimeout();
chrome.alarms.clear(AUTO_LOCK_TIMEOUT_ALARM); chrome.alarms.clear(AUTO_LOCK_TIMEOUT_ALARM);
} }
}); });
});
} else { } else {
this.timer = setTimeout( this.timer = setTimeout(
() => this.onInactiveTimeout(), () => this.onInactiveTimeout(),

View File

@ -162,18 +162,11 @@ export default class MetaMetricsController {
}); });
} }
}); });
chrome.alarms.onAlarm.addListener(() => { chrome.alarms.onAlarm.addListener((alarmInfo) => {
chrome.alarms.getAll((alarms) => { if (alarmInfo.name === METAMETRICS_FINALIZE_EVENT_FRAGMENT_ALARM) {
const hasAlarm = checkAlarmExists(
alarms,
METAMETRICS_FINALIZE_EVENT_FRAGMENT_ALARM,
);
if (hasAlarm) {
this.finalizeAbandonedFragments(); this.finalizeAbandonedFragments();
} }
}); });
});
} else { } else {
setInterval(() => { setInterval(() => {
this.finalizeAbandonedFragments(); this.finalizeAbandonedFragments();