diff --git a/lib/common.dart b/lib/common.dart index 410e9ca03..803cdb3c5 100644 --- a/lib/common.dart +++ b/lib/common.dart @@ -202,6 +202,6 @@ Color str2color(String str, [alpha = 0xFF]) { return Color((hash & 0xFF7FFF) | (alpha << 24)); } -bool isAndroid; -bool isIOS; -bool isWeb; +bool isAndroid = false; +bool isIOS = false; +bool isWeb = false; diff --git a/lib/home_page.dart b/lib/home_page.dart index 7daa30814..299a0ec1a 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import 'package:tuple/tuple.dart'; -import 'package:package_info/package_info.dart'; import 'package:url_launcher/url_launcher.dart'; import 'dart:async'; import 'common.dart'; @@ -342,13 +341,13 @@ void showServer(BuildContext context) { } Future showAbout(BuildContext context) async { - PackageInfo packageInfo = await PackageInfo.fromPlatform(); + var version = await FFI.getVersion(); showAlertDialog( context, (setState) => Tuple3( null, Wrap(direction: Axis.vertical, spacing: 12, children: [ - Text('Version: ${packageInfo.version}'), + Text('Version: $version'), InkWell( onTap: () async { const url = 'https://rustdesk.com/'; diff --git a/lib/model.dart b/lib/model.dart index d914e5b0f..6eb2c0e97 100644 --- a/lib/model.dart +++ b/lib/model.dart @@ -611,6 +611,10 @@ class FFI { static void setByName(String name, [String value = '']) { PlatformFFI.setByName(name, value); } + + static Future getVersion() async { + return await PlatformFFI.getVersion(); + } } class Peer { @@ -690,32 +694,11 @@ void initializeCursorAndCanvas() async { FFI.canvasModel.update(xCanvas, yCanvas, scale); } -final langs = >{ - 'cn': { - 'Remote ID': '远程ID', - 'Paste': '粘贴', - 'Are you sure to close the connection?': '是否确认关闭连接?', - 'Download new version': '下载新版本', - 'Touch mode': '触屏模式', - 'Reset canvas': '重置画布', - }, - 'en': {} -}; - -final bool isCn = localeName.startsWith('zh') && - (localeName.endsWith('CN') || localeName.endsWith('SG')); - String translate(String name) { if (name.startsWith('Failed') && name.contains(':')) { 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 b = '{"locale": "$localeName", "text": "$name"}'; - return FFI.getByName(a, b); - } else { - return v; - } + var a = 'translate'; + var b = '{"locale": "$localeName", "text": "$name"}'; + return FFI.getByName(a, b); } diff --git a/lib/native_model.dart b/lib/native_model.dart index cee8bd0bb..2c9df78b3 100644 --- a/lib/native_model.dart +++ b/lib/native_model.dart @@ -4,7 +4,8 @@ import 'dart:ffi'; import 'package:ffi/ffi.dart'; import 'package:path_provider/path_provider.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 { @Uint32() @@ -38,6 +39,11 @@ class PlatformFFI { return Uint8List.sublistView(ref.data.asTypedList(ref.len)); } + static Future getVersion() async { + PackageInfo packageInfo = await PackageInfo.fromPlatform(); + return packageInfo.version; + } + static String getByName(String name, [String arg = '']) { if (_getByName == null) return ''; var a = name.toNativeUtf8(); diff --git a/lib/remote_page.dart b/lib/remote_page.dart index c5733c83c..dea7b4a56 100644 --- a/lib/remote_page.dart +++ b/lib/remote_page.dart @@ -78,7 +78,8 @@ class _RemotePageState extends State { return _bottom >= 100; } - void interval() { + // crash on web before widgit initiated. + void intervalUnsafe() { var v = MediaQuery.of(context).viewInsets.bottom; if (v != _bottom) { resetTool(); @@ -92,6 +93,12 @@ class _RemotePageState extends State { FFI.ffiModel.update(widget.id, context, handleMsgbox); } + void interval() { + try { + intervalUnsafe(); + } catch (e) {} + } + void handleMsgbox(Map evt, String id) { var type = evt['type']; var title = evt['title']; diff --git a/lib/web_model.dart b/lib/web_model.dart index 6000401b3..a3ddf01fb 100644 --- a/lib/web_model.dart +++ b/lib/web_model.dart @@ -10,6 +10,10 @@ class PlatformFFI { // return Uint8List.sublistView(ref.data.asTypedList(ref.len)); } + static Future getVersion() async { + return ''; + } + static String getByName(String name, [String arg = '']) { return js.context.callMethod('getByName', [name, arg]); } @@ -20,6 +24,7 @@ class PlatformFFI { static Future init() async { isWeb = true; + js.context.callMethod('init'); } } diff --git a/web/index.html b/web/index.html index 57cef37e2..44f4ece57 100644 --- a/web/index.html +++ b/web/index.html @@ -32,6 +32,8 @@ RustDesk + +