optimize model.dart

This commit is contained in:
csf 2022-09-13 21:52:22 +08:00
parent e9d94fdb24
commit 2e2bf3b8fb

View File

@ -331,7 +331,7 @@ class ImageModel with ChangeNotifier {
ui.Image? get image => _image;
String _id = '';
String id = '';
WeakReference<FFI> parent;
@ -375,7 +375,7 @@ class ImageModel with ChangeNotifier {
await initializeCursorAndCanvas(parent.target!);
}
if (parent.target?.ffiModel.isPeerAndroid ?? false) {
bind.sessionPeerOption(id: _id, name: 'view-style', value: 'adaptive');
bind.sessionPeerOption(id: id, name: 'view-style', value: 'adaptive');
parent.target?.canvasModel.updateViewStyle();
}
}
@ -468,7 +468,7 @@ class CanvasModel with ChangeNotifier {
double _scale = 1.0;
// the tabbar over the image
double tabBarHeight = 0.0;
// TODO multi canvas model
// remote id
String id = '';
// scroll offset x percent
double _scrollX = 0.0;
@ -681,7 +681,7 @@ class CursorModel with ChangeNotifier {
double _hoty = 0;
double _displayOriginX = 0;
double _displayOriginY = 0;
String id = ''; // TODO multi cursor model
String id = '';
WeakReference<FFI> parent;
ui.Image? get image => _image;
@ -991,7 +991,7 @@ extension ToString on MouseButtons {
enum ConnType { defaultConn, fileTransfer, portForward, rdp }
/// FFI class for communicating with the Rust core.
/// Flutter state manager and data communication with the Rust core.
class FFI {
var id = '';
var shift = false;
@ -1020,7 +1020,7 @@ class FFI {
ffiModel = FfiModel(WeakReference(this));
cursorModel = CursorModel(WeakReference(this));
canvasModel = CanvasModel(WeakReference(this));
serverModel = ServerModel(WeakReference(this)); // use global FFI
serverModel = ServerModel(WeakReference(this));
chatModel = ChatModel(WeakReference(this));
fileModel = FileModel(WeakReference(this));
abModel = AbModel(WeakReference(this));
@ -1042,12 +1042,6 @@ class FFI {
.encode(modify({'id': id, 'type': 'wheel', 'y': y.toString()})));
}
/// Reconnect to the remote peer.
// static reconnect() {
// setByName('reconnect');
// parent.target?.ffiModel.clearPermissions();
// }
/// Reset key modifiers to false, including [shift], [ctrl], [alt] and [command].
resetModifiers() {
shift = ctrl = alt = command = false;
@ -1070,7 +1064,7 @@ class FFI {
msg: json.encode(modify({'type': type, 'buttons': button.value})));
}
// Raw Key
/// Send raw Key Event
inputRawKey(String name, int keyCode, int scanCode, bool down) {
bind.sessionHandleFlutterKeyEvent(
id: id,
@ -1080,10 +1074,6 @@ class FFI {
downOrUp: down);
}
Future<String> getKeyboardMode() {
return bind.sessionGetKeyboardName(id: id);
}
enterOrLeave(bool enter) {
// Fix status
if (!enter) {
@ -1097,18 +1087,6 @@ class FFI {
/// [press] indicates a click event(down and up).
inputKey(String name, {bool? down, bool? press}) {
if (!ffiModel.keyboard()) return;
// final Map<String, String> out = Map();
// out['name'] = name;
// // default: down = false
// if (down == true) {
// out['down'] = 'true';
// }
// // default: press = true
// if (press != false) {
// out['press'] = 'true';
// }
// setByName('input_key', json.encode(modify(out)));
// TODO id
bind.sessionInputKey(
id: id,
name: name,
@ -1161,7 +1139,7 @@ class FFI {
} else {
chatModel.resetClientMode();
canvasModel.id = id;
imageModel._id = id;
imageModel.id = id;
cursorModel.id = id;
}
// ignore: unused_local_variable
@ -1212,17 +1190,6 @@ class FFI {
debugPrint('model $id closed');
}
/// Send **get** command to the Rust core based on [name] and [arg].
/// Return the result as a string.
// String getByName(String name, [String arg = '']) {
// return platformFFI.getByName(name, arg);
// }
/// Send **set** command to the Rust core based on [name] and [value].
// setByName(String name, [String value = '']) {
// platformFFI.setByName(name, value);
// }
handleMouse(Map<String, dynamic> evt, {double tabBarHeight = 0.0}) {
var type = '';
var isMove = false;