refactor
This commit is contained in:
parent
0cdef55e3d
commit
600f604611
@ -2,74 +2,11 @@ import 'package:flutter/material.dart';
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||||
import 'package:tuple/tuple.dart';
|
import 'package:tuple/tuple.dart';
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
final bool isZh = Platform.localeName.startsWith('zh');
|
typedef F = String Function(String);
|
||||||
|
|
||||||
final langs = <String, Map<String, String>>{
|
class Translator {
|
||||||
'zh': <String, String>{
|
static F call;
|
||||||
'Remote ID': '远程ID',
|
|
||||||
'ID/Relay Server': 'ID/中继服务器',
|
|
||||||
'About': '关于',
|
|
||||||
'Mute': '静音',
|
|
||||||
'ID Server': 'ID服务器',
|
|
||||||
'Relay Server': '中继服务器',
|
|
||||||
'Invalid IP': '无效IP',
|
|
||||||
'Invalid format': '无效格式',
|
|
||||||
'Cancel': '取消',
|
|
||||||
'Close': '关闭',
|
|
||||||
'Retry': '再试',
|
|
||||||
'OK': '确认',
|
|
||||||
'Password Required': '需要密码',
|
|
||||||
'Enter your password': '输入你的密码',
|
|
||||||
'Please enter your password': '请输入密码',
|
|
||||||
'Remember password': '记住密码',
|
|
||||||
'Wrong Password': '密码错误',
|
|
||||||
'Do you want to enter again?': '还想输入一次吗?',
|
|
||||||
'Connection Error': '连接错误',
|
|
||||||
'Error': '错误',
|
|
||||||
'Reset by the peer': '连接被对方关闭',
|
|
||||||
'Connecting...': '正在连接...',
|
|
||||||
'Connection in progress. Please wait.': '连接进行中,请稍等。',
|
|
||||||
'Please try 1 minute later': '一分钟后再试',
|
|
||||||
'Login Error': '登录错误',
|
|
||||||
'Successful': '成功',
|
|
||||||
'Custom Image Quality': '设置画面质量',
|
|
||||||
'Privacy mode': '隐私模式',
|
|
||||||
'Remove': '删除',
|
|
||||||
'Adjust Window': '调节窗口',
|
|
||||||
'Good image quality': '好画质',
|
|
||||||
'Balanced': '一般画质',
|
|
||||||
'Optimize reaction time': '优化反应时间',
|
|
||||||
'Custom': '自定义画质',
|
|
||||||
'Show remote cursor': '显示远程光标',
|
|
||||||
'Disable clipboard': '禁止剪贴板',
|
|
||||||
'Lock after session end': '断开后锁定远程电脑',
|
|
||||||
'Insert': '插入',
|
|
||||||
'Insert Lock': '锁定远程电脑',
|
|
||||||
'Refresh': '刷新画面',
|
|
||||||
'ID does not exist': 'ID不存在',
|
|
||||||
'Failed to connect to rendezvous server': '连接服务器失败',
|
|
||||||
'Remote desktop is offline': '远程电脑不在线',
|
|
||||||
'Key mismatch': 'Key不匹配',
|
|
||||||
'Timeout': '连接超时',
|
|
||||||
'Failed to connect to relay server': '无法连接到中继服务器',
|
|
||||||
'Failed to connect via rendezvous server': '无法通过服务器建立连接',
|
|
||||||
'Failed to make direct connection to remote desktop': '无法建立直接连接',
|
|
||||||
'OS Password': '操作系统密码',
|
|
||||||
'Password': '密码',
|
|
||||||
'Paste': '粘贴',
|
|
||||||
'Logging in...': '正在登录...',
|
|
||||||
'Are you sure to close the connection?': '是否确认关闭连接?',
|
|
||||||
'Waiting for image...': '等待画面传输...',
|
|
||||||
},
|
|
||||||
'en': <String, String>{}
|
|
||||||
};
|
|
||||||
|
|
||||||
String translate(name) {
|
|
||||||
final tmp = isZh ? langs['zh'] : langs['en'];
|
|
||||||
final v = tmp[name];
|
|
||||||
return v != null ? v : name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyTheme {
|
class MyTheme {
|
||||||
@ -83,6 +20,15 @@ class MyTheme {
|
|||||||
static const Color border = Color(0xFFCCCCCC);
|
static const Color border = Color(0xFFCCCCCC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final ButtonStyle flatButtonStyle = TextButton.styleFrom(
|
||||||
|
primary: MyTheme.accent,
|
||||||
|
minimumSize: Size(88, 36),
|
||||||
|
padding: EdgeInsets.symmetric(horizontal: 16.0),
|
||||||
|
shape: const RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.all(Radius.circular(2.0)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
void showLoading(String text, BuildContext context) {
|
void showLoading(String text, BuildContext context) {
|
||||||
if (_hasDialog && context != null) {
|
if (_hasDialog && context != null) {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
@ -141,11 +87,11 @@ void msgbox(String type, String title, String text, BuildContext context,
|
|||||||
.shrinkWrap, //limits the touch area to the button area
|
.shrinkWrap, //limits the touch area to the button area
|
||||||
minWidth: 0, //wraps child's width
|
minWidth: 0, //wraps child's width
|
||||||
height: 0,
|
height: 0,
|
||||||
child: FlatButton(
|
child: TextButton(
|
||||||
focusColor: MyTheme.accent,
|
style: flatButtonStyle,
|
||||||
onPressed: onPressed,
|
onPressed: onPressed,
|
||||||
child:
|
child: Text(Translator.call(text),
|
||||||
Text(translate(text), style: TextStyle(color: MyTheme.accent))));
|
style: TextStyle(color: MyTheme.accent))));
|
||||||
|
|
||||||
dismissLoading();
|
dismissLoading();
|
||||||
if (_hasDialog) {
|
if (_hasDialog) {
|
||||||
@ -153,7 +99,7 @@ void msgbox(String type, String title, String text, BuildContext context,
|
|||||||
}
|
}
|
||||||
final buttons = [
|
final buttons = [
|
||||||
Expanded(child: Container()),
|
Expanded(child: Container()),
|
||||||
wrap(translate('OK'), () {
|
wrap(Translator.call('OK'), () {
|
||||||
dismissLoading();
|
dismissLoading();
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
})
|
})
|
||||||
@ -164,7 +110,7 @@ void msgbox(String type, String title, String text, BuildContext context,
|
|||||||
if (hasCancel) {
|
if (hasCancel) {
|
||||||
buttons.insert(
|
buttons.insert(
|
||||||
1,
|
1,
|
||||||
wrap(translate('Cancel'), () {
|
wrap(Translator.call('Cancel'), () {
|
||||||
dismissLoading();
|
dismissLoading();
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -172,9 +118,9 @@ void msgbox(String type, String title, String text, BuildContext context,
|
|||||||
Column(
|
Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(translate(title), style: TextStyle(fontSize: 21)),
|
Text(Translator.call(title), style: TextStyle(fontSize: 21)),
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
Text(translate(text), style: TextStyle(fontSize: 15)),
|
Text(Translator.call(text), style: TextStyle(fontSize: 15)),
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
Row(
|
Row(
|
||||||
children: buttons,
|
children: buttons,
|
||||||
@ -203,8 +149,8 @@ class _PasswordWidgetState extends State<PasswordWidget> {
|
|||||||
obscureText: !_passwordVisible, //This will obscure text dynamically
|
obscureText: !_passwordVisible, //This will obscure text dynamically
|
||||||
keyboardType: TextInputType.visiblePassword,
|
keyboardType: TextInputType.visiblePassword,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
labelText: translate('Password'),
|
labelText: Translator.call('Password'),
|
||||||
hintText: translate('Enter your password'),
|
hintText: Translator.call('Enter your password'),
|
||||||
// Here is key idea
|
// Here is key idea
|
||||||
suffixIcon: IconButton(
|
suffixIcon: IconButton(
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
|
@ -300,15 +300,15 @@ void showServer(BuildContext context) {
|
|||||||
),
|
),
|
||||||
])),
|
])),
|
||||||
[
|
[
|
||||||
FlatButton(
|
TextButton(
|
||||||
textColor: MyTheme.accent,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
child: Text(translate('Cancel')),
|
child: Text(translate('Cancel')),
|
||||||
),
|
),
|
||||||
FlatButton(
|
TextButton(
|
||||||
textColor: MyTheme.accent,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (formKey.currentState.validate()) {
|
if (formKey.currentState.validate()) {
|
||||||
formKey.currentState.save();
|
formKey.currentState.save();
|
||||||
|
@ -44,6 +44,7 @@ class FfiModel with ChangeNotifier {
|
|||||||
get pi => _pi;
|
get pi => _pi;
|
||||||
|
|
||||||
FfiModel() {
|
FfiModel() {
|
||||||
|
Translator.call = translate;
|
||||||
clear();
|
clear();
|
||||||
() async {
|
() async {
|
||||||
await FFI.init();
|
await FFI.init();
|
||||||
@ -193,7 +194,7 @@ class FfiModel with ChangeNotifier {
|
|||||||
initializeCursorAndCanvas();
|
initializeCursorAndCanvas();
|
||||||
}
|
}
|
||||||
if (displays.length > 0) {
|
if (displays.length > 0) {
|
||||||
showLoading(translate('Waiting for image...'), context);
|
showLoading(translate('Connected, waiting for image...'), context);
|
||||||
_waitForImage = true;
|
_waitForImage = true;
|
||||||
}
|
}
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
@ -728,3 +729,26 @@ void initializeCursorAndCanvas() async {
|
|||||||
FFI.ffiModel.display.x, FFI.ffiModel.display.y, xCursor, yCursor);
|
FFI.ffiModel.display.x, FFI.ffiModel.display.y, xCursor, yCursor);
|
||||||
FFI.canvasModel.update(xCanvas, yCanvas, scale);
|
FFI.canvasModel.update(xCanvas, yCanvas, scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final bool isCn = Platform.localeName.endsWith('CN');
|
||||||
|
|
||||||
|
final langs = <String, Map<String, String>>{
|
||||||
|
'cn': <String, String>{
|
||||||
|
'Remote ID': '远程ID',
|
||||||
|
'Paste': '粘贴',
|
||||||
|
'Are you sure to close the connection?': '是否确认关闭连接?',
|
||||||
|
},
|
||||||
|
'en': <String, String>{}
|
||||||
|
};
|
||||||
|
|
||||||
|
String translate(name) {
|
||||||
|
final tmp = isCn ? langs['cn'] : langs['en'];
|
||||||
|
final v = tmp[name];
|
||||||
|
if (v == null) {
|
||||||
|
var a = 'translate';
|
||||||
|
var b = '{"locale": "${Platform.localeName}", "text": "${name}"}';
|
||||||
|
return FFI.getByName(a, b);
|
||||||
|
} else {
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -360,12 +360,13 @@ class _RemotePageState extends State<RemotePage> {
|
|||||||
.shrinkWrap, //limits the touch area to the button area
|
.shrinkWrap, //limits the touch area to the button area
|
||||||
minWidth: 0, //wraps child's width
|
minWidth: 0, //wraps child's width
|
||||||
height: 0,
|
height: 0,
|
||||||
child: FlatButton(
|
child: TextButton(
|
||||||
splashColor: MyTheme.accent,
|
style: TextButton.styleFrom(
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(5.0),
|
borderRadius: BorderRadius.circular(5.0),
|
||||||
|
),
|
||||||
|
primary: active == true ? MyTheme.accent80 : null,
|
||||||
),
|
),
|
||||||
color: active == true ? MyTheme.accent80 : null,
|
|
||||||
child: icon != null
|
child: icon != null
|
||||||
? Icon(icon, size: 17, color: Colors.white)
|
? Icon(icon, size: 17, color: Colors.white)
|
||||||
: Text(translate(text),
|
: Text(translate(text),
|
||||||
@ -596,16 +597,16 @@ void enterPasswordDialog(String id, BuildContext context) {
|
|||||||
),
|
),
|
||||||
]),
|
]),
|
||||||
[
|
[
|
||||||
FlatButton(
|
TextButton(
|
||||||
textColor: MyTheme.accent,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
child: Text(translate('Cancel')),
|
child: Text(translate('Cancel')),
|
||||||
),
|
),
|
||||||
FlatButton(
|
TextButton(
|
||||||
textColor: MyTheme.accent,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
var text = controller.text.trim();
|
var text = controller.text.trim();
|
||||||
if (text == '') return;
|
if (text == '') return;
|
||||||
@ -624,16 +625,16 @@ void wrongPasswordDialog(String id, BuildContext context) {
|
|||||||
context,
|
context,
|
||||||
(_) => Tuple3(Text(translate('Wrong Password')),
|
(_) => Tuple3(Text(translate('Wrong Password')),
|
||||||
Text(translate('Do you want to enter again?')), [
|
Text(translate('Do you want to enter again?')), [
|
||||||
FlatButton(
|
TextButton(
|
||||||
textColor: MyTheme.accent,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
child: Text(translate('Cancel')),
|
child: Text(translate('Cancel')),
|
||||||
),
|
),
|
||||||
FlatButton(
|
TextButton(
|
||||||
textColor: MyTheme.accent,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
enterPasswordDialog(id, context);
|
enterPasswordDialog(id, context);
|
||||||
},
|
},
|
||||||
@ -781,8 +782,8 @@ void showActions(BuildContext context) {
|
|||||||
child: Row(
|
child: Row(
|
||||||
children: ([
|
children: ([
|
||||||
Text(translate('OS Password')),
|
Text(translate('OS Password')),
|
||||||
FlatButton(
|
TextButton(
|
||||||
textColor: MyTheme.accent,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
showSetOSPassword(context);
|
showSetOSPassword(context);
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
@ -850,15 +851,15 @@ void showSetOSPassword(BuildContext context) async {
|
|||||||
PasswordWidget(controller: controller),
|
PasswordWidget(controller: controller),
|
||||||
]),
|
]),
|
||||||
[
|
[
|
||||||
FlatButton(
|
TextButton(
|
||||||
textColor: MyTheme.accent,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
child: Text(translate('Cancel')),
|
child: Text(translate('Cancel')),
|
||||||
),
|
),
|
||||||
FlatButton(
|
TextButton(
|
||||||
textColor: MyTheme.accent,
|
style: flatButtonStyle,
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
var text = controller.text.trim();
|
var text = controller.text.trim();
|
||||||
savePassword(FFI.id, text);
|
savePassword(FFI.id, text);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user