|
1 | 1 | import 'package:flutter/foundation.dart'; |
2 | 2 |
|
| 3 | +import 'diagnostics.dart'; |
| 4 | + |
3 | 5 | /// What the computer is actually doing, as last reported by it. |
4 | 6 | /// |
5 | 7 | /// These are not the user's settings. They are the companion's, and the phone |
@@ -191,14 +193,24 @@ class AppSettings extends ChangeNotifier { |
191 | 193 | bool get isConnectedToComputer => _remote.known; |
192 | 194 |
|
193 | 195 | /// Load stored preferences. Safe to call more than once. |
| 196 | + /// |
| 197 | + /// Failure-proof on purpose: opened settings that spin forever are worse |
| 198 | + /// than controls built from defaults, and a broken preferences channel has |
| 199 | + /// actually shipped (shared_preferences_android 2.5.0, release-mode only - |
| 200 | + /// flutter/flutter#194649). A phone that cannot read its keys gets its |
| 201 | + /// defaults and one named trace line, not a permanent spinner. |
194 | 202 | Future<void> load() async { |
195 | 203 | if (_loaded) return; |
196 | | - _haptics = await _storage.readBool(_kHaptics) ?? true; |
197 | | - _leftHanded = await _storage.readBool(_kLeftHanded) ?? false; |
198 | | - _keepAwake = await _storage.readBool(_kKeepAwake) ?? true; |
199 | | - _wantedCursorSpeed = |
200 | | - await _storage.readDouble(_kCursorSpeed) ?? 1.0; |
201 | | - _wantedAccel = await _storage.readDouble(_kAccel) ?? 1.6; |
| 204 | + try { |
| 205 | + _haptics = await _storage.readBool(_kHaptics) ?? true; |
| 206 | + _leftHanded = await _storage.readBool(_kLeftHanded) ?? false; |
| 207 | + _keepAwake = await _storage.readBool(_kKeepAwake) ?? true; |
| 208 | + _wantedCursorSpeed = |
| 209 | + await _storage.readDouble(_kCursorSpeed) ?? 1.0; |
| 210 | + _wantedAccel = await _storage.readDouble(_kAccel) ?? 1.6; |
| 211 | + } catch (error) { |
| 212 | + trace.add('stored settings unreadable ($error); using defaults'); |
| 213 | + } |
202 | 214 | _loaded = true; |
203 | 215 | notifyListeners(); |
204 | 216 | } |
|
0 commit comments