Skip to content

Commit cbff6a9

Browse files
committed
Clean up the code.
1 parent e5e3a98 commit cbff6a9

22 files changed

+430
-1592
lines changed

analysis_options.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ analyzer:
3636
# Ignore analyzer hints for updating pubspecs when using Future or
3737
# Stream and not importing dart:async
3838
# Please see https://github.com/flutter/flutter/pull/24528 for details.
39-
sdk_version_async_exported_from_core: ignore
4039
invalid_annotation_target: ignore
4140
exclude:
4241
- "bin/cache/**"
@@ -151,7 +150,6 @@ linter:
151150
# - prefer_constructors_over_static_methods # not yet tested
152151
- prefer_contains
153152
# - prefer_double_quotes # opposite of prefer_single_quotes
154-
- prefer_equal_for_default_values
155153
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
156154
- prefer_final_fields
157155
- prefer_final_in_for_each

ios/Runner/AppDelegate.swift

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,35 @@ import flutter_downloader
1919
}
2020

2121
override func applicationDidEnterBackground(_ application: UIApplication) {
22-
// 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.
23-
// 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.
24-
22+
print("applicationDidEnterBackground")
23+
addBlurEffect()
24+
}
25+
26+
// override func applicationWillResignActive(_ application: UIApplication) {
27+
// print("applicationWillResignActive")
28+
// addBlurEffect()
29+
// }
30+
31+
override func applicationDidBecomeActive(_ application: UIApplication) {
32+
print("applicationDidBecomeActive")
33+
SecurityBlurEffect.removeBlurEffect()
34+
}
35+
36+
override func applicationWillEnterForeground(_ application: UIApplication) {
37+
print("applicationWillEnterForeground")
38+
SecurityBlurEffect.removeBlurEffect()
39+
}
40+
41+
func addBlurEffect() {
2542
let BLURRED_IN_RECENT_TASK = "flutter.blurredInRecentTasks"
26-
43+
2744
let isBlurredInRecentTasks = UserDefaults.standard.bool(forKey: BLURRED_IN_RECENT_TASK)
28-
45+
2946
print("isBlurredInRecentTasks :", isBlurredInRecentTasks)
3047
if isBlurredInRecentTasks {
3148
SecurityBlurEffect.addBlurEffect()
3249
}
3350
}
34-
35-
override func applicationWillEnterForeground(_ application: UIApplication) {
36-
// 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.
37-
38-
print("applicationWillEnterForeground")
39-
SecurityBlurEffect.removeBlurEffect()
40-
41-
}
4251
}
4352

4453
private func registerPlugins(registry: FlutterPluginRegistry) {

ios/Runner/GoProxy.swift

Lines changed: 0 additions & 8 deletions
This file was deleted.

lib/common/controller/auto_lock_controller.dart

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'dart:ui';
2-
31
import 'package:fehviewer/common/service/ehsetting_service.dart';
42
import 'package:fehviewer/generated/l10n.dart';
53
import 'package:fehviewer/models/index.dart';
@@ -75,21 +73,22 @@ class AutoLockController extends GetxController {
7573
}
7674
}
7775

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

83-
logger.t('now time ${nowTime}, lastLeaveTime: ${lastLeaveTime}');
81+
logger.t('now time $nowTime, lastLeaveTime: $lastLeaveTime');
8482

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

