more web api

This commit is contained in:
open-trade 2022-01-26 19:00:23 +08:00
parent 3d77365edc
commit 16218a731b
7 changed files with 34 additions and 32 deletions

View File

@ -202,6 +202,6 @@ Color str2color(String str, [alpha = 0xFF]) {
return Color((hash & 0xFF7FFF) | (alpha << 24)); return Color((hash & 0xFF7FFF) | (alpha << 24));
} }
bool isAndroid; bool isAndroid = false;
bool isIOS; bool isIOS = false;
bool isWeb; bool isWeb = false;

View File

@ -1,7 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
import 'package:package_info/package_info.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
import 'dart:async'; import 'dart:async';
import 'common.dart'; import 'common.dart';
@ -342,13 +341,13 @@ void showServer(BuildContext context) {
} }
Future<Null> showAbout(BuildContext context) async { Future<Null> showAbout(BuildContext context) async {
PackageInfo packageInfo = await PackageInfo.fromPlatform(); var version = await FFI.getVersion();
showAlertDialog( showAlertDialog(
context, context,
(setState) => Tuple3( (setState) => Tuple3(
null, null,
Wrap(direction: Axis.vertical, spacing: 12, children: [ Wrap(direction: Axis.vertical, spacing: 12, children: [
Text('Version: ${packageInfo.version}'), Text('Version: $version'),
InkWell( InkWell(
onTap: () async { onTap: () async {
const url = 'https://rustdesk.com/'; const url = 'https://rustdesk.com/';

View File

@ -611,6 +611,10 @@ class FFI {
static void setByName(String name, [String value = '']) { static void setByName(String name, [String value = '']) {
PlatformFFI.setByName(name, value); PlatformFFI.setByName(name, value);
} }
static Future<String> getVersion() async {
return await PlatformFFI.getVersion();
}
} }
class Peer { class Peer {
@ -690,32 +694,11 @@ void initializeCursorAndCanvas() async {
FFI.canvasModel.update(xCanvas, yCanvas, scale); FFI.canvasModel.update(xCanvas, yCanvas, scale);
} }
final langs = <String, Map<String, String>>{
'cn': <String, String>{
'Remote ID': '远程ID',
'Paste': '粘贴',
'Are you sure to close the connection?': '是否确认关闭连接?',
'Download new version': '下载新版本',
'Touch mode': '触屏模式',
'Reset canvas': '重置画布',
},
'en': <String, String>{}
};
final bool isCn = localeName.startsWith('zh') &&
(localeName.endsWith('CN') || localeName.endsWith('SG'));
String translate(String name) { String translate(String name) {
if (name.startsWith('Failed') && name.contains(':')) { if (name.startsWith('Failed') && name.contains(':')) {
return name.split(': ').map((x) => translate(x)).join(': '); return name.split(': ').map((x) => translate(x)).join(': ');
} }
final tmp = isCn ? langs['cn'] : langs['en'];
final v = tmp[name];
if (v == null) {
var a = 'translate'; var a = 'translate';
var b = '{"locale": "$localeName", "text": "$name"}'; var b = '{"locale": "$localeName", "text": "$name"}';
return FFI.getByName(a, b); return FFI.getByName(a, b);
} else {
return v;
}
} }

View File

@ -4,7 +4,8 @@ import 'dart:ffi';
import 'package:ffi/ffi.dart'; import 'package:ffi/ffi.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
import 'package:device_info/device_info.dart'; import 'package:device_info/device_info.dart';
import "common.dart"; import 'package:package_info/package_info.dart';
import 'common.dart';
class RgbaFrame extends Struct { class RgbaFrame extends Struct {
@Uint32() @Uint32()
@ -38,6 +39,11 @@ class PlatformFFI {
return Uint8List.sublistView(ref.data.asTypedList(ref.len)); return Uint8List.sublistView(ref.data.asTypedList(ref.len));
} }
static Future<String> getVersion() async {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
return packageInfo.version;
}
static String getByName(String name, [String arg = '']) { static String getByName(String name, [String arg = '']) {
if (_getByName == null) return ''; if (_getByName == null) return '';
var a = name.toNativeUtf8(); var a = name.toNativeUtf8();

View File

@ -78,7 +78,8 @@ class _RemotePageState extends State<RemotePage> {
return _bottom >= 100; return _bottom >= 100;
} }
void interval() { // crash on web before widgit initiated.
void intervalUnsafe() {
var v = MediaQuery.of(context).viewInsets.bottom; var v = MediaQuery.of(context).viewInsets.bottom;
if (v != _bottom) { if (v != _bottom) {
resetTool(); resetTool();
@ -92,6 +93,12 @@ class _RemotePageState extends State<RemotePage> {
FFI.ffiModel.update(widget.id, context, handleMsgbox); FFI.ffiModel.update(widget.id, context, handleMsgbox);
} }
void interval() {
try {
intervalUnsafe();
} catch (e) {}
}
void handleMsgbox(Map<String, dynamic> evt, String id) { void handleMsgbox(Map<String, dynamic> evt, String id) {
var type = evt['type']; var type = evt['type'];
var title = evt['title']; var title = evt['title'];

View File

@ -10,6 +10,10 @@ class PlatformFFI {
// return Uint8List.sublistView(ref.data.asTypedList(ref.len)); // return Uint8List.sublistView(ref.data.asTypedList(ref.len));
} }
static Future<String> getVersion() async {
return '';
}
static String getByName(String name, [String arg = '']) { static String getByName(String name, [String arg = '']) {
return js.context.callMethod('getByName', [name, arg]); return js.context.callMethod('getByName', [name, arg]);
} }
@ -20,6 +24,7 @@ class PlatformFFI {
static Future<Null> init() async { static Future<Null> init() async {
isWeb = true; isWeb = true;
js.context.callMethod('init');
} }
} }

View File

@ -32,6 +32,8 @@
<title>RustDesk</title> <title>RustDesk</title>
<link rel="manifest" href="manifest.json"> <link rel="manifest" href="manifest.json">
<script src="ogvjs/ogv.js"></script> <script src="ogvjs/ogv.js"></script>
<script type="module" crossorigin src="/assets/index.d55bf9f9.js"></script>
<link rel="modulepreload" href="/assets/vendor.fd8ceed9.js">
</head> </head>
<body> <body>
<!-- This script installs service_worker.js to provide PWA functionality to <!-- This script installs service_worker.js to provide PWA functionality to