Skip to content

Commit 9e4619c

Browse files
committed
tweak: disable stow writes on non-main isolates
1 parent 7b901b9 commit 9e4619c

File tree

3 files changed

+81
-77
lines changed

3 files changed

+81
-77
lines changed

lib/data/prefs.dart

Lines changed: 72 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,24 @@ class Stows {
4646
final log = Logger('Stows');
4747

4848
final customDataDir =
49-
PlainStow<String?>('customDataDir', null, autoRead: _isOnMainIsolate);
49+
PlainStow<String?>('customDataDir', null, volatile: !_isOnMainIsolate);
5050

51-
final allowInsecureConnections =
52-
SecureStow.bool('allowInsecureConnections', false, autoRead: _isOnMainIsolate);
53-
final url = SecureStow('url', '', autoRead: _isOnMainIsolate);
54-
final username = SecureStow('username', '', autoRead: _isOnMainIsolate);
51+
final allowInsecureConnections = SecureStow.bool(
52+
'allowInsecureConnections', false,
53+
volatile: !_isOnMainIsolate);
54+
final url = SecureStow('url', '', volatile: !_isOnMainIsolate);
55+
final username = SecureStow('username', '', volatile: !_isOnMainIsolate);
5556

5657
/// the password used to login to Nextcloud
57-
final ncPassword = SecureStow('ncPassword', '', autoRead: _isOnMainIsolate);
58+
final ncPassword = SecureStow('ncPassword', '', volatile: !_isOnMainIsolate);
5859
// TODO(adil192): maybe deprecate?
59-
final ncPasswordIsAnAppPassword =
60-
PlainStow('ncPasswordIsAnAppPassword', false, autoRead: _isOnMainIsolate);
60+
final ncPasswordIsAnAppPassword = PlainStow(
61+
'ncPasswordIsAnAppPassword', false,
62+
volatile: !_isOnMainIsolate);
6163

6264
/// the password used to encrypt/decrypt notes
63-
final encPassword = SecureStow('encPassword', '', autoRead: _isOnMainIsolate);
65+
final encPassword =
66+
SecureStow('encPassword', '', volatile: !_isOnMainIsolate);
6467

6568
/// Whether the user is logged in and has provided both passwords.
6669
/// Please ensure that the relevant Prefs are loaded before using this.
@@ -69,163 +72,164 @@ class Stows {
6972
ncPassword.value.isNotEmpty &&
7073
encPassword.value.isNotEmpty;
7174

72-
final key = SecureStow('key', '', autoRead: _isOnMainIsolate);
73-
final iv = SecureStow('iv', '', autoRead: _isOnMainIsolate);
75+
final key = SecureStow('key', '', volatile: !_isOnMainIsolate);
76+
final iv = SecureStow('iv', '', volatile: !_isOnMainIsolate);
7477

7578
final pfp = PlainStow<Uint8List?>('pfp', null,
76-
codec: const Base64StowCodec(), autoRead: _isOnMainIsolate);
79+
codec: const Base64StowCodec(), volatile: !_isOnMainIsolate);
7780
final syncInBackground =
78-
PlainStow('syncInBackground', true, autoRead: _isOnMainIsolate);
81+
PlainStow('syncInBackground', true, volatile: !_isOnMainIsolate);
7982

8083
final appTheme = PlainStow('appTheme', ThemeMode.system,
81-
codec: EnumCodec(ThemeMode.values), autoRead: _isOnMainIsolate);
84+
codec: EnumCodec(ThemeMode.values), volatile: !_isOnMainIsolate);
8285

8386
/// The type of platform to theme. Default value is [defaultTargetPlatform].
8487
final platform = PlainStow('platform', defaultTargetPlatform,
85-
codec: EnumCodec(TargetPlatform.values), autoRead: _isOnMainIsolate);
88+
codec: EnumCodec(TargetPlatform.values), volatile: !_isOnMainIsolate);
8689
final layoutSize = PlainStow('layoutSize', LayoutSize.auto,
87-
codec: LayoutSize.codec, autoRead: _isOnMainIsolate);
90+
codec: LayoutSize.codec, volatile: !_isOnMainIsolate);
8891

