fix: android prefs migration - #208
Open
michaeljwalla wants to merge 5 commits into
Open
Conversation
bwees
reviewed
Aug 15, 2026
bwees
reviewed
Aug 15, 2026
Comment on lines
+14
to
+76
| async function readLegacyPrefs(): Promise<Record<string, string> | null> { | ||
| const platform = Capacitor.getPlatform(); | ||
|
|
||
| if (platform === 'ios') { | ||
| try { | ||
| const iosRCTPrefs = await Filesystem.readFile({ | ||
| directory: Directory.Library, | ||
| path: 'Application Support/com.bwees.reveille-rides/RCTAsyncLocalStorage_V1/manifest.json', | ||
| }); | ||
|
|
||
| return JSON.parse(atob(iosRCTPrefs.data as string)); | ||
| } catch (e) { | ||
| console.log('Error migrating iOS RCTAsyncLocalStorage_V1 manifest:', e); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| if (platform === 'android') { | ||
| try { | ||
| const { available, entries } = await LegacyPrefs.getLegacyPrefs(); | ||
| return available ? entries : null; | ||
| } catch (e) { | ||
| console.log('Error migrating Android RKStorage database:', e); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| async function importLegacyPrefs( | ||
| legacy: Record<string, string | null>, | ||
| { fillOnly = false }: { fillOnly?: boolean } = {}, | ||
| ) { | ||
| const favorites = legacy['favorites']; | ||
| if (favorites) { | ||
| const current = (await Preferences.get({ key: 'favorites' })).value; | ||
| const currentIsEmpty = !current || current === '[]'; | ||
|
|
||
| if (!fillOnly || currentIsEmpty) { | ||
| await Preferences.set({ key: 'favorites', value: favorites }); | ||
| } | ||
| } | ||
|
|
||
| // rn stored the default group as an index | ||
| const defaultGroup = legacy['default-group'] === '1' ? 'favorites' : 'all'; | ||
| const currentGroup = (await Preferences.get({ key: 'defaultGroup' })).value; | ||
|
|
||
| if (!fillOnly || !currentGroup || currentGroup === 'all') { | ||
| await Preferences.set({ key: 'defaultGroup', value: defaultGroup }); | ||
| } | ||
|
|
||
| const userPickedMode = localStorage.getItem(modeStorageKey.current) !== null; | ||
| if (!fillOnly || !userPickedMode) { | ||
| let mode = 'system'; | ||
| if (legacy['app-theme'] === '1') { | ||
| mode = 'light'; | ||
| } else if (legacy['app-theme'] === '2') { | ||
| mode = 'dark'; | ||
| } | ||
| setMode(mode as 'system' | 'light' | 'dark'); | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
This should all go in another file
bwees
reviewed
Aug 15, 2026
| import { Directory, Filesystem } from '@capacitor/filesystem'; | ||
| import { Preferences } from '@capacitor/preferences'; | ||
|
|
||
| export const PREFS_VERSION = 2; |
Member
There was a problem hiding this comment.
this should be in src/lib/utils/prefs.ts. This file should only be used to interact with the old async storage DBs. All migrations steps should be in src/lib/utils/prefs.ts. I want to abstract the access of the pref files into this file and then the actual conversion to the new format in prefs.ts.
Looks like just the readLegacyPrefs function should stay and the importLegacyPrefs moves to prefs.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
android prefs lost due to different storage patterns so add java plugin to add back
also some small sync issues I noticed w ui that were mostly fixed by adding await