Skip to content
Open
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/remote_frame_buffer_client_isolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ Future<void> startRemoteFrameBufferClient(
hostname: initMessage.hostName,
password: initMessage.password.toNullable(),
port: initMessage.port,
timeout: initMessage.timeout,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: the current client implementation does not have a timeout parameter. Are you planing on creating a PR in that project as well?

);

client
..handleIncomingMessages()
..requestUpdate();
Expand Down
94 changes: 54 additions & 40 deletions lib/src/remote_frame_buffer_gesture_detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,51 +76,65 @@ class RemoteFrameBufferGestureDetector extends GestureDetector {
GestureTapDownCallback? get onTapDown =>
(final TapDownDetails details) => _sendPort.match(
() {},
(final SendPort sendPort) => sendPort.send(
RemoteFrameBufferIsolateSendMessage.pointerEvent(
button1Down: true,
button2Down: false,
button3Down: false,
button4Down: false,
button5Down: false,
button6Down: false,
button7Down: false,
button8Down: false,
x: (details.localPosition.dx /
_remoteFrameBufferWidgetSize.width *
_image.width)
.toInt(),
y: (details.localPosition.dy /
_remoteFrameBufferWidgetSize.height *
_image.height)
.toInt(),
),
),
(final SendPort sendPort) {
num x = details.localPosition.dx /
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
num x = details.localPosition.dx /
final num x = details.localPosition.dx /

_remoteFrameBufferWidgetSize.width *
_image.width;
num y = details.localPosition.dy /
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
num y = details.localPosition.dy /
final num y = details.localPosition.dy /

_remoteFrameBufferWidgetSize.height *
_image.height;

if (x.isInfinite || y.isInfinite) {
return;
}

sendPort.send(
RemoteFrameBufferIsolateSendMessage.pointerEvent(
button1Down: true,
button2Down: false,
button3Down: false,
button4Down: false,
button5Down: false,
button6Down: false,
button7Down: false,
button8Down: false,
x: x.toInt(),
y: y.toInt(),
),
);
},
);

@override
GestureTapUpCallback? get onTapUp =>
(final TapUpDetails details) => _sendPort.match(
() {},
(final SendPort sendPort) => sendPort.send(
RemoteFrameBufferIsolateSendMessage.pointerEvent(
button1Down: false,
button2Down: false,
button3Down: false,
button4Down: false,
button5Down: false,
button6Down: false,
button7Down: false,
button8Down: false,
x: (details.localPosition.dx /
_remoteFrameBufferWidgetSize.width *
_image.width)
.toInt(),
y: (details.localPosition.dy /
_remoteFrameBufferWidgetSize.height *
_image.height)
.toInt(),
),
),
(final SendPort sendPort) {
num x = details.localPosition.dx /
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
num x = details.localPosition.dx /
final num x = details.localPosition.dx /

_remoteFrameBufferWidgetSize.width *
_image.width;
num y = details.localPosition.dy /
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
num y = details.localPosition.dy /
final num y = details.localPosition.dy /

_remoteFrameBufferWidgetSize.height *
_image.height;

if (x.isInfinite || y.isInfinite) {
return;
}

sendPort.send(
RemoteFrameBufferIsolateSendMessage.pointerEvent(
button1Down: false,
button2Down: false,
button3Down: false,
button4Down: false,
button5Down: false,
button6Down: false,
button7Down: false,
button8Down: false,
x: x.toInt(),
y: y.toInt(),
),
);
},
);
}
1 change: 1 addition & 0 deletions lib/src/remote_frame_buffer_isolate_messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class RemoteFrameBufferIsolateInitMessage
required final String hostName,
required final Option<String> password,
required final int port,
required final Duration? timeout,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: I want to avoid all null-aware code in this package. My suggestion would be to make this an Option<Duration> instead.


