|
|
@ -2,6 +2,8 @@ import EventEmitter from 'events'; |
|
|
|
import { ObservableStore } from '@metamask/obs-store'; |
|
|
|
import { ObservableStore } from '@metamask/obs-store'; |
|
|
|
import { METAMASK_CONTROLLER_EVENTS } from '../metamask-controller'; |
|
|
|
import { METAMASK_CONTROLLER_EVENTS } from '../metamask-controller'; |
|
|
|
import { MINUTE } from '../../../shared/constants/time'; |
|
|
|
import { MINUTE } from '../../../shared/constants/time'; |
|
|
|
|
|
|
|
import { AUTO_LOCK_TIMEOUT_ALARM } from '../../../shared/constants/alarms'; |
|
|
|
|
|
|
|
import { isManifestV3 } from '../../../shared/modules/mv3.utils'; |
|
|
|
|
|
|
|
|
|
|
|
export default class AppStateController extends EventEmitter { |
|
|
|
export default class AppStateController extends EventEmitter { |
|
|
|
/** |
|
|
|
/** |
|
|
@ -187,22 +189,45 @@ export default class AppStateController extends EventEmitter { |
|
|
|
* |
|
|
|
* |
|
|
|
* @private |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
/* eslint-disable no-undef */ |
|
|
|
_resetTimer() { |
|
|
|
_resetTimer() { |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!timeoutMinutes) { |
|
|
|
if (!timeoutMinutes) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isManifestV3) { |
|
|
|
|
|
|
|
chrome.alarms.create(AUTO_LOCK_TIMEOUT_ALARM, { |
|
|
|
|
|
|
|
delayInMinutes: timeoutMinutes, |
|
|
|
|
|
|
|
periodInMinutes: timeoutMinutes, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
chrome.alarms.onAlarm.addListener(() => { |
|
|
|
|
|
|
|
chrome.alarms.getAll((alarms) => { |
|
|
|
|
|
|
|
const hasAlarm = alarms.find( |
|
|
|
|
|
|
|
(alarm) => alarm.name === AUTO_LOCK_TIMEOUT_ALARM, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
if (hasAlarm) { |
|
|
|
|
|
|
|
this.onInactiveTimeout(); |
|
|
|
|
|
|
|
chrome.alarms.clear(AUTO_LOCK_TIMEOUT_ALARM); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} else { |
|
|
|
this.timer = setTimeout( |
|
|
|
this.timer = setTimeout( |
|
|
|
() => this.onInactiveTimeout(), |
|
|
|
() => this.onInactiveTimeout(), |
|
|
|
timeoutMinutes * MINUTE, |
|
|
|
timeoutMinutes * MINUTE, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets the current browser and OS environment |
|
|
|
* Sets the current browser and OS environment |
|
|
|