Skip to content

Commit b5b30ac

Browse files
committed
fix(cli): enable cleartext for live reload (#7563)
1 parent 47eafa9 commit b5b30ac

File tree

3 files changed

+35
-34
lines changed

3 files changed

+35
-34
lines changed

cli/src/cordova.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ export async function writeCordovaAndroidManifest(
760760
cordovaPlugins: Plugin[],
761761
config: Config,
762762
platform: string,
763+
cleartext?: boolean,
763764
): Promise<void> {
764765
const manifestPath = join(
765766
config.android.cordovaPluginsDirAbs,
@@ -1078,15 +1079,15 @@ export async function writeCordovaAndroidManifest(
10781079
});
10791080
});
10801081
const cleartextString = 'android:usesCleartextTraffic="true"';
1081-
const cleartext =
1082-
config.app.extConfig.server?.cleartext &&
1082+
const cleartextValue =
1083+
(cleartext || config.app.extConfig.server?.cleartext) &&
10831084
!applicationXMLAttributes.includes(cleartextString)
10841085
? cleartextString
10851086
: '';
10861087
let content = `<?xml version='1.0' encoding='utf-8'?>
10871088
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
10881089
xmlns:amazon="http://schemas.amazon.com/apk/res/android">
1089-
<application ${applicationXMLAttributes.join('\n')} ${cleartext}>
1090+
<application ${applicationXMLAttributes.join('\n')} ${cleartextValue}>
10901091
${applicationXMLEntries.join('\n')}
10911092
</application>
10921093
${rootXMLEntries.join('\n')}

cli/src/tasks/run.ts

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
promptForPlatform,
1212
getPlatformTargetName,
1313
} from '../common';
14-
import type { AppConfig, Config } from '../definitions';
14+
import { getCordovaPlugins, writeCordovaAndroidManifest } from '../cordova';
15+
import type { Config } from '../definitions';
1516
import { fatal, isFatal } from '../errors';
1617
import { runIOS } from '../ios/run';
1718
import { logger, output } from '../log';
@@ -91,44 +92,41 @@ export async function runCommand(
9192

9293
try {
9394
if (options.sync) {
94-
if (options.liveReload) {
95-
const newExtConfig =
96-
await CapLiveReloadHelper.editExtConfigForLiveReload(
97-
config,
98-
platformName,
99-
options,
100-
);
101-
const cfg: {
102-
-readonly [K in keyof Config]: Config[K];
103-
} = config;
104-
const cfgapp: {
105-
-readonly [K in keyof AppConfig]: AppConfig[K];
106-
} = config.app;
107-
cfgapp.extConfig = newExtConfig;
108-
cfg.app = cfgapp;
109-
await sync(cfg, platformName, false, true);
110-
} else {
111-
await sync(config, platformName, false, true);
112-
}
113-
} else {
114-
if (options.liveReload) {
115-
await CapLiveReloadHelper.editCapConfigForLiveReload(
95+
await sync(config, platformName, false, true);
96+
}
97+
const cordovaPlugins = await getCordovaPlugins(config, platformName);
98+
if (options.liveReload) {
99+
await CapLiveReloadHelper.editCapConfigForLiveReload(
100+
config,
101+
platformName,
102+
options,
103+
);
104+
if (platformName === config.android.name) {
105+
await await writeCordovaAndroidManifest(
106+
cordovaPlugins,
116107
config,
117108
platformName,
118-
options,
109+
true,
119110
);
120111
}
121112
}
122113
await run(config, platformName, options);
123114
if (options.liveReload) {
124-
process.on('SIGINT', async () => {
125-
if (options.liveReload) {
115+
new Promise(resolve => process.on('SIGINT', resolve))
116+
.then(async () => {
126117
await CapLiveReloadHelper.revertCapConfigForLiveReload();
127-
}
128-
process.exit();
129-
});
130-
console.log(
131-
`\nApp running with live reload listing for: http://${options.host}:${options.port}. Press Ctrl+C to quit.`,
118+
if (platformName === config.android.name) {
119+
await writeCordovaAndroidManifest(
120+
cordovaPlugins,
121+
config,
122+
platformName,
123+
false,
124+
);
125+
}
126+
})
127+
.then(() => process.exit());
128+
logger.info(
129+
`App running with live reload listing for: http://${options.host}:${options.port}. Press Ctrl+C to quit.`,
132130
);
133131
await sleepForever();
134132
}

cli/src/util/livereload.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class CapLiveReload {
120120
return !all.length ? loopback(family) : all[0];
121121
}
122122

123+
// TODO remove on next major as it's unused
123124
async editExtConfigForLiveReload(
124125
config: Config,
125126
platformName: string,
@@ -147,6 +148,7 @@ class CapLiveReload {
147148
return configJson;
148149
}
149150

151+
// TODO remove rootConfigChange param on next major as it's unused
150152
async editCapConfigForLiveReload(
151153
config: Config,
152154
platformName: string,

0 commit comments

Comments
 (0)