rustdesk/lib/pages/settings_page.dart

189 lines
5.7 KiB
Dart
Raw Normal View History

import 'package:settings_ui/settings_ui.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import '../common.dart';
import '../models/model.dart';
import 'home_page.dart';
class SettingsPage extends StatelessWidget implements PageShape {
@override
2022-03-23 15:28:21 +08:00
final title = translate("Settings");
@override
final icon = Icon(Icons.settings);
@override
final appBarActions = [];
static const url = 'https://rustdesk.com/';
@override
Widget build(BuildContext context) {
return SettingsList(
sections: [
SettingsSection(
title: Text("Common"),
tiles: [
SettingsTile.navigation(
2022-03-24 21:31:47 +08:00
title: Text(translate('ID/Relay Server')),
leading: Icon(Icons.cloud),
onPressed: (context) {
showServer();
},
),
],
),
SettingsSection(
title: Text("About"),
tiles: [
SettingsTile.navigation(
2022-03-13 00:32:44 +08:00
title: Text("Version: " + version),
value: InkWell(
onTap: () async {
const url = 'https://rustdesk.com/';
if (await canLaunch(url)) {
await launch(url);
}
},
child: Padding(
padding: EdgeInsets.symmetric(vertical: 8),
child: Text('Support',
style: TextStyle(
decoration: TextDecoration.underline,
)),
),
),
leading: Icon(Icons.info)),
],
),
],
);
}
}
void showServer() {
final formKey = GlobalKey<FormState>();
final id0 = FFI.getByName('option', 'custom-rendezvous-server');
final relay0 = FFI.getByName('option', 'relay-server');
final key0 = FFI.getByName('option', 'key');
var id = '';
var relay = '';
var key = '';
2022-03-13 23:07:52 +08:00
DialogManager.show((setState, close) {
2022-03-13 00:32:44 +08:00
return CustomAlertDialog(
2022-03-24 21:31:47 +08:00
title: Text(translate('ID/Relay Server')),
2022-03-24 21:23:22 +08:00
content: Form(
key: formKey,
2022-03-24 21:31:47 +08:00
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
TextFormField(
initialValue: id0,
decoration: InputDecoration(
labelText: translate('ID Server'),
),
validator: validate,
onSaved: (String? value) {
if (value != null) id = value.trim();
},
)
] +
(isAndroid
? [
TextFormField(
initialValue: relay0,
decoration: InputDecoration(
labelText: translate('Relay Server'),
),
validator: validate,
onSaved: (String? value) {
if (value != null) relay = value.trim();
},
)
]
: []) +
[
TextFormField(
initialValue: key0,
decoration: InputDecoration(
labelText: 'Key',
),
validator: null,
onSaved: (String? value) {
if (value != null) key = value.trim();
},
),
2022-03-24 21:31:47 +08:00
])),
2022-03-24 21:23:22 +08:00
actions: [
TextButton(
style: flatButtonStyle,
onPressed: () {
close();
},
child: Text(translate('Cancel')),
),
TextButton(
style: flatButtonStyle,
onPressed: () {
if (formKey.currentState != null &&
formKey.currentState!.validate()) {
formKey.currentState!.save();
if (id != id0)
FFI.setByName('option',
'{"name": "custom-rendezvous-server", "value": "$id"}');
if (relay != relay0)
FFI.setByName(
'option', '{"name": "relay-server", "value": "$relay"}');
if (key != key0)
FFI.setByName('option', '{"name": "key", "value": "$key"}');
2022-03-13 23:07:52 +08:00
close();
2022-03-24 21:23:22 +08:00
}
},
child: Text(translate('OK')),
),
],
onWillPop: () async {
return true;
},
);
}, barrierDismissible: true);
}
String? validate(value) {
value = value.trim();
if (value.isEmpty) {
return null;
}
final res = FFI.getByName('test_if_valid_server', value);
return res.isEmpty ? null : res;
}
2022-03-24 20:57:30 +08:00
void showAbout() {
DialogManager.show((setState, close) {
return CustomAlertDialog(
title: Text(translate('About') + ' RustDesk'),
content: Wrap(direction: Axis.vertical, spacing: 12, children: [
Text('Version: $version'),
InkWell(
onTap: () async {
const url = 'https://rustdesk.com/';
if (await canLaunch(url)) {
await launch(url);
}
},
child: Padding(
padding: EdgeInsets.symmetric(vertical: 8),
child: Text('Support',
style: TextStyle(
decoration: TextDecoration.underline,
)),
)),
]),
2022-03-24 21:23:22 +08:00
actions: [],
2022-03-24 20:57:30 +08:00
onWillPop: () async {
return true;
},
);
2022-03-24 21:23:22 +08:00
}, barrierDismissible: true);
2022-03-24 20:57:30 +08:00
}