aboutsummaryrefslogtreecommitdiff
path: root/source/settings
diff options
context:
space:
mode:
Diffstat (limited to 'source/settings')
-rw-r--r--source/settings/ChangeQueue.mc29
1 files changed, 29 insertions, 0 deletions
diff --git a/source/settings/ChangeQueue.mc b/source/settings/ChangeQueue.mc
index c5919f6..5de74e0 100644
--- a/source/settings/ChangeQueue.mc
+++ b/source/settings/ChangeQueue.mc
@@ -27,6 +27,10 @@ module ChangeQueue {
// all" that follows it (ChangeQueueJob). Replaced at every PIN.
var _lockLines as Array<String> = [] as Array<String>;
+ // countToConfirm()'s cached result and the vault it is for.
+ var _toConfirm as Number? = null;
+ var _toConfirmFor as Vault? = null;
+
function count(vault as Vault) as Number {
var stored = vault.storage().getValue(KEY);
return stored instanceof Array ? stored.size() : 0;
@@ -42,6 +46,7 @@ module ChangeQueue {
var plain = action.toBytes();
items.add(SealedBox.seal(vault.keyManager.deviceKeys(), Bytes.fromUtf8(AAD), plain));
Bytes.wipe(plain);
+ changed();
try {
vault.storage().setValue(KEY, items);
} catch (e instanceof Lang.Exception) {
@@ -84,6 +89,26 @@ module ChangeQueue {
return out;
}
+ // The number of waiting changes that need "Confirm all": all but
+ // "Require PIN", which applies at the next PIN by itself. For the list's
+ // title and the menu; cached until the queue changes, because the list
+ // asks at every draw and counting opens every item.
+ function countToConfirm(vault as Vault) as Number {
+ var n = _toConfirm;
+ if (n == null || _toConfirmFor != vault) {
+ var total = count(vault);
+ n = total > 0 ? total - countLocks(vault) : 0;
+ _toConfirm = n;
+ _toConfirmFor = vault;
+ }
+ return n;
+ }
+
+ // The queue changed: count again next time.
+ function changed() as Void {
+ _toConfirm = null;
+ }
+
// The number of waiting "Require PIN" actions (applied at the next PIN).
function countLocks(vault as Vault) as Number {
var actions = load(vault);
@@ -104,6 +129,7 @@ module ChangeQueue {
// already locked) is dropped too.
function applyLocks(vault as Vault) as Void {
_lockLines = [] as Array<String>;
+ changed();
var stored = vault.storage().getValue(KEY);
if (!(stored instanceof Array) || !vault.session.isUnlocked()) {
return;
@@ -127,6 +153,7 @@ module ChangeQueue {
kept.add(box as Application.Storage.ValueType); // damaged items are dropped by the next clear()
}
}
+ Diag.data("locks_applied", "count=" + _lockLines.size()); // for UI scripts: no names
if (kept.size() == stored.size()) {
return;
}
@@ -150,12 +177,14 @@ module ChangeQueue {
}
function clear(vault as Vault) as Void {
+ changed();
vault.storage().deleteValue(KEY);
}
// Remove the first n items (the ones just applied), keeping any that
// arrived from the phone meanwhile.
function drop(vault as Vault, n as Number) as Void {
+ changed();
var stored = vault.storage().getValue(KEY);
if (!(stored instanceof Array) || stored.size() <= n) {
clear(vault);