8992
/// The accent color of the app. If 0, the system accent color will be used.
9093
final accentColor = PlainStow<Color?>('accentColor', null,
91-
codec: ColorCodec(), autoRead: _isOnMainIsolate);
94+
codec: ColorCodec(), volatile: !_isOnMainIsolate);
9295
final hyperlegibleFont =
93-
PlainStow('hyperlegibleFont', false, autoRead: _isOnMainIsolate);
96+
PlainStow('hyperlegibleFont', false, volatile: !_isOnMainIsolate);
9497

9598
final editorToolbarAlignment = PlainStow(
9699
'editorToolbarAlignment', AxisDirection.down,
97-
codec: EnumCodec(AxisDirection.values), autoRead: _isOnMainIsolate);
100+
codec: EnumCodec(AxisDirection.values), volatile: !_isOnMainIsolate);
98101
final editorToolbarShowInFullscreen = PlainStow(
99102
'editorToolbarShowInFullscreen', true,
100-
autoRead: _isOnMainIsolate);
103+
volatile: !_isOnMainIsolate);
101104
final editorFingerDrawing =
102-
PlainStow('editorFingerDrawing', true, autoRead: _isOnMainIsolate);
105+
PlainStow('editorFingerDrawing', true, volatile: !_isOnMainIsolate);
103106
final editorAutoInvert =
104-
PlainStow('editorAutoInvert', true, autoRead: _isOnMainIsolate);
107+
PlainStow('editorAutoInvert', true, volatile: !_isOnMainIsolate);
105108
final preferGreyscale =
106-
PlainStow('preferGreyscale', false, autoRead: _isOnMainIsolate);
109+
PlainStow('preferGreyscale', false, volatile: !_isOnMainIsolate);
107110
final editorPromptRename =
108-
PlainStow('editorPromptRename', isDesktop, autoRead: _isOnMainIsolate);
111+
PlainStow('editorPromptRename', isDesktop, volatile: !_isOnMainIsolate);
109112
final autosaveDelay =
110-
PlainStow('autosaveDelay', 10000, autoRead: _isOnMainIsolate);
113+
PlainStow('autosaveDelay', 10000, volatile: !_isOnMainIsolate);
111114
final shapeRecognitionDelay =
112-
PlainStow('shapeRecognitionDelay', 500, autoRead: _isOnMainIsolate);
115+
PlainStow('shapeRecognitionDelay', 500, volatile: !_isOnMainIsolate);
113116
final autoStraightenLines =
114-
PlainStow('autoStraightenLines', true, autoRead: _isOnMainIsolate);
117+
PlainStow('autoStraightenLines', true, volatile: !_isOnMainIsolate);
115118
final pencilSound = PlainStow(
116119
'pencilSound', PencilSoundSetting.onButNotInSilentMode,
117-
codec: PencilSoundSetting.codec, autoRead: _isOnMainIsolate);
120+
codec: PencilSoundSetting.codec, volatile: !_isOnMainIsolate);
118121

119122
final simplifiedHomeLayout =
120-
PlainStow('simplifiedHomeLayout', false, autoRead: _isOnMainIsolate);
123+
PlainStow('simplifiedHomeLayout', false, volatile: !_isOnMainIsolate);
121124
final hideHomeBackgrounds =
122-
PlainStow('hideHomeBackgrounds', false, autoRead: _isOnMainIsolate);
125+
PlainStow('hideHomeBackgrounds', false, volatile: !_isOnMainIsolate);
123126
final printPageIndicators =
124-
PlainStow('printPageIndicators', false, autoRead: _isOnMainIsolate);
127+
PlainStow('printPageIndicators', false, volatile: !_isOnMainIsolate);
125128

