Skip to content

Commit

Permalink
Allow Blurred Recent Tasks in andrid
Browse files Browse the repository at this point in the history
  • Loading branch information
3003h committed Nov 10, 2023
1 parent 7e8dfbc commit 77ce88d
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 12 deletions.
5 changes: 3 additions & 2 deletions lib/common/global.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
23 changes: 20 additions & 3 deletions lib/common/service/ehsetting_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 = 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;
Expand Down Expand Up @@ -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<bool>(blurredInRecentTasks,
blurredInRecentTasks =
storageUtil.getBool(BLURRED_IN_RECENT_TASK) ?? blurredInRecentTasks;
// applyBlurredInRecentTasks(blurredInRecentTasks);
everProfile<bool>(_blurredInRecentTasks,
(bool value) => storageUtil.setBool(BLURRED_IN_RECENT_TASK, value));

// autoLockTimeOut
Expand Down Expand Up @@ -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<void> setProxy() async {
final proxy = await getProxy(
proxyType: proxyType,
Expand Down
10 changes: 10 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -150,6 +151,12 @@ class _MyAppState extends State<MyApp> 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');
Expand All @@ -160,6 +167,9 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
// loggerTime.d('resumed');
_autoLockController.resumed();

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

_ehSettingService.chkClipboardLink(context);
}
}
Expand Down
7 changes: 3 additions & 4 deletions lib/pages/setting/security_setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ class ListViewSecuritySetting extends StatelessWidget {
@override
Widget build(BuildContext context) {
final List<Widget> _list = <Widget>[
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),
];
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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<bool>? remove(String key) {
Expand Down
16 changes: 16 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 77ce88d

Please sign in to comment.