From a957327203bd940c4803a5f5f1fd7714b7d61743 Mon Sep 17 00:00:00 2001 From: Hidenori Matsubayashi Date: Wed, 16 Aug 2023 01:24:35 +0000 Subject: [PATCH] custom-device: add customizable stopApp command (#202) This change adds `stopApp` command to custom-devices json file to quit flutter app from host PC remotely. Fixed #157 Signed-off-by: Hidenori Matsubayashi --- lib/elinux_device.dart | 15 +++++++++++++++ lib/elinux_remote_device_config.dart | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/elinux_device.dart b/lib/elinux_device.dart index 3d454a7..217908d 100644 --- a/lib/elinux_device.dart +++ b/lib/elinux_device.dart @@ -255,6 +255,21 @@ class ELinuxDevice extends Device { {String? userIdentifier}) async { _maybeUnforwardPort(); + // Stop app for remote devices. + if (!_desktop && _config!.stopAppCommand.isNotEmpty) { + final List interpolated = interpolateCommand( + _config!.stopAppCommand, {'appName': app!.name!}); + try { + _logger.printStatus('Stop ${app.name!} for custom device.'); + await _processUtils.run(interpolated, + throwOnError: true, timeout: const Duration(seconds: 10)); + _logger.printStatus('Stop Success.'); + } on ProcessException catch (e) { + _logger.printError( + 'Error executing Stop app command for custom device $id: $e'); + } + } + bool succeeded = true; // Walk a copy of _runningProcesses, since the exit handler removes from the // set. diff --git a/lib/elinux_remote_device_config.dart b/lib/elinux_remote_device_config.dart index 446ed66..a47ce3d 100644 --- a/lib/elinux_remote_device_config.dart +++ b/lib/elinux_remote_device_config.dart @@ -81,6 +81,7 @@ class ELinuxRemoteDeviceConfig { required this.installCommand, required this.uninstallCommand, required this.runDebugCommand, + this.stopAppCommand = const [], this.forwardPortCommand, this.forwardPortSuccessRegex, this.screenshotCommand}) @@ -133,6 +134,7 @@ class ELinuxRemoteDeviceConfig { runDebugCommand: _castStringList( typedMap[_kRunDebugCommand], _kRunDebugCommand, 'array of strings with at least one element', minLength: 1), + stopAppCommand: _castStringList(typedMap[_kStopAppCommand], _kStopAppCommand, 'array of strings with at least one element', minLength: 1), forwardPortCommand: forwardPortCommand, forwardPortSuccessRegex: forwardPortSuccessRegex, screenshotCommand: _castStringListOrNull(typedMap[_kScreenshotCommand], _kScreenshotCommand, 'array of strings with at least one element', minLength: 1)); @@ -150,6 +152,7 @@ class ELinuxRemoteDeviceConfig { static const String _kInstallCommand = 'install'; static const String _kUninstallCommand = 'uninstall'; static const String _kRunDebugCommand = 'runDebug'; + static const String _kStopAppCommand = 'stopApp'; static const String _kForwardPortCommand = 'forwardPort'; static const String _kForwardPortSuccessRegex = 'forwardPortSuccessRegex'; static const String _kScreenshotCommand = 'screenshot'; @@ -166,6 +169,7 @@ class ELinuxRemoteDeviceConfig { final List installCommand; final List uninstallCommand; final List runDebugCommand; + final List stopAppCommand; final List? forwardPortCommand; final RegExp? forwardPortSuccessRegex; final List? screenshotCommand; @@ -292,6 +296,7 @@ class ELinuxRemoteDeviceConfig { _kInstallCommand: installCommand, _kUninstallCommand: uninstallCommand, _kRunDebugCommand: runDebugCommand, + _kStopAppCommand: stopAppCommand, _kForwardPortCommand: forwardPortCommand, _kForwardPortSuccessRegex: forwardPortSuccessRegex?.pattern, _kScreenshotCommand: screenshotCommand, @@ -313,6 +318,7 @@ class ELinuxRemoteDeviceConfig { _listsEqual(other.installCommand, installCommand) && _listsEqual(other.uninstallCommand, uninstallCommand) && _listsEqual(other.runDebugCommand, runDebugCommand) && + _listsEqual(other.stopAppCommand, stopAppCommand) && _listsEqual(other.forwardPortCommand, forwardPortCommand) && _regexesEqual(other.forwardPortSuccessRegex, forwardPortSuccessRegex) && _listsEqual(other.screenshotCommand, screenshotCommand); @@ -332,6 +338,7 @@ class ELinuxRemoteDeviceConfig { installCommand.hashCode ^ uninstallCommand.hashCode ^ runDebugCommand.hashCode ^ + stopAppCommand.hashCode ^ forwardPortCommand.hashCode ^ (forwardPortSuccessRegex?.pattern).hashCode ^ screenshotCommand.hashCode; @@ -352,6 +359,7 @@ class ELinuxRemoteDeviceConfig { 'installCommand: $installCommand, ' 'uninstallCommand: $uninstallCommand, ' 'runDebugCommand: $runDebugCommand, ' + 'stopAppCommand: $stopAppCommand, ' 'forwardPortCommand: $forwardPortCommand, ' 'forwardPortSuccessRegex: $forwardPortSuccessRegex, ' 'screenshotCommand: $screenshotCommand)';