Skip to content

Commit

Permalink
Clean up the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
3003h committed Nov 17, 2023
1 parent e5e3a98 commit cbff6a9
Show file tree
Hide file tree
Showing 22 changed files with 430 additions and 1,592 deletions.
2 changes: 0 additions & 2 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ analyzer:
# Ignore analyzer hints for updating pubspecs when using Future or
# Stream and not importing dart:async
# Please see https://github.com/flutter/flutter/pull/24528 for details.
sdk_version_async_exported_from_core: ignore
invalid_annotation_target: ignore
exclude:
- "bin/cache/**"
Expand Down Expand Up @@ -151,7 +150,6 @@ linter:
# - prefer_constructors_over_static_methods # not yet tested
- prefer_contains
# - prefer_double_quotes # opposite of prefer_single_quotes
- prefer_equal_for_default_values
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
- prefer_final_fields
- prefer_final_in_for_each
Expand Down
35 changes: 22 additions & 13 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,35 @@ import flutter_downloader
}

override func applicationDidEnterBackground(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

print("applicationDidEnterBackground")
addBlurEffect()
}

// override func applicationWillResignActive(_ application: UIApplication) {
// print("applicationWillResignActive")
// addBlurEffect()
// }

override func applicationDidBecomeActive(_ application: UIApplication) {
print("applicationDidBecomeActive")
SecurityBlurEffect.removeBlurEffect()
}

override func applicationWillEnterForeground(_ application: UIApplication) {
print("applicationWillEnterForeground")
SecurityBlurEffect.removeBlurEffect()
}

func addBlurEffect() {
let BLURRED_IN_RECENT_TASK = "flutter.blurredInRecentTasks"

let isBlurredInRecentTasks = UserDefaults.standard.bool(forKey: BLURRED_IN_RECENT_TASK)

print("isBlurredInRecentTasks :", isBlurredInRecentTasks)
if isBlurredInRecentTasks {
SecurityBlurEffect.addBlurEffect()
}
}

override func applicationWillEnterForeground(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

print("applicationWillEnterForeground")
SecurityBlurEffect.removeBlurEffect()

}
}

private func registerPlugins(registry: FlutterPluginRegistry) {
Expand Down
8 changes: 0 additions & 8 deletions ios/Runner/GoProxy.swift

This file was deleted.

15 changes: 6 additions & 9 deletions lib/common/controller/auto_lock_controller.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:ui';

import 'package:fehviewer/common/service/ehsetting_service.dart';
import 'package:fehviewer/generated/l10n.dart';
import 'package:fehviewer/models/index.dart';
Expand Down Expand Up @@ -75,21 +73,22 @@ class AutoLockController extends GetxController {
}
}

