mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: 调整设置,支持导入导出,代码优化
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import 'package:PiliPalaX/utils/cookie.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
@@ -6,6 +8,11 @@ import 'package:PiliPalaX/http/interceptor_anonymity.dart';
|
||||
import 'package:PiliPalaX/http/member.dart';
|
||||
import 'package:PiliPalaX/utils/storage.dart';
|
||||
|
||||
import '../../http/user.dart';
|
||||
import '../../models/user/info.dart';
|
||||
import '../../utils/login.dart';
|
||||
import '../home/controller.dart';
|
||||
import '../media/controller.dart';
|
||||
import '../mine/controller.dart';
|
||||
|
||||
class PrivacySetting extends StatefulWidget {
|
||||
@@ -18,13 +25,16 @@ class PrivacySetting extends StatefulWidget {
|
||||
class _PrivacySettingState extends State<PrivacySetting> {
|
||||
bool userLogin = false;
|
||||
Box userInfoCache = GStrorage.userInfo;
|
||||
var userInfo;
|
||||
UserInfoData? userInfo;
|
||||
late bool hiddenSettingUnlocked;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
userInfo = userInfoCache.get('userInfoCache');
|
||||
userLogin = userInfo != null;
|
||||
hiddenSettingUnlocked = GStrorage.setting
|
||||
.get(SettingBoxKey.hiddenSettingUnlocked, defaultValue: false);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -56,6 +66,7 @@ class _PrivacySettingState extends State<PrivacySetting> {
|
||||
dense: false,
|
||||
title: Text('黑名单管理', style: titleStyle),
|
||||
subtitle: Text('已拉黑用户', style: subTitleStyle),
|
||||
leading: const Icon(Icons.block),
|
||||
),
|
||||
ListTile(
|
||||
onTap: () {
|
||||
@@ -66,15 +77,33 @@ class _PrivacySettingState extends State<PrivacySetting> {
|
||||
},
|
||||
dense: false,
|
||||
title: Text('刷新access_key', style: titleStyle),
|
||||
leading: const Icon(Icons.perm_device_info_outlined),
|
||||
subtitle: Text(
|
||||
'access_key是app端的用户凭证,用于推荐接口。刷新将使用cookie请求新的access_key,小概率导致其他设备下线。若发现app端推荐内容不是个性化内容,可尝试刷新',
|
||||
'用于app端推荐接口的用户凭证。刷新有小概率导致其他设备下线。若app端未推荐个性化内容,可尝试刷新或清除本app数据后重新登录',
|
||||
style: subTitleStyle),
|
||||
),
|
||||
if (hiddenSettingUnlocked)
|
||||
ListTile(
|
||||
title: Text(
|
||||
'导入/导出cookie',
|
||||
style: titleStyle,
|
||||
),
|
||||
subtitle: Text(
|
||||
'cookie代表您的登录状态,仅供高级用户使用',
|
||||
style: subTitleStyle,
|
||||
),
|
||||
leading: const Icon(Icons.cookie_outlined),
|
||||
dense: false,
|
||||
onTap: () {
|
||||
import_export_cookies(titleStyle, subTitleStyle);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
onTap: () {
|
||||
MineController.onChangeAnonymity(context);
|
||||
setState(() {});
|
||||
},
|
||||
leading: const Icon(Icons.privacy_tip_outlined),
|
||||
dense: false,
|
||||
title: Text(MineController.anonymity ? '退出无痕模式' : '进入无痕模式',
|
||||
style: titleStyle),
|
||||
@@ -104,6 +133,7 @@ class _PrivacySettingState extends State<PrivacySetting> {
|
||||
},
|
||||
);
|
||||
},
|
||||
leading: const Icon(Icons.flag_outlined),
|
||||
dense: false,
|
||||
title: Text('了解无痕模式', style: titleStyle),
|
||||
subtitle: Text('查看无痕模式作用的API列表', style: subTitleStyle),
|
||||
@@ -112,4 +142,146 @@ class _PrivacySettingState extends State<PrivacySetting> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void import_export_cookies(TextStyle titleStyle, TextStyle subTitleStyle) {
|
||||
SmartDialog.show(
|
||||
useSystem: true,
|
||||
builder: (BuildContext context) {
|
||||
return SimpleDialog(
|
||||
title: const Text('导入/导出cookie', style: TextStyle(color: Colors.red)),
|
||||
children: [
|
||||
ListTile(
|
||||
title: Text(
|
||||
'导出cookie至剪贴板',
|
||||
style: titleStyle.copyWith(color: Colors.red),
|
||||
),
|
||||
leading: const Icon(
|
||||
Icons.warning_amber,
|
||||
color: Colors.red,
|
||||
),
|
||||
subtitle: Text(
|
||||
'泄露账号cookie等同于绕过账号密码与验证码直接登录,可导致隐私泄露、风控、毁号、盗号等各类问题。\n'
|
||||
'你应妥善保管该cookie且仅供自己使用。你承诺,不会利用本服务进行任何违法或不当的活动。你承诺,对所进行的一切活动'
|
||||
'(包括但不限于网上点击同意或提交各类规则协议或购买服务、分享资讯或图片等)负全部责任。\n'
|
||||
'你承诺、理解、同意并确认,在你的账户遭到未获授权的使用,或者发生其他任何安全问题时,'
|
||||
'作者不对上述情形产生的任何直接或间接的遗失或损害承担责任。',
|
||||
style: subTitleStyle.copyWith(color: Colors.redAccent),
|
||||
),
|
||||
dense: false,
|
||||
onTap: () async {
|
||||
await SmartDialog.dismiss();
|
||||
if (!userLogin) {
|
||||
SmartDialog.showToast('请先登录');
|
||||
return;
|
||||
}
|
||||
final String cookie = await CookieTool.exportCookie();
|
||||
await SmartDialog.show(
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: const Text('导出cookie(危险)',
|
||||
style: TextStyle(color: Colors.red)),
|
||||
content: Text(cookie),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await SmartDialog.dismiss();
|
||||
await Clipboard.setData(
|
||||
ClipboardData(text: cookie));
|
||||
},
|
||||
child: const Text('复制(危险)',
|
||||
style: TextStyle(color: Colors.red)),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await SmartDialog.dismiss();
|
||||
},
|
||||
child: const Text('取消'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}),
|
||||
ListTile(
|
||||
title: Text(
|
||||
'从剪贴板导入cookie',
|
||||
style: titleStyle,
|
||||
),
|
||||
leading: const Icon(
|
||||
Icons.warning_amber,
|
||||
color: Colors.red,
|
||||
),
|
||||
subtitle: Text(
|
||||
'导入将覆盖当前登录状态,你应自行对利用服务从事的所有行为及结果承担责任,请慎用',
|
||||
style: subTitleStyle,
|
||||
),
|
||||
dense: false,
|
||||
onTap: () async {
|
||||
await SmartDialog.dismiss();
|
||||
ClipboardData? data = await Clipboard.getData('text/plain');
|
||||
if (data == null || data.text == null || data.text == '') {
|
||||
SmartDialog.showToast('未检测到剪贴板内容');
|
||||
return;
|
||||
}
|
||||
await SmartDialog.show(
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: const Text('导入剪贴板中的cookie'),
|
||||
content: Text(data.text!),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await SmartDialog.dismiss();
|
||||
},
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await SmartDialog.dismiss();
|
||||
final String cookie = data.text!;
|
||||
try {
|
||||
await CookieTool.importCookie(cookie);
|
||||
await SmartDialog.showToast('已导入');
|
||||
await CookieTool.onSet();
|
||||
final result = await UserHttp.userInfo();
|
||||
if (result['status'] &&
|
||||
result['data'].isLogin) {
|
||||
SmartDialog.showToast('登录成功,当前采用「'
|
||||
'${GStrorage.setting.get(SettingBoxKey.defaultRcmdType, defaultValue: 'web')}'
|
||||
'端」推荐');
|
||||
Box userInfoCache = GStrorage.userInfo;
|
||||
await userInfoCache.put(
|
||||
'userInfoCache', result['data']);
|
||||
final HomeController homeCtr =
|
||||
Get.find<HomeController>();
|
||||
homeCtr.updateLoginStatus(true);
|
||||
homeCtr.userFace.value = result['data'].face;
|
||||
final MediaController mediaCtr =
|
||||
Get.find<MediaController>();
|
||||
mediaCtr.mid = result['data'].mid;
|
||||
await LoginUtils.refreshLoginStatus(true);
|
||||
Get.back();
|
||||
} else {
|
||||
// 获取用户信息失败
|
||||
SmartDialog.showNotify(
|
||||
msg:
|
||||
'登录失败,请检查cookie是否正确,${result['message']}',
|
||||
notifyType: NotifyType.warning);
|
||||
}
|
||||
} catch (e) {
|
||||
SmartDialog.showToast('导入失败:$e');
|
||||
}
|
||||
},
|
||||
child: const Text('确认'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user