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