Future<void> resumed({bool forceLock = false}) async {
Future<void> checkLock({bool forceLock = false}) async {
final nowTime = DateTime.now().millisecondsSinceEpoch;
final subTime = nowTime - lastLeaveTime;
final autoLockTimeOut = _ehSettingService.autoLockTimeOut.value;

logger.t('now time ${nowTime}, lastLeaveTime: ${lastLeaveTime}');
logger.t('now time $nowTime, lastLeaveTime: $lastLeaveTime');

final _locked =
final locked =
autoLockTimeOut >= 0 && (subTime / 1000 > autoLockTimeOut || forceLock);
logger.t('离开时间为: ${subTime}ms 锁定超时为: $autoLockTimeOut 需要解锁: $_locked');
logger.t('离开时间为: ${subTime}ms 锁定超时为: $autoLockTimeOut 需要解锁: $locked');

if (_locked && !_isResumed) {
if (locked && !_isResumed) {
_isLocking = true;

final result = await Get.toNamed(EHRoutes.unlockPage);

if (result is bool) {
final bool didAuthenticate = result;
if (didAuthenticate) {
Expand All @@ -100,6 +99,4 @@ class AutoLockController extends GetxController {
}
}
}

void updateStat(AppLifecycleState state) {}
}
1 change: 0 additions & 1 deletion lib/common/parser/home_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:html/dom.dart';
import 'package:html/parser.dart' show parse;

import '../../models/base/eh_models.dart';
import '../../utils/logger.dart';

EhHome parserEhHome(String response) {
final Document document = parse(response);
Expand Down
20 changes: 8 additions & 12 deletions lib/common/parser/mytags_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ import '../../fehviewer.dart';
EhMytags parseMyTags(String html) {
final Document document = parse(html);

final tagsets = <EhMytagSet>[];

late String selectedValue = '';
final tagSets = <EhMytagSet>[];

// 解析tagsets
final Element? tagsetElm =
final Element? tagSetElm =
document.querySelector('#tagset_outer > div:nth-child(3) > select');

if (tagsetElm != null) {
final tagsetElms = tagsetElm.children;
if (tagSetElm != null) {
final tagsetElms = tagSetElm.children;
// logger.d('tagsetElms.length ${tagsetElms.length}');
for (final _tagset in tagsetElms) {
final value = _tagset.attributes['value'];
Expand All @@ -30,25 +28,23 @@ EhMytags parseMyTags(String html) {
RegExp(r'(.+)\((\d+)\)'), (match) => match.group(1) ?? '');
final count = _tagset.text.replaceAllMapped(
RegExp(r'(.+)\((\d+)\)'), (match) => match.group(2) ?? '');
if (isSelected) {
selectedValue = value;
}
if (isSelected) {}

// if (_tagset.text.trim().endsWith('(Default)')) {
// // defaultProfile = value;
// }

// logger.d('name:$name count:$count');

tagsets.add(EhMytagSet(
tagSets.add(EhMytagSet(
name: name.trim(),
tagCount: count.trim(),
value: value.trim(),
));
}
}

tagsets.sort((a, b) =>
tagSets.sort((a, b) =>
(int.tryParse(a.value ?? '0') ?? 0) -
(int.tryParse(b.value ?? '0') ?? 0));

Expand Down Expand Up @@ -127,7 +123,7 @@ EhMytags parseMyTags(String html) {
'';

return EhMytags(
tagsets: tagsets,
tagsets: tagSets,
usertags: usertags,
canDelete: html.contains('do_tagset_delete()'),
apikey: _apikey,
Expand Down
1 change: 0 additions & 1 deletion lib/extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ extension ExtTagTranlat on TagTranslat {
case TagIntroImgLv.r18:
// 去除R18g, 把r18的格式修正
return _fix(regR18And18g, _remove(regR18g, intro));
break;
case TagIntroImgLv.r18g:
// 把r18和r18g的格式修正
return _fix(regR18And18g, intro);
Expand Down
83 changes: 49 additions & 34 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:flutter_windowmanager/flutter_windowmanager.dart';
Expand Down Expand Up @@ -116,8 +118,10 @@ Future<void> main() async {
}

class MyApp extends StatefulWidget {
const MyApp({super.key});

@override
_MyAppState createState() => _MyAppState();
State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
Expand All @@ -126,11 +130,51 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
final EhSettingService _ehSettingService = Get.find();
final AutoLockController _autoLockController = Get.find();

late final AppLifecycleListener _listener;
late AppLifecycleState? _state;

@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
_autoLockController.resumed();
_autoLockController.checkLock();

_state = SchedulerBinding.instance.lifecycleState;
_listener = AppLifecycleListener(
onShow: () {
_handleTransition('show');
// Get.toNamed(EHRoutes.unlockPage);
// _autoLockController.checkLock();
},
onResume: () async {
_handleTransition('resume');

await _autoLockController.checkLock();

// resumed 时清除 FLAG_SECURE ,避免无法截屏
FlutterWindowManager.clearFlags(FlutterWindowManager.FLAG_SECURE);

if (context.mounted) {
_ehSettingService.chkClipboardLink(context);
}
},
onHide: () {
_handleTransition('hide');
_autoLockController.paused();
},
onInactive: () {
_handleTransition('inactive');
// 添加 FLAG_SECURE
_ehSettingService.applyBlurredInRecentTasks();
},
onPause: () => _handleTransition('pause'),
onDetach: () => _handleTransition('detach'),
onRestart: () => _handleTransition('restart'),
);
}

void _handleTransition(String name) {
logger.d('########################## main $name');
}

@override
Expand All @@ -145,34 +189,6 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
View.of(context).platformDispatcher.platformBrightness;
}

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
logger.t('state: $state');
_autoLockController.updateStat(state);
if (state != AppLifecycleState.resumed) {
logger.d('applyBlurredInRecentTasks');

// 非 resumed 时根据设置 添加 FLAG_SECURE
_ehSettingService.applyBlurredInRecentTasks();
}
if (state == AppLifecycleState.paused) {
// went to Background
// loggerTime.d('paused');
_autoLockController.paused();
}
if (state == AppLifecycleState.resumed) {
// came back to Foreground
// loggerTime.d('resumed');
_autoLockController.resumed();

// resumed 时清除 FLAG_SECURE ,避免无法截屏
FlutterWindowManager.clearFlags(FlutterWindowManager.FLAG_SECURE);

_ehSettingService.chkClipboardLink(context);
}
}

@override
Widget build(BuildContext context) {
Widget cupertinoApp() {
Expand Down Expand Up @@ -218,7 +234,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
initialRoute: EHRoutes.root,
theme: themeService.themeData,
locale: localeService.locale,
enableLog: false && kDebugMode,
enableLog: false,
logWriterCallback: loggerGetx,
supportedLocales: <Locale>[
...L10n.delegate.supportedLocales,
Expand All @@ -232,12 +248,11 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
],

localeResolutionCallback: (_, Iterable<Locale> supportedLocales) {
final Locale _locale = PlatformDispatcher.instance.locale;
final Locale locale = PlatformDispatcher.instance.locale;

return localeService.locale ??
supportedLocales.firstWhere(
(Locale locale) =>
locale.languageCode == _locale.languageCode,
(Locale sl) => sl.languageCode == locale.languageCode,
orElse: () => supportedLocales.first,
);
},
Expand Down
2 changes: 0 additions & 2 deletions lib/pages/controller/fav_controller.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:fehviewer/common/controller/localfav_controller.dart';
import 'package:fehviewer/common/controller/user_controller.dart';
import 'package:fehviewer/common/global.dart';
import 'package:fehviewer/common/service/ehsetting_service.dart';
import 'package:fehviewer/common/service/theme_service.dart';
Expand All @@ -19,7 +18,6 @@ import 'favorite_sel_controller.dart';

class FavController extends GetxController {
final EhSettingService _ehSettingService = Get.find();
final UserController _userController = Get.find();
final LocalFavController _localFavController = Get.find();

// 收藏输入框控制器
Expand Down
10 changes: 7 additions & 3 deletions lib/pages/gallery/view/add_tags_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ const CupertinoDynamicColor _kClearButtonColor =
);

class AddTagPage extends StatefulWidget {
const AddTagPage({super.key});

@override
_AddTagPageState createState() => _AddTagPageState();
State<AddTagPage> createState() => _AddTagPageState();
}

class _AddTagPageState extends State<AddTagPage> {
Expand Down Expand Up @@ -111,7 +113,7 @@ class _AddTagPageState extends State<AddTagPage> {
// 滑动收起键盘
FocusScope.of(context).requestFocus(FocusNode());
},
child: CustomScrollView(
child: const CustomScrollView(
slivers: [
QryTagSliverList(),
],
Expand All @@ -125,7 +127,9 @@ class _AddTagPageState extends State<AddTagPage> {
}

class QryTagSliverList extends StatelessWidget {
final TagInfoController controller = Get.find(tag: pageCtrlTag);
const QryTagSliverList({super.key});

TagInfoController get controller => Get.find(tag: pageCtrlTag);

@override
Widget build(BuildContext context) {
Expand Down
3 changes: 1 addition & 2 deletions lib/pages/tab/controller/splash_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ class SplashController extends GetxController {
}

Future<void> _startHome(String url, {bool replace = true}) async {
// await _autoLockController.resumed(forceLock: true && !kDebugMode);
await _autoLockController.resumed(forceLock: true);
await _autoLockController.checkLock(forceLock: true);

final RegExp regGalleryUrl =
RegExp(r'https?://e[-x]hentai.org/g/[0-9]+/[0-9a-z]+/?');
Expand Down
6 changes: 5 additions & 1 deletion lib/pages/tab/controller/tabhome_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class TabHomeController extends GetxController {

late BuildContext tContext;

/// 需要初始化获取BuildContext 否则修改语言时tabitem的文字不会立即生效
/// 需要初始化获取BuildContext 否则修改语言时 tabitem 的文字不会立即生效
void init({required BuildContext inContext}) {
// logger.d(' rebuild home');
tContext = inContext;
Expand Down Expand Up @@ -319,4 +319,8 @@ class TabHomeController extends GetxController {
return await doubleClickBack();
}
}

Future<void> onPopInvoked(bool didPop) async {
logger.d('onPopInvoked $didPop');
}
}
Loading

0 comments on commit cbff6a9

Please sign in to comment.