pikapika/lib/screens/InitScreen.dart

188 lines
6.1 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';
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';
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';
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';
import 'package:pikapika/screens/PkzArchiveScreen.dart';
import 'package:app_links/app_links.dart';
import 'package:uri_to_file/uri_to_file.dart';
2022-02-25 10:46:11 +00:00
import '../basic/config/ExportRename.dart';
2021-09-29 23:57:09 +00:00
import 'AccountScreen.dart';
import 'AppScreen.dart';
// 初始化界面
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();
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();
2021-11-11 09:05:48 +00:00
autoCheckNewVersion();
2022-06-29 19:02:01 +00:00
final appLinks = AppLinks();
String? initUrl;
if (Platform.isAndroid || Platform.isIOS) {
try {
initUrl = (await appLinks.getInitialAppLink())?.toString();
// 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) {
RegExp regExp = RegExp(r"^.*\.pkz$");
final matches = regExp.allMatches(initUrl!);
if (matches.isNotEmpty) {
File file = await toFile(initUrl!);
Navigator.of(context).pushReplacement(MaterialPageRoute(
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;
}
}
2022-05-14 13:45:00 +00:00
setState(() {
_authenticating = currentAuthentication();
});
if (_authenticating) {
_goAuthentication();
2021-09-29 23:57:09 +00:00
} else {
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,
MaterialPageRoute(builder: (context) => const AppScreen()),
);
} else {
// 否则跳转到登录页
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => const AccountScreen()),
);
}
}
Future _goAuthentication() async {
if (await method.verifyAuthentication()) {
_goApplication();
}
}
2021-09-29 23:57:09 +00:00
}