126129
final maxImageSize =
127-
PlainStow<double>('maxImageSize', 1000, autoRead: _isOnMainIsolate);
130+
PlainStow<double>('maxImageSize', 1000, volatile: !_isOnMainIsolate);
128131

129-
final autoClearWhiteboardOnExit =
130-
PlainStow('autoClearWhiteboardOnExit', false, autoRead: _isOnMainIsolate);
132+
final autoClearWhiteboardOnExit = PlainStow(
133+
'autoClearWhiteboardOnExit', false,
134+
volatile: !_isOnMainIsolate);
131135

132136
final disableEraserAfterUse =
133-
PlainStow('disableEraserAfterUse', false, autoRead: _isOnMainIsolate);
137+
PlainStow('disableEraserAfterUse', false, volatile: !_isOnMainIsolate);
134138
final hideFingerDrawingToggle =
135-
PlainStow('hideFingerDrawingToggle', false, autoRead: _isOnMainIsolate);
139+
PlainStow('hideFingerDrawingToggle', false, volatile: !_isOnMainIsolate);
136140

137141
final recentColorsChronological = PlainStow(
138142
'recentColorsChronological', <String>[],
139-
autoRead: _isOnMainIsolate);
143+
volatile: !_isOnMainIsolate);
140144
final recentColorsPositioned = PlainStow('recentColorsPositioned', <String>[],
141-
autoRead: _isOnMainIsolate);
145+
volatile: !_isOnMainIsolate);
142146
final pinnedColors =
143-
PlainStow('pinnedColors', <String>[], autoRead: _isOnMainIsolate);
147+
PlainStow('pinnedColors', <String>[], volatile: !_isOnMainIsolate);
144148
final recentColorsDontSavePresets =
145-
PlainStow('dontSavePresetColors', false, autoRead: _isOnMainIsolate);
149+
PlainStow('dontSavePresetColors', false, volatile: !_isOnMainIsolate);
146150
final recentColorsLength =
147-
PlainStow('recentColorsLength', 5, autoRead: _isOnMainIsolate);
151+
PlainStow('recentColorsLength', 5, volatile: !_isOnMainIsolate);
148152

