Merge branch 'main' into feature-cookies

This commit is contained in:
guozhigq
2024-12-01 21:13:49 +08:00
168 changed files with 2481 additions and 1772 deletions

View File

@ -1,9 +1,9 @@
import 'package:app_links/app_links.dart';
import 'package:appscheme/appscheme.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:pilipala/pages/message/utils/index.dart';
import 'package:pilipala/utils/route_push.dart';
import '../http/search.dart';
import 'id_utils.dart';
@ -12,37 +12,20 @@ import 'utils.dart';
class PiliSchame {
static late AppLinks appLinks;
static AppScheme appScheme = AppSchemeImpl.getInstance()!;
static Future<void> init() async {
appLinks = AppLinks();
appLinks.uriLinkStream.listen((Uri uri) {
final String scheme = uri.scheme;
if (RegExp(r'^pili', caseSensitive: false).hasMatch(scheme)) {
piliScheme(uri);
}
});
appScheme.getInitScheme().then((SchemeEntity? value) {
if (value != null) {
routePush(value);
}
});
appScheme.getLatestScheme().then((SchemeEntity? value) {
if (value != null) {
routePush(value);
}
});
appScheme.registerSchemeListener().listen((SchemeEntity? event) {
if (event != null) {
routePush(event);
} else {
routePush(uri);
}
});
}
/// 路由跳转
static void routePush(value) async {
static void routePush(Uri value) async {
final String scheme = value.scheme;
if (scheme == 'bilibili') {
biliScheme(value);
@ -212,9 +195,9 @@ class PiliSchame {
}
}
static Future<void> biliScheme(SchemeEntity value) async {
final String host = value.host!;
final String path = value.path!;
static Future<void> biliScheme(Uri value) async {
final String host = value.host;
final String path = value.path;
switch (host) {
case 'root':
Navigator.popUntil(
@ -288,20 +271,19 @@ class PiliSchame {
break;
case 'following':
if (path.startsWith('/detail')) {
var opusId = path.split('/').last;
Get.toNamed(
'/webview',
parameters: {
'url': 'https://m.bilibili.com/opus/$opusId',
'type': 'url',
'pageTitle': ''
},
);
final String opusId = path.split('/').last;
MessageUtils.navigateToDynamicDetail(opusId);
}
break;
default:
SmartDialog.showToast('未匹配地址,请联系开发者');
Clipboard.setData(ClipboardData(text: value.toString()));
final Map<String, String> queryParameters = value.queryParameters;
final String? enterUri = queryParameters['enterUri'];
if (enterUri != null && enterUri.startsWith('bilibili://')) {
biliScheme(Uri.parse(enterUri));
} else {
SmartDialog.showToast('未匹配地址,请联系开发者');
Clipboard.setData(ClipboardData(text: value.toString()));
}
break;
}
}

View File

@ -9,8 +9,8 @@ class Data {
}
static Future historyStatus() async {
Box localCache = GStrorage.localCache;
Box userInfoCache = GStrorage.userInfo;
Box localCache = GStorage.localCache;
Box userInfoCache = GStorage.userInfo;
if (userInfoCache.get('userInfoCache') == null) {
return;
}

View File

@ -2,7 +2,7 @@ import 'package:flutter/services.dart';
import 'package:hive/hive.dart';
import 'storage.dart';
Box<dynamic> setting = GStrorage.setting;
Box<dynamic> setting = GStorage.setting;
void feedBack() {
// 设置中是否开启
final bool enable =

View File

@ -1,3 +1,4 @@
import 'dart:io';
import 'package:hive/hive.dart';
import 'package:pilipala/models/user/info.dart';
import 'package:pilipala/plugin/pl_player/models/play_repeat.dart';
@ -5,54 +6,62 @@ import 'package:pilipala/plugin/pl_player/models/play_speed.dart';
import 'package:pilipala/utils/storage.dart';
import '../models/common/index.dart';
Box setting = GStrorage.setting;
Box localCache = GStrorage.localCache;
Box videoStorage = GStrorage.video;
Box userInfoCache = GStrorage.userInfo;
Box settingBox = GStorage.setting;
Box localCache = GStorage.localCache;
Box videoStorage = GStorage.video;
Box userInfoCache = GStorage.userInfo;
class GlobalDataCache {
late int imgQuality;
late FullScreenGestureMode fullScreenGestureMode;
late bool enablePlayerControlAnimation;
late List<String> actionTypeSort;
late double sheetHeight;
String? wWebid;
static late int imgQuality;
static late FullScreenGestureMode fullScreenGestureMode;
static late bool enablePlayerControlAnimation;
static late List<String> actionTypeSort;
static late double sheetHeight;
static String? wWebid;
/// 播放器相关
// 弹幕开关
late bool isOpenDanmu;
static late bool isOpenDanmu;
// 弹幕屏蔽类型
late List<dynamic> blockTypes;
static late List<dynamic> blockTypes;
// 弹幕展示区域
late double showArea;
static late double showArea;
// 弹幕透明度
late double opacityVal;
static late double opacityVal;
// 弹幕字体大小
late double fontSizeVal;
static late double fontSizeVal;
// 弹幕显示时间
late double danmakuDurationVal;
static late double danmakuDurationVal;
// 弹幕描边宽度
late double strokeWidth;
static late double strokeWidth;
// 播放器循环模式
late PlayRepeat playRepeat;
static late PlayRepeat playRepeat;
// 播放器默认播放速度
late double playbackSpeed;
static late double playbackSpeed;
// 播放器自动长按速度
late bool enableAutoLongPressSpeed;
static late bool enableAutoLongPressSpeed;
// 播放器长按速度
late double longPressSpeed;
static late double longPressSpeed;
// 播放器速度列表
late List<double> speedsList;
static late List<double> speedsList;
// 用户信息
UserInfoData? userInfo;
static UserInfoData? userInfo;
// 搜索历史
late List historyCacheList;
//
late bool enableSearchSuggest = true;
static late List historyCacheList;
// 搜索建议
static late bool enableSearchSuggest;
// 简介默认展开
late bool enableAutoExpand = false;
//
late bool enableDynamicSwitch = true;
static late bool enableAutoExpand;
// 动态切换
static late bool enableDynamicSwitch;
// 投屏开关
static bool enableDlna = false;
// 硬件解码格式
static late String hardwareDecodeFormat;
// sponsorBlock开关
static bool enableSponsorBlock = false;
// 视频评论开关
static List<String> enableComment = ['video', 'bangumi'];
// 私有构造函数
GlobalDataCache._();
@ -64,19 +73,19 @@ class GlobalDataCache {
factory GlobalDataCache() => _instance;
// 异步初始化方法
Future<void> initialize() async {
imgQuality = await setting.get(SettingBoxKey.defaultPicQa,
static Future<void> initialize() async {
imgQuality = await settingBox.get(SettingBoxKey.defaultPicQa,
defaultValue: 10); // 设置全局变量
fullScreenGestureMode = FullScreenGestureMode.values[setting.get(
fullScreenGestureMode = FullScreenGestureMode.values[settingBox.get(
SettingBoxKey.fullScreenGestureMode,
defaultValue: FullScreenGestureMode.fromBottomtoTop.index)];
enablePlayerControlAnimation = setting
enablePlayerControlAnimation = settingBox
.get(SettingBoxKey.enablePlayerControlAnimation, defaultValue: true);
actionTypeSort = await setting.get(SettingBoxKey.actionTypeSort,
actionTypeSort = await settingBox.get(SettingBoxKey.actionTypeSort,
defaultValue: ['like', 'coin', 'collect', 'watchLater', 'share']);
isOpenDanmu =
await setting.get(SettingBoxKey.enableShowDanmaku, defaultValue: false);
isOpenDanmu = await settingBox.get(SettingBoxKey.enableShowDanmaku,
defaultValue: false);
blockTypes =
await localCache.get(LocalCacheKey.danmakuBlockType, defaultValue: []);
showArea =
@ -97,7 +106,7 @@ class GlobalDataCache {
.firstWhere((e) => e.value == defaultPlayRepeat);
playbackSpeed =
await videoStorage.get(VideoBoxKey.playSpeedDefault, defaultValue: 1.0);
enableAutoLongPressSpeed = await setting
enableAutoLongPressSpeed = await settingBox
.get(SettingBoxKey.enableAutoLongPressSpeed, defaultValue: false);
if (!enableAutoLongPressSpeed) {
longPressSpeed = await videoStorage.get(VideoBoxKey.longPressSpeedDefault,
@ -115,10 +124,21 @@ class GlobalDataCache {
sheetHeight = localCache.get('sheetHeight', defaultValue: 0.0);
historyCacheList = localCache.get('cacheList', defaultValue: []);
enableSearchSuggest =
setting.get(SettingBoxKey.enableSearchSuggest, defaultValue: true);
settingBox.get(SettingBoxKey.enableSearchSuggest, defaultValue: true);
enableAutoExpand =
setting.get(SettingBoxKey.enableAutoExpand, defaultValue: false);
settingBox.get(SettingBoxKey.enableAutoExpand, defaultValue: false);
enableDynamicSwitch =
setting.get(SettingBoxKey.enableDynamicSwitch, defaultValue: true);
settingBox.get(SettingBoxKey.enableDynamicSwitch, defaultValue: true);
enableDlna = settingBox.get(SettingBoxKey.enableDlna, defaultValue: false);
hardwareDecodeFormat = settingBox.get(SettingBoxKey.hardwareDecodeFormat,
defaultValue: Platform.isAndroid ? 'auto-safe' : 'auto');
settingBox.get(SettingBoxKey.enableDynamicSwitch, defaultValue: true);
enableDlna = settingBox.get(SettingBoxKey.enableDlna, defaultValue: false);
enableSponsorBlock =
settingBox.get(SettingBoxKey.enableSponsorBlock, defaultValue: false);
settingBox.get(SettingBoxKey.enableDynamicSwitch, defaultValue: true);
enableDlna = settingBox.get(SettingBoxKey.enableDlna, defaultValue: false);
enableComment = settingBox
.get(SettingBoxKey.enableComment, defaultValue: ['video', 'bangumi']);
}
}

View File

@ -17,9 +17,6 @@ import 'package:pilipala/utils/storage.dart';
import 'package:uuid/uuid.dart';
class LoginUtils {
static Box userInfoCache = GStrorage.userInfo;
static Box localCache = GStrorage.localCache;
static Future refreshLoginStatus(bool status) async {
try {
// 更改我的页面登录状态
@ -74,7 +71,7 @@ class LoginUtils {
if (result['status'] && result['data'].isLogin) {
SmartDialog.showToast('登录成功');
try {
Box userInfoCache = GStrorage.userInfo;
Box userInfoCache = GStorage.userInfo;
if (!userInfoCache.isOpen) {
userInfoCache = await Hive.openBox('userInfo');
}
@ -119,7 +116,7 @@ class LoginUtils {
Request.dio.options.headers['cookie'] = '';
userInfoCache.put('userInfoCache', null);
localCache.put(LocalCacheKey.accessKey, {'mid': -1, 'value': ''});
GlobalDataCache().userInfo = null;
GlobalDataCache.userInfo = null;
await refreshLoginStatus(false);
}
}

View File

@ -13,7 +13,7 @@ class RecommendFilter {
}
static void update() {
var setting = GStrorage.setting;
var setting = GStorage.setting;
// filterUnfollowedRatio =
// setting.get(SettingBoxKey.filterUnfollowedRatio, defaultValue: 0);
minDurationForRcmd =

View File

@ -3,7 +3,7 @@ import 'package:hive_flutter/hive_flutter.dart';
import 'package:path_provider/path_provider.dart';
import 'package:pilipala/models/user/info.dart';
class GStrorage {
class GStorage {
static late final Box<dynamic> userInfo;
static late final Box<dynamic> localCache;
static late final Box<dynamic> setting;
@ -115,7 +115,11 @@ class SettingBoxKey {
enableAi = 'enableAi',
enableAutoExpand = 'enableAutoExpand',
defaultHomePage = 'defaultHomePage',
enableRelatedVideo = 'enableRelatedVideo';
enableRelatedVideo = 'enableRelatedVideo',
enableDlna = 'enableDlna',
hardwareDecodeFormat = 'hardwareDecodeFormat',
enableSponsorBlock = 'enableSponsorBlock',
enableComment = 'enableComment';
/// 外观
static const String themeMode = 'themeMode',

View File

@ -9,7 +9,7 @@ import '../http/index.dart';
import 'storage.dart';
class WbiSign {
static Box<dynamic> localCache = GStrorage.localCache;
static Box<dynamic> localCache = GStorage.localCache;
final List<int> mixinKeyEncTab = <int>[
46,
47,