This commit is contained in:
open-trade
2020-11-19 00:32:46 +08:00
parent 13eee42008
commit b594c8836e
5 changed files with 333 additions and 306 deletions

View File

@@ -1,11 +1,11 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'common.dart';
import 'package:flutter/services.dart';
import 'dart:ui' as ui;
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'dart:convert';
import 'dart:async';
import 'common.dart';
import 'model.dart';
class RemotePage extends StatefulWidget {
RemotePage({Key key, this.id}) : super(key: key);
@@ -19,9 +19,6 @@ class RemotePage extends StatefulWidget {
// https://github.com/hanxu317317/flutter_plan_demo/blob/master/lib/src/enter.dart
class _RemotePageState extends State<RemotePage> {
Timer _interval;
PeerInfo _pi = PeerInfo();
Display _display = Display();
bool _decoding = false;
@override
void initState() {
@@ -42,88 +39,11 @@ class _RemotePageState extends State<RemotePage> {
FFI.close();
_interval.cancel();
dismissLoading();
_decoding = null;
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
}
void interval() {
var evt = FFI.popEvent();
if (evt != null) {
var name = evt['name'];
if (name == 'msgbox') {
handleMsgbox(evt);
} else if (name == 'peer_info') {
handlePeerInfo(evt);
} else if (name == 'switch_display') {
handleSwitchDisplay(evt);
} else if (name == 'cursor_data') {
FFI.cursorModel.updateCursorData(evt);
} else if (name == 'cursor_id') {
FFI.cursorModel.updateCursorId(evt);
} else if (name == 'cursor_position') {
FFI.cursorModel.updateCursorPosition(evt);
}
}
if (!_decoding) {
var rgba = FFI.getRgba();
if (rgba != null) {
_decoding = true;
ui.decodeImageFromPixels(
rgba, _display.width, _display.height, ui.PixelFormat.bgra8888,
(image) {
FFI.clearRgbaFrame();
if (_decoding == null) return;
_decoding = false;
FFI.imageModel.update(image);
});
}
}
}
void handleSwitchDisplay(Map<String, dynamic> evt) {
_pi.currentDisplay = int.parse(evt['display']);
_display.x = int.parse(evt['x']);
_display.y = int.parse(evt['y']);
_display.width = int.parse(evt['width']);
_display.height = int.parse(evt['height']);
setState(() {});
}
void handlePeerInfo(Map<String, dynamic> evt) {
dismissLoading();
_pi.username = evt['username'];
_pi.hostname = evt['hostname'];
_pi.platform = evt['platform'];
_pi.sasEnabled = evt['sas_enabled'] == "true";
_pi.currentDisplay = int.parse(evt['current_display']);
List<dynamic> displays = json.decode(evt['displays']);
_pi.displays = List<Display>();
for (int i = 0; i < displays.length; ++i) {
Map<String, dynamic> d0 = displays[i];
var d = Display();
d.x = d0['x'];
d.y = d0['y'];
d.width = d0['width'];
d.height = d0['height'];
_pi.displays.add(d);
}
if (_pi.currentDisplay < _pi.displays.length) {
_display = _pi.displays[_pi.currentDisplay];
}
setState(() {});
}
void handleMsgbox(Map<String, dynamic> evt) {
var type = evt['type'];
var title = evt['title'];
var text = evt['text'];
if (type == 're-input-password') {
wrongPasswordDialog(widget.id, context);
} else if (type == 'input-password') {
enterPasswordDialog(widget.id, context);
} else {
msgbox(type, title, text, context);
}
FFI.ffiModel.update(widget.id, context);
}
@override
@@ -170,19 +90,3 @@ class ImagePainter extends CustomPainter {
return oldDelegate != this;
}
}
class Display {
int x = 0;
int y = 0;
int width = 0;
int height = 0;
}
class PeerInfo {
String username;
String hostname;
String platform;
bool sasEnabled;
int currentDisplay;
List<Display> displays;
}