This commit is contained in:
wgh19
2024-05-16 09:31:21 +08:00
parent 2f0b1b9554
commit 945d386d17
3 changed files with 61 additions and 14 deletions

View File

@@ -18,7 +18,8 @@ class _Appdata {
"downloadSubPath": r"/${id}-p${index}.${ext}",
"tagsWeight": "風景 ロリ 巨乳 女の子",
"useTranslatedNameForDownload": true,
"maxParallels": 3
"maxParallels": 3,
"proxy": "",
};
bool lock = false;

View File

@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:dio/dio.dart';
import 'package:dio/io.dart';
import 'package:flutter/services.dart';
import 'package:pixes/appdata.dart';
import 'package:pixes/foundation/app.dart';
import 'package:pixes/foundation/log.dart';
import 'package:pixes/utils/ext.dart';
@@ -132,7 +133,9 @@ class _ProxyHttpOverrides extends HttpOverrides {
String proxy = "DIRECT";
String findProxy(Uri uri) {
if(!App.isLinux) {
var haveUserProxy = appdata.settings["proxy"] != null
&& appdata.settings["proxy"].toString().isNotEmpty;
if(!App.isLinux && !haveUserProxy){
var channel = const MethodChannel("pixes/proxy");
channel.invokeMethod("getProxy").then((value) {
if(value.toString().toLowerCase() == "no proxy"){
@@ -150,6 +153,10 @@ class _ProxyHttpOverrides extends HttpOverrides {
proxy = "PROXY $value";
}
});
} else {
if(haveUserProxy){
proxy = "PROXY ${appdata.settings["proxy"]}";
}
}
return proxy;
}

View File

@@ -31,6 +31,8 @@ class _SettingsPageState extends State<SettingsPage> {
SliverTitleBar(title: "Settings".tl),
buildHeader("Account".tl),
buildAccount(),
buildHeader("Browser".tl),
buildBrowser(),
buildHeader("Download".tl),
buildDownload(),
buildHeader("About".tl),
@@ -123,10 +125,20 @@ class _SettingsPageState extends State<SettingsPage> {
child: Text("Manage".tl).fixWidth(64),
onPressed: () {
if (Platform.isIOS) {
showToast(context, message: "Unsupport platform".tl);
showToast(context, message: "Unsupported platform".tl);
return;
}
context.to(() => const _SetDownloadPathPage());
context.to(() => _SetSingleFieldPage(
"Download Path".tl,
"downloadPath",
check: (text) {
if(!Directory(text).havePermission()) {
return "No permission".tl;
} else {
return null;
}
},
));
}),
),
buildItem(
@@ -189,25 +201,51 @@ class _SettingsPageState extends State<SettingsPage> {
),
);
}
Widget buildBrowser() {
return SliverToBoxAdapter(
child: Column(
children: [
buildItem(
title: "Proxy".tl,
action: Button(
child: Text("Edit".tl).fixWidth(64),
onPressed: () {
context.to(() => _SetSingleFieldPage(
"Http ${"Proxy".tl}",
"proxy",
));
},
)),
],
),
);
}
}
class _SetDownloadPathPage extends StatefulWidget {
const _SetDownloadPathPage();
class _SetSingleFieldPage extends StatefulWidget {
const _SetSingleFieldPage(this.title, this.field, {this.check});
final String title;
final String field;
final String? Function(String)? check;
@override
State<_SetDownloadPathPage> createState() => __SetDownloadPathPageState();
State<_SetSingleFieldPage> createState() => _SetSingleFieldPageState();
}
class __SetDownloadPathPageState extends State<_SetDownloadPathPage> {
final controller =
TextEditingController(text: appdata.settings["downloadPath"]);
class _SetSingleFieldPageState extends State<_SetSingleFieldPage> {
late final controller =
TextEditingController(text: appdata.settings[widget.field]);
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TitleBar(title: "Download Path".tl),
TitleBar(title: widget.title),
TextBox(
controller: controller,
).paddingHorizontal(16),
@@ -218,12 +256,13 @@ class __SetDownloadPathPageState extends State<_SetDownloadPathPage> {
child: Text("Confirm".tl),
onPressed: () {
var text = controller.text;
if (Directory(text).havePermission()) {
appdata.settings["downloadPath"] = text;
var checkRes = widget.check?.call(text);
if (checkRes == null) {
appdata.settings[widget.field] = text;
appdata.writeData();
context.pop();
} else {
showToast(context, message: "No Permission".tl);
showToast(context, message: checkRes);
}
},
).toAlign(Alignment.centerRight).paddingRight(16),