2022-01-25 18:13:11 +08:00
|
|
|
import 'dart:typed_data';
|
2022-01-26 12:48:16 +08:00
|
|
|
import 'dart:js' as js;
|
2022-01-25 18:13:11 +08:00
|
|
|
import 'common.dart';
|
2022-02-03 00:53:59 +08:00
|
|
|
import 'dart:html';
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
final List<StreamSubscription<MouseEvent>> mouselisteners = [];
|
2022-01-25 18:13:11 +08:00
|
|
|
|
2022-01-26 12:48:16 +08:00
|
|
|
class PlatformFFI {
|
2022-01-25 18:13:11 +08:00
|
|
|
static void clearRgbaFrame() {}
|
|
|
|
|
2022-01-26 12:48:16 +08:00
|
|
|
static Uint8List getRgba() {
|
2022-01-29 15:55:00 +08:00
|
|
|
return js.context.callMethod('getRgba');
|
2022-01-25 18:13:11 +08:00
|
|
|
}
|
|
|
|
|
2022-01-26 19:00:23 +08:00
|
|
|
static Future<String> getVersion() async {
|
2022-01-31 16:22:05 +08:00
|
|
|
return getByName('version');
|
2022-01-26 19:00:23 +08:00
|
|
|
}
|
|
|
|
|
2022-01-26 12:48:16 +08:00
|
|
|
static String getByName(String name, [String arg = '']) {
|
|
|
|
return js.context.callMethod('getByName', [name, arg]);
|
2022-01-25 18:13:11 +08:00
|
|
|
}
|
|
|
|
|
2022-01-26 12:48:16 +08:00
|
|
|
static void setByName(String name, [String value = '']) {
|
|
|
|
js.context.callMethod('setByName', [name, value]);
|
2022-01-25 18:13:11 +08:00
|
|
|
}
|
|
|
|
|
2022-01-26 12:48:16 +08:00
|
|
|
static Future<Null> init() async {
|
2022-02-03 00:53:59 +08:00
|
|
|
window.document.onContextMenu.listen((evt) => evt.preventDefault());
|
2022-01-26 12:48:16 +08:00
|
|
|
isWeb = true;
|
2022-01-31 16:22:05 +08:00
|
|
|
isDesktop = !js.context.callMethod('isMobile');
|
2022-01-26 19:00:23 +08:00
|
|
|
js.context.callMethod('init');
|
2022-01-25 18:13:11 +08:00
|
|
|
}
|
2022-02-03 00:53:59 +08:00
|
|
|
|
|
|
|
// MouseRegion onHover not work for mouse move when right button down
|
|
|
|
static void startDesktopWebListener(
|
|
|
|
Function(Map<String, dynamic>) handleMouse) {
|
|
|
|
// document.body.getElementsByTagName('flt-glass-pane')[0].style.cursor = 'none';
|
|
|
|
mouselisteners.add(window.document.onMouseMove
|
|
|
|
.listen((evt) => handleMouse(getEvent(evt))));
|
|
|
|
mouselisteners.add(window.document.onMouseDown
|
|
|
|
.listen((evt) => handleMouse(getEvent(evt))));
|
|
|
|
mouselisteners.add(
|
|
|
|
window.document.onMouseUp.listen((evt) => handleMouse(getEvent(evt))));
|
|
|
|
mouselisteners.add(window.document.onMouseWheel.listen((evt) => {}));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stopDesktopWebListener() {
|
|
|
|
mouselisteners.forEach((l) {
|
|
|
|
l.cancel();
|
|
|
|
});
|
|
|
|
mouselisteners.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, dynamic> getEvent(MouseEvent evt) {
|
|
|
|
// https://github.com/novnc/noVNC/blob/679b45fa3b453c7cf32f4b4455f4814818ecf161/core/rfb.js
|
|
|
|
// https://developer.mozilla.org/zh-CN/docs/Web/API/Element/mousedown_event
|
|
|
|
final out = {};
|
|
|
|
out['type'] = evt.type;
|
|
|
|
out['x'] = evt.client.x;
|
|
|
|
out['y'] = evt.client.y;
|
|
|
|
out['ctrl'] = evt.ctrlKey;
|
|
|
|
out['shift'] = evt.shiftKey;
|
|
|
|
out['alt'] = evt.altKey;
|
|
|
|
out['meta'] = evt.metaKey;
|
|
|
|
out['buttons'] = evt
|
|
|
|
.buttons; // left button: 1, right button: 2, middle button: 4, 1 | 2 = 3 (left + right)
|
|
|
|
return out;
|
2022-01-25 18:13:11 +08:00
|
|
|
}
|
|
|
|
|
2022-02-03 00:53:59 +08:00
|
|
|
final localeName = window.navigator.language;
|