Skip to content

Commit

Permalink
✨ 优化:代理设置移动到应用设置
Browse files Browse the repository at this point in the history
  • Loading branch information
gvenusleo committed Nov 10, 2023
1 parent 4d1d9c5 commit 300bc26
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 38 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- ✨ 优化:使用系统通知代替 SnackBar
- 🧩 功能:支持百度高精度 OCR
- 🧩 功能:文字识别历史记录
- ✨ 优化:代理设置移动到应用设置

## 0.1.3(2023-10-19)

Expand Down
49 changes: 49 additions & 0 deletions lib/pages/setting_page/app_setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "package:lex/global.dart";
import "package:lex/providers/theme_provider.dart";
import "package:lex/utils/font_utils.dart";
import "package:lex/widgets/list_tile_group_title.dart";
import "package:local_notifier/local_notifier.dart";
import "package:provider/provider.dart";
import "package:window_manager/window_manager.dart";

Expand All @@ -30,6 +31,12 @@ class _AppSettingPageState extends State<AppSettingPage> {
bool _launchAtStartup = false;
// 启动时隐藏窗口
late bool _hideWindowAtStartup;
// 使用代理
bool _useProxy = prefs.getBool("useProxy") ?? false;
// 代理地址
final String _proxyAddress = prefs.getString("proxyAddress") ?? "";

final TextEditingController _proxyAddressController = TextEditingController();

@override
void initState() {
Expand All @@ -42,6 +49,7 @@ class _AppSettingPageState extends State<AppSettingPage> {
_windowFllowCursor = prefs.getBool("windowFollowCursor") ?? false;
_useRoundedWindow = prefs.getBool("useRoundedWindow") ?? true;
_hideWindowAtStartup = prefs.getBool("hideWindowAtStartup") ?? false;
_proxyAddressController.text = _proxyAddress;
super.initState();
}

Expand Down Expand Up @@ -161,6 +169,47 @@ class _AppSettingPageState extends State<AppSettingPage> {
title: const Text("启动时隐藏窗口"),
subtitle: const Text("启动应用时自动隐藏到系统托盘"),
),
const ListTileGroupTitle(title: "网络设置"),
SwitchListTile(
value: _useProxy,
onChanged: (value) async {
if (value == true &&
(prefs.getString("proxyAddress") ?? "").isEmpty) {
LocalNotification notification = LocalNotification(
title: "Lex",
body: "请先设置代理地址!",
actions: [
LocalNotificationAction(
text: "确定",
),
],
);
notification.show();
return;
}
setState(() {
_useProxy = value;
});
await prefs.setBool("useProxy", value);
},
secondary: const Icon(Icons.travel_explore_outlined),
title: const Text("使用代理"),
subtitle: const Text("使用代理服务器进行翻译"),
),
Padding(
padding: const EdgeInsets.only(left: 54, right: 28),
child: TextField(
controller: _proxyAddressController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: "代理地址",
prefixText: "http://",
),
onChanged: (value) {
prefs.setString("proxyAddress", value);
},
),
),
],
),
);
Expand Down
38 changes: 0 additions & 38 deletions lib/pages/setting_page/translationg_setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,6 @@ class _TranslationSettingPageState extends State<TranslationSettingPage> {
// 删除换行
bool _deleteTranslationLineBreak =
prefs.getBool("deleteTranslationLineBreak") ?? false;
// 使用代理
bool _useProxy = prefs.getBool("useProxy") ?? false;
// 代理地址
final String _proxyAddress = prefs.getString("proxyAddress") ?? "";

final TextEditingController _proxyAddressController = TextEditingController();

@override
void initState() {
_proxyAddressController.text = _proxyAddress;
super.initState();
}

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -125,32 +113,6 @@ class _TranslationSettingPageState extends State<TranslationSettingPage> {
title: const Text("删除换行"),
subtitle: const Text("删除文本换行符"),
),
SwitchListTile(
value: _useProxy,
onChanged: (value) async {
setState(() {
_useProxy = value;
});
await prefs.setBool("useProxy", value);
},
secondary: const Icon(Icons.travel_explore_outlined),
title: const Text("使用代理"),
subtitle: const Text("使用代理服务器进行翻译"),
),
Padding(
padding: const EdgeInsets.only(left: 54, right: 28),
child: TextField(
controller: _proxyAddressController,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: "代理地址",
prefixText: "http://",
),
onChanged: (value) {
prefs.setString("proxyAddress", value);
},
),
),
],
),
);
Expand Down

0 comments on commit 300bc26

Please sign in to comment.