diff --git a/pkg/base/model.go b/pkg/base/model.go index d0630b8e..991d6c0e 100644 --- a/pkg/base/model.go +++ b/pkg/base/model.go @@ -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 diff --git a/ui/flutter/lib/api/model/downloader_config.dart b/ui/flutter/lib/api/model/downloader_config.dart index 01c596cb..5cab5945 100644 --- a/ui/flutter/lib/api/model/downloader_config.dart +++ b/ui/flutter/lib/api/model/downloader_config.dart @@ -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 = '', diff --git a/ui/flutter/lib/api/model/downloader_config.g.dart b/ui/flutter/lib/api/model/downloader_config.g.dart index 6cd41ae6..662ad483 100644 --- a/ui/flutter/lib/api/model/downloader_config.g.dart +++ b/ui/flutter/lib/api/model/downloader_config.g.dart @@ -9,7 +9,7 @@ part of 'downloader_config.dart'; DownloaderConfig _$DownloaderConfigFromJson(Map 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?) @@ -39,7 +39,7 @@ Map _$ProtocolConfigToJson(ProtocolConfig instance) => HttpConfig _$HttpConfigFromJson(Map 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 _$HttpConfigToJson(HttpConfig instance) => }; BtConfig _$BtConfigFromJson(Map json) => BtConfig() - ..listenPort = json['listenPort'] as int + ..listenPort = (json['listenPort'] as num).toInt() ..trackers = (json['trackers'] as List).map((e) => e as String).toList(); @@ -74,6 +74,7 @@ Map _$ExtraConfigToJson(ExtraConfig instance) => ProxyConfig _$ProxyConfigFromJson(Map 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 json) => ProxyConfig( Map _$ProxyConfigToJson(ProxyConfig instance) => { 'enable': instance.enable, + 'system': instance.system, 'scheme': instance.scheme, 'host': instance.host, 'usr': instance.usr, diff --git a/ui/flutter/lib/api/model/options.g.dart b/ui/flutter/lib/api/model/options.g.dart index b496e9fc..40a1a8a4 100644 --- a/ui/flutter/lib/api/model/options.g.dart +++ b/ui/flutter/lib/api/model/options.g.dart @@ -10,7 +10,7 @@ Options _$OptionsFromJson(Map json) => Options( name: json['name'] as String, path: json['path'] as String, selectFiles: (json['selectFiles'] as List?) - ?.map((e) => e as int) + ?.map((e) => (e as num).toInt()) .toList() ?? const [], extra: json['extra'], @@ -35,7 +35,7 @@ Map _$OptionsToJson(Options instance) { OptsExtraHttp _$OptsExtraHttpFromJson(Map json) => OptsExtraHttp() - ..connections = json['connections'] as int + ..connections = (json['connections'] as num).toInt() ..autoTorrent = json['autoTorrent'] as bool; Map _$OptsExtraHttpToJson(OptsExtraHttp instance) => diff --git a/ui/flutter/lib/api/model/resource.g.dart b/ui/flutter/lib/api/model/resource.g.dart index 2feddd86..0a5e8fc8 100644 --- a/ui/flutter/lib/api/model/resource.g.dart +++ b/ui/flutter/lib/api/model/resource.g.dart @@ -8,7 +8,7 @@ part of 'resource.dart'; Resource _$ResourceFromJson(Map 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) .map((e) => FileInfo.fromJson(e as Map)) @@ -27,7 +27,7 @@ Map _$ResourceToJson(Resource instance) => { FileInfo _$FileInfoFromJson(Map 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), diff --git a/ui/flutter/lib/api/model/result.g.dart b/ui/flutter/lib/api/model/result.g.dart index 452a7c7c..03d4f734 100644 --- a/ui/flutter/lib/api/model/result.g.dart +++ b/ui/flutter/lib/api/model/result.g.dart @@ -11,7 +11,7 @@ Result _$ResultFromJson( T Function(Object? json) fromJsonT, ) => Result( - code: json['code'] as int, + code: (json['code'] as num).toInt(), msg: json['msg'] as String?, data: _$nullableGenericFromJson(json['data'], fromJsonT), ); diff --git a/ui/flutter/lib/api/model/task.g.dart b/ui/flutter/lib/api/model/task.g.dart index b5974a16..c0a77b95 100644 --- a/ui/flutter/lib/api/model/task.g.dart +++ b/ui/flutter/lib/api/model/task.g.dart @@ -34,9 +34,9 @@ const _$StatusEnumMap = { }; Progress _$ProgressFromJson(Map 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 _$ProgressToJson(Progress instance) => { diff --git a/ui/flutter/lib/app/modules/setting/views/setting_view.dart b/ui/flutter/lib/app/modules/setting/views/setting_view.dart index 0340da0e..02bfbbbd 100644 --- a/ui/flutter/lib/app/modules/setting/views/setting_view.dart +++ b/ui/flutter/lib/app/modules/setting/views/setting_view.dart @@ -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 { } // 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( + 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( + value: ProxyModeEnum.noProxy, + child: Text('noProxy'.tr), + ), + DropdownMenuItem( + value: ProxyModeEnum.systemProxy, + child: Text('systemProxy'.tr), + ), + DropdownMenuItem( + value: ProxyModeEnum.customProxy, + child: Text('customProxy'.tr), + ), + ], + ), ); final scheme = SizedBox( - width: 100, + width: 150, child: DropdownButtonFormField( value: proxy.scheme, onChanged: (value) async { @@ -478,7 +503,7 @@ class SettingView extends GetView { 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 { ], ), ), - ]; + ]); 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 { ), ), ), - ]; + ]); + + List 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 { } } } + +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; + } + } +} diff --git a/ui/flutter/lib/core/common/start_config.g.dart b/ui/flutter/lib/core/common/start_config.g.dart index 8732accb..85e67b85 100644 --- a/ui/flutter/lib/core/common/start_config.g.dart +++ b/ui/flutter/lib/core/common/start_config.g.dart @@ -11,7 +11,7 @@ StartConfig _$StartConfigFromJson(Map 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 _$StartConfigToJson(StartConfig instance) => diff --git a/ui/flutter/lib/i18n/langs/en_us.dart b/ui/flutter/lib/i18n/langs/en_us.dart index 0c64beb5..22aa8a75 100644 --- a/ui/flutter/lib/i18n/langs/en_us.dart +++ b/ui/flutter/lib/i18n/langs/en_us.dart @@ -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', diff --git a/ui/flutter/lib/i18n/langs/zh_cn.dart b/ui/flutter/lib/i18n/langs/zh_cn.dart index a18de6a0..188d3eab 100644 --- a/ui/flutter/lib/i18n/langs/zh_cn.dart +++ b/ui/flutter/lib/i18n/langs/zh_cn.dart @@ -80,6 +80,9 @@ const zhCN = { 'serviceText': '运行中', 'network': '网络', 'proxy': '代理', + 'noProxy': '不使用代理', + 'systemProxy': '系统代理', + 'customProxy': '自定义代理', 'server': '服务器', 'username': '用户名', 'password': '密码', diff --git a/ui/flutter/lib/i18n/langs/zh_tw.dart b/ui/flutter/lib/i18n/langs/zh_tw.dart index 30c6ff66..044227f2 100644 --- a/ui/flutter/lib/i18n/langs/zh_tw.dart +++ b/ui/flutter/lib/i18n/langs/zh_tw.dart @@ -80,6 +80,9 @@ const zhTW = { 'serviceText': '執行中', 'network': '網路', 'proxy': '代理', + 'noProxy': '不使用代理', + 'systemProxy': '系統代理', + 'customProxy': '自定義代理', 'server': '伺服器', 'username': '名稱', 'password': '密碼',