Skip to content

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

refact: web, keyboard, translate mode (#9432)

fufesouf5354069628b
diff --git a/flutter/lib/models/input_model.dart b/flutter/lib/models/input_model.dart
index ac78e1730..b57048a08 100644
--- a/flutter/lib/models/input_model.dart
+++ b/flutter/lib/models/input_model.dart
@@ -469,8 +469,12 @@ class InputModel {
KeyEventResult handleRawKeyEvent(RawKeyEvent e) {
if (isViewOnly) return KeyEventResult.handled;
- if ((isDesktop || isWebDesktop) && !isInputSourceFlutter) {
- return KeyEventResult.handled;
+ if (!isInputSourceFlutter) {
+ if (isDesktop) {
+ return KeyEventResult.handled;
+ } else if (isWeb) {
+ return KeyEventResult.ignored;
+ }
}
final key = e.logicalKey;
@@ -519,8 +523,12 @@ class InputModel {
KeyEventResult handleKeyEvent(KeyEvent e) {
if (isViewOnly) return KeyEventResult.handled;
- if ((isDesktop || isWebDesktop) && !isInputSourceFlutter) {
- return KeyEventResult.handled;
+ if (!isInputSourceFlutter) {
+ if (isDesktop) {
+ return KeyEventResult.handled;
+ } else if (isWeb) {
+ return KeyEventResult.ignored;
+ }
}
if (isWindows || isLinux) {
// Ignore meta keys. Because flutter window will loose focus if meta key is pressed.
diff --git a/flutter/lib/web/bridge.dart b/flutter/lib/web/bridge.dart
index c952c55d2..d28e0c26a 100644
--- a/flutter/lib/web/bridge.dart
+++ b/flutter/lib/web/bridge.dart
@@ -352,7 +352,11 @@ class RustdeskImpl {
bool sessionIsKeyboardModeSupported(
{required UuidValue sessionId, required String mode, dynamic hint}) {
- return [kKeyLegacyMode, kKeyMapMode].contains(mode);
+ if (mainGetInputSource(hint: hint) == 'Input source 1') {
+ return [kKeyMapMode, kKeyTranslateMode].contains(mode);
+ } else {
+ return [kKeyLegacyMode, kKeyMapMode].contains(mode);
+ }
}
bool sessionIsMultiUiSession({required UuidValue sessionId, dynamic hint}) {
@@ -429,7 +433,7 @@ class RustdeskImpl {
void sessionEnterOrLeave(
{required UuidValue sessionId, required bool enter, dynamic hint}) {
- throw UnimplementedError();
+ js.context.callMethod('setByName', ['enter_or_leave', enter]);
}
Future<void> sessionInputKey(
@@ -846,16 +850,21 @@ class RustdeskImpl {
}
String mainGetInputSource({dynamic hint}) {
- // // rdev grab mode
- // const CONFIG_INPUT_SOURCE_1 = "Input source 1";
+ final inputSource =
+ js.context.callMethod('getByName', ['option:local', 'input-source']);
+ // // js grab mode
+ // export const CONFIG_INPUT_SOURCE_1 = "Input source 1";
// // flutter grab mode
- // const CONFIG_INPUT_SOURCE_2 = "Input source 2";
- return 'Input source 2';
+ // export const CONFIG_INPUT_SOURCE_2 = "Input source 2";
+ return inputSource != '' ? inputSource : 'Input source 1';
}
Future<void> mainSetInputSource(
{required UuidValue sessionId, required String value, dynamic hint}) {
- return Future.value();
+ return Future(() => js.context.callMethod('setByName', [
+ 'option:local',
+ jsonEncode({'name': 'input-source', 'value': value})
+ ]));
}
Future<String> mainGetMyId({dynamic hint}) {
@@ -1610,6 +1619,7 @@ class RustdeskImpl {
String mainSupportedInputSource({dynamic hint}) {
return jsonEncode([
+ ['Input source 1', 'input_source_1_tip'],
['Input source 2', 'input_source_2_tip']
]);
}
diff --git a/flutter/lib/web/common.dart b/flutter/lib/web/common.dart
index 0f3a99681..4d539d5d4 100644
--- a/flutter/lib/web/common.dart
+++ b/flutter/lib/web/common.dart
@@ -1,5 +1,7 @@
import 'dart:js' as js;
import 'dart:html' as html;
+// cycle imports, maybe we can improve this
+import 'package:flutter_hbb/consts.dart';
final isAndroid_ = false;
final isIOS_ = false;
@@ -13,8 +15,7 @@ final isDesktop_ = false;
String get screenInfo_ => js.context.callMethod('getByName', ['screen_info']);
-final _userAgent = html.window.navigator.userAgent.toLowerCase();
-
-final isWebOnWindows_ = _userAgent.contains('win');
-final isWebOnLinux_ = _userAgent.contains('linux');
-final isWebOnMacOS_ = _userAgent.contains('mac');
+final _localOs = js.context.callMethod('getByName', ['local_os', '']);
+final isWebOnWindows_ = _localOs == kPeerPlatformWindows;
+final isWebOnLinux_ = _localOs == kPeerPlatformLinux;
+final isWebOnMacOS_ = _localOs == kPeerPlatformMacOS;