2020-11-17 01:22:14 +08:00
|
|
|
|
import 'package:flutter/material.dart';
|
2022-02-24 18:24:52 +08:00
|
|
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
2022-02-28 16:11:21 +08:00
|
|
|
|
import 'package:flutter_hbb/main.dart';
|
2022-02-23 21:32:33 +08:00
|
|
|
|
import 'package:flutter_hbb/widgets/gesture_help.dart';
|
2020-11-18 23:15:59 +08:00
|
|
|
|
import 'package:provider/provider.dart';
|
2020-11-17 01:22:14 +08:00
|
|
|
|
import 'package:flutter/services.dart';
|
2020-11-17 11:12:55 +08:00
|
|
|
|
import 'dart:ui' as ui;
|
2020-11-17 12:08:31 +08:00
|
|
|
|
import 'dart:async';
|
2020-11-20 17:20:42 +08:00
|
|
|
|
import 'package:tuple/tuple.dart';
|
2020-11-23 13:03:51 +08:00
|
|
|
|
import 'package:wakelock/wakelock.dart';
|
2022-02-28 18:29:25 +08:00
|
|
|
|
import '../common.dart';
|
|
|
|
|
import '../gestures.dart';
|
|
|
|
|
import '../models/model.dart';
|
2020-11-17 01:22:14 +08:00
|
|
|
|
|
2020-11-28 18:06:27 +08:00
|
|
|
|
final initText = '\1' * 1024;
|
|
|
|
|
|
2020-11-17 01:22:14 +08:00
|
|
|
|
class RemotePage extends StatefulWidget {
|
2022-02-17 15:22:14 +08:00
|
|
|
|
RemotePage({Key? key, required this.id}) : super(key: key);
|
2020-11-17 01:22:14 +08:00
|
|
|
|
|
|
|
|
|
final String id;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_RemotePageState createState() => _RemotePageState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _RemotePageState extends State<RemotePage> {
|
2022-02-17 15:22:14 +08:00
|
|
|
|
Timer? _interval;
|
|
|
|
|
Timer? _timer;
|
2022-02-06 16:29:56 +08:00
|
|
|
|
bool _showBar = !isDesktop;
|
2020-11-20 17:20:42 +08:00
|
|
|
|
double _bottom = 0;
|
2020-11-25 16:28:46 +08:00
|
|
|
|
String _value = '';
|
2020-11-23 23:18:42 +08:00
|
|
|
|
double _scale = 1;
|
2022-02-17 18:00:44 +08:00
|
|
|
|
|
2020-12-24 10:44:44 +08:00
|
|
|
|
var _more = true;
|
2020-11-25 16:28:46 +08:00
|
|
|
|
var _fn = false;
|
2020-11-20 17:51:49 +08:00
|
|
|
|
final FocusNode _focusNode = FocusNode();
|
2021-09-01 01:35:01 +08:00
|
|
|
|
var _showEdit = false;
|
2020-11-27 16:06:35 +08:00
|
|
|
|
var _reconnects = 1;
|
2021-08-21 17:18:14 +08:00
|
|
|
|
var _touchMode = false;
|
2020-11-17 12:08:31 +08:00
|
|
|
|
|
2020-11-17 11:12:55 +08:00
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
FFI.connect(widget.id);
|
2022-02-17 15:22:14 +08:00
|
|
|
|
WidgetsBinding.instance!.addPostFrameCallback((_) {
|
2022-02-24 18:24:52 +08:00
|
|
|
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
|
2022-02-28 16:11:21 +08:00
|
|
|
|
showLoading(translate('Connecting...'));
|
2020-11-17 12:08:31 +08:00
|
|
|
|
_interval =
|
|
|
|
|
Timer.periodic(Duration(milliseconds: 30), (timer) => interval());
|
|
|
|
|
});
|
2020-11-23 12:00:56 +08:00
|
|
|
|
Wakelock.enable();
|
2021-08-21 17:18:14 +08:00
|
|
|
|
_touchMode = FFI.getByName('peer_option', "touch-mode") != '';
|
2020-11-17 12:08:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
2020-11-20 17:51:49 +08:00
|
|
|
|
_focusNode.dispose();
|
2020-11-28 18:06:27 +08:00
|
|
|
|
FFI.close();
|
2022-02-17 15:22:14 +08:00
|
|
|
|
_interval?.cancel();
|
2020-11-27 16:06:35 +08:00
|
|
|
|
_timer?.cancel();
|
2022-02-28 16:11:21 +08:00
|
|
|
|
EasyLoading.dismiss();
|
2022-02-24 18:24:52 +08:00
|
|
|
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
|
|
|
|
|
overlays: SystemUiOverlay.values);
|
2020-11-23 12:00:56 +08:00
|
|
|
|
Wakelock.disable();
|
2021-08-18 02:01:03 +08:00
|
|
|
|
super.dispose();
|
2020-11-17 12:08:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-25 16:28:46 +08:00
|
|
|
|
void resetTool() {
|
|
|
|
|
FFI.resetModifiers();
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-01 01:35:01 +08:00
|
|
|
|
bool isKeyboardShown() {
|
|
|
|
|
return _bottom >= 100;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-24 18:24:52 +08:00
|
|
|
|
// crash on web before widget initiated.
|
2022-01-26 19:00:23 +08:00
|
|
|
|
void intervalUnsafe() {
|
2020-11-20 17:20:42 +08:00
|
|
|
|
var v = MediaQuery.of(context).viewInsets.bottom;
|
|
|
|
|
if (v != _bottom) {
|
2020-11-25 16:28:46 +08:00
|
|
|
|
resetTool();
|
2020-11-20 17:20:42 +08:00
|
|
|
|
setState(() {
|
|
|
|
|
_bottom = v;
|
2020-11-25 16:28:46 +08:00
|
|
|
|
if (v < 100) {
|
2022-02-24 18:24:52 +08:00
|
|
|
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
|
|
|
|
|
overlays: []);
|
2020-11-20 17:20:42 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-02-24 18:24:52 +08:00
|
|
|
|
FFI.ffiModel.update(widget.id, context, handleMsgBox);
|
2020-11-19 21:59:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-26 19:00:23 +08:00
|
|
|
|
void interval() {
|
|
|
|
|
try {
|
|
|
|
|
intervalUnsafe();
|
|
|
|
|
} catch (e) {}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-24 18:24:52 +08:00
|
|
|
|
void handleMsgBox(Map<String, dynamic> evt, String id) {
|
2020-11-19 21:59:49 +08:00
|
|
|
|
var type = evt['type'];
|
|
|
|
|
var title = evt['title'];
|
|
|
|
|
var text = evt['text'];
|
|
|
|
|
if (type == 're-input-password') {
|
2022-02-28 16:11:21 +08:00
|
|
|
|
wrongPasswordDialog(id);
|
2020-11-19 21:59:49 +08:00
|
|
|
|
} else if (type == 'input-password') {
|
2022-02-28 16:11:21 +08:00
|
|
|
|
enterPasswordDialog(id);
|
2020-11-19 21:59:49 +08:00
|
|
|
|
} else {
|
2021-08-11 01:38:21 +08:00
|
|
|
|
var hasRetry = evt['hasRetry'] == 'true';
|
2022-02-06 16:29:56 +08:00
|
|
|
|
print(evt);
|
2021-08-11 01:11:29 +08:00
|
|
|
|
showMsgBox(type, title, text, hasRetry);
|
2020-11-29 00:13:55 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-11 01:11:29 +08:00
|
|
|
|
void showMsgBox(String type, String title, String text, bool hasRetry) {
|
2022-02-28 16:11:21 +08:00
|
|
|
|
msgBox(type, title, text);
|
2020-11-29 00:13:55 +08:00
|
|
|
|
if (hasRetry) {
|
|
|
|
|
_timer?.cancel();
|
|
|
|
|
_timer = Timer(Duration(seconds: _reconnects), () {
|
|
|
|
|
FFI.reconnect();
|
2022-02-28 16:11:21 +08:00
|
|
|
|
showLoading(translate('Connecting...'));
|
2020-11-29 00:13:55 +08:00
|
|
|
|
});
|
|
|
|
|
_reconnects *= 2;
|
|
|
|
|
} else {
|
|
|
|
|
_reconnects = 1;
|
2020-11-19 21:59:49 +08:00
|
|
|
|
}
|
2020-11-17 11:12:55 +08:00
|
|
|
|
}
|
2020-11-17 01:22:14 +08:00
|
|
|
|
|
2020-11-28 18:06:27 +08:00
|
|
|
|
void handleInput(String newValue) {
|
2021-08-17 22:57:35 +08:00
|
|
|
|
var oldValue = _value;
|
|
|
|
|
_value = newValue;
|
2022-01-25 18:13:11 +08:00
|
|
|
|
if (isIOS) {
|
2021-08-17 22:57:35 +08:00
|
|
|
|
var i = newValue.length - 1;
|
|
|
|
|
for (; i >= 0 && newValue[i] != '\1'; --i) {}
|
|
|
|
|
var j = oldValue.length - 1;
|
|
|
|
|
for (; j >= 0 && oldValue[j] != '\1'; --j) {}
|
|
|
|
|
if (i < j) j = i;
|
|
|
|
|
newValue = newValue.substring(j + 1);
|
|
|
|
|
oldValue = oldValue.substring(j + 1);
|
|
|
|
|
var common = 0;
|
|
|
|
|
for (;
|
|
|
|
|
common < oldValue.length &&
|
|
|
|
|
common < newValue.length &&
|
|
|
|
|
newValue[common] == oldValue[common];
|
|
|
|
|
++common);
|
|
|
|
|
for (i = 0; i < oldValue.length - common; ++i) {
|
|
|
|
|
FFI.inputKey('VK_BACK');
|
|
|
|
|
}
|
|
|
|
|
if (newValue.length > common) {
|
|
|
|
|
var s = newValue.substring(common);
|
|
|
|
|
if (s.length > 1) {
|
|
|
|
|
FFI.setByName('input_string', s);
|
|
|
|
|
} else {
|
|
|
|
|
inputChar(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (oldValue.length > 0 &&
|
|
|
|
|
newValue.length > 0 &&
|
|
|
|
|
oldValue[0] == '\1' &&
|
|
|
|
|
newValue[0] != '\1') {
|
2020-11-28 18:06:27 +08:00
|
|
|
|
// clipboard
|
2021-08-17 22:57:35 +08:00
|
|
|
|
oldValue = '';
|
2020-11-28 18:06:27 +08:00
|
|
|
|
}
|
2021-09-01 01:48:41 +08:00
|
|
|
|
if (newValue.length == oldValue.length) {
|
|
|
|
|
// ?
|
|
|
|
|
} else if (newValue.length < oldValue.length) {
|
2020-11-28 18:06:27 +08:00
|
|
|
|
final char = 'VK_BACK';
|
|
|
|
|
FFI.inputKey(char);
|
|
|
|
|
} else {
|
2021-08-17 22:57:35 +08:00
|
|
|
|
final content = newValue.substring(oldValue.length);
|
2020-11-28 18:06:27 +08:00
|
|
|
|
if (content.length > 1) {
|
2021-08-17 22:57:35 +08:00
|
|
|
|
if (oldValue != '' &&
|
2020-12-22 16:00:10 +08:00
|
|
|
|
content.length == 2 &&
|
|
|
|
|
(content == '""' ||
|
|
|
|
|
content == '()' ||
|
|
|
|
|
content == '[]' ||
|
|
|
|
|
content == '<>' ||
|
|
|
|
|
content == "{}" ||
|
|
|
|
|
content == '”“' ||
|
|
|
|
|
content == '《》' ||
|
|
|
|
|
content == '()' ||
|
|
|
|
|
content == '【】')) {
|
2020-12-22 16:07:48 +08:00
|
|
|
|
// can not only input content[0], because when input ], [ are also auo insert, which cause ] never be input
|
|
|
|
|
FFI.setByName('input_string', content);
|
2020-12-22 16:00:10 +08:00
|
|
|
|
openKeyboard();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-11-28 18:06:27 +08:00
|
|
|
|
FFI.setByName('input_string', content);
|
|
|
|
|
} else {
|
2021-08-17 22:57:35 +08:00
|
|
|
|
inputChar(content);
|
2020-11-28 18:06:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-17 22:57:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void inputChar(String char) {
|
|
|
|
|
if (char == '\n') {
|
|
|
|
|
char = 'VK_RETURN';
|
|
|
|
|
} else if (char == ' ') {
|
|
|
|
|
char = 'VK_SPACE';
|
|
|
|
|
}
|
|
|
|
|
FFI.inputKey(char);
|
2020-11-28 18:06:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void openKeyboard() {
|
|
|
|
|
// destroy first, so that our _value trick can work
|
2020-12-22 15:26:35 +08:00
|
|
|
|
_value = initText;
|
2021-09-01 01:35:01 +08:00
|
|
|
|
setState(() => _showEdit = false);
|
2020-11-28 18:06:27 +08:00
|
|
|
|
_timer?.cancel();
|
|
|
|
|
_timer = Timer(Duration(milliseconds: 30), () {
|
|
|
|
|
// show now, and sleep a while to requestFocus to
|
|
|
|
|
// make sure edit ready, so that keyboard wont show/hide/show/hide happen
|
2021-09-01 01:35:01 +08:00
|
|
|
|
setState(() => _showEdit = true);
|
2020-11-28 18:06:27 +08:00
|
|
|
|
_timer?.cancel();
|
|
|
|
|
_timer = Timer(Duration(milliseconds: 30), () {
|
2022-02-24 18:24:52 +08:00
|
|
|
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
|
|
|
|
|
overlays: SystemUiOverlay.values);
|
2020-11-28 18:06:27 +08:00
|
|
|
|
SystemChannels.textInput.invokeMethod('TextInput.show');
|
|
|
|
|
_focusNode.requestFocus();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-17 01:22:14 +08:00
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2020-11-29 14:28:07 +08:00
|
|
|
|
final pi = Provider.of<FfiModel>(context).pi;
|
2021-09-01 01:35:01 +08:00
|
|
|
|
final hideKeyboard = isKeyboardShown() && _showEdit;
|
2021-08-17 15:07:01 +08:00
|
|
|
|
final showActionButton = !_showBar || hideKeyboard;
|
2020-11-22 18:29:04 +08:00
|
|
|
|
return WillPopScope(
|
2020-11-29 14:19:01 +08:00
|
|
|
|
onWillPop: () async {
|
|
|
|
|
close();
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
child: Scaffold(
|
2022-02-03 00:53:59 +08:00
|
|
|
|
// resizeToAvoidBottomInset: true,
|
2021-08-17 15:07:01 +08:00
|
|
|
|
floatingActionButton: !showActionButton
|
2020-11-29 14:19:01 +08:00
|
|
|
|
? null
|
|
|
|
|
: FloatingActionButton(
|
2021-08-17 15:07:01 +08:00
|
|
|
|
mini: !hideKeyboard,
|
|
|
|
|
child: Icon(
|
|
|
|
|
hideKeyboard ? Icons.expand_more : Icons.expand_less),
|
2020-11-29 14:19:01 +08:00
|
|
|
|
backgroundColor: MyTheme.accent50,
|
|
|
|
|
onPressed: () {
|
2021-08-17 15:07:01 +08:00
|
|
|
|
setState(() {
|
|
|
|
|
if (hideKeyboard) {
|
2021-09-01 01:35:01 +08:00
|
|
|
|
_showEdit = false;
|
2021-08-17 15:07:01 +08:00
|
|
|
|
} else {
|
|
|
|
|
_showBar = !_showBar;
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-11-29 14:19:01 +08:00
|
|
|
|
}),
|
2022-02-02 01:20:14 +08:00
|
|
|
|
bottomNavigationBar:
|
|
|
|
|
_showBar && pi.displays != null ? getBottomAppBar() : null,
|
2022-02-24 18:24:52 +08:00
|
|
|
|
body: Overlay(
|
|
|
|
|
initialEntries: [
|
|
|
|
|
OverlayEntry(builder: (context) {
|
|
|
|
|
return Container(
|
|
|
|
|
color: Colors.black,
|
|
|
|
|
child: isDesktop
|
|
|
|
|
? getBodyForDesktopWithListener()
|
|
|
|
|
: SafeArea(child: getBodyForMobileWithGesture()));
|
|
|
|
|
})
|
|
|
|
|
],
|
|
|
|
|
)),
|
2020-11-29 14:19:01 +08:00
|
|
|
|
);
|
2020-11-20 16:37:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-02 01:20:14 +08:00
|
|
|
|
Widget getBottomAppBar() {
|
|
|
|
|
return BottomAppBar(
|
|
|
|
|
elevation: 10,
|
|
|
|
|
color: MyTheme.accent,
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
IconButton(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
icon: Icon(Icons.clear),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
close();
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
] +
|
|
|
|
|
<Widget>[
|
|
|
|
|
IconButton(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
icon: Icon(Icons.tv),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
setState(() => _showEdit = false);
|
|
|
|
|
showOptions(context);
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
] +
|
|
|
|
|
(isDesktop
|
|
|
|
|
? []
|
|
|
|
|
: [
|
2022-02-23 21:32:33 +08:00
|
|
|
|
IconButton(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
icon: Icon(Icons.keyboard),
|
|
|
|
|
onPressed: openKeyboard),
|
|
|
|
|
IconButton(
|
|
|
|
|
color: Colors.white,
|
2022-02-24 15:59:03 +08:00
|
|
|
|
icon: Icon(
|
|
|
|
|
_touchMode ? Icons.touch_app : Icons.mouse),
|
|
|
|
|
onPressed: changeTouchMode,
|
2022-02-23 21:32:33 +08:00
|
|
|
|
)
|
2022-02-02 01:20:14 +08:00
|
|
|
|
]) +
|
|
|
|
|
<Widget>[
|
|
|
|
|
IconButton(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
icon: Icon(Icons.more_vert),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
setState(() => _showEdit = false);
|
|
|
|
|
showActions(context);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
]),
|
|
|
|
|
IconButton(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
icon: Icon(Icons.expand_more),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
setState(() => _showBar = !_showBar);
|
|
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-17 18:00:44 +08:00
|
|
|
|
/// touchMode only:
|
|
|
|
|
/// LongPress -> right click
|
|
|
|
|
/// OneFingerPan -> start/end -> left down start/end
|
|
|
|
|
/// onDoubleTapDown -> move to
|
|
|
|
|
/// onLongPressDown => move to
|
|
|
|
|
///
|
|
|
|
|
/// mouseMode only:
|
|
|
|
|
/// DoubleFiner -> right click
|
|
|
|
|
/// HoldDrag -> left drag
|
|
|
|
|
|
2022-02-16 23:08:23 +08:00
|
|
|
|
Widget getBodyForMobileWithGesture() {
|
|
|
|
|
return getMixinGestureDetector(
|
|
|
|
|
child: getBodyForMobile(),
|
|
|
|
|
onTapUp: (d) {
|
|
|
|
|
if (_touchMode) {
|
2022-02-17 18:00:44 +08:00
|
|
|
|
FFI.cursorModel.touch(
|
|
|
|
|
d.localPosition.dx, d.localPosition.dy, MouseButtons.left);
|
2022-02-16 23:08:23 +08:00
|
|
|
|
} else {
|
2022-02-17 18:00:44 +08:00
|
|
|
|
FFI.tap(MouseButtons.left);
|
|
|
|
|
}
|
|
|
|
|
},
|
2022-02-23 21:32:33 +08:00
|
|
|
|
onDoubleTapDown: (d) {
|
|
|
|
|
if (_touchMode) {
|
2022-02-17 18:00:44 +08:00
|
|
|
|
FFI.cursorModel.move(d.localPosition.dx, d.localPosition.dy);
|
2022-02-16 23:08:23 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onDoubleTap: () {
|
2022-02-17 18:00:44 +08:00
|
|
|
|
FFI.tap(MouseButtons.left);
|
|
|
|
|
FFI.tap(MouseButtons.left);
|
|
|
|
|
},
|
2022-02-23 21:32:33 +08:00
|
|
|
|
onLongPressDown: (d) {
|
|
|
|
|
if (_touchMode) {
|
2022-02-17 18:00:44 +08:00
|
|
|
|
FFI.cursorModel.move(d.localPosition.dx, d.localPosition.dy);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
onLongPress: () {
|
|
|
|
|
if (_touchMode) {
|
|
|
|
|
FFI.tap(MouseButtons.right);
|
|
|
|
|
}
|
2022-02-16 23:08:23 +08:00
|
|
|
|
},
|
|
|
|
|
onDoubleFinerTap: (d) {
|
2022-02-17 18:00:44 +08:00
|
|
|
|
if (!_touchMode) {
|
|
|
|
|
FFI.tap(MouseButtons.right);
|
|
|
|
|
}
|
2022-02-16 23:08:23 +08:00
|
|
|
|
},
|
|
|
|
|
onHoldDragStart: (d) {
|
2022-02-17 18:00:44 +08:00
|
|
|
|
if (!_touchMode) {
|
|
|
|
|
FFI.sendMouse('down', MouseButtons.left);
|
|
|
|
|
}
|
2022-02-16 23:08:23 +08:00
|
|
|
|
},
|
|
|
|
|
onHoldDragUpdate: (d) {
|
2022-02-17 18:00:44 +08:00
|
|
|
|
if (!_touchMode) {
|
|
|
|
|
FFI.cursorModel.updatePan(d.delta.dx, d.delta.dy, _touchMode);
|
|
|
|
|
}
|
2022-02-16 23:08:23 +08:00
|
|
|
|
},
|
|
|
|
|
onHoldDragCancel: () {
|
2022-02-17 18:00:44 +08:00
|
|
|
|
if (!_touchMode) {
|
|
|
|
|
FFI.sendMouse('up', MouseButtons.left);
|
|
|
|
|
}
|
2022-02-16 23:08:23 +08:00
|
|
|
|
},
|
|
|
|
|
onOneFingerPanStart: (d) {
|
2022-02-17 18:00:44 +08:00
|
|
|
|
if (_touchMode) {
|
|
|
|
|
debugPrint("_touchMode , onOneFingerPanStart");
|
|
|
|
|
FFI.cursorModel.move(d.localPosition.dx, d.localPosition.dy);
|
|
|
|
|
FFI.sendMouse('down', MouseButtons.left);
|
|
|
|
|
} else {
|
|
|
|
|
FFI.sendMouse('up', MouseButtons.left);
|
|
|
|
|
}
|
2022-02-16 23:08:23 +08:00
|
|
|
|
},
|
|
|
|
|
onOneFingerPanUpdate: (d) {
|
2022-02-17 18:00:44 +08:00
|
|
|
|
FFI.cursorModel.updatePan(d.delta.dx, d.delta.dy, _touchMode);
|
|
|
|
|
},
|
|
|
|
|
onOneFingerPanEnd: (d) {
|
|
|
|
|
if (_touchMode) {
|
|
|
|
|
FFI.sendMouse('up', MouseButtons.left);
|
|
|
|
|
}
|
2022-02-16 23:08:23 +08:00
|
|
|
|
},
|
|
|
|
|
onTwoFingerScaleUpdate: (d) {
|
2022-02-17 18:00:44 +08:00
|
|
|
|
FFI.canvasModel.updateScale(d.scale / _scale);
|
2022-02-17 15:22:14 +08:00
|
|
|
|
_scale = d.scale;
|
2022-02-17 18:00:44 +08:00
|
|
|
|
FFI.canvasModel.panX(d.focalPointDelta.dx);
|
|
|
|
|
FFI.canvasModel.panY(d.focalPointDelta.dy);
|
2022-02-16 23:08:23 +08:00
|
|
|
|
},
|
2022-02-17 18:00:44 +08:00
|
|
|
|
onTwoFingerScaleEnd: (d) => _scale = 1,
|
2022-02-16 23:08:23 +08:00
|
|
|
|
onTwoFingerVerticalDragUpdate: (d) {
|
2022-02-17 15:22:14 +08:00
|
|
|
|
FFI.scroll(d.delta.dy / 2);
|
2022-02-02 01:20:14 +08:00
|
|
|
|
},
|
2022-02-17 18:00:44 +08:00
|
|
|
|
onTwoFingerPanUpdate: (d) {
|
|
|
|
|
FFI.canvasModel.panX(d.delta.dx);
|
|
|
|
|
FFI.canvasModel.panY(d.delta.dy);
|
|
|
|
|
});
|
2022-02-02 01:20:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-03 00:53:59 +08:00
|
|
|
|
Widget getBodyForMobile() {
|
|
|
|
|
return Container(
|
|
|
|
|
color: MyTheme.canvasColor,
|
|
|
|
|
child: Stack(children: [
|
|
|
|
|
ImagePaint(),
|
|
|
|
|
CursorPaint(),
|
|
|
|
|
getHelpTools(),
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: 0,
|
|
|
|
|
height: 0,
|
|
|
|
|
child: !_showEdit
|
|
|
|
|
? Container()
|
|
|
|
|
: TextFormField(
|
|
|
|
|
textInputAction: TextInputAction.newline,
|
|
|
|
|
autocorrect: false,
|
|
|
|
|
enableSuggestions: false,
|
|
|
|
|
focusNode: _focusNode,
|
|
|
|
|
maxLines: null,
|
2022-02-16 23:08:23 +08:00
|
|
|
|
initialValue: _value,
|
|
|
|
|
// trick way to make backspace work always
|
2022-02-03 00:53:59 +08:00
|
|
|
|
keyboardType: TextInputType.multiline,
|
|
|
|
|
onChanged: handleInput,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget getBodyForDesktopWithListener() {
|
2022-02-06 16:29:56 +08:00
|
|
|
|
final keyboard = FFI.ffiModel.permissions['keyboard'] != false;
|
|
|
|
|
var paints = <Widget>[ImagePaint()];
|
|
|
|
|
if (keyboard ||
|
|
|
|
|
FFI.getByName('toggle-option', 'show-remote-cursor') == 'true') {
|
|
|
|
|
paints.add(CursorPaint());
|
|
|
|
|
}
|
2022-02-03 00:53:59 +08:00
|
|
|
|
return MouseRegion(
|
2022-02-17 15:22:14 +08:00
|
|
|
|
cursor: keyboard ? SystemMouseCursors.none : MouseCursor.defer,
|
|
|
|
|
// TODO old null // still laggy, set cursor directly for web is better
|
2022-02-03 00:53:59 +08:00
|
|
|
|
onEnter: (event) {
|
|
|
|
|
print('enter');
|
|
|
|
|
FFI.listenToMouse(true);
|
|
|
|
|
},
|
|
|
|
|
onExit: (event) {
|
|
|
|
|
print('exit');
|
|
|
|
|
FFI.listenToMouse(false);
|
|
|
|
|
},
|
2022-02-02 01:20:14 +08:00
|
|
|
|
child: Container(
|
2022-02-06 16:29:56 +08:00
|
|
|
|
color: MyTheme.canvasColor, child: Stack(children: paints)));
|
2022-02-02 01:20:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-21 17:18:14 +08:00
|
|
|
|
void showActions(BuildContext context) {
|
|
|
|
|
final size = MediaQuery.of(context).size;
|
|
|
|
|
final x = 120.0;
|
|
|
|
|
final y = size.height;
|
|
|
|
|
final more = <PopupMenuItem<String>>[];
|
2022-02-02 00:46:21 +08:00
|
|
|
|
final pi = FFI.ffiModel.pi;
|
|
|
|
|
final perms = FFI.ffiModel.permissions;
|
|
|
|
|
if (pi.version.isNotEmpty) {
|
2021-08-21 17:18:14 +08:00
|
|
|
|
more.add(PopupMenuItem<String>(
|
|
|
|
|
child: Text(translate('Refresh')), value: 'refresh'));
|
|
|
|
|
}
|
|
|
|
|
more.add(PopupMenuItem<String>(
|
|
|
|
|
child: Row(
|
|
|
|
|
children: ([
|
|
|
|
|
Container(width: 100.0, child: Text(translate('OS Password'))),
|
|
|
|
|
TextButton(
|
|
|
|
|
style: flatButtonStyle,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
showSetOSPassword(context, false);
|
|
|
|
|
},
|
|
|
|
|
child: Icon(Icons.edit, color: MyTheme.accent),
|
|
|
|
|
)
|
|
|
|
|
])),
|
|
|
|
|
value: 'enter_os_password'));
|
2022-02-02 00:46:21 +08:00
|
|
|
|
if (!isDesktop) {
|
|
|
|
|
if (perms['keyboard'] != false && perms['clipboard'] != false) {
|
|
|
|
|
more.add(PopupMenuItem<String>(
|
|
|
|
|
child: Text(translate('Paste')), value: 'paste'));
|
|
|
|
|
}
|
|
|
|
|
more.add(PopupMenuItem<String>(
|
|
|
|
|
child: Text(translate('Reset canvas')), value: 'reset_canvas'));
|
|
|
|
|
}
|
|
|
|
|
if (perms['keyboard'] != false) {
|
|
|
|
|
if (pi.platform == 'Linux' || pi.sasEnabled) {
|
|
|
|
|
more.add(PopupMenuItem<String>(
|
|
|
|
|
child: Text(translate('Insert') + ' Ctrl + Alt + Del'),
|
|
|
|
|
value: 'cad'));
|
|
|
|
|
}
|
|
|
|
|
more.add(PopupMenuItem<String>(
|
|
|
|
|
child: Text(translate('Insert Lock')), value: 'lock'));
|
|
|
|
|
if (pi.platform == 'Windows' &&
|
|
|
|
|
FFI.getByName('toggle_option', 'privacy-mode') != 'true') {
|
|
|
|
|
more.add(PopupMenuItem<String>(
|
|
|
|
|
child: Text(translate(
|
|
|
|
|
(FFI.ffiModel.inputBlocked ? 'Unb' : 'B') + 'lock user input')),
|
|
|
|
|
value: 'block-input'));
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-08-21 17:18:14 +08:00
|
|
|
|
() async {
|
|
|
|
|
var value = await showMenu(
|
|
|
|
|
context: context,
|
|
|
|
|
position: RelativeRect.fromLTRB(x, y, x, y),
|
2022-02-02 00:46:21 +08:00
|
|
|
|
items: more,
|
2021-08-21 17:18:14 +08:00
|
|
|
|
elevation: 8,
|
|
|
|
|
);
|
|
|
|
|
if (value == 'cad') {
|
|
|
|
|
FFI.setByName('ctrl_alt_del');
|
|
|
|
|
} else if (value == 'lock') {
|
|
|
|
|
FFI.setByName('lock_screen');
|
2022-02-02 00:46:21 +08:00
|
|
|
|
} else if (value == 'block-input') {
|
|
|
|
|
FFI.setByName('toggle_option',
|
2022-02-28 16:11:21 +08:00
|
|
|
|
(FFI.ffiModel.inputBlocked ? 'un' : '') + 'block-input');
|
2022-02-02 00:46:21 +08:00
|
|
|
|
FFI.ffiModel.inputBlocked = !FFI.ffiModel.inputBlocked;
|
2021-08-21 17:18:14 +08:00
|
|
|
|
} else if (value == 'refresh') {
|
|
|
|
|
FFI.setByName('refresh');
|
|
|
|
|
} else if (value == 'paste') {
|
|
|
|
|
() async {
|
2022-02-17 15:22:14 +08:00
|
|
|
|
ClipboardData? data = await Clipboard.getData(Clipboard.kTextPlain);
|
|
|
|
|
if (data != null && data.text != null) {
|
2021-08-21 17:18:14 +08:00
|
|
|
|
FFI.setByName('input_string', '${data.text}');
|
|
|
|
|
}
|
|
|
|
|
}();
|
|
|
|
|
} else if (value == 'enter_os_password') {
|
|
|
|
|
var password = FFI.getByName('peer_option', "os-password");
|
|
|
|
|
if (password != "") {
|
|
|
|
|
FFI.setByName('input_os_password', password);
|
|
|
|
|
} else {
|
|
|
|
|
showSetOSPassword(context, true);
|
|
|
|
|
}
|
|
|
|
|
} else if (value == 'reset_canvas') {
|
|
|
|
|
FFI.cursorModel.reset();
|
|
|
|
|
}
|
|
|
|
|
}();
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-24 15:59:03 +08:00
|
|
|
|
void changeTouchMode() {
|
|
|
|
|
setState(() => _showEdit = false);
|
|
|
|
|
showModalBottomSheet(
|
|
|
|
|
backgroundColor: MyTheme.grayBg,
|
|
|
|
|
isScrollControlled: true,
|
|
|
|
|
context: context,
|
|
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.vertical(top: Radius.circular(5))),
|
|
|
|
|
builder: (context) => DraggableScrollableSheet(
|
|
|
|
|
expand: false,
|
|
|
|
|
builder: (context, scrollController) {
|
|
|
|
|
return SingleChildScrollView(
|
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 10),
|
|
|
|
|
child: GestureHelp(
|
|
|
|
|
touchMode: _touchMode,
|
|
|
|
|
onTouchModeChange: (t) {
|
|
|
|
|
setState(() => _touchMode = t);
|
|
|
|
|
final v = _touchMode ? 'Y' : '';
|
|
|
|
|
FFI.setByName('peer_option',
|
|
|
|
|
'{"name": "touch-mode", "value": "$v"}');
|
|
|
|
|
}));
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-20 16:37:48 +08:00
|
|
|
|
void close() {
|
2022-02-28 16:11:21 +08:00
|
|
|
|
msgBox('', 'Close', 'Are you sure to close the connection?');
|
2020-11-17 11:12:55 +08:00
|
|
|
|
}
|
2020-11-25 13:03:48 +08:00
|
|
|
|
|
|
|
|
|
Widget getHelpTools() {
|
2021-09-01 01:35:01 +08:00
|
|
|
|
final keyboard = isKeyboardShown();
|
2022-02-24 15:59:03 +08:00
|
|
|
|
if (!keyboard) {
|
2020-11-25 13:03:48 +08:00
|
|
|
|
return SizedBox();
|
|
|
|
|
}
|
2021-08-17 15:07:01 +08:00
|
|
|
|
final size = MediaQuery.of(context).size;
|
2022-02-17 15:22:14 +08:00
|
|
|
|
var wrap = (String text, void Function() onPressed,
|
|
|
|
|
[bool? active, IconData? icon]) {
|
2021-08-02 22:21:23 +08:00
|
|
|
|
return TextButton(
|
|
|
|
|
style: TextButton.styleFrom(
|
|
|
|
|
minimumSize: Size(0, 0),
|
2022-02-16 23:08:23 +08:00
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 10, horizontal: 9.75),
|
|
|
|
|
//adds padding inside the button
|
|
|
|
|
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
|
|
|
//limits the touch area to the button area
|
2021-08-02 22:21:23 +08:00
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(5.0),
|
|
|
|
|
),
|
|
|
|
|
backgroundColor: active == true ? MyTheme.accent80 : null,
|
|
|
|
|
),
|
|
|
|
|
child: icon != null
|
|
|
|
|
? Icon(icon, size: 17, color: Colors.white)
|
|
|
|
|
: Text(translate(text),
|
|
|
|
|
style: TextStyle(color: Colors.white, fontSize: 11)),
|
|
|
|
|
onPressed: onPressed);
|
2020-11-25 13:03:48 +08:00
|
|
|
|
};
|
2021-08-11 00:22:47 +08:00
|
|
|
|
final pi = FFI.ffiModel.pi;
|
|
|
|
|
final isMac = pi.platform == "Mac OS";
|
2020-11-25 16:28:46 +08:00
|
|
|
|
final modifiers = <Widget>[
|
2021-08-17 15:07:01 +08:00
|
|
|
|
wrap('Ctrl ', () {
|
2020-11-25 16:28:46 +08:00
|
|
|
|
setState(() => FFI.ctrl = !FFI.ctrl);
|
|
|
|
|
}, FFI.ctrl),
|
2021-08-17 15:07:01 +08:00
|
|
|
|
wrap(' Alt ', () {
|
2020-11-25 16:28:46 +08:00
|
|
|
|
setState(() => FFI.alt = !FFI.alt);
|
|
|
|
|
}, FFI.alt),
|
|
|
|
|
wrap('Shift', () {
|
|
|
|
|
setState(() => FFI.shift = !FFI.shift);
|
|
|
|
|
}, FFI.shift),
|
2021-08-17 15:07:01 +08:00
|
|
|
|
wrap(isMac ? ' Cmd ' : ' Win ', () {
|
2020-11-25 16:28:46 +08:00
|
|
|
|
setState(() => FFI.command = !FFI.command);
|
|
|
|
|
}, FFI.command),
|
|
|
|
|
];
|
|
|
|
|
final keys = <Widget>[
|
|
|
|
|
wrap(
|
2021-08-17 15:07:01 +08:00
|
|
|
|
' Fn ',
|
2020-11-25 16:28:46 +08:00
|
|
|
|
() => setState(
|
|
|
|
|
() {
|
|
|
|
|
_fn = !_fn;
|
|
|
|
|
if (_fn) {
|
|
|
|
|
_more = false;
|
2020-11-25 13:03:48 +08:00
|
|
|
|
}
|
2020-11-25 16:28:46 +08:00
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
_fn),
|
|
|
|
|
wrap(
|
2021-08-17 15:07:01 +08:00
|
|
|
|
' ... ',
|
2020-11-25 16:28:46 +08:00
|
|
|
|
() => setState(
|
|
|
|
|
() {
|
|
|
|
|
_more = !_more;
|
|
|
|
|
if (_more) {
|
|
|
|
|
_fn = false;
|
2020-11-25 13:03:48 +08:00
|
|
|
|
}
|
2020-11-25 16:28:46 +08:00
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
_more),
|
|
|
|
|
];
|
|
|
|
|
final fn = <Widget>[
|
|
|
|
|
SizedBox(width: 9999),
|
|
|
|
|
];
|
|
|
|
|
for (var i = 1; i <= 12; ++i) {
|
|
|
|
|
final name = 'F' + i.toString();
|
|
|
|
|
fn.add(wrap(name, () {
|
|
|
|
|
FFI.inputKey('VK_' + name);
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
final more = <Widget>[
|
|
|
|
|
SizedBox(width: 9999),
|
|
|
|
|
wrap('Esc', () {
|
|
|
|
|
FFI.inputKey('VK_ESCAPE');
|
|
|
|
|
}),
|
|
|
|
|
wrap('Tab', () {
|
|
|
|
|
FFI.inputKey('VK_TAB');
|
|
|
|
|
}),
|
|
|
|
|
wrap('Home', () {
|
|
|
|
|
FFI.inputKey('VK_HOME');
|
|
|
|
|
}),
|
|
|
|
|
wrap('End', () {
|
|
|
|
|
FFI.inputKey('VK_END');
|
|
|
|
|
}),
|
|
|
|
|
wrap('Del', () {
|
|
|
|
|
FFI.inputKey('VK_DELETE');
|
|
|
|
|
}),
|
2020-11-27 02:14:27 +08:00
|
|
|
|
wrap('PgUp', () {
|
2020-11-25 16:28:46 +08:00
|
|
|
|
FFI.inputKey('VK_PRIOR');
|
|
|
|
|
}),
|
2021-08-17 15:07:01 +08:00
|
|
|
|
wrap('PgDn', () {
|
2020-11-25 16:28:46 +08:00
|
|
|
|
FFI.inputKey('VK_NEXT');
|
|
|
|
|
}),
|
2020-12-24 10:44:44 +08:00
|
|
|
|
SizedBox(width: 9999),
|
|
|
|
|
wrap('', () {
|
|
|
|
|
FFI.inputKey('VK_LEFT');
|
|
|
|
|
}, false, Icons.keyboard_arrow_left),
|
|
|
|
|
wrap('', () {
|
|
|
|
|
FFI.inputKey('VK_UP');
|
|
|
|
|
}, false, Icons.keyboard_arrow_up),
|
|
|
|
|
wrap('', () {
|
|
|
|
|
FFI.inputKey('VK_DOWN');
|
|
|
|
|
}, false, Icons.keyboard_arrow_down),
|
|
|
|
|
wrap('', () {
|
|
|
|
|
FFI.inputKey('VK_RIGHT');
|
|
|
|
|
}, false, Icons.keyboard_arrow_right),
|
2021-08-11 00:22:47 +08:00
|
|
|
|
wrap(isMac ? 'Cmd+C' : 'Ctrl+C', () {
|
|
|
|
|
sendPrompt(isMac, 'VK_C');
|
2020-12-24 10:44:44 +08:00
|
|
|
|
}),
|
2021-08-11 00:22:47 +08:00
|
|
|
|
wrap(isMac ? 'Cmd+V' : 'Ctrl+V', () {
|
|
|
|
|
sendPrompt(isMac, 'VK_V');
|
2021-08-06 22:45:45 +08:00
|
|
|
|
}),
|
2021-08-11 00:22:47 +08:00
|
|
|
|
wrap(isMac ? 'Cmd+S' : 'Ctrl+S', () {
|
|
|
|
|
sendPrompt(isMac, 'VK_S');
|
2020-12-24 10:44:44 +08:00
|
|
|
|
}),
|
2020-11-25 16:28:46 +08:00
|
|
|
|
];
|
2021-08-17 15:07:01 +08:00
|
|
|
|
final space = size.width > 320 ? 4.0 : 2.0;
|
2020-11-25 16:28:46 +08:00
|
|
|
|
return Container(
|
2020-11-27 02:14:27 +08:00
|
|
|
|
color: Color(0xAA000000),
|
2020-11-25 16:28:46 +08:00
|
|
|
|
padding: EdgeInsets.only(
|
2021-08-17 15:07:01 +08:00
|
|
|
|
top: keyboard ? 24 : 4, left: 0, right: 0, bottom: 8),
|
2020-11-25 16:28:46 +08:00
|
|
|
|
child: Wrap(
|
2021-08-17 15:07:01 +08:00
|
|
|
|
spacing: space,
|
|
|
|
|
runSpacing: space,
|
2020-11-25 16:28:46 +08:00
|
|
|
|
children: <Widget>[SizedBox(width: 9999)] +
|
|
|
|
|
(keyboard
|
2020-12-24 10:44:44 +08:00
|
|
|
|
? modifiers + keys + (_fn ? fn : []) + (_more ? more : [])
|
2022-02-17 18:00:44 +08:00
|
|
|
|
: modifiers),
|
2020-11-25 16:28:46 +08:00
|
|
|
|
));
|
2020-11-25 13:03:48 +08:00
|
|
|
|
}
|
2020-11-17 11:12:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-18 23:15:59 +08:00
|
|
|
|
class ImagePaint extends StatelessWidget {
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final m = Provider.of<ImageModel>(context);
|
2020-11-23 23:18:42 +08:00
|
|
|
|
final c = Provider.of<CanvasModel>(context);
|
2020-11-25 11:20:40 +08:00
|
|
|
|
final adjust = FFI.cursorModel.adjustForKeyboard();
|
2020-11-23 23:18:42 +08:00
|
|
|
|
var s = c.scale;
|
2020-11-18 23:15:59 +08:00
|
|
|
|
return CustomPaint(
|
2020-11-25 11:20:40 +08:00
|
|
|
|
painter: new ImagePainter(
|
|
|
|
|
image: m.image, x: c.x / s, y: (c.y - adjust) / s, scale: s),
|
2020-11-19 18:22:06 +08:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class CursorPaint extends StatelessWidget {
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final m = Provider.of<CursorModel>(context);
|
2020-11-23 23:18:42 +08:00
|
|
|
|
final c = Provider.of<CanvasModel>(context);
|
2020-11-25 11:20:40 +08:00
|
|
|
|
final adjust = FFI.cursorModel.adjustForKeyboard();
|
2020-11-23 23:18:42 +08:00
|
|
|
|
var s = c.scale;
|
2020-11-19 18:22:06 +08:00
|
|
|
|
return CustomPaint(
|
2020-11-23 23:18:42 +08:00
|
|
|
|
painter: new ImagePainter(
|
|
|
|
|
image: m.image,
|
|
|
|
|
x: m.x * s - m.hotx + c.x,
|
2020-11-25 11:20:40 +08:00
|
|
|
|
y: m.y * s - m.hoty + c.y - adjust,
|
2020-11-23 23:18:42 +08:00
|
|
|
|
scale: 1),
|
2020-11-18 23:15:59 +08:00
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ImagePainter extends CustomPainter {
|
|
|
|
|
ImagePainter({
|
2022-02-17 15:22:14 +08:00
|
|
|
|
required this.image,
|
|
|
|
|
required this.x,
|
|
|
|
|
required this.y,
|
|
|
|
|
required this.scale,
|
2020-11-17 11:12:55 +08:00
|
|
|
|
});
|
|
|
|
|
|
2022-02-17 15:22:14 +08:00
|
|
|
|
ui.Image? image;
|
2020-11-19 18:22:06 +08:00
|
|
|
|
double x;
|
|
|
|
|
double y;
|
2020-11-23 23:18:42 +08:00
|
|
|
|
double scale;
|
2020-11-17 11:12:55 +08:00
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void paint(Canvas canvas, Size size) {
|
2020-11-17 12:08:31 +08:00
|
|
|
|
if (image == null) return;
|
2020-11-23 23:18:42 +08:00
|
|
|
|
canvas.scale(scale, scale);
|
2022-02-17 15:22:14 +08:00
|
|
|
|
canvas.drawImage(image!, new Offset(x, y), new Paint());
|
2020-11-17 11:12:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
bool shouldRepaint(CustomPainter oldDelegate) {
|
2020-11-17 12:08:31 +08:00
|
|
|
|
return oldDelegate != this;
|
2020-11-17 01:22:14 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-19 21:59:49 +08:00
|
|
|
|
|
2022-02-28 16:11:21 +08:00
|
|
|
|
void enterPasswordDialog(String id) {
|
2020-11-19 21:59:49 +08:00
|
|
|
|
final controller = TextEditingController();
|
2020-11-20 02:12:48 +08:00
|
|
|
|
var remember = FFI.getByName('remember', id) == 'true';
|
2022-02-28 16:11:21 +08:00
|
|
|
|
if (globalKey.currentContext == null) return;
|
|
|
|
|
showAlertDialog((setState) => Tuple3(
|
|
|
|
|
Text(translate('Password Required')),
|
|
|
|
|
Column(mainAxisSize: MainAxisSize.min, children: [
|
|
|
|
|
PasswordWidget(controller: controller),
|
|
|
|
|
CheckboxListTile(
|
|
|
|
|
contentPadding: const EdgeInsets.all(0),
|
|
|
|
|
dense: true,
|
|
|
|
|
controlAffinity: ListTileControlAffinity.leading,
|
|
|
|
|
title: Text(
|
|
|
|
|
translate('Remember password'),
|
|
|
|
|
),
|
|
|
|
|
value: remember,
|
|
|
|
|
onChanged: (v) {
|
|
|
|
|
if (v != null) {
|
|
|
|
|
setState(() => remember = v);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
]),
|
|
|
|
|
[
|
|
|
|
|
TextButton(
|
|
|
|
|
style: flatButtonStyle,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
DialogManager.reset();
|
|
|
|
|
Navigator.pop(globalKey.currentContext!);
|
|
|
|
|
},
|
|
|
|
|
child: Text(translate('Cancel')),
|
|
|
|
|
),
|
|
|
|
|
TextButton(
|
|
|
|
|
style: flatButtonStyle,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
var text = controller.text.trim();
|
|
|
|
|
if (text == '') return;
|
|
|
|
|
FFI.login(text, remember);
|
|
|
|
|
DialogManager.reset();
|
|
|
|
|
showLoading(translate('Logging in...'));
|
|
|
|
|
},
|
|
|
|
|
child: Text(translate('OK')),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
));
|
2020-11-19 21:59:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 16:11:21 +08:00
|
|
|
|
void wrongPasswordDialog(String id) {
|
|
|
|
|
if (globalKey.currentContext == null) return;
|
|
|
|
|
showAlertDialog((_) => Tuple3(Text(translate('Wrong Password')),
|
|
|
|
|
Text(translate('Do you want to enter again?')), [
|
|
|
|
|
TextButton(
|
|
|
|
|
style: flatButtonStyle,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
DialogManager.reset();
|
|
|
|
|
Navigator.pop(globalKey.currentContext!);
|
|
|
|
|
},
|
|
|
|
|
child: Text(translate('Cancel')),
|
|
|
|
|
),
|
|
|
|
|
TextButton(
|
|
|
|
|
style: flatButtonStyle,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
enterPasswordDialog(id);
|
|
|
|
|
},
|
|
|
|
|
child: Text(translate('Retry')),
|
|
|
|
|
),
|
|
|
|
|
]));
|
2020-11-19 21:59:49 +08:00
|
|
|
|
}
|
2020-11-20 02:12:48 +08:00
|
|
|
|
|
2022-02-02 00:46:21 +08:00
|
|
|
|
CheckboxListTile getToggle(
|
|
|
|
|
void Function(void Function()) setState, option, name) {
|
|
|
|
|
return CheckboxListTile(
|
|
|
|
|
value: FFI.getByName('toggle_option', option) == 'true',
|
|
|
|
|
onChanged: (v) {
|
|
|
|
|
setState(() {
|
|
|
|
|
FFI.setByName('toggle_option', option);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
dense: true,
|
|
|
|
|
title: Text(translate(name)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RadioListTile<String> getRadio(String name, String toValue, String curValue,
|
2022-02-17 15:22:14 +08:00
|
|
|
|
void Function(String?) onChange) {
|
2022-02-02 00:46:21 +08:00
|
|
|
|
return RadioListTile<String>(
|
|
|
|
|
controlAffinity: ListTileControlAffinity.trailing,
|
|
|
|
|
title: Text(translate(name)),
|
|
|
|
|
value: toValue,
|
|
|
|
|
groupValue: curValue,
|
|
|
|
|
onChanged: onChange,
|
|
|
|
|
dense: true,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-20 16:37:48 +08:00
|
|
|
|
void showOptions(BuildContext context) {
|
2020-11-20 13:06:52 +08:00
|
|
|
|
String quality = FFI.getByName('image_quality');
|
|
|
|
|
if (quality == '') quality = 'balanced';
|
2022-02-02 00:46:21 +08:00
|
|
|
|
String viewStyle = FFI.getByName('peer_option', 'view-style');
|
|
|
|
|
if (viewStyle == '') viewStyle = 'original';
|
2020-11-25 23:52:58 +08:00
|
|
|
|
var displays = <Widget>[];
|
|
|
|
|
final pi = FFI.ffiModel.pi;
|
2020-11-29 00:13:55 +08:00
|
|
|
|
final image = FFI.ffiModel.getConnectionImage();
|
|
|
|
|
if (image != null)
|
|
|
|
|
displays.add(Padding(padding: const EdgeInsets.only(top: 8), child: image));
|
2020-11-25 23:52:58 +08:00
|
|
|
|
if (pi.displays.length > 1) {
|
|
|
|
|
final cur = pi.currentDisplay;
|
|
|
|
|
final children = <Widget>[];
|
|
|
|
|
for (var i = 0; i < pi.displays.length; ++i)
|
|
|
|
|
children.add(InkWell(
|
|
|
|
|
onTap: () {
|
|
|
|
|
if (i == cur) return;
|
|
|
|
|
FFI.setByName('switch_display', i.toString());
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
},
|
|
|
|
|
child: Ink(
|
|
|
|
|
width: 40,
|
|
|
|
|
height: 40,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
border: Border.all(color: Colors.black87),
|
|
|
|
|
color: i == cur ? Colors.black87 : Colors.white),
|
|
|
|
|
child: Center(
|
|
|
|
|
child: Text((i + 1).toString(),
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: i == cur ? Colors.white : Colors.black87))))));
|
|
|
|
|
displays.add(Padding(
|
|
|
|
|
padding: const EdgeInsets.only(top: 8),
|
|
|
|
|
child: Wrap(
|
|
|
|
|
alignment: WrapAlignment.center,
|
|
|
|
|
spacing: 8,
|
|
|
|
|
children: children,
|
|
|
|
|
)));
|
2020-11-29 00:13:55 +08:00
|
|
|
|
}
|
|
|
|
|
if (displays.isNotEmpty) {
|
2020-11-25 23:52:58 +08:00
|
|
|
|
displays.add(Divider(color: MyTheme.border));
|
|
|
|
|
}
|
2022-02-02 00:46:21 +08:00
|
|
|
|
final perms = FFI.ffiModel.permissions;
|
2022-02-28 16:11:21 +08:00
|
|
|
|
showAlertDialog((setState) {
|
2020-11-28 15:24:44 +08:00
|
|
|
|
final more = <Widget>[];
|
2022-02-02 00:46:21 +08:00
|
|
|
|
if (perms['audio'] != false) {
|
|
|
|
|
more.add(getToggle(setState, 'disable-audio', 'Mute'));
|
2020-11-28 13:34:59 +08:00
|
|
|
|
}
|
2022-02-02 00:46:21 +08:00
|
|
|
|
if (perms['keyboard'] != false) {
|
|
|
|
|
if (perms['clipboard'] != false)
|
|
|
|
|
more.add(getToggle(setState, 'disable-clipboard', 'Disable clipboard'));
|
|
|
|
|
more.add(getToggle(
|
|
|
|
|
setState, 'lock-after-session-end', 'Lock after session end'));
|
|
|
|
|
if (pi.platform == 'Windows') {
|
|
|
|
|
more.add(getToggle(setState, 'privacy-mode', 'Privacy mode'));
|
|
|
|
|
}
|
2020-11-30 16:05:23 +08:00
|
|
|
|
}
|
2022-02-17 15:22:14 +08:00
|
|
|
|
var setQuality = (String? value) {
|
2022-02-17 18:00:44 +08:00
|
|
|
|
if (value == null) return;
|
2022-02-02 00:46:21 +08:00
|
|
|
|
setState(() {
|
|
|
|
|
quality = value;
|
|
|
|
|
FFI.setByName('image_quality', value);
|
|
|
|
|
});
|
|
|
|
|
};
|
2022-02-17 15:22:14 +08:00
|
|
|
|
var setViewStyle = (String? value) {
|
2022-02-17 18:00:44 +08:00
|
|
|
|
if (value == null) return;
|
2022-02-02 00:46:21 +08:00
|
|
|
|
setState(() {
|
|
|
|
|
viewStyle = value;
|
|
|
|
|
FFI.setByName(
|
|
|
|
|
'peer_option', '{"name": "view-style", "value": "$value"}');
|
2022-02-03 00:53:59 +08:00
|
|
|
|
FFI.canvasModel.updateViewStyle();
|
2022-02-02 00:46:21 +08:00
|
|
|
|
});
|
|
|
|
|
};
|
2020-11-28 13:34:59 +08:00
|
|
|
|
return Tuple3(
|
2022-02-17 15:22:14 +08:00
|
|
|
|
SizedBox.shrink(),
|
2020-11-28 13:34:59 +08:00
|
|
|
|
Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: displays +
|
2022-02-02 00:46:21 +08:00
|
|
|
|
(isDesktop
|
|
|
|
|
? <Widget>[
|
|
|
|
|
getRadio(
|
|
|
|
|
'Original', 'original', viewStyle, setViewStyle),
|
|
|
|
|
getRadio('Shrink', 'shrink', viewStyle, setViewStyle),
|
|
|
|
|
getRadio('Stretch', 'stretch', viewStyle, setViewStyle),
|
|
|
|
|
Divider(color: MyTheme.border),
|
|
|
|
|
]
|
2022-02-17 15:22:14 +08:00
|
|
|
|
: []) +
|
2020-11-28 13:34:59 +08:00
|
|
|
|
<Widget>[
|
2022-02-02 00:46:21 +08:00
|
|
|
|
getRadio('Good image quality', 'best', quality, setQuality),
|
|
|
|
|
getRadio('Balanced', 'balanced', quality, setQuality),
|
|
|
|
|
getRadio(
|
|
|
|
|
'Optimize reaction time', 'low', quality, setQuality),
|
2020-11-28 13:34:59 +08:00
|
|
|
|
Divider(color: MyTheme.border),
|
2022-02-02 00:46:21 +08:00
|
|
|
|
getToggle(
|
|
|
|
|
setState, 'show-remote-cursor', 'Show remote cursor'),
|
2020-11-28 13:34:59 +08:00
|
|
|
|
] +
|
|
|
|
|
more),
|
2022-02-17 15:22:14 +08:00
|
|
|
|
[]);
|
2020-11-28 13:34:59 +08:00
|
|
|
|
}, () async => true, true, 0);
|
2020-11-20 16:37:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-06 22:29:11 +08:00
|
|
|
|
void showSetOSPassword(BuildContext context, bool login) {
|
2020-12-21 19:05:31 +08:00
|
|
|
|
final controller = TextEditingController();
|
2021-08-06 22:29:11 +08:00
|
|
|
|
var password = FFI.getByName('peer_option', "os-password");
|
|
|
|
|
var autoLogin = FFI.getByName('peer_option', "auto-login") != "";
|
2020-12-21 19:05:31 +08:00
|
|
|
|
controller.text = password;
|
2022-02-28 16:11:21 +08:00
|
|
|
|
showAlertDialog((setState) => Tuple3(
|
|
|
|
|
Text(translate('OS Password')),
|
|
|
|
|
Column(mainAxisSize: MainAxisSize.min, children: [
|
|
|
|
|
PasswordWidget(controller: controller),
|
|
|
|
|
CheckboxListTile(
|
|
|
|
|
contentPadding: const EdgeInsets.all(0),
|
|
|
|
|
dense: true,
|
|
|
|
|
controlAffinity: ListTileControlAffinity.leading,
|
|
|
|
|
title: Text(
|
|
|
|
|
translate('Auto Login'),
|
|
|
|
|
),
|
|
|
|
|
value: autoLogin,
|
|
|
|
|
onChanged: (v) {
|
|
|
|
|
if (v == null) return;
|
|
|
|
|
setState(() => autoLogin = v);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
]),
|
|
|
|
|
[
|
|
|
|
|
TextButton(
|
|
|
|
|
style: flatButtonStyle,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
},
|
|
|
|
|
child: Text(translate('Cancel')),
|
|
|
|
|
),
|
|
|
|
|
TextButton(
|
|
|
|
|
style: flatButtonStyle,
|
|
|
|
|
onPressed: () {
|
|
|
|
|
var text = controller.text.trim();
|
|
|
|
|
FFI.setByName(
|
|
|
|
|
'peer_option', '{"name": "os-password", "value": "$text"}');
|
|
|
|
|
FFI.setByName('peer_option',
|
|
|
|
|
'{"name": "auto-login", "value": "${autoLogin ? 'Y' : ''}"}');
|
|
|
|
|
if (text != "" && login) {
|
|
|
|
|
FFI.setByName('input_os_password', text);
|
|
|
|
|
}
|
|
|
|
|
Navigator.pop(context);
|
|
|
|
|
},
|
|
|
|
|
child: Text(translate('OK')),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
));
|
2020-12-21 19:05:31 +08:00
|
|
|
|
}
|
2021-08-11 00:22:47 +08:00
|
|
|
|
|
|
|
|
|
void sendPrompt(bool isMac, String key) {
|
|
|
|
|
final old = isMac ? FFI.command : FFI.ctrl;
|
|
|
|
|
if (isMac) {
|
|
|
|
|
FFI.command = true;
|
|
|
|
|
} else {
|
|
|
|
|
FFI.ctrl = true;
|
|
|
|
|
}
|
|
|
|
|
FFI.inputKey(key);
|
|
|
|
|
if (isMac) {
|
|
|
|
|
FFI.command = old;
|
|
|
|
|
} else {
|
|
|
|
|
FFI.ctrl = old;
|
|
|
|
|
}
|
|
|
|
|
}
|