149153
final lastTool = PlainStow('lastTool', ToolId.fountainPen,
150-
codec: ToolId.codec, autoRead: _isOnMainIsolate);
154+
codec: ToolId.codec, volatile: !_isOnMainIsolate);
151155
static StrokeOptions _strokeOptionsFromJson(Object json) =>
152156
StrokeOptions.fromJson(json as Map<String, dynamic>);
153157
final lastFountainPenOptions = PlainStow.json(
154158
'lastFountainPenProperties', Pen.fountainPenOptions,
155-
fromJson: _strokeOptionsFromJson, autoRead: _isOnMainIsolate),
159+
fromJson: _strokeOptionsFromJson, volatile: !_isOnMainIsolate),
156160
lastBallpointPenOptions = PlainStow.json(
157161
'lastBallpointPenProperties', Pen.ballpointPenOptions,
158-
fromJson: _strokeOptionsFromJson, autoRead: _isOnMainIsolate),
162+
fromJson: _strokeOptionsFromJson, volatile: !_isOnMainIsolate),
159163
lastHighlighterOptions = PlainStow.json(
160164
'lastHighlighterProperties', Pen.highlighterOptions,
161-
fromJson: _strokeOptionsFromJson, autoRead: _isOnMainIsolate),
165+
fromJson: _strokeOptionsFromJson, volatile: !_isOnMainIsolate),
162166
lastPencilOptions = PlainStow.json(
163167
'lastPencilProperties', Pen.pencilOptions,
164-
fromJson: _strokeOptionsFromJson, autoRead: _isOnMainIsolate),
168+
fromJson: _strokeOptionsFromJson, volatile: !_isOnMainIsolate),
165169
lastShapePenOptions = PlainStow.json(
166170
'lastShapePenProperties', Pen.shapePenOptions,
167-
fromJson: _strokeOptionsFromJson, autoRead: _isOnMainIsolate);
171+
fromJson: _strokeOptionsFromJson, volatile: !_isOnMainIsolate);
168172
final lastFountainPenColor = PlainStow(
169173
'lastFountainPenColor', Colors.black.toARGB32(),
170-
autoRead: _isOnMainIsolate),
174+
volatile: !_isOnMainIsolate),
171175
lastBallpointPenColor = PlainStow(
172176
'lastBallpointPenColor', Colors.black.toARGB32(),
173-
autoRead: _isOnMainIsolate),
177+
volatile: !_isOnMainIsolate),
174178
lastHighlighterColor = PlainStow('lastHighlighterColor',
175179
Colors.yellow.withAlpha(Highlighter.alpha).toARGB32(),
176-
autoRead: _isOnMainIsolate),
180+
volatile: !_isOnMainIsolate),
177181
lastPencilColor = PlainStow('lastPencilColor', Colors.black.toARGB32(),
178-
autoRead: _isOnMainIsolate),
182+
volatile: !_isOnMainIsolate),
179183
lastShapePenColor = PlainStow(
180184
'lastShapePenColor', Colors.black.toARGB32(),
181-
autoRead: _isOnMainIsolate);
185+
volatile: !_isOnMainIsolate);
182186
final lastBackgroundPattern = PlainStow(
183187
'lastBackgroundPattern', CanvasBackgroundPattern.none,
184-
codec: CanvasBackgroundPattern.codec, autoRead: _isOnMainIsolate);
188+
codec: CanvasBackgroundPattern.codec, volatile: !_isOnMainIsolate);
185189
static const defaultLineHeight = 40;
186190
static const defaultLineThickness = 3;
187191
final lastLineHeight = PlainStow('lastLineHeight', defaultLineHeight,
188-
autoRead: _isOnMainIsolate);
192+
volatile: !_isOnMainIsolate);
189193
final lastLineThickness = PlainStow('lastLineThickness', defaultLineThickness,
190-
autoRead: _isOnMainIsolate);
194+
volatile: !_isOnMainIsolate);
191195
final lastZoomLock =
192-
PlainStow('lastZoomLock', false, autoRead: _isOnMainIsolate),
196+
PlainStow('lastZoomLock', false, volatile: !_isOnMainIsolate),
193197
lastSingleFingerPanLock = PlainStow('lastSingleFingerPanLock', false,
194-
autoRead: _isOnMainIsolate),
198+
volatile: !_isOnMainIsolate),
195199
lastAxisAlignedPanLock = PlainStow('lastAxisAlignedPanLock', false,
196-
autoRead: _isOnMainIsolate);
200+
volatile: !_isOnMainIsolate);
197201

198202
final recentFiles =
199-
PlainStow('recentFiles', <String>[], autoRead: _isOnMainIsolate);
203+
PlainStow('recentFiles', <String>[], volatile: !_isOnMainIsolate);
200204

201205
/// File paths that have been deleted locally
202206
final fileSyncAlreadyDeleted = PlainStow('fileSyncAlreadyDeleted', <String>{},
203-
autoRead: _isOnMainIsolate);
207+
volatile: !_isOnMainIsolate);
204208

205209
/// File paths that are known to be corrupted on Nextcloud
206-
final fileSyncCorruptFiles =
207-
PlainStow('fileSyncCorruptFiles', <String>{}, autoRead: _isOnMainIsolate);
210+
final fileSyncCorruptFiles = PlainStow('fileSyncCorruptFiles', <String>{},
211+
volatile: !_isOnMainIsolate);
208212

209213
/// Set when we want to resync everything.
210214
/// Files on the server older than this date will be
211215
/// reuploaded with the local version.
212216
/// By default, we resync everything uploaded before v0.18.4, since uploads before then resulted in 0B files.
213217
final fileSyncResyncEverythingDate = PlainStow('fileSyncResyncEverythingDate',
214218
DateTime.parse('2023-12-10T10:06:31.000Z'),
215-
codec: DateTimeCodec(), autoRead: _isOnMainIsolate);
219+
codec: DateTimeCodec(), volatile: !_isOnMainIsolate);
216220

