pikapika/lib/screens/InitScreen.dart

228 lines
7.9 KiB
Dart
Raw Normal View History

2022-06-29 19:02:01 +00:00
import 'dart:async';
import 'dart:io';
2021-09-29 23:57:09 +00:00
import 'package:flutter/material.dart';
2021-11-11 03:00:38 +00:00
import 'package:pikapika/basic/config/Address.dart';
import 'package:pikapika/basic/config/AndroidDisplayMode.dart';
import 'package:pikapika/basic/config/AndroidSecureFlag.dart';
2022-05-14 13:45:00 +00:00
import 'package:pikapika/basic/config/Authentication.dart';
2021-11-11 03:00:38 +00:00
import 'package:pikapika/basic/config/AutoClean.dart';
import 'package:pikapika/basic/config/AutoFullScreen.dart';
2022-09-05 04:23:53 +00:00
import 'package:pikapika/basic/config/CategoriesColumnCount.dart';
2021-11-11 03:00:38 +00:00
import 'package:pikapika/basic/config/ChooserRoot.dart';
import 'package:pikapika/basic/config/ContentFailedReloadAction.dart';
import 'package:pikapika/basic/config/DownloadAndExportPath.dart';
import 'package:pikapika/basic/config/DownloadThreadCount.dart';
import 'package:pikapika/basic/config/FullScreenAction.dart';
import 'package:pikapika/basic/config/FullScreenUI.dart';
2021-11-30 02:23:49 +00:00
import 'package:pikapika/basic/config/ImageAddress.dart';
2021-11-11 03:00:38 +00:00
import 'package:pikapika/basic/config/KeyboardController.dart';
2021-11-21 13:18:23 +00:00
import 'package:pikapika/basic/config/NoAnimation.dart';
2021-11-11 03:00:38 +00:00
import 'package:pikapika/basic/config/PagerAction.dart';
import 'package:pikapika/basic/config/Platform.dart';
import 'package:pikapika/basic/config/Proxy.dart';
import 'package:pikapika/basic/config/Quality.dart';
import 'package:pikapika/basic/config/ReaderDirection.dart';
2021-12-09 00:08:01 +00:00
import 'package:pikapika/basic/config/ReaderSliderPosition.dart';
2021-11-11 03:00:38 +00:00
import 'package:pikapika/basic/config/ReaderType.dart';
import 'package:pikapika/basic/config/ShadowCategories.dart';
2022-08-20 15:16:13 +00:00
import 'package:pikapika/basic/config/ShowCommentAtDownload.dart';
2021-11-11 03:00:38 +00:00
import 'package:pikapika/basic/config/Themes.dart';
import 'package:pikapika/basic/Method.dart';
import 'package:pikapika/basic/config/ListLayout.dart';
import 'package:pikapika/basic/config/TimeOffsetHour.dart';
2023-01-21 16:38:09 +00:00
import 'package:pikapika/basic/config/UseApiLoadImage.dart';
2022-03-27 06:19:08 +00:00
import 'package:pikapika/basic/config/UsingRightClickPop.dart';
2021-11-11 03:00:38 +00:00
import 'package:pikapika/basic/config/Version.dart';
import 'package:pikapika/basic/config/VolumeController.dart';
2022-06-29 19:02:01 +00:00
import 'package:pikapika/basic/config/ShadowCategoriesMode.dart';
2022-08-11 03:21:55 +00:00
import 'package:pikapika/basic/config/WillPopNotice.dart';
2022-07-04 02:02:09 +00:00
import 'package:pikapika/screens/ComicInfoScreen.dart';
2022-06-29 19:02:01 +00:00
import 'package:pikapika/screens/PkzArchiveScreen.dart';
2022-06-30 16:31:15 +00:00
import 'package:uni_links/uni_links.dart';
2022-06-29 19:02:01 +00:00
import 'package:uri_to_file/uri_to_file.dart';
2022-10-27 07:21:46 +00:00
import '../basic/config/DownloadCachePath.dart';
2022-02-25 10:46:11 +00:00
import '../basic/config/ExportRename.dart';
2022-09-05 03:05:46 +00:00
import '../basic/config/IconLoading.dart';
2022-07-09 07:11:26 +00:00
import '../basic/config/IsPro.dart';
import '../basic/config/WebDav.dart';
2021-09-29 23:57:09 +00:00
import 'AccountScreen.dart';
import 'AppScreen.dart';
2022-07-01 05:39:08 +00:00
import 'DownloadOnlyImportScreen.dart';
2021-09-29 23:57:09 +00:00
// 初始化界面
class InitScreen extends StatefulWidget {
2022-03-17 03:31:25 +00:00
const InitScreen({Key? key}) : super(key: key);
2021-09-29 23:57:09 +00:00
@override
State<StatefulWidget> createState() => _InitScreenState();
}
class _InitScreenState extends State<InitScreen> {
2022-05-14 13:45:00 +00:00
var _authenticating = false;
2021-09-29 23:57:09 +00:00
@override
initState() {
_init();
super.initState();
}
Future<dynamic> _init() async {
// 初始化配置文件
2021-10-29 03:38:36 +00:00
await initPlatform(); // 必须第一个初始化, 加载设备信息
2021-11-04 05:56:25 +00:00
await initAutoClean();
2021-09-29 23:57:09 +00:00
await initAddress();
2021-11-30 02:23:49 +00:00
await initImageAddress();
2021-09-29 23:57:09 +00:00
await initProxy();
await initQuality();
2021-10-15 06:18:29 +00:00
await initFont();
2021-09-29 23:57:09 +00:00
await initTheme();
await initListLayout();
await initReaderType();
await initReaderDirection();
2021-12-09 00:08:01 +00:00
await initReaderSliderPosition();
2021-09-29 23:57:09 +00:00
await initAutoFullScreen();
await initFullScreenAction();
await initPagerAction();
2021-11-24 13:22:22 +00:00
await initShadowCategoriesMode();
2021-09-29 23:57:09 +00:00
await initShadowCategories();
await initFullScreenUI();
2022-09-05 03:05:46 +00:00
await initIconLoading();
2022-09-05 04:23:53 +00:00
await initCategoriesColumnCount();
2021-09-29 23:57:09 +00:00
switchFullScreenUI();
await initContentFailedReloadAction();
await initVolumeController();
await initKeyboardController();
await initAndroidDisplayMode();
2021-10-07 03:47:28 +00:00
await initChooserRoot();
await initTimeZone();
2021-10-25 11:27:38 +00:00
await initDownloadAndExportPath();
2021-10-29 03:38:36 +00:00
await initAndroidSecureFlag();
2021-10-31 06:01:19 +00:00
await initDownloadThreadCount();
2021-11-21 13:18:23 +00:00
await initNoAnimation();
2022-02-25 10:46:11 +00:00
await initExportRename();
2021-11-11 02:10:18 +00:00
await initVersion();
2022-03-27 06:19:08 +00:00
await initUsingRightClickPop();
2022-05-14 13:45:00 +00:00
await initAuthentication();
2022-07-09 07:11:26 +00:00
await reloadIsPro();
2021-11-11 09:05:48 +00:00
autoCheckNewVersion();
2022-08-11 03:21:55 +00:00
await initWillPopNotice();
2022-08-20 15:16:13 +00:00
await initShowCommentAtDownload();
2022-10-27 07:21:46 +00:00
await initDownloadCachePath();
2023-01-21 16:38:09 +00:00
await initUseApiLoadImage();
await initWebDav();
2022-06-29 19:02:01 +00:00
String? initUrl;
if (Platform.isAndroid || Platform.isIOS) {
try {
2022-06-30 16:31:15 +00:00
initUrl = (await getInitialUri())?.toString();
2022-06-29 19:02:01 +00:00
// Use the uri and warn the user, if it is not correct,
// but keep in mind it could be `null`.
} on FormatException {
// Handle exception by warning the user their action did not succeed
// return?
}
}
if (initUrl != null) {
var parsed = Uri.parse(initUrl!);
2022-07-04 02:02:09 +00:00
if (RegExp(r"^pika://comic/([0-9A-z]+)/$").allMatches(initUrl!).isNotEmpty) {
String comicId = RegExp(r"^pika://comic/([0-9A-z]+)/$").allMatches(initUrl!).first.group(1)!;
2023-01-31 10:50:51 +00:00
Navigator.of(context).pushReplacement(mixRoute(
2022-07-04 02:02:09 +00:00
builder: (BuildContext context) =>
ComicInfoScreen(comicId: comicId, holdPkz: true),
));
return;
} if (RegExp(r"^https?://pika/comic/([0-9A-z]+)/$").allMatches(initUrl!).isNotEmpty) {
String comicId = RegExp(r"^https?://pika/comic/([0-9A-z]+)/$").allMatches(initUrl!).first.group(1)!;
Navigator.of(context).pushReplacement(mixRoute(
builder: (BuildContext context) =>
ComicInfoScreen(comicId: comicId, holdPkz: true),
));
return;
} else if (RegExp(r"^.*\.pkz$").allMatches(parsed.path).isNotEmpty) {
2022-06-29 19:02:01 +00:00
File file = await toFile(initUrl!);
2023-01-31 10:50:51 +00:00
Navigator.of(context).pushReplacement(mixRoute(
2022-06-29 19:02:01 +00:00
builder: (BuildContext context) =>
2022-06-30 15:38:42 +00:00
PkzArchiveScreen(pkzPath: file.path, holdPkz: true),
2022-06-29 19:02:01 +00:00
));
return;
} else if (RegExp(r"^.*\.((pki)|(zip))$").allMatches(parsed.path).isNotEmpty) {
2022-07-01 05:39:08 +00:00
File file = await toFile(initUrl!);
Navigator.of(context).pushReplacement(
2023-01-31 10:50:51 +00:00
mixRoute(
2022-07-01 05:39:08 +00:00
builder: (BuildContext context) =>
DownloadOnlyImportScreen(path: file.path, holdPkz: true),
),
);
return;
2022-06-29 19:02:01 +00:00
}
}
2022-05-14 13:45:00 +00:00
setState(() {
_authenticating = currentAuthentication();
});
if (_authenticating) {
_goAuthentication();
2021-09-29 23:57:09 +00:00
} else {
syncWebDavIfAuto(context);
2022-05-14 13:45:00 +00:00
_goApplication();
2021-09-29 23:57:09 +00:00
}
}
@override
Widget build(BuildContext context) {
2022-05-14 13:45:00 +00:00
if (_authenticating) {
return Scaffold(
appBar: AppBar(
title: const Text("身份验证"),
),
body: Center(
child: Container(
padding: const EdgeInsets.all(20),
child: MaterialButton(
onPressed: () {
_goAuthentication();
},
2022-06-29 19:02:01 +00:00
child:
const Text('您在之前使用APP时开启了身份验证, 请点这段文字进行身份核查, 核查通过后将会进入APP'),
2022-05-14 13:45:00 +00:00
),
),
),
);
}
2021-09-29 23:57:09 +00:00
return Scaffold(
2022-03-19 04:12:27 +00:00
backgroundColor: const Color(0xfffffced),
2021-09-29 23:57:09 +00:00
body: ConstrainedBox(
2022-03-19 04:12:27 +00:00
constraints: const BoxConstraints.expand(),
2022-03-17 03:31:25 +00:00
child: Image.asset(
2021-09-29 23:57:09 +00:00
"lib/assets/init.jpg",
fit: BoxFit.contain,
),
),
);
}
2022-05-14 13:45:00 +00:00
Future _goApplication() async {
// 登录, 如果token失效重新登录, 网络不好的时候可能需要1分钟
if (await method.preLogin()) {
// 如果token或username+password有效则直接进入登录好的界面
Navigator.pushReplacement(
context,
2023-01-31 10:50:51 +00:00
mixRoute(builder: (context) => const AppScreen()),
2022-05-14 13:45:00 +00:00
);
} else {
// 否则跳转到登录页
Navigator.pushReplacement(
context,
2023-01-31 10:50:51 +00:00
mixRoute(builder: (context) => const AccountScreen()),
2022-05-14 13:45:00 +00:00
);
}
}
Future _goAuthentication() async {
if (await method.verifyAuthentication()) {
_goApplication();
}
}
2021-09-29 23:57:09 +00:00
}