From bb23779bd843dcc70b6fb9259d9d013b7846e885 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Fri, 26 Jul 2024 15:36:54 +0200 Subject: [PATCH] fix(cli): enable cleartext for live reload (#7563) (#7587) --- cli/src/cordova.ts | 7 +++-- cli/src/tasks/run.ts | 60 ++++++++++++++++++-------------------- cli/src/util/livereload.ts | 2 ++ 3 files changed, 35 insertions(+), 34 deletions(-) diff --git a/cli/src/cordova.ts b/cli/src/cordova.ts index 216e465cf..0391acf25 100644 --- a/cli/src/cordova.ts +++ b/cli/src/cordova.ts @@ -760,6 +760,7 @@ export async function writeCordovaAndroidManifest( cordovaPlugins: Plugin[], config: Config, platform: string, + cleartext?: boolean, ): Promise { const manifestPath = join( config.android.cordovaPluginsDirAbs, @@ -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 = ` - + ${applicationXMLEntries.join('\n')} ${rootXMLEntries.join('\n')} diff --git a/cli/src/tasks/run.ts b/cli/src/tasks/run.ts index c1b676d56..b590ba4f2 100644 --- a/cli/src/tasks/run.ts +++ b/cli/src/tasks/run.ts @@ -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'; @@ -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(); } diff --git a/cli/src/util/livereload.ts b/cli/src/util/livereload.ts index 07ebe7d29..384abe0ec 100644 --- a/cli/src/util/livereload.ts +++ b/cli/src/util/livereload.ts @@ -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, @@ -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,