217221
/// The last storage quota that was fetched from Nextcloud
218222
final lastStorageQuota = PlainStow<Quota?>('lastStorageQuota', null,
219-
codec: QuotaCodec(), autoRead: _isOnMainIsolate);
223+
codec: QuotaCodec(), volatile: !_isOnMainIsolate);
220224

221225
final shouldCheckForUpdates = PlainStow('shouldCheckForUpdates',
222226
FlavorConfig.shouldCheckForUpdatesByDefault && !Platform.isLinux,
223-
autoRead: _isOnMainIsolate);
227+
volatile: !_isOnMainIsolate);
224228
final shouldAlwaysAlertForUpdates = PlainStow('shouldAlwaysAlertForUpdates',
225229
(kDebugMode || FlavorConfig.dirty) ? true : false,
226-
autoRead: _isOnMainIsolate);
230+
volatile: !_isOnMainIsolate);
227231

228-
final locale = PlainStow('locale', '', autoRead: _isOnMainIsolate);
232+
final locale = PlainStow('locale', '', volatile: !_isOnMainIsolate);
229233

230234
static bool get isDesktop =>
231235
Platform.isLinux || Platform.isWindows || Platform.isMacOS;
@@ -236,7 +240,7 @@ abstract class IPref<T> extends Stow<String, T, Object?> {
236240
super.key,
237241
super.defaultValue, {
238242
super.codec,
239-
super.autoRead,
243+
super.volatile,
240244
});
241245

242246
/// Removes the value from shared preferences, and resets the pref to its default value.

pubspec.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,10 +1566,10 @@ packages:
15661566
dependency: "direct main"
15671567
description:
15681568
name: stow
1569-
sha256: dbe9c5665cfa7d3df7b65a7ea50000f0815ad8a6acc7e1cb1a7196bb5bb696c3
1569+
sha256: "0caa7c292ed44138b0dfb5a30142426f745f2a850ad10999937fb20314a36052"
15701570
url: "https://pub.dev"
15711571
source: hosted
1572-
version: "0.3.1"
1572+
version: "0.4.0"
15731573
stow_codecs:
15741574
dependency: "direct main"
15751575
description:
@@ -1582,18 +1582,18 @@ packages:
15821582
dependency: "direct main"
15831583
description:
15841584
name: stow_plain
1585-
sha256: "44833735f54fb8db16033066780b3ebf17ae827b9e9d98899b9c54bfeb07dfd6"
1585+
sha256: ad75704e212ee3f77f3863c417eab7344efd69fa82c8166df48a00ad81ee0e7a
15861586
url: "https://pub.dev"
15871587
source: hosted
1588-
version: "0.2.1+3"
1588+
version: "0.4.0"
15891589
stow_secure:
15901590
dependency: "direct main"
15911591
description:
15921592
name: stow_secure
1593-
sha256: be9883f9d3736f3e434ce77ec21a4da719bdd919488a2b150c99c86035ab00c9
1593+
sha256: "26b827d7be721882fdabf7def4254071eaf47f5bacf68b68fafb0ffb83da2532"
15941594
url: "https://pub.dev"
15951595
source: hosted
1596-
version: "0.3.0"
1596+
version: "0.4.0"
15971597
stream_channel:
15981598
dependency: transitive
15991599
description:

pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ dependencies:
146146
pdfrx: ^1.0.85
147147
path: ^1.9.1
148148

149-
stow: ^0.3.1
150-
stow_plain: ^0.2.1+3
151-
stow_secure: ^0.3.0
149+
stow: ^0.4.0
150+
stow_plain: ^0.4.0
151+
stow_secure: ^0.4.0
152152
stow_codecs: ^1.2.0
153153

154154
dev_dependencies:

0 commit comments

Comments
 (0)