Commit ae7734ee authored by Alhaad Gokhale's avatar Alhaad Gokhale

Merge pull request #2861 from alhaad/run_mojo_with_url

Allow run_mojo command to run an app at a URL.
parents 7940e26b 58edc7ed
...@@ -86,7 +86,7 @@ class RunMojoCommand extends FlutterCommand { ...@@ -86,7 +86,7 @@ class RunMojoCommand extends FlutterCommand {
return result; return result;
} }
Future<List<String>> _getShellConfig(String bundlePath) async { Future<List<String>> _getShellConfig(String targetApp) async {
List<String> args = <String>[]; List<String> args = <String>[];
final bool useDevtools = _useDevtools(); final bool useDevtools = _useDevtools();
...@@ -94,7 +94,6 @@ class RunMojoCommand extends FlutterCommand { ...@@ -94,7 +94,6 @@ class RunMojoCommand extends FlutterCommand {
args.add(command); args.add(command);
BuildConfiguration config = _getCurrentHostConfig(); BuildConfiguration config = _getCurrentHostConfig();
final String appPath = _makePathAbsolute(bundlePath);
String flutterPath; String flutterPath;
if (config == null || config.type == BuildType.prebuilt) { if (config == null || config.type == BuildType.prebuilt) {
...@@ -108,17 +107,30 @@ class RunMojoCommand extends FlutterCommand { ...@@ -108,17 +107,30 @@ class RunMojoCommand extends FlutterCommand {
if (argResults['android']) { if (argResults['android']) {
args.add('--android'); args.add('--android');
final String appName = path.basename(appPath); }
final String appDir = path.dirname(appPath);
args.add('mojo:launcher http://app/$appName'); final Uri appUri = Uri.parse(targetApp);
args.add('--map-origin=http://app/=$appDir'); if (appUri.scheme.isEmpty || appUri.scheme == 'file') {
final String appPath = _makePathAbsolute(targetApp);
if (argResults['android']) {
final String appName = path.basename(appPath);
final String appDir = path.dirname(appPath);
args.add('mojo:launcher http://app/$appName');
args.add('--map-origin=http://app/=$appDir');
} else {
args.add('mojo:launcher file://$appPath');
}
} else {
args.add('mojo:launcher $targetApp');
}
// Add url-mapping for mojo:flutter.
if (argResults['android']) {
final String flutterName = path.basename(flutterPath); final String flutterName = path.basename(flutterPath);
final String flutterDir = path.dirname(flutterPath); final String flutterDir = path.dirname(flutterPath);
args.add('--map-origin=http://flutter/=$flutterDir'); args.add('--map-origin=http://flutter/=$flutterDir');
args.add('--url-mappings=mojo:flutter=http://flutter/$flutterName'); args.add('--url-mappings=mojo:flutter=http://flutter/$flutterName');
} else { } else {
args.add('mojo:launcher file://$appPath');
args.add('--url-mappings=mojo:flutter=file://$flutterPath'); args.add('--url-mappings=mojo:flutter=file://$flutterPath');
} }
...@@ -152,21 +164,21 @@ class RunMojoCommand extends FlutterCommand { ...@@ -152,21 +164,21 @@ class RunMojoCommand extends FlutterCommand {
await downloadToolchain(); await downloadToolchain();
String bundlePath = argResults['app']; String targetApp = argResults['app'];
if (bundlePath == null) { if (targetApp == null) {
bundlePath = _kDefaultBundlePath; targetApp = _kDefaultBundlePath;
String mainPath = findMainDartFile(argResults['target']); String mainPath = findMainDartFile(argResults['target']);
int result = await flx.build( int result = await flx.build(
toolchain, toolchain,
mainPath: mainPath, mainPath: mainPath,
outputPath: bundlePath outputPath: targetApp
); );
if (result != 0) if (result != 0)
return result; return result;
} }
return await runCommandAndStreamOutput(await _getShellConfig(bundlePath)); return await runCommandAndStreamOutput(await _getShellConfig(targetApp));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment