|
|
|
@ -12,6 +12,7 @@ class AppStateController extends EventEmitter { |
|
|
|
|
isUnlocked, |
|
|
|
|
initState, |
|
|
|
|
onInactiveTimeout, |
|
|
|
|
showUnlockRequest, |
|
|
|
|
preferencesStore, |
|
|
|
|
} = opts |
|
|
|
|
const { preferences } = preferencesStore.getState() |
|
|
|
@ -29,6 +30,8 @@ class AppStateController extends EventEmitter { |
|
|
|
|
this.waitingForUnlock = [] |
|
|
|
|
addUnlockListener(this.handleUnlock.bind(this)) |
|
|
|
|
|
|
|
|
|
this._showUnlockRequest = showUnlockRequest |
|
|
|
|
|
|
|
|
|
preferencesStore.subscribe((state) => { |
|
|
|
|
this._setInactiveTimeout(state.preferences.autoLockTimeLimit) |
|
|
|
|
}) |
|
|
|
@ -40,20 +43,38 @@ class AppStateController extends EventEmitter { |
|
|
|
|
* Get a Promise that resolves when the extension is unlocked. |
|
|
|
|
* This Promise will never reject. |
|
|
|
|
* |
|
|
|
|
* @param {boolean} shouldShowUnlockRequest - Whether the extension notification |
|
|
|
|
* popup should be opened. |
|
|
|
|
* @returns {Promise<void>} A promise that resolves when the extension is |
|
|
|
|
* unlocked, or immediately if the extension is already unlocked. |
|
|
|
|
*/ |
|
|
|
|
getUnlockPromise () { |
|
|
|
|
getUnlockPromise (shouldShowUnlockRequest) { |
|
|
|
|
return new Promise((resolve) => { |
|
|
|
|
if (this.isUnlocked()) { |
|
|
|
|
resolve() |
|
|
|
|
} else { |
|
|
|
|
this.waitingForUnlock.push({ resolve }) |
|
|
|
|
this.emit('updateBadge') |
|
|
|
|
this.waitForUnlock(resolve, shouldShowUnlockRequest) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Adds a Promise's resolve function to the waitingForUnlock queue. |
|
|
|
|
* Also opens the extension popup if specified. |
|
|
|
|
* |
|
|
|
|
* @param {Promise.resolve} resolve - A Promise's resolve function that will |
|
|
|
|
* be called when the extension is unlocked. |
|
|
|
|
* @param {boolean} shouldShowUnlockRequest - Whether the extension notification |
|
|
|
|
* popup should be opened. |
|
|
|
|
*/ |
|
|
|
|
waitForUnlock (resolve, shouldShowUnlockRequest) { |
|
|
|
|
this.waitingForUnlock.push({ resolve }) |
|
|
|
|
this.emit('updateBadge') |
|
|
|
|
if (shouldShowUnlockRequest) { |
|
|
|
|
this._showUnlockRequest() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Drains the waitingForUnlock queue, resolving all the related Promises. |
|
|
|
|
*/ |
|
|
|
|