89-
if (_locked && !_isResumed) {
87+
if (locked && !_isResumed) {
9088
_isLocking = true;
9189

9290
final result = await Get.toNamed(EHRoutes.unlockPage);
91+
9392
if (result is bool) {
9493
final bool didAuthenticate = result;
9594
if (didAuthenticate) {
@@ -100,6 +99,4 @@ class AutoLockController extends GetxController {
10099
}
101100
}
102101
}
103-
104-
void updateStat(AppLifecycleState state) {}
105102
}

lib/common/parser/home_parser.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import 'package:html/dom.dart';
22
import 'package:html/parser.dart' show parse;
33

44
import '../../models/base/eh_models.dart';
5-
import '../../utils/logger.dart';
65

76
EhHome parserEhHome(String response) {
87
final Document document = parse(response);

lib/common/parser/mytags_parser.dart

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@ import '../../fehviewer.dart';
66
EhMytags parseMyTags(String html) {
77
final Document document = parse(html);
88

9-
final tagsets = <EhMytagSet>[];
10-
11-
late String selectedValue = '';
9+
final tagSets = <EhMytagSet>[];
1210

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

17-
if (tagsetElm != null) {
18-
final tagsetElms = tagsetElm.children;
15+
if (tagSetElm != null) {
16+
final tagsetElms = tagSetElm.children;
1917
// logger.d('tagsetElms.length ${tagsetElms.length}');
2018
for (final _tagset in tagsetElms) {
2119
final value = _tagset.attributes['value'];
@@ -30,25 +28,23 @@ EhMytags parseMyTags(String html) {
3028
RegExp(r'(.+)\((\d+)\)'), (match) => match.group(1) ?? '');
3129
final count = _tagset.text.replaceAllMapped(
3230
RegExp(r'(.+)\((\d+)\)'), (match) => match.group(2) ?? '');
33-
if (isSelected) {
34-
selectedValue = value;
35-
}
31+
if (isSelected) {}
3632

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

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

43-
tagsets.add(EhMytagSet(
39+
tagSets.add(EhMytagSet(
4440
name: name.trim(),
4541
tagCount: count.trim(),
4642
value: value.trim(),
4743
));
4844
}
4945
}
5046

51-
tagsets.sort((a, b) =>
47+
tagSets.sort((a, b) =>
5248
(int.tryParse(a.value ?? '0') ?? 0) -
5349
(int.tryParse(b.value ?? '0') ?? 0));
5450

@@ -127,7 +123,7 @@ EhMytags parseMyTags(String html) {
127123
'';
128124

129125
return EhMytags(
130-
tagsets: tagsets,
126+
tagsets: tagSets,
131127
usertags: usertags,
132128
canDelete: html.contains('do_tagset_delete()'),
133129
apikey: _apikey,

lib/extension.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ extension ExtTagTranlat on TagTranslat {
240240
case TagIntroImgLv.r18:
241241
// 去除R18g, 把r18的格式修正
242242
return _fix(regR18And18g, _remove(regR18g, intro));
243-
break;
244243
case TagIntroImgLv.r18g:
245244
// 把r18和r18g的格式修正
246245
return _fix(regR18And18g, intro);

lib/main.dart

Lines changed: 49 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import 'package:firebase_core/firebase_core.dart';
1414
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
1515
import 'package:flutter/cupertino.dart';
1616
import 'package:flutter/foundation.dart';
17+
import 'package:flutter/material.dart';
18+
import 'package:flutter/scheduler.dart';
1719
import 'package:flutter_localizations/flutter_localizations.dart';
1820
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
1921
import 'package:flutter_windowmanager/flutter_windowmanager.dart';
@@ -116,8 +118,10 @@ Future<void> main() async {
116118
}
117119

118120
class MyApp extends StatefulWidget {
121+
const MyApp({super.key});
122+
119123
@override
120-
_MyAppState createState() => _MyAppState();
124+
State<MyApp> createState() => _MyAppState();
121125
}
122126

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

133+
late final AppLifecycleListener _listener;
134+
late AppLifecycleState? _state;
135+
129136
@override
130137
void initState() {
131138
super.initState();
132139
WidgetsBinding.instance.addObserver(this);
133-
_autoLockController.resumed();
140+
_autoLockController.checkLock();
141+
142+
_state = SchedulerBinding.instance.lifecycleState;
143+
_listener = AppLifecycleListener(
144+
onShow: () {
145+
_handleTransition('show');
146+
// Get.toNamed(EHRoutes.unlockPage);
147+
// _autoLockController.checkLock();
148+
},
149+
onResume: () async {
150+
_handleTransition('resume');
151+
152+
await _autoLockController.checkLock();
153+
154+
// resumed 时清除 FLAG_SECURE ,避免无法截屏
155+
FlutterWindowManager.clearFlags(FlutterWindowManager.FLAG_SECURE);
156+
157+
if (context.mounted) {
158+
_ehSettingService.chkClipboardLink(context);
159+
}
160+
},
161+
onHide: () {
162+
_handleTransition('hide');
163+
_autoLockController.paused();
164+
},
165+
onInactive: () {
166+
_handleTransition('inactive');
167+
// 添加 FLAG_SECURE
168+
_ehSettingService.applyBlurredInRecentTasks();
169+
},
170+
onPause: () => _handleTransition('pause'),
171+
onDetach: () => _handleTransition('detach'),
172+
onRestart: () => _handleTransition('restart'),
173+
);
174+
}
175+
176+
void _handleTransition(String name) {
177+
logger.d('########################## main $name');
134178
}
135179

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

148-
@override
149-
void didChangeAppLifecycleState(AppLifecycleState state) {
150-
super.didChangeAppLifecycleState(state);
151-
logger.t('state: $state');
152-
_autoLockController.updateStat(state);
153-
if (state != AppLifecycleState.resumed) {
154-
logger.d('applyBlurredInRecentTasks');
155-
156-
// 非 resumed 时根据设置 添加 FLAG_SECURE
157-
_ehSettingService.applyBlurredInRecentTasks();
158-
}
159-
if (state == AppLifecycleState.paused) {
160-
// went to Background
161-
// loggerTime.d('paused');
162-
_autoLockController.paused();
163-
}
164-
if (state == AppLifecycleState.resumed) {
165-
// came back to Foreground
166-
// loggerTime.d('resumed');
167-
_autoLockController.resumed();
168-
169-
// resumed 时清除 FLAG_SECURE ,避免无法截屏
170-
FlutterWindowManager.clearFlags(FlutterWindowManager.FLAG_SECURE);
171-
172-
_ehSettingService.chkClipboardLink(context);
173-
}
174-
}
175-
176192
@override
177193
Widget build(BuildContext context) {
178194
Widget cupertinoApp() {
@@ -218,7 +234,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
218234
initialRoute: EHRoutes.root,
219235
theme: themeService.themeData,
220236
locale: localeService.locale,
221-
enableLog: false && kDebugMode,
237+
enableLog: false,
222238
logWriterCallback: loggerGetx,
223239
supportedLocales: <Locale>[
224240
...L10n.delegate.supportedLocales,
@@ -232,12 +248,11 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
232248
],
233249

234250
localeResolutionCallback: (_, Iterable<Locale> supportedLocales) {
235-
final Locale _locale = PlatformDispatcher.instance.locale;
251+
final Locale locale = PlatformDispatcher.instance.locale;
236252

237253
return localeService.locale ??
238254
supportedLocales.firstWhere(
239-
(Locale locale) =>
240-
locale.languageCode == _locale.languageCode,
255+
(Locale sl) => sl.languageCode == locale.languageCode,
241256
orElse: () => supportedLocales.first,
242257
);
243258
},

lib/pages/controller/fav_controller.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:fehviewer/common/controller/localfav_controller.dart';
2-
import 'package:fehviewer/common/controller/user_controller.dart';
32
import 'package:fehviewer/common/global.dart';
43
import 'package:fehviewer/common/service/ehsetting_service.dart';
54
import 'package:fehviewer/common/service/theme_service.dart';
@@ -19,7 +18,6 @@ import 'favorite_sel_controller.dart';
1918

2019
class FavController extends GetxController {
2120
final EhSettingService _ehSettingService = Get.find();
22-
final UserController _userController = Get.find();
2321
final LocalFavController _localFavController = Get.find();
2422

2523
// 收藏输入框控制器

lib/pages/gallery/view/add_tags_page.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ const CupertinoDynamicColor _kClearButtonColor =
1717
);
1818

1919
class AddTagPage extends StatefulWidget {
20+
const AddTagPage({super.key});
21+
2022
@override
21-
_AddTagPageState createState() => _AddTagPageState();
23+
State<AddTagPage> createState() => _AddTagPageState();
2224
}
2325

2426
class _AddTagPageState extends State<AddTagPage> {
@@ -111,7 +113,7 @@ class _AddTagPageState extends State<AddTagPage> {
111113
// 滑动收起键盘
112114
FocusScope.of(context).requestFocus(FocusNode());
113115
},
114-
child: CustomScrollView(
116+
child: const CustomScrollView(
115117
slivers: [
116118
QryTagSliverList(),
117119
],
@@ -125,7 +127,9 @@ class _AddTagPageState extends State<AddTagPage> {
125127
}
126128

127129
class QryTagSliverList extends StatelessWidget {
128-
final TagInfoController controller = Get.find(tag: pageCtrlTag);
130+
const QryTagSliverList({super.key});
131+
132+
TagInfoController get controller => Get.find(tag: pageCtrlTag);
129133

130134
@override
131135
Widget build(BuildContext context) {

0 commit comments

Comments
 (0)