Skip to content

Commit e06648f

Browse files
authored
fix(cli): enable cleartext for live reload (#7563)
1 parent 4561515 commit e06648f

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
@@ -763,6 +763,7 @@ export async function writeCordovaAndroidManifest(
763763
cordovaPlugins: Plugin[],
764764
config: Config,
765765
platform: string,
766+
cleartext?: boolean,
766767
): Promise<void> {
767768
const manifestPath = join(
768769
config.android.cordovaPluginsDirAbs,
@@ -1081,15 +1082,15 @@ export async function writeCordovaAndroidManifest(
10811082
});
10821083
});
10831084
const cleartextString = 'android:usesCleartextTraffic="true"';
1084-
const cleartext =
1085-
config.app.extConfig.server?.cleartext &&
1085+
const cleartextValue =
1086+
(cleartext || config.app.extConfig.server?.cleartext) &&
10861087
!applicationXMLAttributes.includes(cleartextString)
10871088
? cleartextString
10881089
: '';
10891090
let content = `<?xml version='1.0' encoding='utf-8'?>
10901091
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
10911092
xmlns:amazon="http://schemas.amazon.com/apk/res/android">
1092-
<application ${applicationXMLAttributes.join('\n')} ${cleartext}>
1093+
<application ${applicationXMLAttributes.join('\n')} ${cleartextValue}>
10931094
${applicationXMLEntries.join('\n')}
10941095
</application>
10951096
${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';
@@ -92,44 +93,41 @@ export async function runCommand(
9293

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

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)