Skip to content

Commit

Permalink
fix(cli): enable cleartext for live reload (#7563) (#7587)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Jul 26, 2024
1 parent 47eafa9 commit bb23779
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 34 deletions.
7 changes: 4 additions & 3 deletions cli/src/cordova.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ export async function writeCordovaAndroidManifest(
cordovaPlugins: Plugin[],
config: Config,
platform: string,
cleartext?: boolean,
): Promise<void> {
const manifestPath = join(
config.android.cordovaPluginsDirAbs,
Expand Down Expand Up @@ -1078,15 +1079,15 @@ export async function writeCordovaAndroidManifest(
});
});
const cleartextString = 'android:usesCleartextTraffic="true"';
const cleartext =
config.app.extConfig.server?.cleartext &&
const cleartextValue =
(cleartext || config.app.extConfig.server?.cleartext) &&
!applicationXMLAttributes.includes(cleartextString)
? cleartextString
: '';
let content = `<?xml version='1.0' encoding='utf-8'?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:amazon="http://schemas.amazon.com/apk/res/android">
<application ${applicationXMLAttributes.join('\n')} ${cleartext}>
<application ${applicationXMLAttributes.join('\n')} ${cleartextValue}>
${applicationXMLEntries.join('\n')}
</application>
${rootXMLEntries.join('\n')}
Expand Down
60 changes: 29 additions & 31 deletions cli/src/tasks/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
promptForPlatform,
getPlatformTargetName,
} from '../common';
import type { AppConfig, Config } from '../definitions';
import { getCordovaPlugins, writeCordovaAndroidManifest } from '../cordova';
import type { Config } from '../definitions';
import { fatal, isFatal } from '../errors';
import { runIOS } from '../ios/run';
import { logger, output } from '../log';
Expand Down Expand Up @@ -91,44 +92,41 @@ export async function runCommand(

try {
if (options.sync) {
if (options.liveReload) {
const newExtConfig =
await CapLiveReloadHelper.editExtConfigForLiveReload(
config,
platformName,
options,
);
const cfg: {
-readonly [K in keyof Config]: Config[K];
} = config;
const cfgapp: {
-readonly [K in keyof AppConfig]: AppConfig[K];
} = config.app;
cfgapp.extConfig = newExtConfig;
cfg.app = cfgapp;
await sync(cfg, platformName, false, true);
} else {
await sync(config, platformName, false, true);
}
} else {
if (options.liveReload) {
await CapLiveReloadHelper.editCapConfigForLiveReload(
await sync(config, platformName, false, true);
}
const cordovaPlugins = await getCordovaPlugins(config, platformName);
if (options.liveReload) {
await CapLiveReloadHelper.editCapConfigForLiveReload(
config,
platformName,
options,
);
if (platformName === config.android.name) {
await await writeCordovaAndroidManifest(
cordovaPlugins,
config,
platformName,
options,
true,
);
}
}
await run(config, platformName, options);
if (options.liveReload) {
process.on('SIGINT', async () => {
if (options.liveReload) {
new Promise(resolve => process.on('SIGINT', resolve))
.then(async () => {
await CapLiveReloadHelper.revertCapConfigForLiveReload();
}
process.exit();
});
console.log(
`\nApp running with live reload listing for: http://${options.host}:${options.port}. Press Ctrl+C to quit.`,
if (platformName === config.android.name) {
await writeCordovaAndroidManifest(
cordovaPlugins,
config,
platformName,
false,
);
}
})
.then(() => process.exit());
logger.info(
`App running with live reload listing for: http://${options.host}:${options.port}. Press Ctrl+C to quit.`,
);
await sleepForever();
}
Expand Down
2 changes: 2 additions & 0 deletions cli/src/util/livereload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class CapLiveReload {
return !all.length ? loopback(family) : all[0];
}

// TODO remove on next major as it's unused
async editExtConfigForLiveReload(
config: Config,
platformName: string,
Expand Down Expand Up @@ -147,6 +148,7 @@ class CapLiveReload {
return configJson;
}

// TODO remove rootConfigChange param on next major as it's unused
async editCapConfigForLiveReload(
config: Config,
platformName: string,
Expand Down

0 comments on commit bb23779

Please sign in to comment.