setting ui

This commit is contained in:
liwei committed 2024-05-01 18:35:32 +08:00
1 parent 5134446c3f
commit 91ac841b9d
12 files changed
+115 -40

No files matched your search

+2
View File
@@ -168,6 +168,7 @@ func (cfg *DownloaderProxyConfig) ToHandler() func(r *http.Request) (*url.URL, e
return nil
}
if cfg.System {
ieproxy.ReloadConf()
return ieproxy.GetProxyFunc()
}
if cfg.Scheme == "" || cfg.Host == "" {
@@ -182,6 +183,7 @@ func (cfg *DownloaderProxyConfig) ToUrl() *url.URL {
return nil
}
if cfg.System {
ieproxy.ReloadConf()
static := ieproxy.GetConf().Static
if static.Active && len(static.Protocols) > 0 {
// If only one protocol, use it
@@ -78,6 +78,7 @@ class ExtraConfig {
@JsonSerializable()
class ProxyConfig {
bool enable;
bool system;
String scheme;
String host;
String usr;
@@ -85,6 +86,7 @@ class ProxyConfig {
ProxyConfig({
this.enable = false,
this.system = false,
this.scheme = '',
this.host = '',
this.usr = '',
@@ -9,7 +9,7 @@ part of 'downloader_config.dart';
DownloaderConfig _$DownloaderConfigFromJson(Map<String, dynamic> json) =>
DownloaderConfig(
downloadDir: json['downloadDir'] as String? ?? '',
maxRunning: json['maxRunning'] as int? ?? 0,
maxRunning: (json['maxRunning'] as num?)?.toInt() ?? 0,
)
..protocolConfig = ProtocolConfig.fromJson(
json['protocolConfig'] as Map<String, dynamic>?)
@@ -39,7 +39,7 @@ Map<String, dynamic> _$ProtocolConfigToJson(ProtocolConfig instance) =>
HttpConfig _$HttpConfigFromJson(Map<String, dynamic> json) => HttpConfig(
userAgent: json['userAgent'] as String? ??
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
connections: json['connections'] as int? ?? 16,
connections: (json['connections'] as num?)?.toInt() ?? 16,
useServerCtime: json['useServerCtime'] as bool? ?? false,
);
@@ -51,7 +51,7 @@ Map<String, dynamic> _$HttpConfigToJson(HttpConfig instance) =>
};
BtConfig _$BtConfigFromJson(Map<String, dynamic> json) => BtConfig()
..listenPort = json['listenPort'] as int
..listenPort = (json['listenPort'] as num).toInt()
..trackers =
(json['trackers'] as List<dynamic>).map((e) => e as String).toList();
@@ -74,6 +74,7 @@ Map<String, dynamic> _$ExtraConfigToJson(ExtraConfig instance) =>
ProxyConfig _$ProxyConfigFromJson(Map<String, dynamic> json) => ProxyConfig(
enable: json['enable'] as bool? ?? false,
system: json['system'] as bool? ?? false,
scheme: json['scheme'] as String? ?? '',
host: json['host'] as String? ?? '',
usr: json['usr'] as String? ?? '',
@@ -83,6 +84,7 @@ ProxyConfig _$ProxyConfigFromJson(Map<String, dynamic> json) => ProxyConfig(
Map<String, dynamic> _$ProxyConfigToJson(ProxyConfig instance) =>
<String, dynamic>{
'enable': instance.enable,
'system': instance.system,
'scheme': instance.scheme,
'host': instance.host,
'usr': instance.usr,
+2 -2
View File
@@ -10,7 +10,7 @@ Options _$OptionsFromJson(Map<String, dynamic> json) => Options(
name: json['name'] as String,
path: json['path'] as String,
selectFiles: (json['selectFiles'] as List<dynamic>?)
?.map((e) => e as int)
?.map((e) => (e as num).toInt())
.toList() ??
const [],
extra: json['extra'],
@@ -35,7 +35,7 @@ Map<String, dynamic> _$OptionsToJson(Options instance) {
OptsExtraHttp _$OptsExtraHttpFromJson(Map<String, dynamic> json) =>
OptsExtraHttp()
..connections = json['connections'] as int
..connections = (json['connections'] as num).toInt()
..autoTorrent = json['autoTorrent'] as bool;
Map<String, dynamic> _$OptsExtraHttpToJson(OptsExtraHttp instance) =>
+2 -2
View File
@@ -8,7 +8,7 @@ part of 'resource.dart';
Resource _$ResourceFromJson(Map<String, dynamic> json) => Resource(
name: json['name'] as String? ?? "",
size: json['size'] as int? ?? 0,
size: (json['size'] as num?)?.toInt() ?? 0,
range: json['range'] as bool? ?? false,
files: (json['files'] as List<dynamic>)
.map((e) => FileInfo.fromJson(e as Map<String, dynamic>))
@@ -27,7 +27,7 @@ Map<String, dynamic> _$ResourceToJson(Resource instance) => <String, dynamic>{
FileInfo _$FileInfoFromJson(Map<String, dynamic> json) => FileInfo(
path: json['path'] as String? ?? "",
name: json['name'] as String,
size: json['size'] as int? ?? 0,
size: (json['size'] as num?)?.toInt() ?? 0,
req: json['req'] == null
? null
: Request.fromJson(json['req'] as Map<String, dynamic>),
+1 -1
View File
@@ -11,7 +11,7 @@ Result<T> _$ResultFromJson<T>(
T Function(Object? json) fromJsonT,
) =>
Result<T>(
code: json['code'] as int,
code: (json['code'] as num).toInt(),
msg: json['msg'] as String?,
data: _$nullableGenericFromJson(json['data'], fromJsonT),
);
+3 -3
View File
@@ -34,9 +34,9 @@ const _$StatusEnumMap = {
};
Progress _$ProgressFromJson(Map<String, dynamic> json) => Progress(
used: json['used'] as int,
speed: json['speed'] as int,
downloaded: json['downloaded'] as int,
used: (json['used'] as num).toInt(),
speed: (json['speed'] as num).toInt(),
downloaded: (json['downloaded'] as num).toInt(),
);
Map<String, dynamic> _$ProgressToJson(Progress instance) => <String, dynamic>{
@@ -7,6 +7,7 @@ import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../../../api/model/downloader_config.dart';
import '../../../../i18n/message.dart';
import '../../../../util/input_formatter.dart';
import '../../../../util/locale_manager.dart';
@@ -408,29 +409,53 @@ class SettingView extends GetView<SettingController> {
}
// advanced config proxy items start
final proxy = downloaderCfg.value.proxy;
final buildProxy = _buildConfigItem(
'proxy',
() => downloaderCfg.value.proxy.enable
? '${downloaderCfg.value.proxy.scheme}://${downloaderCfg.value.proxy.host}'
: 'notSet'.tr,
() {
switch (proxy.proxyMode) {
case ProxyModeEnum.noProxy:
return 'noProxy'.tr;
case ProxyModeEnum.systemProxy:
return 'systemProxy'.tr;
case ProxyModeEnum.customProxy:
return '${downloaderCfg.value.proxy.scheme}://${downloaderCfg.value.proxy.host}';
}
},
(Key key) {
final proxy = downloaderCfg.value.proxy;
final mode = SizedBox(
width: 150,
child: DropdownButtonFormField<ProxyModeEnum>(
value: proxy.proxyMode,
onChanged: (value) async {
if (value != null && value != proxy.proxyMode) {
proxy.proxyMode = value;
downloaderCfg.update((val) {
val!.proxy = proxy;
});
final switcher = Switch(
value: proxy.enable,
onChanged: (bool value) async {
if (value != proxy.enable) {
downloaderCfg.update((val) {
val!.proxy.enable = value;
});
await debounceSave();
}
},
await debounceSave();
}
},
items: [
DropdownMenuItem<ProxyModeEnum>(
value: ProxyModeEnum.noProxy,
child: Text('noProxy'.tr),
),
DropdownMenuItem<ProxyModeEnum>(
value: ProxyModeEnum.systemProxy,
child: Text('systemProxy'.tr),
),
DropdownMenuItem<ProxyModeEnum>(
value: ProxyModeEnum.customProxy,
child: Text('customProxy'.tr),
),
],
),
);
final scheme = SizedBox(
width: 100,
width: 150,
child: DropdownButtonFormField<String>(
value: proxy.scheme,
onChanged: (value) async {
@@ -478,7 +503,7 @@ class SettingView extends GetView<SettingController> {
ipController.addListener(updateAddress);
portController.addListener(updateAddress);
final server = [
final server = Row(children: [
Flexible(
child: TextFormField(
controller: ipController,
@@ -503,12 +528,12 @@ class SettingView extends GetView<SettingController> {
],
),
),
];
]);
final usrController = TextEditingController(text: proxy.usr);
final pwdController = TextEditingController(text: proxy.pwd);
final auth = [
final auth = Row(children: [
Flexible(
child: TextFormField(
controller: usrController,
@@ -528,20 +553,21 @@ class SettingView extends GetView<SettingController> {
),
),
),
];
]);
List<Widget> customView() {
if (proxy.proxyMode != ProxyModeEnum.customProxy) {
return [];
}
return [scheme, server, auth];
}
return Form(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: _addPadding([
switcher,
scheme,
Row(
children: server,
),
Row(
children: auth,
),
mode,
...customView(),
]),
),
);
@@ -857,3 +883,37 @@ class SettingView extends GetView<SettingController> {
}
}
}
enum ProxyModeEnum {
noProxy,
systemProxy,
customProxy,
}
extension ProxyMode on ProxyConfig {
ProxyModeEnum get proxyMode {
if (!enable) {
return ProxyModeEnum.noProxy;
}
if (system) {
return ProxyModeEnum.systemProxy;
}
return ProxyModeEnum.customProxy;
}
set proxyMode(ProxyModeEnum value) {
switch (value) {
case ProxyModeEnum.noProxy:
enable = false;
break;
case ProxyModeEnum.systemProxy:
enable = true;
system = true;
break;
case ProxyModeEnum.customProxy:
enable = true;
system = false;
break;
}
}
}
@@ -11,7 +11,7 @@ StartConfig _$StartConfigFromJson(Map<String, dynamic> json) => StartConfig()
..address = json['address'] as String
..storage = json['storage'] as String
..storageDir = json['storageDir'] as String
..refreshInterval = json['refreshInterval'] as int
..refreshInterval = (json['refreshInterval'] as num).toInt()
..apiToken = json['apiToken'] as String;
Map<String, dynamic> _$StartConfigToJson(StartConfig instance) =>
+3
View File
@@ -82,6 +82,9 @@ const enUS = {
'serviceText': 'Running',
'network': 'Network',
'proxy': 'Proxy',
'noProxy': 'No Proxy',
'systemProxy': 'System Proxy',
'customProxy': 'Custom Proxy',
'server': 'Server',
'username': 'Username',
'password': 'Password',
+3
View File
@@ -80,6 +80,9 @@ const zhCN = {
'serviceText': '运行中',
'network': '网络',
'proxy': '代理',
'noProxy': '不使用代理',
'systemProxy': '系统代理',
'customProxy': '自定义代理',
'server': '服务器',
'username': '用户名',
'password': '密码',
+3
View File
@@ -80,6 +80,9 @@ const zhTW = {
'serviceText': '執行中',
'network': '網路',
'proxy': '代理',
'noProxy': '不使用代理',
'systemProxy': '系統代理',
'customProxy': '自定義代理',
'server': '伺服器',
'username': '名稱',
'password': '密碼',