Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

fix, flutter, keyboard mode

fufesou4a9e7f29da0b
diff --git a/flutter/lib/desktop/widgets/remote_toolbar.dart b/flutter/lib/desktop/widgets/remote_toolbar.dart
index e38aa9546..1ae380761 100644
--- a/flutter/lib/desktop/widgets/remote_toolbar.dart
+++ b/flutter/lib/desktop/widgets/remote_toolbar.dart
@@ -1628,6 +1628,7 @@ class _KeyboardMenu extends StatelessWidget {
if (value == null) return;
await bind.sessionSetKeyboardMode(
sessionId: ffi.sessionId, value: value);
+ await ffi.inputModel.updateKeyboardMode();
}
for (InputModeMenu mode in modes) {
@@ -1704,6 +1705,7 @@ class _KeyboardMenu extends StatelessWidget {
if (v != null) {
await stateGlobal.setInputSource(ffi.sessionId, v);
await ffi.ffiModel.checkDesktopKeyboardMode();
+ await ffi.inputModel.updateKeyboardMode();
}
}
: null,
diff --git a/flutter/lib/models/input_model.dart b/flutter/lib/models/input_model.dart
index 322897145..458ccf3ad 100644
--- a/flutter/lib/models/input_model.dart
+++ b/flutter/lib/models/input_model.dart
@@ -159,7 +159,7 @@ class ToReleaseKeys {
class InputModel {
final WeakReference<FFI> parent;
- String keyboardMode = "legacy";
+ String keyboardMode = '';
// keyboard
var shift = false;
@@ -194,6 +194,24 @@ class InputModel {
InputModel(this.parent) {
sessionId = parent.target!.sessionId;
+
+ // It is ok to call updateKeyboardMode() directly.
+ // Because `bind` is initialized in `PlatformFFI.init()` which is called very early.
+ // But we still wrap it in a Future.delayed() to make it more clear.
+ Future.delayed(Duration(milliseconds: 100), () {
+ updateKeyboardMode();
+ });
+ }
+
+ updateKeyboardMode() async {
+ // * Currently mobile does not enable map mode
+ if (isDesktop) {
+ if (keyboardMode.isEmpty) {
+ keyboardMode =
+ await bind.sessionGetKeyboardMode(sessionId: sessionId) ??
+ kKeyLegacyMode;
+ }
+ }
}
KeyEventResult handleRawKeyEvent(RawKeyEvent e) {
@@ -201,13 +219,6 @@ class InputModel {
return KeyEventResult.handled;
}
- // * Currently mobile does not enable map mode
- if (isDesktop) {
- bind.sessionGetKeyboardMode(sessionId: sessionId).then((result) {
- keyboardMode = result.toString();
- });
- }
-
final key = e.logicalKey;
if (e is RawKeyDownEvent) {
if (!e.repeat) {