mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-23 09:38:37 +00:00
338
lib/main.dart
338
lib/main.dart
@@ -117,15 +117,13 @@ void main() async {
|
|||||||
Request();
|
Request();
|
||||||
Request.setCookie();
|
Request.setCookie();
|
||||||
RequestUtils.syncHistoryStatus();
|
RequestUtils.syncHistoryStatus();
|
||||||
if (Utils.isMobile) {
|
|
||||||
PiliScheme.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
SmartDialog.config.toast = SmartConfigToast(
|
SmartDialog.config.toast = SmartConfigToast(
|
||||||
displayType: SmartToastType.onlyRefresh,
|
displayType: SmartToastType.onlyRefresh,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (Utils.isMobile) {
|
if (Utils.isMobile) {
|
||||||
|
PiliScheme.init();
|
||||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
||||||
SystemChrome.setSystemUIOverlayStyle(
|
SystemChrome.setSystemUIOverlayStyle(
|
||||||
const SystemUiOverlayStyle(
|
const SystemUiOverlayStyle(
|
||||||
@@ -135,6 +133,22 @@ void main() async {
|
|||||||
systemNavigationBarContrastEnforced: false,
|
systemNavigationBarContrastEnforced: false,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
late List<DisplayMode> modes;
|
||||||
|
FlutterDisplayMode.supported.then((value) {
|
||||||
|
modes = value;
|
||||||
|
final String? storageDisplay = GStorage.setting.get(
|
||||||
|
SettingBoxKey.displayMode,
|
||||||
|
);
|
||||||
|
DisplayMode? displayMode;
|
||||||
|
if (storageDisplay != null) {
|
||||||
|
displayMode = modes.firstWhereOrNull(
|
||||||
|
(e) => e.toString() == storageDisplay,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
FlutterDisplayMode.setPreferredMode(displayMode ?? DisplayMode.auto);
|
||||||
|
});
|
||||||
|
}
|
||||||
} else if (Utils.isDesktop) {
|
} else if (Utils.isDesktop) {
|
||||||
await windowManager.ensureInitialized();
|
await windowManager.ensureInitialized();
|
||||||
|
|
||||||
@@ -159,10 +173,12 @@ void main() async {
|
|||||||
|
|
||||||
if (Pref.enableLog) {
|
if (Pref.enableLog) {
|
||||||
// 异常捕获 logo记录
|
// 异常捕获 logo记录
|
||||||
String buildConfig =
|
final customParameters = {
|
||||||
'''\n
|
'BuildConfig':
|
||||||
|
'''\n
|
||||||
Build Time: ${DateFormatUtils.format(BuildConfig.buildTime, format: DateFormatUtils.longFormatDs)}
|
Build Time: ${DateFormatUtils.format(BuildConfig.buildTime, format: DateFormatUtils.longFormatDs)}
|
||||||
Commit Hash: ${BuildConfig.commitHash}''';
|
Commit Hash: ${BuildConfig.commitHash}''',
|
||||||
|
};
|
||||||
final Catcher2Options debugConfig = Catcher2Options(
|
final Catcher2Options debugConfig = Catcher2Options(
|
||||||
SilentReportMode(),
|
SilentReportMode(),
|
||||||
[
|
[
|
||||||
@@ -173,30 +189,22 @@ Commit Hash: ${BuildConfig.commitHash}''';
|
|||||||
enableCustomParameters: true,
|
enableCustomParameters: true,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
customParameters: {
|
customParameters: customParameters,
|
||||||
'BuildConfig': buildConfig,
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
final Catcher2Options releaseConfig = Catcher2Options(
|
final Catcher2Options releaseConfig = Catcher2Options(
|
||||||
SilentReportMode(),
|
SilentReportMode(),
|
||||||
[
|
[
|
||||||
FileHandler(await LoggerUtils.getLogsPath()),
|
FileHandler(await LoggerUtils.getLogsPath()),
|
||||||
ConsoleHandler(
|
ConsoleHandler(enableCustomParameters: true),
|
||||||
enableCustomParameters: true,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
customParameters: {
|
customParameters: customParameters,
|
||||||
'BuildConfig': buildConfig,
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Catcher2(
|
Catcher2(
|
||||||
debugConfig: debugConfig,
|
debugConfig: debugConfig,
|
||||||
releaseConfig: releaseConfig,
|
releaseConfig: releaseConfig,
|
||||||
runAppFunction: () {
|
runAppFunction: () => runApp(const MyApp()),
|
||||||
runApp(const MyApp());
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
runApp(const MyApp());
|
runApp(const MyApp());
|
||||||
@@ -208,169 +216,149 @@ class MyApp extends StatelessWidget {
|
|||||||
|
|
||||||
static ThemeData? darkThemeData;
|
static ThemeData? darkThemeData;
|
||||||
|
|
||||||
@override
|
static void _onBack() {
|
||||||
Widget build(BuildContext context) {
|
if (SmartDialog.checkExist()) {
|
||||||
Color brandColor = colorThemeTypes[Pref.customColor].color;
|
SmartDialog.dismiss();
|
||||||
bool isDynamicColor = Pref.dynamicColor;
|
return;
|
||||||
FlexSchemeVariant variant = FlexSchemeVariant.values[Pref.schemeVariant];
|
|
||||||
|
|
||||||
// 强制设置高帧率
|
|
||||||
if (Platform.isAndroid) {
|
|
||||||
late List<DisplayMode> modes;
|
|
||||||
FlutterDisplayMode.supported.then((value) {
|
|
||||||
modes = value;
|
|
||||||
final String? storageDisplay = GStorage.setting.get(
|
|
||||||
SettingBoxKey.displayMode,
|
|
||||||
);
|
|
||||||
DisplayMode? displayMode;
|
|
||||||
if (storageDisplay != null) {
|
|
||||||
displayMode = modes.firstWhereOrNull(
|
|
||||||
(e) => e.toString() == storageDisplay,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
displayMode ??= DisplayMode.auto;
|
|
||||||
FlutterDisplayMode.setPreferredMode(displayMode);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return DynamicColorBuilder(
|
if (Get.isDialogOpen ?? Get.isBottomSheetOpen ?? false) {
|
||||||
builder: ((ColorScheme? lightDynamic, ColorScheme? darkDynamic) {
|
Get.back();
|
||||||
ColorScheme? lightColorScheme;
|
return;
|
||||||
ColorScheme? darkColorScheme;
|
}
|
||||||
if (lightDynamic != null && darkDynamic != null && isDynamicColor) {
|
|
||||||
// dynamic取色成功
|
final plCtr = PlPlayerController.instance;
|
||||||
lightColorScheme = lightDynamic.harmonized();
|
if (plCtr != null) {
|
||||||
darkColorScheme = darkDynamic.harmonized();
|
if (plCtr.isFullScreen.value) {
|
||||||
} else {
|
plCtr
|
||||||
// dynamic取色失败,采用品牌色
|
..triggerFullScreen(status: false)
|
||||||
lightColorScheme = SeedColorScheme.fromSeeds(
|
..controlsLock.value = false
|
||||||
primaryKey: brandColor,
|
..showControls.value = false;
|
||||||
brightness: Brightness.light,
|
return;
|
||||||
variant: variant,
|
}
|
||||||
// dynamicSchemeVariant: dynamicSchemeVariant,
|
|
||||||
// tones: FlexTones.soft(Brightness.light),
|
if (plCtr.isDesktopPip) {
|
||||||
useExpressiveOnContainerColors: false,
|
plCtr
|
||||||
|
..exitDesktopPip().whenComplete(
|
||||||
|
() => plCtr.initialFocalPoint = Offset.zero,
|
||||||
|
)
|
||||||
|
..controlsLock.value = false
|
||||||
|
..showControls.value = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Get.back();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Widget _build({
|
||||||
|
ColorScheme? lightColorScheme,
|
||||||
|
ColorScheme? darkColorScheme,
|
||||||
|
}) {
|
||||||
|
late final brandColor = colorThemeTypes[Pref.customColor].color;
|
||||||
|
late final variant = FlexSchemeVariant.values[Pref.schemeVariant];
|
||||||
|
return GetMaterialApp(
|
||||||
|
title: Constants.appName,
|
||||||
|
theme: ThemeUtils.getThemeData(
|
||||||
|
colorScheme:
|
||||||
|
lightColorScheme ??
|
||||||
|
SeedColorScheme.fromSeeds(
|
||||||
|
variant: variant,
|
||||||
|
primaryKey: brandColor,
|
||||||
|
brightness: Brightness.light,
|
||||||
|
useExpressiveOnContainerColors: false,
|
||||||
|
),
|
||||||
|
isDynamic: lightColorScheme != null,
|
||||||
|
),
|
||||||
|
darkTheme: ThemeUtils.getThemeData(
|
||||||
|
isDark: true,
|
||||||
|
colorScheme:
|
||||||
|
darkColorScheme ??
|
||||||
|
SeedColorScheme.fromSeeds(
|
||||||
|
variant: variant,
|
||||||
|
primaryKey: brandColor,
|
||||||
|
brightness: Brightness.dark,
|
||||||
|
useExpressiveOnContainerColors: false,
|
||||||
|
),
|
||||||
|
isDynamic: darkColorScheme != null,
|
||||||
|
),
|
||||||
|
themeMode: Pref.themeMode,
|
||||||
|
localizationsDelegates: const [
|
||||||
|
GlobalCupertinoLocalizations.delegate,
|
||||||
|
GlobalMaterialLocalizations.delegate,
|
||||||
|
GlobalWidgetsLocalizations.delegate,
|
||||||
|
],
|
||||||
|
locale: const Locale("zh", "CN"),
|
||||||
|
fallbackLocale: const Locale("zh", "CN"),
|
||||||
|
supportedLocales: const [Locale("zh", "CN"), Locale("en", "US")],
|
||||||
|
initialRoute: '/',
|
||||||
|
getPages: Routes.getPages,
|
||||||
|
builder: FlutterSmartDialog.init(
|
||||||
|
toastBuilder: (String msg) => CustomToast(msg: msg),
|
||||||
|
loadingBuilder: (msg) => LoadingWidget(msg: msg),
|
||||||
|
builder: (context, child) {
|
||||||
|
child = MediaQuery(
|
||||||
|
data: MediaQuery.of(context).copyWith(
|
||||||
|
textScaler: TextScaler.linear(Pref.defaultTextScale),
|
||||||
|
),
|
||||||
|
child: child!,
|
||||||
);
|
);
|
||||||
darkColorScheme = SeedColorScheme.fromSeeds(
|
if (Utils.isDesktop) {
|
||||||
primaryKey: brandColor,
|
return Focus(
|
||||||
brightness: Brightness.dark,
|
canRequestFocus: false,
|
||||||
variant: variant,
|
onKeyEvent: (_, event) {
|
||||||
// dynamicSchemeVariant: dynamicSchemeVariant,
|
if (event.logicalKey == LogicalKeyboardKey.escape &&
|
||||||
// tones: FlexTones.soft(Brightness.dark),
|
event is KeyDownEvent) {
|
||||||
useExpressiveOnContainerColors: false,
|
_onBack();
|
||||||
);
|
return KeyEventResult.handled;
|
||||||
}
|
|
||||||
|
|
||||||
// 图片缓存
|
|
||||||
// PaintingBinding.instance.imageCache.maximumSizeBytes = 1000 << 20;
|
|
||||||
return GetMaterialApp(
|
|
||||||
title: Constants.appName,
|
|
||||||
theme: ThemeUtils.getThemeData(
|
|
||||||
colorScheme: lightColorScheme,
|
|
||||||
isDynamic: lightDynamic != null && isDynamicColor,
|
|
||||||
variant: variant,
|
|
||||||
),
|
|
||||||
darkTheme: ThemeUtils.getThemeData(
|
|
||||||
colorScheme: darkColorScheme,
|
|
||||||
isDynamic: darkDynamic != null && isDynamicColor,
|
|
||||||
isDark: true,
|
|
||||||
variant: variant,
|
|
||||||
),
|
|
||||||
themeMode: Pref.themeMode,
|
|
||||||
localizationsDelegates: const [
|
|
||||||
GlobalCupertinoLocalizations.delegate,
|
|
||||||
GlobalMaterialLocalizations.delegate,
|
|
||||||
GlobalWidgetsLocalizations.delegate,
|
|
||||||
],
|
|
||||||
locale: const Locale("zh", "CN"),
|
|
||||||
supportedLocales: const [Locale("zh", "CN"), Locale("en", "US")],
|
|
||||||
fallbackLocale: const Locale("zh", "CN"),
|
|
||||||
getPages: Routes.getPages,
|
|
||||||
initialRoute: '/',
|
|
||||||
builder: FlutterSmartDialog.init(
|
|
||||||
toastBuilder: (String msg) => CustomToast(msg: msg),
|
|
||||||
loadingBuilder: (msg) => LoadingWidget(msg: msg),
|
|
||||||
builder: (context, child) {
|
|
||||||
child = MediaQuery(
|
|
||||||
data: MediaQuery.of(context).copyWith(
|
|
||||||
textScaler: TextScaler.linear(Pref.defaultTextScale),
|
|
||||||
),
|
|
||||||
child: child!,
|
|
||||||
);
|
|
||||||
if (Utils.isDesktop) {
|
|
||||||
void onBack() {
|
|
||||||
if (SmartDialog.checkExist()) {
|
|
||||||
SmartDialog.dismiss();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Get.isDialogOpen ?? Get.isBottomSheetOpen ?? false) {
|
|
||||||
Get.back();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final plCtr = PlPlayerController.instance;
|
|
||||||
if (plCtr != null) {
|
|
||||||
if (plCtr.isFullScreen.value) {
|
|
||||||
plCtr
|
|
||||||
..triggerFullScreen(status: false)
|
|
||||||
..controlsLock.value = false
|
|
||||||
..showControls.value = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plCtr.isDesktopPip) {
|
|
||||||
plCtr
|
|
||||||
..exitDesktopPip().whenComplete(
|
|
||||||
() => plCtr.initialFocalPoint = Offset.zero,
|
|
||||||
)
|
|
||||||
..controlsLock.value = false
|
|
||||||
..showControls.value = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Get.back();
|
|
||||||
}
|
}
|
||||||
|
return KeyEventResult.ignored;
|
||||||
return Focus(
|
},
|
||||||
canRequestFocus: false,
|
child: MouseBackDetector(
|
||||||
onKeyEvent: (_, event) {
|
onTapDown: _onBack,
|
||||||
if (event.logicalKey == LogicalKeyboardKey.escape &&
|
child: child,
|
||||||
event is KeyDownEvent) {
|
),
|
||||||
onBack();
|
);
|
||||||
return KeyEventResult.handled;
|
}
|
||||||
}
|
return child;
|
||||||
return KeyEventResult.ignored;
|
},
|
||||||
},
|
),
|
||||||
child: MouseBackDetector(
|
navigatorObservers: [
|
||||||
onTapDown: onBack,
|
PageUtils.routeObserver,
|
||||||
child: child,
|
FlutterSmartDialog.observer,
|
||||||
),
|
],
|
||||||
);
|
scrollBehavior: const MaterialScrollBehavior().copyWith(
|
||||||
}
|
scrollbars: false,
|
||||||
return child;
|
dragDevices: {
|
||||||
},
|
PointerDeviceKind.touch,
|
||||||
),
|
PointerDeviceKind.stylus,
|
||||||
navigatorObservers: [
|
PointerDeviceKind.invertedStylus,
|
||||||
FlutterSmartDialog.observer,
|
PointerDeviceKind.trackpad,
|
||||||
PageUtils.routeObserver,
|
PointerDeviceKind.unknown,
|
||||||
],
|
if (Utils.isDesktop) PointerDeviceKind.mouse,
|
||||||
scrollBehavior: const MaterialScrollBehavior().copyWith(
|
},
|
||||||
scrollbars: false,
|
),
|
||||||
dragDevices: {
|
|
||||||
PointerDeviceKind.touch,
|
|
||||||
PointerDeviceKind.stylus,
|
|
||||||
PointerDeviceKind.invertedStylus,
|
|
||||||
PointerDeviceKind.trackpad,
|
|
||||||
PointerDeviceKind.unknown,
|
|
||||||
if (Utils.isDesktop) PointerDeviceKind.mouse,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (!Platform.isIOS && Pref.dynamicColor) {
|
||||||
|
return DynamicColorBuilder(
|
||||||
|
builder: ((ColorScheme? lightDynamic, ColorScheme? darkDynamic) {
|
||||||
|
if (lightDynamic != null && darkDynamic != null) {
|
||||||
|
return _build(
|
||||||
|
lightColorScheme: lightDynamic.harmonized(),
|
||||||
|
darkColorScheme: darkDynamic.harmonized(),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return _build();
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CustomHttpOverrides extends HttpOverrides {
|
class _CustomHttpOverrides extends HttpOverrides {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import 'package:PiliPlus/common/constants.dart';
|
|||||||
import 'package:PiliPlus/main.dart';
|
import 'package:PiliPlus/main.dart';
|
||||||
import 'package:PiliPlus/utils/extension.dart';
|
import 'package:PiliPlus/utils/extension.dart';
|
||||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||||
import 'package:flex_seed_scheme/flex_seed_scheme.dart';
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
@@ -11,7 +10,6 @@ abstract class ThemeUtils {
|
|||||||
required ColorScheme colorScheme,
|
required ColorScheme colorScheme,
|
||||||
required bool isDynamic,
|
required bool isDynamic,
|
||||||
bool isDark = false,
|
bool isDark = false,
|
||||||
required FlexSchemeVariant variant,
|
|
||||||
}) {
|
}) {
|
||||||
final appFontWeight = Pref.appFontWeight.clamp(
|
final appFontWeight = Pref.appFontWeight.clamp(
|
||||||
-1,
|
-1,
|
||||||
|
|||||||
Reference in New Issue
Block a user