Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

mobile-preferences.ts

572 lines21.8 KB

1import * as Context from "effect/Context";
2import * as Effect from "effect/Effect";
3import * as Layer from "effect/Layer";
4import * as Option from "effect/Option";
5import * as Ref from "effect/Ref";
6import * as Schema from "effect/Schema";
7import * as Semaphore from "effect/Semaphore";
8import {
9 EnvironmentId,
10 PullRequestInvolvement,
11 PullRequestListFilters,
12 PullRequestListState,
13 type ProviderInstanceId,
14 PullRequestMergeMethod,
15 type SidebarProjectGroupingMode,
16} from "@t3tools/contracts";
17import { ToolCallVisibility } from "@t3tools/contracts/settings";
18import type { AndroidNavigationStyle } from "../lib/androidNavigationStyle";
19import type { ComposerEnterBehavior } from "../lib/composerEnterBehavior";
20import type { FollowUpBehavior } from "../lib/followUpBehavior";
21import { isMicrophoneKind, type MicrophoneEntry } from "../lib/microphonePriority";
22import { MOBILE_THEME_IDS, type MobileThemeId, type MobileThemeMode } from "../lib/mobileTheme";
23import * as MobileDatabase from "./mobile-database";
24import * as MobileSecureStorage from "./mobile-secure-storage";
25import { MobileStorageDecodeError, MobileStorageEncodeError } from "./mobile-storage";
26​
27const PREFERENCES_KEY = "t3code.preferences";
28const PREFERENCES_FALLBACK_KEY = "t3code.preferences.fallback";
29const encodeJson = Schema.encodeUnknownEffect(Schema.fromJsonString(Schema.Unknown));
30​
31export const PullRequestListControls = Schema.Struct({
32 state: PullRequestListState,
33 involvement: PullRequestInvolvement,
34 filters: PullRequestListFilters,
35 projectId: Schema.optional(Schema.String),
36 projectEnvironmentId: Schema.optional(Schema.String),
37 sort: Schema.Literals(["updated", "created", "oldest"]),
38});
39export type PullRequestListControls = typeof PullRequestListControls.Type;
40​
41const ThreadListFilters = Schema.Struct({
42 environmentId: Schema.NullOr(EnvironmentId),
43 projectKey: Schema.NullOr(Schema.String),
44});
45export type ThreadListFilters = typeof ThreadListFilters.Type;
46​
47const PullRequestListPreferences = Schema.Struct({
48 environmentId: Schema.NullOr(Schema.String),
49 controls: Schema.Record(Schema.String, PullRequestListControls),
50});
51export type PullRequestListPreferences = typeof PullRequestListPreferences.Type;
52​
53/**
54 * The page each workspace tab last showed, reopened when the tab returns with columns. `key` is
55 * that page's route key: reopening under the same key reuses the screen a tab kept mounted.
56 */
57const WorkspaceSelections = Schema.Struct({
58 threads: Schema.optional(
59 Schema.Struct({
60 environmentId: Schema.String,
61 threadId: Schema.String,
62 key: Schema.optional(Schema.String),
63 }),
64 ),
65 pullRequests: Schema.optional(
66 Schema.Struct({
67 environmentId: Schema.String,
68 projectId: Schema.String,
69 repository: Schema.String,
70 number: Schema.Number,
71 host: Schema.optional(Schema.String),
72 key: Schema.optional(Schema.String),
73 }),
74 ),
75 settings: Schema.optional(Schema.String),
76 settingsKey: Schema.optional(Schema.String),
77 /** A draft the threads tab showed after its last chat; only meaningful in its session. */
78 threadsDraft: Schema.optional(Schema.Struct({ key: Schema.String, params: Schema.Unknown })),
79});
80export type WorkspaceSelections = typeof WorkspaceSelections.Type;
81​
82const isThreadListFilters = Schema.is(ThreadListFilters);
83const isWorkspaceSelections = Schema.is(WorkspaceSelections);
84const isPullRequestListPreferences = Schema.is(PullRequestListPreferences);
85const ThreadProject = Schema.Struct({
86 environmentId: Schema.NonEmptyString,
87 projectId: Schema.NonEmptyString,
88});
89const isThreadProject = Schema.is(ThreadProject);
90​
91export interface Preferences {
92 readonly navigationTabOrder?: readonly string[];
93 readonly hiddenNavigationTabs?: readonly string[];
94 readonly pullRequestHideTestFiles?: boolean;
95 readonly pullRequestMergeMethod?: PullRequestMergeMethod;
96 readonly liveActivitiesEnabled?: boolean;
97 readonly themeId?: MobileThemeId;
98 readonly lightThemeId?: MobileThemeId;
99 readonly darkThemeId?: MobileThemeId;
100 readonly themeMode?: MobileThemeMode;
101 readonly androidNavigationStyle?: AndroidNavigationStyle;
102 readonly baseFontSize?: number;
103 readonly terminalFontSize?: number | null;
104 readonly markdownFontSize?: number;
105 readonly codeFontSize?: number | null;
106 readonly codeWordBreak?: boolean;
107 readonly mathRenderingEnabled?: boolean;
108 /** Unset means on: crash reports are sent unless the user turns them off. */
109 readonly crashReportsEnabled?: boolean;
110 readonly connectOnboardingOptOutAccounts?: ReadonlyArray<string>;
111 readonly collapsedProjectGroups?: readonly string[];
112 readonly dismissedDatabaseStorageNotices?: readonly string[];
113 /** Hardware-keyboard Return behavior in the composer. */
114 readonly composerEnterBehavior?: ComposerEnterBehavior;
115 readonly followUpBehavior?: FollowUpBehavior;
116 /** The client `language` setting: a locale code or "system". Unset means English. */
117 readonly language?: string;
118 readonly microphones?: ReadonlyArray<MicrophoneEntry>;
119 readonly projectGroupingEnabled?: boolean;
120 readonly projectGroupingMode?: SidebarProjectGroupingMode;
121 readonly toolCallVisibility?: ToolCallVisibility;
122 readonly workingShelfEnabled?: boolean;
123 readonly useLastProjectForNewThreads?: boolean;
124 readonly lastThreadProject?: typeof ThreadProject.Type;
125 readonly modelFavorites?: ReadonlyArray<{
126 readonly provider: ProviderInstanceId;
127 readonly model: string;
128 }>;
129 readonly threadListSettledShelfExpanded?: boolean;
130 readonly threadListSnoozedShelfExpanded?: boolean;
131 readonly threadListWorkingShelfExpanded?: boolean;
132 readonly threadListFilters?: ThreadListFilters;
133 readonly pullRequestListFilters?: PullRequestListPreferences;
134 readonly workspaceSelections?: WorkspaceSelections;
136​
137export class MobilePreferencesLoadError extends Schema.TaggedError<MobilePreferencesLoadError>()(
138 "MobilePreferencesLoadError",
139 { cause: Schema.Defect() },
140) {
141 override get message(): string {
142 return "Failed to load mobile preferences.";
143 }
145​
146export class MobilePreferencesSaveError extends Schema.TaggedError<MobilePreferencesSaveError>()(
147 "MobilePreferencesSaveError",
148 { cause: Schema.Defect() },
149) {
150 override get message(): string {
151 return "Failed to save mobile preferences.";
152 }
154​
155const isMobilePreferencesSaveError = Schema.is(MobilePreferencesSaveError);
156​
157interface PreferencesFallback {
158 readonly payload: string;
159 readonly updatedAt: number;
160 readonly preferences: Preferences;
162​
163export class MobilePreferencesStore extends Context.Service<
164 MobilePreferencesStore,
165 {
166 readonly load: Effect.Effect<Preferences, MobilePreferencesLoadError>;
167 readonly savePatch: (
168 patch: Partial<Preferences>,
169 ) => Effect.Effect<Preferences, MobilePreferencesSaveError>;
170 readonly update: (
171 transform: (current: Preferences) => Partial<Preferences>,
172 ) => Effect.Effect<Preferences, MobilePreferencesSaveError>;
173 }
174>()("@t3tools/mobile/persistence/mobile-preferences/MobilePreferencesStore") {}
175​
176const isToolCallVisibility = Schema.is(ToolCallVisibility);
177const isPullRequestMergeMethod = Schema.is(PullRequestMergeMethod);
178​
179function sanitizePreferences(parsed: Preferences): Preferences {
180 const preferences: {
181 navigationTabOrder?: readonly string[];
182 hiddenNavigationTabs?: readonly string[];
183 pullRequestHideTestFiles?: boolean;
184 pullRequestMergeMethod?: PullRequestMergeMethod;
185 liveActivitiesEnabled?: boolean;
186 themeId?: MobileThemeId;
187 lightThemeId?: MobileThemeId;
188 darkThemeId?: MobileThemeId;
189 themeMode?: MobileThemeMode;
190 androidNavigationStyle?: AndroidNavigationStyle;
191 baseFontSize?: number;
192 terminalFontSize?: number | null;
193 markdownFontSize?: number;
194 codeFontSize?: number | null;
195 codeWordBreak?: boolean;
196 mathRenderingEnabled?: boolean;
197 crashReportsEnabled?: boolean;
198 connectOnboardingOptOutAccounts?: ReadonlyArray<string>;
199 collapsedProjectGroups?: readonly string[];
200 dismissedDatabaseStorageNotices?: readonly string[];
201 composerEnterBehavior?: ComposerEnterBehavior;
202 followUpBehavior?: FollowUpBehavior;
203 language?: string;
204 microphones?: ReadonlyArray<MicrophoneEntry>;
205 projectGroupingEnabled?: boolean;
206 projectGroupingMode?: SidebarProjectGroupingMode;
207 toolCallVisibility?: ToolCallVisibility;
208 workingShelfEnabled?: boolean;
209 useLastProjectForNewThreads?: boolean;
210 lastThreadProject?: typeof ThreadProject.Type;
211 modelFavorites?: Preferences["modelFavorites"];
212 threadListSettledShelfExpanded?: boolean;
213 threadListSnoozedShelfExpanded?: boolean;
214 threadListWorkingShelfExpanded?: boolean;
215 threadListFilters?: ThreadListFilters;
216 pullRequestListFilters?: PullRequestListPreferences;
217 workspaceSelections?: WorkspaceSelections;
218 } = {};
219​
220 if (Array.isArray(parsed.hiddenNavigationTabs)) {
221 preferences.hiddenNavigationTabs = parsed.hiddenNavigationTabs.filter(
222 (tab): tab is string => typeof tab === "string",
223 );
224 }
225​
226 if (Array.isArray(parsed.navigationTabOrder)) {
227 preferences.navigationTabOrder = parsed.navigationTabOrder.filter(
228 (tab): tab is string => typeof tab === "string",
229 );
230 }
231​
232 if (typeof parsed.pullRequestHideTestFiles === "boolean") {
233 preferences.pullRequestHideTestFiles = parsed.pullRequestHideTestFiles;
234 }
235​
236 if (isPullRequestMergeMethod(parsed.pullRequestMergeMethod)) {
237 preferences.pullRequestMergeMethod = parsed.pullRequestMergeMethod;
238 }
239​
240 if (typeof parsed.liveActivitiesEnabled === "boolean") {
241 preferences.liveActivitiesEnabled = parsed.liveActivitiesEnabled;
242 }
243 if (
244 typeof parsed.themeId === "string" &&
245 (MOBILE_THEME_IDS as readonly string[]).includes(parsed.themeId)
246 ) {
247 preferences.themeId = parsed.themeId as MobileThemeId;
248 }
249 if (
250 typeof parsed.lightThemeId === "string" &&
251 (MOBILE_THEME_IDS as readonly string[]).includes(parsed.lightThemeId)
252 ) {
253 preferences.lightThemeId = parsed.lightThemeId as MobileThemeId;
254 }
255 if (
256 typeof parsed.darkThemeId === "string" &&
257 (MOBILE_THEME_IDS as readonly string[]).includes(parsed.darkThemeId)
258 ) {
259 preferences.darkThemeId = parsed.darkThemeId as MobileThemeId;
260 }
261 if (
262 parsed.themeMode === "system" ||
263 parsed.themeMode === "light" ||
264 parsed.themeMode === "dark"
265 ) {
266 preferences.themeMode = parsed.themeMode;
267 }
268 if (parsed.androidNavigationStyle === "one-ui" || parsed.androidNavigationStyle === "material") {
269 preferences.androidNavigationStyle = parsed.androidNavigationStyle;
270 }
271 if (typeof parsed.baseFontSize === "number") preferences.baseFontSize = parsed.baseFontSize;
272 if (typeof parsed.terminalFontSize === "number" || parsed.terminalFontSize === null) {
273 preferences.terminalFontSize = parsed.terminalFontSize;
274 }
275 if (typeof parsed.markdownFontSize === "number") {
276 preferences.markdownFontSize = parsed.markdownFontSize;
277 }
278 if (typeof parsed.codeFontSize === "number" || parsed.codeFontSize === null) {
279 preferences.codeFontSize = parsed.codeFontSize;
280 }
281 if (typeof parsed.codeWordBreak === "boolean") preferences.codeWordBreak = parsed.codeWordBreak;
282 if (typeof parsed.mathRenderingEnabled === "boolean")
283 preferences.mathRenderingEnabled = parsed.mathRenderingEnabled;
284 if (typeof parsed.crashReportsEnabled === "boolean") {
285 preferences.crashReportsEnabled = parsed.crashReportsEnabled;
286 }
287 if (Array.isArray(parsed.connectOnboardingOptOutAccounts)) {
288 preferences.connectOnboardingOptOutAccounts = parsed.connectOnboardingOptOutAccounts.filter(
289 (account): account is string => typeof account === "string",
290 );
291 }
292 if (Array.isArray(parsed.collapsedProjectGroups)) {
293 preferences.collapsedProjectGroups = parsed.collapsedProjectGroups.filter(
294 (key): key is string => typeof key === "string",
295 );
296 }
297 if (Array.isArray(parsed.dismissedDatabaseStorageNotices)) {
298 preferences.dismissedDatabaseStorageNotices = parsed.dismissedDatabaseStorageNotices.filter(
299 (value): value is string => typeof value === "string",
300 );
301 }
302 if (parsed.composerEnterBehavior === "send" || parsed.composerEnterBehavior === "newline") {
303 preferences.composerEnterBehavior = parsed.composerEnterBehavior;
304 }
305 if (parsed.followUpBehavior === "queue" || parsed.followUpBehavior === "steer") {
306 preferences.followUpBehavior = parsed.followUpBehavior;
307 }
308 if (typeof parsed.language === "string") preferences.language = parsed.language;
309 if (Array.isArray(parsed.microphones)) {
310 preferences.microphones = parsed.microphones.flatMap((entry): MicrophoneEntry[] => {
311 if (typeof entry !== "object" || entry === null || !isMicrophoneKind(entry.kind)) return [];
312 if (!("uid" in entry)) return [{ kind: entry.kind }];
313 return typeof entry.uid === "string" && typeof entry.name === "string"
314 ? [{ kind: entry.kind, uid: entry.uid, name: entry.name }]
315 : [];
316 });
317 }
318 if (typeof parsed.projectGroupingEnabled === "boolean") {
319 preferences.projectGroupingEnabled = parsed.projectGroupingEnabled;
320 }
321 if (
322 parsed.projectGroupingMode === "repository" ||
323 parsed.projectGroupingMode === "repository_path" ||
324 parsed.projectGroupingMode === "separate"
325 ) {
326 preferences.projectGroupingMode = parsed.projectGroupingMode;
327 }
328 if (isToolCallVisibility(parsed.toolCallVisibility)) {
329 preferences.toolCallVisibility = parsed.toolCallVisibility;
330 }
331 if (typeof parsed.workingShelfEnabled === "boolean") {
332 preferences.workingShelfEnabled = parsed.workingShelfEnabled;
333 }
334 if (typeof parsed.useLastProjectForNewThreads === "boolean") {
335 preferences.useLastProjectForNewThreads = parsed.useLastProjectForNewThreads;
336 }
337 if (isThreadProject(parsed.lastThreadProject)) {
338 preferences.lastThreadProject = parsed.lastThreadProject;
339 }
340 if (Array.isArray(parsed.modelFavorites)) {
341 preferences.modelFavorites = parsed.modelFavorites.filter(
342 (favorite) =>
343 typeof favorite === "object" &&
344 favorite !== null &&
345 typeof favorite.provider === "string" &&
346 favorite.provider.length > 0 &&
347 typeof favorite.model === "string" &&
348 favorite.model.trim().length > 0,
349 );
350 }
351 if (typeof parsed.threadListSettledShelfExpanded === "boolean") {
352 preferences.threadListSettledShelfExpanded = parsed.threadListSettledShelfExpanded;
353 }
354 if (typeof parsed.threadListSnoozedShelfExpanded === "boolean") {
355 preferences.threadListSnoozedShelfExpanded = parsed.threadListSnoozedShelfExpanded;
356 }
357 if (typeof parsed.threadListWorkingShelfExpanded === "boolean") {
358 preferences.threadListWorkingShelfExpanded = parsed.threadListWorkingShelfExpanded;
359 }
360 if (isThreadListFilters(parsed.threadListFilters)) {
361 preferences.threadListFilters = parsed.threadListFilters;
362 }
363 if (isPullRequestListPreferences(parsed.pullRequestListFilters)) {
364 preferences.pullRequestListFilters = parsed.pullRequestListFilters;
365 }
366 if (isWorkspaceSelections(parsed.workspaceSelections)) {
367 preferences.workspaceSelections = parsed.workspaceSelections;
368 }
369 return preferences;
371​
372const make = Effect.fn("MobilePreferencesStore.make")(function* () {
373 const database = yield* MobileDatabase.MobileDatabase;
374 const secureStorage = yield* MobileSecureStorage.MobileSecureStorage;
375 const lock = yield* Semaphore.make(1);
376 const lastUpdatedAt = yield* Ref.make(0);
377​
378 const parsePayload = (raw: string | null): Preferences | null => {
379 if (raw === null || !raw.trim()) return null;
380 let parsed: unknown;
381 try {
382 parsed = JSON.parse(raw);
383 } catch (cause) {
384 console.warn(
385 "[mobile-storage] ignored invalid JSON",
386 new MobileStorageDecodeError({ key: PREFERENCES_KEY, cause }),
387 );
388 return null;
389 }
390 return typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)
391 ? (parsed as Preferences)
392 : null;
393 };
394​
395 const parseFallback = (raw: string | null): PreferencesFallback | null => {
396 if (raw === null || !raw.trim()) return null;
397 let parsed: unknown;
398 try {
399 parsed = JSON.parse(raw);
400 } catch (cause) {
401 console.warn(
402 "[mobile-storage] ignored invalid JSON",
403 new MobileStorageDecodeError({ key: PREFERENCES_FALLBACK_KEY, cause }),
404 );
405 return null;
406 }
407 if (
408 typeof parsed !== "object" ||
409 parsed === null ||
410 !("payload" in parsed) ||
411 typeof parsed.payload !== "string" ||
412 !("updatedAt" in parsed) ||
413 typeof parsed.updatedAt !== "number"
414 ) {
415 return null;
416 }
417 const preferences = parsePayload(parsed.payload);
418 return preferences === null
419 ? null
420 : { payload: parsed.payload, updatedAt: parsed.updatedAt, preferences };
421 };
422​
423 const encode = Effect.fn("MobilePreferencesStore.encode")(function* (
424 key: string,
425 value: unknown,
426 ) {
427 return yield* encodeJson(value).pipe(
428 Effect.mapError((cause) => new MobileStorageEncodeError({ key, cause })),
429 );
430 });
431​
432 const nextUpdatedAt = Ref.modify(lastUpdatedAt, (last) => {
433 const next = Math.max(Date.now(), last + 1);
434 return [next, next] as const;
435 });
436​
437 const saveJson = Effect.fn("MobilePreferencesStore.saveJson")(function* (
438 payload: string,
439 updatedAt?: number,
440 ) {
441 const timestamp = updatedAt ?? (yield* nextUpdatedAt);
442 yield* Ref.update(lastUpdatedAt, (last) => Math.max(last, timestamp));
443 const databaseResult = yield* Effect.result(database.savePreferencesJson(payload, timestamp));
444 if (databaseResult._tag === "Failure") {
445 yield* Effect.logWarning("Database unavailable; saving preferences to secure storage.").pipe(
446 Effect.annotateLogs({ cause: databaseResult.failure }),
447 );
448 const fallback = yield* encode(PREFERENCES_FALLBACK_KEY, { payload, updatedAt: timestamp });
449 yield* secureStorage.setItem(PREFERENCES_FALLBACK_KEY, fallback);
450 return;
451 }
452 yield* secureStorage
453 .removeItem(PREFERENCES_FALLBACK_KEY)
454 .pipe(
455 Effect.catch((error) =>
456 Effect.logWarning("Could not remove the mobile preferences fallback.").pipe(
457 Effect.annotateLogs({ error }),
458 ),
459 ),
460 );
461 });
462​
463 const loadUnlocked = Effect.gen(function* () {
464 const databaseResult = yield* Effect.result(database.loadPreferencesJson);
465 const databaseAvailable = databaseResult._tag === "Success";
466 const storedJson = databaseAvailable
467 ? databaseResult.success
468 : Option.none<MobileDatabase.StoredPreferencesJson>();
469 if (databaseResult._tag === "Failure") {
470 yield* Effect.logWarning("Database unavailable; loading fallback preferences.").pipe(
471 Effect.annotateLogs({ cause: databaseResult.failure }),
472 );
473 }
474​
475 const fallbackResult = yield* Effect.result(secureStorage.getItem(PREFERENCES_FALLBACK_KEY));
476 let fallbackJson: string | null = null;
477 if (fallbackResult._tag === "Success") {
478 fallbackJson = fallbackResult.success;
479 } else if (Option.isNone(storedJson)) {
480 return yield* fallbackResult.failure;
481 } else {
482 yield* Effect.logWarning("Could not inspect the mobile preferences fallback.").pipe(
483 Effect.annotateLogs({ error: fallbackResult.failure }),
484 );
485 }
486​
487 const fallback = parseFallback(fallbackJson);
488 const storedPreferences = Option.isSome(storedJson)
489 ? parsePayload(storedJson.value.payload)
490 : null;
491 const fallbackIsNewer =
492 fallback !== null &&
493 (storedPreferences === null ||
494 (Option.isSome(storedJson) && fallback.updatedAt > storedJson.value.updatedAt));
495​
496 let parsed: Preferences | null = null;
497 if (fallbackIsNewer) {
498 parsed = fallback.preferences;
499 yield* Ref.update(lastUpdatedAt, (last) => Math.max(last, fallback.updatedAt));
500 if (databaseAvailable) yield* saveJson(fallback.payload, fallback.updatedAt);
501 } else if (storedPreferences !== null && Option.isSome(storedJson)) {
502 parsed = storedPreferences;
503 yield* Ref.update(lastUpdatedAt, (last) => Math.max(last, storedJson.value.updatedAt));
504 if (fallbackJson !== null) {
505 yield* secureStorage
506 .removeItem(PREFERENCES_FALLBACK_KEY)
507 .pipe(
508 Effect.catch((error) =>
509 Effect.logWarning("Could not remove a stale mobile preferences fallback.").pipe(
510 Effect.annotateLogs({ error }),
511 ),
512 ),
513 );
514 }
515 }
516​
517 if (parsed === null) {
518 const legacyJson = yield* secureStorage.getItem(PREFERENCES_KEY);
519 const legacyPreferences = parsePayload(legacyJson);
520 parsed = legacyPreferences;
521 if (legacyJson !== null && legacyPreferences !== null && databaseAvailable) {
522 yield* saveJson(legacyJson);
523 yield* secureStorage
524 .removeItem(PREFERENCES_KEY)
525 .pipe(
526 Effect.catch((error) =>
527 Effect.logWarning("Could not remove migrated mobile preferences.").pipe(
528 Effect.annotateLogs({ error }),
529 ),
530 ),
531 );
532 }
533 }
534​
535 return parsed === null ? {} : sanitizePreferences(parsed);
536 });
537​
538 const load = lock
539 .withPermits(1)(loadUnlocked)
540 .pipe(Effect.mapError((cause) => new MobilePreferencesLoadError({ cause })));
541​
542 const update = Effect.fn("MobilePreferencesStore.update")(
543 (transform: (current: Preferences) => Partial<Preferences>) =>
544 lock
545 .withPermits(1)(
546 Effect.gen(function* () {
547 const current = yield* loadUnlocked;
548 const patch = yield* Effect.try({
549 try: () => transform(current),
550 catch: (cause) => new MobilePreferencesSaveError({ cause }),
551 });
552 const next: Preferences = { ...current, ...patch };
553 const payload = yield* encode(PREFERENCES_KEY, next);
554 yield* saveJson(payload);
555 return next;
556 }),
557 )
558 .pipe(
559 Effect.mapError((cause) =>
560 isMobilePreferencesSaveError(cause) ? cause : new MobilePreferencesSaveError({ cause }),
561 ),
562 ),
563 );
564​
565 return MobilePreferencesStore.of({
566 load,
567 update,
568 savePatch: Effect.fn("MobilePreferencesStore.savePatch")((patch) => update(() => patch)),
569 });
570});
571​
572export const layer = Layer.effect(MobilePreferencesStore, make());