Add install/uninstall to/from remote devices (#25)
This commit is contained in:
+68
-5
@@ -13,8 +13,10 @@ import 'package:flutter_tools/src/android/android_device.dart';
|
|||||||
import 'package:flutter_tools/src/base/common.dart';
|
import 'package:flutter_tools/src/base/common.dart';
|
||||||
import 'package:flutter_tools/src/base/logger.dart';
|
import 'package:flutter_tools/src/base/logger.dart';
|
||||||
import 'package:flutter_tools/src/base/os.dart';
|
import 'package:flutter_tools/src/base/os.dart';
|
||||||
|
import 'package:flutter_tools/src/base/process.dart';
|
||||||
import 'package:flutter_tools/src/build_info.dart';
|
import 'package:flutter_tools/src/build_info.dart';
|
||||||
import 'package:flutter_tools/src/convert.dart';
|
import 'package:flutter_tools/src/convert.dart';
|
||||||
|
import 'package:flutter_tools/src/custom_devices/custom_device.dart';
|
||||||
import 'package:flutter_tools/src/device.dart';
|
import 'package:flutter_tools/src/device.dart';
|
||||||
import 'package:flutter_tools/src/device_port_forwarder.dart';
|
import 'package:flutter_tools/src/device_port_forwarder.dart';
|
||||||
import 'package:flutter_tools/src/project.dart';
|
import 'package:flutter_tools/src/project.dart';
|
||||||
@@ -25,6 +27,7 @@ import 'package:process/process.dart';
|
|||||||
|
|
||||||
import 'elinux_builder.dart';
|
import 'elinux_builder.dart';
|
||||||
import 'elinux_package.dart';
|
import 'elinux_package.dart';
|
||||||
|
import 'elinux_remote_device_config.dart';
|
||||||
|
|
||||||
/// eLinux device implementation.
|
/// eLinux device implementation.
|
||||||
///
|
///
|
||||||
@@ -32,6 +35,7 @@ import 'elinux_package.dart';
|
|||||||
class ELinuxDevice extends Device {
|
class ELinuxDevice extends Device {
|
||||||
ELinuxDevice(
|
ELinuxDevice(
|
||||||
String id, {
|
String id, {
|
||||||
|
@required ELinuxRemoteDeviceConfig config,
|
||||||
@required bool desktop,
|
@required bool desktop,
|
||||||
@required String backendType,
|
@required String backendType,
|
||||||
@required String targetArch,
|
@required String targetArch,
|
||||||
@@ -39,24 +43,29 @@ class ELinuxDevice extends Device {
|
|||||||
@required Logger logger,
|
@required Logger logger,
|
||||||
@required ProcessManager processManager,
|
@required ProcessManager processManager,
|
||||||
@required OperatingSystemUtils operatingSystemUtils,
|
@required OperatingSystemUtils operatingSystemUtils,
|
||||||
}) : _desktop = desktop,
|
}) : _config = config,
|
||||||
|
_desktop = desktop,
|
||||||
_backendType = backendType,
|
_backendType = backendType,
|
||||||
_targetArch = targetArch,
|
_targetArch = targetArch,
|
||||||
_sdkNameAndVersion = sdkNameAndVersion,
|
_sdkNameAndVersion = sdkNameAndVersion,
|
||||||
_logger = logger,
|
_logger = logger,
|
||||||
_processManager = processManager,
|
_processManager = processManager,
|
||||||
|
_processUtils =
|
||||||
|
ProcessUtils(processManager: processManager, logger: logger),
|
||||||
_operatingSystemUtils = operatingSystemUtils,
|
_operatingSystemUtils = operatingSystemUtils,
|
||||||
super(id,
|
super(id,
|
||||||
category: desktop ? Category.desktop : Category.mobile,
|
category: desktop ? Category.desktop : Category.mobile,
|
||||||
platformType: PlatformType.custom,
|
platformType: PlatformType.custom,
|
||||||
ephemeral: true);
|
ephemeral: true);
|
||||||
|
|
||||||
|
final ELinuxRemoteDeviceConfig _config;
|
||||||
final bool _desktop;
|
final bool _desktop;
|
||||||
final String _backendType;
|
final String _backendType;
|
||||||
final String _targetArch;
|
final String _targetArch;
|
||||||
final String _sdkNameAndVersion;
|
final String _sdkNameAndVersion;
|
||||||
final Logger _logger;
|
final Logger _logger;
|
||||||
final ProcessManager _processManager;
|
final ProcessManager _processManager;
|
||||||
|
final ProcessUtils _processUtils;
|
||||||
final OperatingSystemUtils _operatingSystemUtils;
|
final OperatingSystemUtils _operatingSystemUtils;
|
||||||
final Set<Process> _runningProcesses = <Process>{};
|
final Set<Process> _runningProcesses = <Process>{};
|
||||||
final ELinuxLogReader _logReader = ELinuxLogReader();
|
final ELinuxLogReader _logReader = ELinuxLogReader();
|
||||||
@@ -88,22 +97,31 @@ class ELinuxDevice extends Device {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> isAppInstalled(ELinuxApp app, {String userIdentifier}) async {
|
Future<bool> isAppInstalled(ELinuxApp app, {String userIdentifier}) async {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> isLatestBuildInstalled(ELinuxApp app) async {
|
Future<bool> isLatestBuildInstalled(ELinuxApp app) async {
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> installApp(ELinuxApp app, {String userIdentifier}) async {
|
Future<bool> installApp(ELinuxApp app, {String userIdentifier}) async {
|
||||||
return true;
|
if (!await tryUninstall(appName: app.name)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final String bundlePath =
|
||||||
|
app.outputDirectory(BuildMode.fromName('debug'), _targetArch);
|
||||||
|
final bool result =
|
||||||
|
await tryInstall(localPath: bundlePath, appName: app.name);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> uninstallApp(ELinuxApp app, {String userIdentifier}) async {
|
Future<bool> uninstallApp(ELinuxApp app, {String userIdentifier}) async {
|
||||||
return true;
|
return tryUninstall(appName: app.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Source: [AndroidDevice.startApp] in `android_device.dart`
|
/// Source: [AndroidDevice.startApp] in `android_device.dart`
|
||||||
@@ -337,6 +355,51 @@ class ELinuxDevice extends Device {
|
|||||||
finish();
|
finish();
|
||||||
return environment;
|
return environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Source: [tryUninstall] in `custom_device.dart`
|
||||||
|
Future<bool> tryUninstall(
|
||||||
|
{@required String appName,
|
||||||
|
Duration timeout,
|
||||||
|
Map<String, String> additionalReplacementValues =
|
||||||
|
const <String, String>{}}) async {
|
||||||
|
final List<String> interpolated = interpolateCommand(
|
||||||
|
_config.uninstallCommand, <String, String>{'appName': appName},
|
||||||
|
additionalReplacementValues: additionalReplacementValues);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await _processUtils.run(interpolated,
|
||||||
|
throwOnError: true, timeout: timeout);
|
||||||
|
_logger.printStatus('Uninstallation Success: $appName');
|
||||||
|
return true;
|
||||||
|
} on ProcessException catch (e) {
|
||||||
|
_logger.printError(
|
||||||
|
'Error executing uninstall command for custom device $id: $e');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Source: [tryInstall] in `custom_device.dart`
|
||||||
|
Future<bool> tryInstall(
|
||||||
|
{@required String localPath,
|
||||||
|
@required String appName,
|
||||||
|
Duration timeout,
|
||||||
|
Map<String, String> additionalReplacementValues =
|
||||||
|
const <String, String>{}}) async {
|
||||||
|
final List<String> interpolated = interpolateCommand(_config.installCommand,
|
||||||
|
<String, String>{'localPath': localPath, 'appName': appName},
|
||||||
|
additionalReplacementValues: additionalReplacementValues);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await _processUtils.run(interpolated,
|
||||||
|
throwOnError: true, timeout: timeout);
|
||||||
|
_logger.printStatus('Installation Success: $appName ($localPath)');
|
||||||
|
return true;
|
||||||
|
} on ProcessException catch (e) {
|
||||||
|
_logger.printError(
|
||||||
|
'Error executing install command for custom device $id: $e');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ELinuxLogReader extends DeviceLogReader {
|
class ELinuxLogReader extends DeviceLogReader {
|
||||||
|
|||||||
@@ -122,6 +122,7 @@ class ELinuxDeviceDiscovery extends PollingDeviceDiscovery {
|
|||||||
// Adds current desktop host.
|
// Adds current desktop host.
|
||||||
devices.add(
|
devices.add(
|
||||||
ELinuxDevice('elinux-wayland',
|
ELinuxDevice('elinux-wayland',
|
||||||
|
config: null,
|
||||||
desktop: true,
|
desktop: true,
|
||||||
targetArch: _getCurrentHostPlatformArchName(),
|
targetArch: _getCurrentHostPlatformArchName(),
|
||||||
backendType: 'wayland',
|
backendType: 'wayland',
|
||||||
@@ -136,6 +137,7 @@ class ELinuxDeviceDiscovery extends PollingDeviceDiscovery {
|
|||||||
);
|
);
|
||||||
devices.add(
|
devices.add(
|
||||||
ELinuxDevice('elinux-x11',
|
ELinuxDevice('elinux-x11',
|
||||||
|
config: null,
|
||||||
desktop: true,
|
desktop: true,
|
||||||
targetArch: _getCurrentHostPlatformArchName(),
|
targetArch: _getCurrentHostPlatformArchName(),
|
||||||
backendType: 'x11',
|
backendType: 'x11',
|
||||||
@@ -169,6 +171,7 @@ class ELinuxDeviceDiscovery extends PollingDeviceDiscovery {
|
|||||||
if (result.exitCode == 0 &&
|
if (result.exitCode == 0 &&
|
||||||
stdout.contains(remoteDevice.pingSuccessRegex)) {
|
stdout.contains(remoteDevice.pingSuccessRegex)) {
|
||||||
final ELinuxDevice device = ELinuxDevice(remoteDevice.id,
|
final ELinuxDevice device = ELinuxDevice(remoteDevice.id,
|
||||||
|
config: remoteDevice,
|
||||||
desktop: false,
|
desktop: false,
|
||||||
targetArch: remoteDevice.platform,
|
targetArch: remoteDevice.platform,
|
||||||
backendType: remoteDevice.backend,
|
backendType: remoteDevice.backend,
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ abstract class ELinuxApp extends ApplicationPackage {
|
|||||||
factory ELinuxApp.fromPrebuiltApp(FileSystemEntity applicationBinary) {
|
factory ELinuxApp.fromPrebuiltApp(FileSystemEntity applicationBinary) {
|
||||||
return PrebuiltELinuxApp(
|
return PrebuiltELinuxApp(
|
||||||
executable: applicationBinary.path,
|
executable: applicationBinary.path,
|
||||||
|
outputDirectory: applicationBinary.path,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,19 +64,28 @@ abstract class ELinuxApp extends ApplicationPackage {
|
|||||||
String get displayName => id;
|
String get displayName => id;
|
||||||
|
|
||||||
String executable(BuildMode buildMode, String targetArch);
|
String executable(BuildMode buildMode, String targetArch);
|
||||||
|
|
||||||
|
String outputDirectory(BuildMode buildMode, String targetArch);
|
||||||
}
|
}
|
||||||
|
|
||||||
class PrebuiltELinuxApp extends ELinuxApp {
|
class PrebuiltELinuxApp extends ELinuxApp {
|
||||||
PrebuiltELinuxApp({
|
PrebuiltELinuxApp({
|
||||||
@required String executable,
|
@required String executable,
|
||||||
|
@required String outputDirectory,
|
||||||
}) : _executable = executable,
|
}) : _executable = executable,
|
||||||
|
_outputDirectory = outputDirectory,
|
||||||
super(projectBundleId: executable);
|
super(projectBundleId: executable);
|
||||||
|
|
||||||
final String _executable;
|
final String _executable;
|
||||||
|
final String _outputDirectory;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String executable(BuildMode buildMode, String targetArch) => _executable;
|
String executable(BuildMode buildMode, String targetArch) => _executable;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String outputDirectory(BuildMode buildMode, String targetArch) =>
|
||||||
|
_outputDirectory;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get name => _executable;
|
String get name => _executable;
|
||||||
}
|
}
|
||||||
@@ -98,6 +108,16 @@ class BuildableELinuxApp extends ELinuxApp {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String outputDirectory(BuildMode buildMode, String targetArch) {
|
||||||
|
return globals.fs.path.join(
|
||||||
|
'build/elinux/',
|
||||||
|
targetArch,
|
||||||
|
getNameForBuildMode(buildMode),
|
||||||
|
'bundle',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get name => project.parent.manifest.appName;
|
String get name => project.parent.manifest.appName;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user