Skip to content

Commit 721f1e4

Browse files
committed
Fix: Don't assume Prefs are available on the worker isolate
1 parent e24d32a commit 721f1e4

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

lib/data/editor/editor_core_info.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,14 @@ class EditorCoreInfo {
171171
}
172172
return CanvasBackgroundPattern.none;
173173
}(),
174-
lineHeight: json['l'] as int? ?? Prefs.lastLineHeight.value,
175-
lineThickness: json['lt'] as int? ?? Prefs.lastLineThickness.value,
174+
lineHeight: json['l'] as int? ??
175+
(Prefs.available
176+
? Prefs.lastLineHeight.value
177+
: Prefs.defaultLineHeight),
178+
lineThickness: json['lt'] as int? ??
179+
(Prefs.available
180+
? Prefs.lastLineThickness.value
181+
: Prefs.defaultLineThickness),
176182
pages: _parsePagesJson(
177183
json['z'] as List?,
178184
inlineAssets: inlineAssets,

lib/data/prefs.dart

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ abstract class Prefs {
3535
@visibleForTesting
3636
static bool warnIfPrefAccessedBeforeLoaded = true;
3737

38+
/// Returns whether you can use Prefs.
39+
///
40+
/// This may be false if [init] has not been called yet,
41+
/// or on a non-main isolate.
42+
static bool get available => _available;
43+
static bool _available = false;
44+
3845
static late final PlainPref<String?> customDataDir;
3946

4047
static late final EncPref<bool> allowInsecureConnections;
@@ -118,6 +125,8 @@ abstract class Prefs {
118125
lastPencilColor,
119126
lastShapePenColor;
120127
static late final PlainPref<CanvasBackgroundPattern> lastBackgroundPattern;
128+
static const defaultLineHeight = 40;
129+
static const defaultLineThickness = 3;
121130
static late final PlainPref<int> lastLineHeight;
122131
static late final PlainPref<int> lastLineThickness;
123132
static late final PlainPref<bool> lastZoomLock,
@@ -156,6 +165,8 @@ abstract class Prefs {
156165
static late final PlainPref<String> locale;
157166

158167
static void init() {
168+
_available = true;
169+
159170
customDataDir = PlainPref('customDataDir', null);
160171
allowInsecureConnections = EncPref('allowInsecureConnections', false);
161172
url = EncPref('url', '');
@@ -247,8 +258,8 @@ abstract class Prefs {
247258

248259
lastBackgroundPattern =
249260
PlainPref('lastBackgroundPattern', CanvasBackgroundPattern.none);
250-
lastLineHeight = PlainPref('lastLineHeight', 40);
251-
lastLineThickness = PlainPref('lastLineThickness', 3);
261+
lastLineHeight = PlainPref('lastLineHeight', defaultLineHeight);
262+
lastLineThickness = PlainPref('lastLineThickness', defaultLineThickness);
252263
lastZoomLock = PlainPref('lastZoomLock', false);
253264
lastSingleFingerPanLock = PlainPref('lastSingleFingerPanLock', false,
254265
historicalKeys: const ['lastPanLock']);
6 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)