-
Notifications
You must be signed in to change notification settings - Fork 10
error handling and add custom keyboard key listener #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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 / | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| _remoteFrameBufferWidgetSize.width * | ||||||
| _image.width; | ||||||
| num y = details.localPosition.dy / | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| _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 / | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| _remoteFrameBufferWidgetSize.width * | ||||||
| _image.width; | ||||||
| num y = details.localPosition.dy / | ||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| _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(), | ||||||
| ), | ||||||
| ); | ||||||
| }, | ||||||
| ); | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ class RemoteFrameBufferIsolateInitMessage | |
| required final String hostName, | ||
| required final Option<String> password, | ||
| required final int port, | ||
| required final Duration? timeout, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| /// The [SendPort] used for communicating with the caller. | ||
| required final SendPort sendPort, | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: can't this be a simple |
||
| final Duration? _timeout; | ||
|
|
||
| /// Immediately tries to establish a connection to a remote server at | ||
| /// [hostName]:[port], optionally using [password]. | ||
|
|
@@ -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, | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| 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() => | ||
|
|
@@ -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) => | ||
|
|
@@ -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()); | ||
| } | ||
|
|
@@ -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, | ||
|
|
@@ -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( | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
There was a problem hiding this comment.
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
timeoutparameter. Are you planing on creating a PR in that project as well?