// Author: cirakg & claude ai // Summary: Runs the settings forms (SettingsJob) on a timer from the app, then stores and shows the results (README 10.3). // // Rules (README 10.3): // * Runs from onSettingsChanged, at every start (after the first frame) // and after the PIN is entered (which may let "Encrypt names" finish). // * The work itself is SettingsJob; this class only drives it on a timer // (one step per tick), and when forms were looked at, stores the // results lines and opens the results screen. // * New settings arriving while a run is going start another run when it // ends, so nothing is missed. // Only the full app runs this, never the glance. import Toybox.Lang; import Toybox.WatchUi; class SettingsProcessor { private var _job as SettingsJob? = null; // The job's timer driver (kept so it isn't collected while it runs). var runner as Jobs.JobRunner? = null; private var _again as Boolean = false; function initialize() { } function isBusy() as Boolean { return _job != null; } // "Importing… 40%" or "Applying settings…" while a run goes, else null. function busyText() as String? { var job = _job; return job != null && job.forms > 0 ? job.busyText() : null; } // Start a run if any form asks for one (or the About fields are stale). function start() as Void { if (AppState.vault == null) { return; } if (_job != null) { _again = true; return; } var vault = AppState.theVault(); var store = new Forms.PropertyStore(); if (!SettingsJob.hasWork(vault, store)) { return; } var job = new SettingsJob(vault, store, Clock.nowUnix(0)); _job = job; var r = new Jobs.JobRunner(job, 1, method(:onDone)); runner = r; r.start(); WatchUi.requestUpdate(); } function onDone() as Void { var job = _job as SettingsJob; _job = null; runner = null; if (job.changed) { AppState.theCodes().clear(); } if (job.forms > 0) { var lines = job.lines; // "Require PIN" items apply by themselves at the next PIN. var vault = AppState.theVault(); var locks = ChangeQueue.countLocks(vault); var waiting = ChangeQueue.count(vault) - locks; if (waiting > 0) { lines.add(waiting + (waiting == 1 ? " change waits" : " changes wait") + " for your PIN: menu, Phone changes."); } if (locks > 0) { lines.add(locks + (locks == 1 ? " entry locks" : " entries lock") + " when you next enter your PIN."); } Results.save(lines); WatchUi.pushView(new InfoView("Results", lines, "results"), new InfoDelegate(), WatchUi.SLIDE_UP); Results.markSeen(); } WatchUi.requestUpdate(); if (_again) { _again = false; start(); } } }