Merge pull request #2758 from devoncarew/listen_update
update listen to work w/ ios devices
This commit is contained in:
commit
69f6630ad5
@ -5,17 +5,19 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import '../base/os.dart';
|
||||||
import '../base/process.dart';
|
import '../base/process.dart';
|
||||||
import '../globals.dart';
|
import '../globals.dart';
|
||||||
import 'run.dart';
|
import 'run.dart';
|
||||||
|
|
||||||
class ListenCommand extends RunCommandBase {
|
class ListenCommand extends RunCommandBase {
|
||||||
|
ListenCommand({ this.singleRun: false });
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final String name = 'listen';
|
final String name = 'listen';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final String description =
|
final String description = 'Listen for changes to files and reload the running app.';
|
||||||
'Listen for changes to files and reload the running app (Android only).';
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final String usageFooter =
|
final String usageFooter =
|
||||||
@ -25,11 +27,6 @@ class ListenCommand extends RunCommandBase {
|
|||||||
/// Only run once. Used for testing.
|
/// Only run once. Used for testing.
|
||||||
final bool singleRun;
|
final bool singleRun;
|
||||||
|
|
||||||
ListenCommand({ this.singleRun: false });
|
|
||||||
|
|
||||||
@override
|
|
||||||
bool get androidOnly => true;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get requiresDevice => true;
|
bool get requiresDevice => true;
|
||||||
|
|
||||||
@ -38,16 +35,30 @@ class ListenCommand extends RunCommandBase {
|
|||||||
await downloadApplicationPackages();
|
await downloadApplicationPackages();
|
||||||
await downloadToolchain();
|
await downloadToolchain();
|
||||||
|
|
||||||
List<String> watchCommand = _constructWatchCommand(() sync* {
|
Iterable<String> directories = () sync* {
|
||||||
yield* argResults.rest;
|
yield* argResults.rest;
|
||||||
yield '.';
|
yield '.';
|
||||||
yield 'lib';
|
yield 'lib';
|
||||||
}());
|
}();
|
||||||
|
|
||||||
|
List<String> watchCommand = _constructWatchCommand(directories);
|
||||||
|
|
||||||
|
if (watchCommand == null)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
printStatus('Listening for changes in '
|
||||||
|
'${directories.map((String name) => "'$name${Platform.pathSeparator}'").join(', ')}'
|
||||||
|
'.');
|
||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
bool firstTime = true;
|
bool firstTime = true;
|
||||||
do {
|
do {
|
||||||
printStatus('Updating running Flutter apps...');
|
printStatus('');
|
||||||
|
|
||||||
|
// TODO(devoncarew): We could print out here what changes we detected that caused a re-run.
|
||||||
|
if (!firstTime)
|
||||||
|
printStatus('Re-running app...');
|
||||||
|
|
||||||
result = await startApp(
|
result = await startApp(
|
||||||
deviceForCommand,
|
deviceForCommand,
|
||||||
applicationPackages,
|
applicationPackages,
|
||||||
@ -62,29 +73,26 @@ class ListenCommand extends RunCommandBase {
|
|||||||
);
|
);
|
||||||
firstTime = false;
|
firstTime = false;
|
||||||
} while (!singleRun && result == 0 && _watchDirectory(watchCommand));
|
} while (!singleRun && result == 0 && _watchDirectory(watchCommand));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> _constructWatchCommand(Iterable<String> directories) {
|
List<String> _constructWatchCommand(Iterable<String> directories) {
|
||||||
if (Platform.isMacOS) {
|
if (Platform.isMacOS) {
|
||||||
try {
|
if (os.which('fswatch') == null) {
|
||||||
runCheckedSync(<String>['which', 'fswatch']);
|
|
||||||
} catch (e) {
|
|
||||||
printError('"listen" command is only useful if you have installed '
|
printError('"listen" command is only useful if you have installed '
|
||||||
'fswatch on Mac. Run "brew install fswatch" to install it with '
|
'fswatch on Mac. Run "brew install fswatch" to install it with homebrew.');
|
||||||
'homebrew.');
|
|
||||||
return null;
|
return null;
|
||||||
}
|
} else {
|
||||||
return <String>['fswatch', '-r', '-v', '-1']..addAll(directories);
|
return <String>['fswatch', '-r', '-v', '-1']..addAll(directories);
|
||||||
|
}
|
||||||
} else if (Platform.isLinux) {
|
} else if (Platform.isLinux) {
|
||||||
try {
|
if (os.which('inotifywait') == null) {
|
||||||
runCheckedSync(<String>['which', 'inotifywait']);
|
|
||||||
} catch (e) {
|
|
||||||
printError('"listen" command is only useful if you have installed '
|
printError('"listen" command is only useful if you have installed '
|
||||||
'inotifywait on Linux. Run "apt-get install inotify-tools" or '
|
'inotifywait on Linux. Run "apt-get install inotify-tools" or '
|
||||||
'equivalent to install it.');
|
'equivalent to install it.');
|
||||||
return null;
|
return null;
|
||||||
}
|
} else {
|
||||||
return <String>[
|
return <String>[
|
||||||
'inotifywait',
|
'inotifywait',
|
||||||
'-r',
|
'-r',
|
||||||
@ -93,14 +101,15 @@ class ListenCommand extends RunCommandBase {
|
|||||||
// from the editor watching files.
|
// from the editor watching files.
|
||||||
'modify,close_write,move,create,delete',
|
'modify,close_write,move,create,delete',
|
||||||
]..addAll(directories);
|
]..addAll(directories);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
printError('"listen" command is only available on Mac and Linux.');
|
printError('"listen" command is only available on Mac and Linux.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _watchDirectory(List<String> watchCommand) {
|
bool _watchDirectory(List<String> watchCommand) {
|
||||||
printStatus('Attempting to listen to these directories: ${watchCommand.join(", ")}');
|
|
||||||
assert(watchCommand != null);
|
assert(watchCommand != null);
|
||||||
try {
|
try {
|
||||||
runCheckedSync(watchCommand);
|
runCheckedSync(watchCommand);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user