Skip to content

Commit

Permalink
Merge branch 'rustdesk:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangbo8418 authored Oct 31, 2024
2 parents a2ca95d + 4c12b83 commit e85676e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 75 deletions.
3 changes: 2 additions & 1 deletion flutter/lib/common/widgets/remote_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ class _RawTouchGestureDetectorRegionState
} else {
// mobile
_scale = 1;
bind.sessionSetViewStyle(sessionId: sessionId, value: "");
// No idea why we need to set the view style to "" here.
// bind.sessionSetViewStyle(sessionId: sessionId, value: "");
}
inputModel.sendMouse('up', MouseButtons.left);
}
Expand Down
49 changes: 30 additions & 19 deletions flutter/lib/desktop/pages/desktop_home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,21 @@ class _DesktopHomePageState extends State<DesktopHomePage>
}

buildPasswordBoard(BuildContext context) {
final model = gFFI.serverModel;
return ChangeNotifierProvider.value(
value: gFFI.serverModel,
child: Consumer<ServerModel>(
builder: (context, model, child) {
return buildPasswordBoard2(context, model);
},
));
}

buildPasswordBoard2(BuildContext context, ServerModel model) {
RxBool refreshHover = false.obs;
RxBool editHover = false.obs;
final textColor = Theme.of(context).textTheme.titleLarge?.color;
final showOneTime = model.approveMode != 'click' &&
model.verificationMethod != kUsePermanentPassword;
return Container(
margin: EdgeInsets.only(left: 20.0, right: 16, top: 13, bottom: 13),
child: Row(
Expand Down Expand Up @@ -304,8 +315,7 @@ class _DesktopHomePageState extends State<DesktopHomePage>
Expanded(
child: GestureDetector(
onDoubleTap: () {
if (model.verificationMethod !=
kUsePermanentPassword) {
if (showOneTime) {
Clipboard.setData(
ClipboardData(text: model.serverPasswd.text));
showToast(translate("Copied"));
Expand All @@ -323,22 +333,23 @@ class _DesktopHomePageState extends State<DesktopHomePage>
),
),
),
AnimatedRotationWidget(
onPressed: () => bind.mainUpdateTemporaryPassword(),
child: Tooltip(
message: translate('Refresh Password'),
child: Obx(() => RotatedBox(
quarterTurns: 2,
child: Icon(
Icons.refresh,
color: refreshHover.value
? textColor
: Color(0xFFDDDDDD),
size: 22,
))),
),
onHover: (value) => refreshHover.value = value,
).marginOnly(right: 8, top: 4),
if (showOneTime)
AnimatedRotationWidget(
onPressed: () => bind.mainUpdateTemporaryPassword(),
child: Tooltip(
message: translate('Refresh Password'),
child: Obx(() => RotatedBox(
quarterTurns: 2,
child: Icon(
Icons.refresh,
color: refreshHover.value
? textColor
: Color(0xFFDDDDDD),
size: 22,
))),
),
onHover: (value) => refreshHover.value = value,
).marginOnly(right: 8, top: 4),
if (!bind.isDisableSettings())
InkWell(
child: Tooltip(
Expand Down
38 changes: 14 additions & 24 deletions flutter/lib/mobile/pages/remote_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ class RemotePage extends StatefulWidget {
State<RemotePage> createState() => _RemotePageState(id);
}

class _RemotePageState extends State<RemotePage> {
class _RemotePageState extends State<RemotePage> with WidgetsBindingObserver {
Timer? _timer;
bool _showBar = !isWebDesktop;
bool _showGestureHelp = false;
String _value = '';
Orientation? _currentOrientation;

Timer? _timerDidChangeMetrics;

final _blockableOverlayState = BlockableOverlayState();

final keyboardVisibilityController = KeyboardVisibilityController();
Expand All @@ -57,7 +59,6 @@ class _RemotePageState extends State<RemotePage> {

final TextEditingController _textController =
TextEditingController(text: initText);
bool _lastComposingChangeValid = false;

_RemotePageState(String id) {
initSharedStates(id);
Expand Down Expand Up @@ -97,13 +98,12 @@ class _RemotePageState extends State<RemotePage> {
showToast(translate('Automatically record outgoing sessions'));
}
});
if (isAndroid) {
_textController.addListener(textAndroidListener);
}
WidgetsBinding.instance.addObserver(this);
}

@override
Future<void> dispose() async {
WidgetsBinding.instance.removeObserver(this);
// https://github.com/flutter/flutter/issues/64935
super.dispose();
gFFI.dialogManager.hideMobileActionsOverlay(store: false);
Expand All @@ -115,6 +115,7 @@ class _RemotePageState extends State<RemotePage> {
_physicalFocusNode.dispose();
await gFFI.close();
_timer?.cancel();
_timerDidChangeMetrics?.cancel();
gFFI.dialogManager.dismissAll();
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
overlays: SystemUiOverlay.values);
Expand All @@ -127,16 +128,14 @@ class _RemotePageState extends State<RemotePage> {
// The inner logic of `on_voice_call_closed` will check if the voice call is active.
// Only one client is considered here for now.
gFFI.chatModel.onVoiceCallClosed("End connetion");
if (isAndroid) {
_textController.removeListener(textAndroidListener);
}
}

// This listener is used to handle the composing region changes for Android soft keyboard input.
void textAndroidListener() {
if (_lastComposingChangeValid) {
_handleNonIOSSoftKeyboardInput(_textController.text);
}
@override
void didChangeMetrics() {
_timerDidChangeMetrics?.cancel();
_timerDidChangeMetrics = Timer(Duration(milliseconds: 100), () {
gFFI.canvasModel.updateViewStyle(refreshMousePos: false);
});
}

// to-do: It should be better to use transparent color instead of the bgColor.
Expand Down Expand Up @@ -223,12 +222,6 @@ class _RemotePageState extends State<RemotePage> {
}

void _handleNonIOSSoftKeyboardInput(String newValue) {
_lastComposingChangeValid = _textController.value.isComposingRangeValid;
if (_lastComposingChangeValid && newValue.length > _value.length) {
// Only early return if is composing new words.
// We need to send `backspace` immediately if is deleting letters.
return;
}
var oldValue = _value;
_value = newValue;
if (oldValue.isNotEmpty &&
Expand Down Expand Up @@ -968,11 +961,9 @@ class ImagePaint extends StatelessWidget {
Widget build(BuildContext context) {
final m = Provider.of<ImageModel>(context);
final c = Provider.of<CanvasModel>(context);
final adjust = gFFI.cursorModel.adjustForKeyboard();
var s = c.scale;
return CustomPaint(
painter: ImagePainter(
image: m.image, x: c.x / s, y: (c.y - adjust) / s, scale: s),
painter: ImagePainter(image: m.image, x: c.x / s, y: c.y / s, scale: s),
);
}
}
Expand All @@ -986,7 +977,6 @@ class CursorPaint extends StatelessWidget {
final m = Provider.of<CursorModel>(context);
final c = Provider.of<CanvasModel>(context);
final ffiModel = Provider.of<FfiModel>(context);
final adjust = gFFI.cursorModel.adjustForKeyboard();
final s = c.scale;
double hotx = m.hotx;
double hoty = m.hoty;
Expand Down Expand Up @@ -1022,7 +1012,7 @@ class CursorPaint extends StatelessWidget {
painter: ImagePainter(
image: image,
x: (m.x - hotx) * factor + c.x / s2,
y: (m.y - hoty) * factor + (c.y - adjust) / s2,
y: (m.y - hoty) * factor + c.y / s2,
scale: s2),
);
}
Expand Down
7 changes: 4 additions & 3 deletions flutter/lib/mobile/pages/server_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ class ServerInfo extends StatelessWidget {

@override
Widget build(BuildContext context) {
final isPermanent = model.verificationMethod == kUsePermanentPassword;
final serverModel = Provider.of<ServerModel>(context);

const Color colorPositive = Colors.green;
Expand Down Expand Up @@ -486,6 +485,8 @@ class ServerInfo extends StatelessWidget {
}
}

final showOneTime = serverModel.approveMode != 'click' &&
serverModel.verificationMethod != kUsePermanentPassword;
return PaddingCard(
title: translate('Your Device'),
child: Column(
Expand Down Expand Up @@ -523,10 +524,10 @@ class ServerInfo extends StatelessWidget {
]),
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Text(
isPermanent ? '-' : model.serverPasswd.value.text,
!showOneTime ? '-' : model.serverPasswd.value.text,
style: textStyleValue,
),
isPermanent
!showOneTime
? SizedBox.shrink()
: Row(children: [
IconButton(
Expand Down
37 changes: 11 additions & 26 deletions flutter/lib/models/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1466,10 +1466,14 @@ class CanvasModel with ChangeNotifier {

updateViewStyle({refreshMousePos = true}) async {
Size getSize() {
final size = MediaQueryData.fromWindow(ui.window).size;
final mediaData = MediaQueryData.fromView(ui.window);
final size = mediaData.size;
// If minimized, w or h may be negative here.
double w = size.width - leftToEdge - rightToEdge;
double h = size.height - topToEdge - bottomToEdge;
if (isMobile) {
h -= (mediaData.padding.top + mediaData.viewInsets.bottom);
}
return Size(w < 0 ? 0 : w, h < 0 ? 0 : h);
}

Expand Down Expand Up @@ -1643,13 +1647,9 @@ class CanvasModel with ChangeNotifier {
// (focalPoint.dx - _x_1) / s1 + displayOriginX = (focalPoint.dx - _x_2) / s2 + displayOriginX
// _x_2 = focalPoint.dx - (focalPoint.dx - _x_1) / s1 * s2
_x = focalPoint.dx - (focalPoint.dx - _x) / s * _scale;
final adjustForKeyboard =
parent.target?.cursorModel.adjustForKeyboard() ?? 0.0;
// (focalPoint.dy - _y_1 + adjust) / s1 + displayOriginY = (focalPoint.dy - _y_2 + adjust) / s2 + displayOriginY
// _y_2 = focalPoint.dy + adjust - (focalPoint.dy - _y_1 + adjust) / s1 * s2
_y = focalPoint.dy +
adjustForKeyboard -
(focalPoint.dy - _y + adjustForKeyboard) / s * _scale;
// (focalPoint.dy - _y_1) / s1 + displayOriginY = (focalPoint.dy - _y_2) / s2 + displayOriginY
// _y_2 = focalPoint.dy - (focalPoint.dy - _y_1) / s1 * s2
_y = focalPoint.dy - (focalPoint.dy - _y) / s * _scale;
notifyListeners();
}

Expand Down Expand Up @@ -1883,7 +1883,6 @@ class CursorModel with ChangeNotifier {
// `lastIsBlocked` is only used in common/widgets/remote_input.dart -> _RawTouchGestureDetectorRegionState -> onDoubleTap()
// Because onDoubleTap() doesn't have the `event` parameter, we can't get the touch event's position.
bool _lastIsBlocked = false;
double _yForKeyboardAdjust = 0;

keyHelpToolsVisibilityChanged(Rect? r) {
_keyHelpToolsRect = r;
Expand All @@ -1895,7 +1894,6 @@ class CursorModel with ChangeNotifier {
// `lastIsBlocked` will be set when the cursor is moving or touch somewhere else.
_lastIsBlocked = true;
}
_yForKeyboardAdjust = _y;
}

get lastIsBlocked => _lastIsBlocked;
Expand Down Expand Up @@ -1947,19 +1945,6 @@ class CursorModel with ChangeNotifier {
get keyboardHeight => MediaQueryData.fromWindow(ui.window).viewInsets.bottom;
get scale => parent.target?.canvasModel.scale ?? 1.0;

double adjustForKeyboard() {
if (keyboardHeight < 100) {
return 0.0;
}

final m = MediaQueryData.fromWindow(ui.window);
final size = m.size;
final thresh = (size.height - keyboardHeight) / 2;
final h = (_yForKeyboardAdjust - getVisibleRect().top) *
scale; // local physical display height
return h - thresh;
}

// mobile Soft keyboard, block touch event from the KeyHelpTools
shouldBlock(double x, double y) {
if (!(parent.target?.ffiModel.touchMode ?? false)) {
Expand All @@ -1980,16 +1965,16 @@ class CursorModel with ChangeNotifier {
return false;
}
_lastIsBlocked = false;
moveLocal(x, y, adjust: adjustForKeyboard());
moveLocal(x, y);
parent.target?.inputModel.moveMouse(_x, _y);
return true;
}

moveLocal(double x, double y, {double adjust = 0}) {
moveLocal(double x, double y) {
final xoffset = parent.target?.canvasModel.x ?? 0;
final yoffset = parent.target?.canvasModel.y ?? 0;
_x = (x - xoffset) / scale + _displayOriginX;
_y = (y - yoffset + adjust) / scale + _displayOriginY;
_y = (y - yoffset) / scale + _displayOriginY;
notifyListeners();
}

Expand Down
5 changes: 3 additions & 2 deletions src/ui/index.tis
Original file line number Diff line number Diff line change
Expand Up @@ -831,11 +831,12 @@ class PasswordEyeArea : Reactor.Component {
render() {
var method = handler.get_option('verification-method');
var mode= handler.get_option('approve-mode');
var value = mode == 'click' || method == 'use-permanent-password' ? "-" : password_cache[0];
var hide_one_time = mode == 'click' || method == 'use-permanent-password';
var value = hide_one_time ? "-" : password_cache[0];
return
<div .eye-area style="width: *">
<input|text @{this.input} readonly value={value} />
{svg_refresh_password}
{hide_one_time ? "" : svg_refresh_password}
</div>;
}

Expand Down

0 comments on commit e85676e

Please sign in to comment.