/// The [SendPort] used for communicating with the caller.
required final SendPort sendPort,
Expand Down
41 changes: 35 additions & 6 deletions lib/src/remote_frame_buffer_isolate_messages.freezed.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 56 additions & 12 deletions lib/src/remote_frame_buffer_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class RemoteFrameBufferWidget extends StatefulWidget {
final Option<void Function(Object error)> _onError;
final Option<String> _password;
final int _port;
final Option<ValueNotifier<Map<String, dynamic>>> _keyEventNotifier;
final Option<bool> _monitorClipBoard;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: can't this be a simple bool? Makes the using code a lot shorter and more readable as well.

final Duration? _timeout;

/// Immediately tries to establish a connection to a remote server at
/// [hostName]:[port], optionally using [password].
Expand All @@ -36,11 +39,17 @@ class RemoteFrameBufferWidget extends StatefulWidget {
final void Function(Object error)? onError,
final String? password,
final int port = 5900,
final ValueNotifier<Map<String, dynamic>>? keyEventNotifier,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: is it a usecase that you need right now? Knowing from outside of this widget, which keys are being pressed? I'd expect that you would just add a surrounding RawKeyboardListener widget (https://api.flutter.dev/flutter/widgets/RawKeyboardListener-class.html) to achieve this.

final bool? monitorClipBoard = true,
final Duration? timeout,
}) : _connectingWidget = optionOf(connectingWidget),
_hostName = hostName,
_onError = optionOf(onError),
_password = optionOf(password),
_port = port;
_port = port,
_keyEventNotifier = optionOf(keyEventNotifier),
_monitorClipBoard = optionOf(monitorClipBoard),
_timeout = timeout;

@override
State<RemoteFrameBufferWidget> createState() =>
Expand Down Expand Up @@ -77,7 +86,9 @@ class RemoteFrameBufferWidgetState extends State<RemoteFrameBufferWidget> {

@override
void dispose() {
_clipBoardMonitorTimer.cancel();
if (widget._monitorClipBoard.getOrElse(() => false)) {
_clipBoardMonitorTimer.cancel();
}
_streamSubscription.match(
() {},
(final StreamSubscription<Object?> subscription) =>
Expand All @@ -91,14 +102,26 @@ class RemoteFrameBufferWidgetState extends State<RemoteFrameBufferWidget> {
() {},
(final Isolate isolate) => isolate.kill(),
);
widget._keyEventNotifier.match(
() {},
(final ValueNotifier<Map<String, dynamic>> notifier) =>
notifier.removeListener(_keyEventListener),
);
RawKeyboard.instance.removeListener(_rawKeyEventListener);
super.dispose();
}

@override
void initState() {
super.initState();
_monitorClipBoard();
if (widget._monitorClipBoard.getOrElse(() => false)) {
_monitorClipBoard();
}
widget._keyEventNotifier.match(
() {},
(final ValueNotifier<Map<String, dynamic>> notifier) =>
notifier.addListener(_keyEventListener),
);
RawKeyboard.instance.addListener(_rawKeyEventListener);
unawaited(_initAsync());
}
Expand Down Expand Up @@ -277,6 +300,7 @@ class RemoteFrameBufferWidgetState extends State<RemoteFrameBufferWidget> {
hostName: widget._hostName,
password: widget._password,
port: widget._port,
timeout: widget._timeout,
sendPort: receivePort.sendPort,
),
onError: receivePort.sendPort,
Expand Down Expand Up @@ -316,16 +340,36 @@ class RemoteFrameBufferWidgetState extends State<RemoteFrameBufferWidget> {
);
}

void _rawKeyEventListener(final RawKeyEvent rawKeyEvent) =>
_isolateSendPort.match(
() {},
(final SendPort sendPort) => sendPort.send(
RemoteFrameBufferIsolateSendMessage.keyEvent(
down: rawKeyEvent.isKeyPressed(rawKeyEvent.logicalKey),
key: rawKeyEvent.logicalKey.asXWindowSystemKey(),
),
void _keyEventListener() {
_isolateSendPort.match(
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format: I prefer those one-liners to be expression methods.

() {},
(final SendPort sendPort) {
widget._keyEventNotifier.match(() => null,
(final ValueNotifier<Map<String, dynamic>> notifier) {
final Map<String, dynamic> event = notifier.value;
final LogicalKeyboardKey keyboardKey = event['keyboardKey'];
sendPort.send(
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: aren't we sending key events twice now?

RemoteFrameBufferIsolateSendMessage.keyEvent(
down: event['isDown'],
key: keyboardKey.asXWindowSystemKey(),
),
);
});
},
);
}

void _rawKeyEventListener(final RawKeyEvent rawKeyEvent) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format: I prefer those one-liners to be expression methods.

_isolateSendPort.match(
() {},
(final SendPort sendPort) => sendPort.send(
RemoteFrameBufferIsolateSendMessage.keyEvent(
down: rawKeyEvent.isKeyPressed(rawKeyEvent.logicalKey),
key: rawKeyEvent.logicalKey.asXWindowSystemKey(),
),
);
),
);
}

/// Updates [frameBuffer] with the given [rectangle]s.
@visibleForTesting
Expand Down