Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/src/cli/commands/devices.dart
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ class DevicesAddCommand extends FlutterpiCommand {
usesDummyDisplayArg();
usesSshRemoteNonOptionArg();
usesFilesystemLayoutArg();
usesRotationArg();
}

@override
Expand Down Expand Up @@ -500,6 +501,7 @@ class DevicesAddCommand extends FlutterpiCommand {
useDummyDisplay: useDummyDisplay,
dummyDisplaySize: dummyDisplaySize,
filesystemLayout: fsLayout,
rotation: rotation?.toInt(),
),
);

Expand Down
31 changes: 31 additions & 0 deletions lib/src/cli/flutterpi_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ mixin FlutterpiCommandMixin on fl.FlutterCommand {
);
}

void usesRotationArg() {
argParser.addOption(
'rotation',
help: 'The rotation of the display in degrees. (0, 90, 180, 270)',
valueHelp: 'degrees',
allowed: ['0', '90', '180', '270'],
);
}

(int, int)? get displaySize {
final size = stringArg('display-size');
if (size == null) {
Expand Down Expand Up @@ -232,6 +241,28 @@ mixin FlutterpiCommandMixin on fl.FlutterCommand {
return remote.contains('@') ? remote.split('@').first : null;
}

int? get rotation {
final rotationArg = stringArg('rotation');
if (rotationArg == null) {
return null;
}

switch (rotationArg) {
case '0':
return 0;
case '90':
return 90;
case '180':
return 180;
case '270':
return 270;
default:
usageException(
'Invalid --rotation: Expected one of "0", "90", "180", or "270".',
);
}
}

final _contextOverrides = <Type, dynamic Function()>{};

void addContextOverride<T>(dynamic Function() fn) {
Expand Down
8 changes: 7 additions & 1 deletion lib/src/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class DeviceConfigEntry {
this.useDummyDisplay = false,
this.dummyDisplaySize,
this.filesystemLayout = FilesystemLayout.flutterPi,
this.rotation,
});

final String id;
Expand All @@ -24,6 +25,7 @@ class DeviceConfigEntry {
final bool useDummyDisplay;
final (int, int)? dummyDisplaySize;
final FilesystemLayout filesystemLayout;
final int? rotation;

static DeviceConfigEntry fromMap(Map<String, dynamic> map) {
return DeviceConfigEntry(
Expand All @@ -45,6 +47,7 @@ class DeviceConfigEntry {
String string => FilesystemLayout.fromString(string),
_ => FilesystemLayout.flutterPi,
},
rotation: (map['rotation'] as num?)?.toInt(),
);
}

Expand All @@ -63,6 +66,7 @@ class DeviceConfigEntry {
'dummyDisplaySize': [width, height],
if (filesystemLayout != FilesystemLayout.flutterPi)
'filesystemLayout': filesystemLayout.toString(),
if (rotation case int rotation) 'rotation': rotation,
};
}

Expand All @@ -82,7 +86,8 @@ class DeviceConfigEntry {
devicePixelRatio == otherEntry.devicePixelRatio &&
useDummyDisplay == otherEntry.useDummyDisplay &&
dummyDisplaySize == otherEntry.dummyDisplaySize &&
filesystemLayout == otherEntry.filesystemLayout;
filesystemLayout == otherEntry.filesystemLayout &&
rotation == otherEntry.rotation;
}

@override
Expand All @@ -96,6 +101,7 @@ class DeviceConfigEntry {
useDummyDisplay,
dummyDisplaySize,
filesystemLayout,
rotation,
);

@override
Expand Down
12 changes: 11 additions & 1 deletion lib/src/devices/flutterpi_ssh/device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,21 @@ class FlutterpiArgs {
this.useDummyDisplay = false,
this.dummyDisplaySize,
this.filesystemLayout = FilesystemLayout.flutterPi,
});
this.rotation,
}) : assert(
rotation == null ||
rotation == 0 ||
rotation == 90 ||
rotation == 180 ||
rotation == 270,
'Rotation must be one of: 0, 90, 180, 270 degrees if non-null.',
);

final (int, int)? explicitDisplaySizeMillimeters;
final bool useDummyDisplay;
final (int, int)? dummyDisplaySize;
final FilesystemLayout filesystemLayout;
final int? rotation;
}

