diff --git a/lib/common/global.dart b/lib/common/global.dart index 5db76719a..6f136f138 100644 --- a/lib/common/global.dart +++ b/lib/common/global.dart @@ -195,13 +195,14 @@ class Global { cookieJar = await Api.cookieJar; // 读取设备第一次打开 - isFirstOpen = !StorageUtil().getBool(STORAGE_DEVICE_ALREADY_OPEN_KEY); + isFirstOpen = + !(StorageUtil().getBool(STORAGE_DEVICE_ALREADY_OPEN_KEY) ?? false); if (isFirstOpen) { creatDirs(); StorageUtil().setBool(STORAGE_DEVICE_ALREADY_OPEN_KEY, true); } - isDBinappSupportPath = StorageUtil().getBool(IS_DB_IN_SUPPORT_DIR); + isDBinappSupportPath = StorageUtil().getBool(IS_DB_IN_SUPPORT_DIR) ?? false; if (Platform.isAndroid) { await iaw.AndroidInAppWebViewController.setWebContentsDebuggingEnabled( diff --git a/lib/common/service/ehsetting_service.dart b/lib/common/service/ehsetting_service.dart index a601a7af3..a4235d2f2 100644 --- a/lib/common/service/ehsetting_service.dart +++ b/lib/common/service/ehsetting_service.dart @@ -17,6 +17,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:flutter_boring_avatars/flutter_boring_avatars.dart'; +import 'package:flutter_windowmanager/flutter_windowmanager.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:get/get.dart'; import 'package:logger/logger.dart'; @@ -41,9 +42,13 @@ class EhSettingService extends ProfileService { RxBool isPureDarkTheme = false.obs; RxBool isClipboardLink = true.obs; RxBool commentTrans = false.obs; - RxBool blurredInRecentTasks = true.obs; + // RxBool blurredInRecentTasks = true.obs; Rx tagIntroImgLv = TagIntroImgLv.nonh.obs; + final _blurredInRecentTasks = false.obs; + bool get blurredInRecentTasks => _blurredInRecentTasks.value; + set blurredInRecentTasks(bool val) => _blurredInRecentTasks.value = val; + final _viewColumnMode = ViewColumnMode.single.obs; ViewColumnMode get viewColumnMode => _viewColumnMode.value; set viewColumnMode(ViewColumnMode val) => _viewColumnMode.value = val; @@ -594,8 +599,10 @@ class EhSettingService extends ProfileService { (bool value) => ehConfig = ehConfig.copyWith(commentTrans: value)); // blurredInRecentTasks - blurredInRecentTasks.value = storageUtil.getBool(BLURRED_IN_RECENT_TASK); - everProfile(blurredInRecentTasks, + blurredInRecentTasks = + storageUtil.getBool(BLURRED_IN_RECENT_TASK) ?? blurredInRecentTasks; + // applyBlurredInRecentTasks(blurredInRecentTasks); + everProfile(_blurredInRecentTasks, (bool value) => storageUtil.setBool(BLURRED_IN_RECENT_TASK, value)); // autoLockTimeOut @@ -843,6 +850,16 @@ class EhSettingService extends ProfileService { _initBlockConfig(); } + void applyBlurredInRecentTasks() { + if (Platform.isAndroid) { + if (blurredInRecentTasks) { + FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE); + } else { + FlutterWindowManager.clearFlags(FlutterWindowManager.FLAG_SECURE); + } + } + } + Future setProxy() async { final proxy = await getProxy( proxyType: proxyType, diff --git a/lib/main.dart b/lib/main.dart index 7b7b509e9..7b75db1cc 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -17,6 +17,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; +import 'package:flutter_windowmanager/flutter_windowmanager.dart'; import 'package:get/get.dart'; import 'package:logger/logger.dart'; import 'package:oktoast/oktoast.dart'; @@ -150,6 +151,12 @@ class _MyAppState extends State with WidgetsBindingObserver { 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'); @@ -160,6 +167,9 @@ class _MyAppState extends State with WidgetsBindingObserver { // loggerTime.d('resumed'); _autoLockController.resumed(); + // resumed 时清除 FLAG_SECURE ,避免无法截屏 + FlutterWindowManager.clearFlags(FlutterWindowManager.FLAG_SECURE); + _ehSettingService.chkClipboardLink(context); } } diff --git a/lib/pages/setting/security_setting_page.dart b/lib/pages/setting/security_setting_page.dart index be56cf435..01b5d2800 100644 --- a/lib/pages/setting/security_setting_page.dart +++ b/lib/pages/setting/security_setting_page.dart @@ -32,12 +32,11 @@ class ListViewSecuritySetting extends StatelessWidget { @override Widget build(BuildContext context) { final List _list = [ - if (GetPlatform.isIOS) + if (GetPlatform.isMobile) TextSwitchItem( L10n.of(context).security_blurredInRecentTasks, - value: _ehSettingService.blurredInRecentTasks.value, - onChanged: (val) => - _ehSettingService.blurredInRecentTasks.value = val, + value: _ehSettingService.blurredInRecentTasks, + onChanged: (val) => _ehSettingService.blurredInRecentTasks = val, ), _buildAutoLockItem(context, hideLine: true), ]; diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index a7b2f057c..e29d1080c 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -22,7 +22,7 @@ class StorageUtil { return _prefs?.setString(key, jsonString); } - dynamic? getJSON(String key) { + dynamic getJSON(String key) { final String? jsonString = _prefs?.getString(key); return jsonString; } @@ -39,9 +39,9 @@ class StorageUtil { return _prefs?.setBool(key, val); } - bool getBool(String key) { + bool? getBool(String key) { final bool? val = _prefs?.getBool(key); - return val ?? false; + return val; } Future? remove(String key) { diff --git a/pubspec.lock b/pubspec.lock index 13b56fee3..e1517b69a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -994,6 +994,14 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.14.6" + flutter_windowmanager: + dependency: "direct main" + description: + name: flutter_windowmanager + sha256: b4d0bc06f6777952b729c0cdb7ce9ad1ecabd8b8b1cb0acb57a36621457dab1b + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.2.0" font_awesome_flutter: dependency: "direct main" description: @@ -1171,6 +1179,14 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.0.3" + integral_isolates: + dependency: "direct main" + description: + name: integral_isolates + sha256: "31b8ef45985ebfba628f1df5366df263578bc62119409588dbd679a2e27f2225" + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.4.1" intl: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index dd4ddf8d7..8d1e751ab 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -194,6 +194,8 @@ dependencies: firebase_performance_dio: ^0.6.0 pull_down_button: ^0.9.3 dio_cache_interceptor_file_store: ^1.2.2 + flutter_windowmanager: ^0.2.0 + integral_isolates: ^0.4.1 dev_dependencies: # flutter pub run build_runner build --delete-conflicting-outputs