Skip to content

Commit

Permalink
chore(cli): make migrate add navigation to configChanges (#7828)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Jan 14, 2025
1 parent 9d08df6 commit 6b14cde
Showing 1 changed file with 22 additions and 25 deletions.
47 changes: 22 additions & 25 deletions cli/src/tasks/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ export async function migrateCommand(config: Config, noprompt: boolean, packagem
}

if (allDependencies['@capacitor/android'] && existsSync(config.android.platformDirAbs)) {
// AndroidManifest.xml add navigation"
await runTask(`Migrating AndroidManifest.xml by adding navigation to Activity configChanges.`, () => {
return updateAndroidManifest(join(config.android.srcMainDirAbs, 'AndroidManifest.xml'));
});

const gradleWrapperVersion = getGradleWrapperVersion(
join(config.android.platformDirAbs, 'gradle', 'wrapper', 'gradle-wrapper.properties'),
);
Expand Down Expand Up @@ -594,6 +599,23 @@ function setAllStringIn(data: string, start: string, end: string, replacement: s
return result;
}

async function updateAndroidManifest(filename: string) {
const txt = readFile(filename);
if (!txt) {
return;
}

if (txt.includes('navigation')) {
return; // Probably already updated
}
const replaced = txt.replace(
'android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"',
'android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode|navigation"',
);

writeFileSync(filename, replaced, 'utf-8');
}

export async function patchOldCapacitorPlugins(config: Config): Promise<void[]> {
const allPlugins = await getPlugins(config, 'android');
const androidPlugins = await getAndroidPlugins(allPlugins);
Expand Down Expand Up @@ -628,28 +650,3 @@ export async function patchOldCapacitorPlugins(config: Config): Promise<void[]>
}),
);
}

async function removeKey(filename: string, key: string) {
const txt = readFile(filename);
if (!txt) {
return;
}
let lines = txt.split('\n');
let removed = false;
let removing = false;
lines = lines.filter((line) => {
if (removing && line.includes('</string>')) {
removing = false;
return false;
}
if (line.includes(`<key>${key}</key`)) {
removing = true;
removed = true;
}
return !removing;
});

if (removed) {
writeFileSync(filename, lines.join('\n'), 'utf-8');
}
}

0 comments on commit 6b14cde

Please sign in to comment.