class FlutterpiSshDevice extends fl.Device {
Expand Down Expand Up @@ -392,6 +401,7 @@ class FlutterpiSshDevice extends fl.Device {
if (args.useDummyDisplay) '--dummy-display',
if (args.dummyDisplaySize case (final width, final height))
'--dummy-display-size=$width,$height',
if (args.rotation != null) '--rotation=${args.rotation}',
if (runtimeModeArg != null) runtimeModeArg,
bundlePath,
...engineArgs,
Expand Down
1 change: 1 addition & 0 deletions lib/src/devices/flutterpi_ssh/device_discovery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class FlutterpiSshDeviceDiscovery extends PollingDeviceDiscovery {
useDummyDisplay: configEntry.useDummyDisplay,
dummyDisplaySize: configEntry.dummyDisplaySize,
filesystemLayout: configEntry.filesystemLayout,
rotation: configEntry.rotation,
),
);
}
Expand Down
180 changes: 180 additions & 0 deletions test/commands/devices_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:args/command_runner.dart';
import 'package:file/memory.dart';
import 'package:file/src/interface/file_system.dart';

Expand Down Expand Up @@ -783,6 +784,185 @@ void main() {
});
});

group('rotation', () {
test('default (0 degrees)', () async {
var addDeviceWasCalled = false;
config
..addDeviceFn = (entry) {
expect(
entry,
src.DeviceConfigEntry(
id: 'test-device',
sshExecutable: null,
sshRemote: 'test-device',
remoteInstallPath: null,
rotation: 0,
),
);
addDeviceWasCalled = true;
}
..containsDeviceFn = (id) {
return false;
};

await _runInTestContext(() async {
await runner.run(['devices', 'add', 'test-device', '--rotation=0']);
});

expect(
addDeviceWasCalled,
isTrue,
reason: 'addDeviceFn should have been called',
);
});

test('90 degrees', () async {
var addDeviceWasCalled = false;
config
..addDeviceFn = (entry) {
expect(
entry,
src.DeviceConfigEntry(
id: 'test-device',
sshExecutable: null,
sshRemote: 'test-device',
remoteInstallPath: null,
filesystemLayout: FilesystemLayout.flutterPi,
rotation: 90,
),
);
addDeviceWasCalled = true;
}
..containsDeviceFn = (id) {
return false;
};

await _runInTestContext(() async {
await runner.run(['devices', 'add', 'test-device', '--rotation=90']);
});
expect(
addDeviceWasCalled,
isTrue,
reason: 'addDeviceFn should have been called',
);
});

test('180 degrees', () async {
var addDeviceWasCalled = false;
config
..addDeviceFn = (entry) {
expect(
entry,
src.DeviceConfigEntry(
id: 'test-device',
sshExecutable: null,
sshRemote: 'test-device',
remoteInstallPath: null,
filesystemLayout: FilesystemLayout.flutterPi,
rotation: 180,
),
);
addDeviceWasCalled = true;
}
..containsDeviceFn = (id) {
return false;
};

await _runInTestContext(() async {
await runner.run(['devices', 'add', 'test-device', '--rotation=180']);
});

expect(
addDeviceWasCalled,
isTrue,
reason: 'addDeviceFn should have been called',
);
});

test('270 degrees', () async {
var addDeviceWasCalled = false;
config
..addDeviceFn = (entry) {
expect(
entry,
src.DeviceConfigEntry(
id: 'test-device',
sshExecutable: null,
sshRemote: 'test-device',
remoteInstallPath: null,
filesystemLayout: FilesystemLayout.flutterPi,
rotation: 270,
),
);
addDeviceWasCalled = true;
}
..containsDeviceFn = (id) {
return false;
};

await _runInTestContext(() async {
await runner.run(['devices', 'add', 'test-device', '--rotation=270']);
});

expect(
addDeviceWasCalled,
isTrue,
reason: 'addDeviceFn should have been called',
);
});

test('without rotation flag (should be null)', () async {
var addDeviceWasCalled = false;
config
..addDeviceFn = (entry) {
expect(
entry,
src.DeviceConfigEntry(
id: 'test-device',
sshExecutable: null,
sshRemote: 'test-device',
remoteInstallPath: null,
filesystemLayout: FilesystemLayout.flutterPi,
rotation: null, // No rotation specified
),
);
addDeviceWasCalled = true;
}
..containsDeviceFn = (id) {
return false;
};

await _runInTestContext(() async {
await runner.run(['devices', 'add', 'test-device']);
});

expect(
addDeviceWasCalled,
isTrue,
reason: 'addDeviceFn should have been called',
);
});
test('179 degrees (should fail - invalid value)', () async {
config
..addDeviceFn = (entry) {
fail(
'addDeviceFn should not have been called with invalid rotation',
);
}
..containsDeviceFn = (id) {
return false;
};

await _runInTestContext(() async {
expect(
() async => await runner
.run(['devices', 'add', 'test-device', '--rotation=179']),
throwsA(isA<UsageException>()),
);
});
});
});

group('diagnostics', () {
test('attempts connecting to new device', () async {
var tryConnectWasCalled = false;
Expand Down