Skip to content

fix: android prefs migration - #208

Open
michaeljwalla wants to merge 5 commits into
mainfrom
android-prefs-migration
Open

fix: android prefs migration#208
michaeljwalla wants to merge 5 commits into
mainfrom
android-prefs-migration

Conversation

@michaeljwalla

Copy link
Copy Markdown
Contributor

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

@michaeljwalla michaeljwalla self-assigned this Aug 15, 2026
@michaeljwalla michaeljwalla linked an issue Aug 15, 2026 that may be closed by this pull request
Comment thread src/lib/utils/prefs.ts Outdated
Comment thread src/lib/utils/prefs.ts Outdated
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');
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should all go in another file

Comment thread src/lib/utils/legacy-migration.ts Outdated
import { Directory, Filesystem } from '@capacitor/filesystem';
import { Preferences } from '@capacitor/preferences';

export const PREFS_VERSION = 2;

@bwees bwees Aug 15, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

android prefs don't migrate to v2

2 participants