Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][auth] Implemented logic for show app content

Aman Raj Singh Mourya78306ccf1d9e
diff --git a/auth/lib/main.dart b/auth/lib/main.dart
index de0257805d..bfc33d7ea8 100644
--- a/auth/lib/main.dart
+++ b/auth/lib/main.dart
@@ -28,12 +28,10 @@ import 'package:ente_auth/utils/window_protocol_handler.dart';
import 'package:ente_crypto_dart/ente_crypto_dart.dart';
import 'package:flutter/foundation.dart';
import "package:flutter/material.dart";
-import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'package:flutter_displaymode/flutter_displaymode.dart';
import 'package:logging/logging.dart';
import 'package:path_provider/path_provider.dart';
-import 'package:privacy_screen/privacy_screen.dart';
import 'package:tray_manager/tray_manager.dart';
import 'package:window_manager/window_manager.dart';
@@ -85,7 +83,6 @@ void main() async {
}
await _runInForeground();
- await _setupPrivacyScreen();
if (Platform.isAndroid) {
FlutterDisplayMode.setHighRefreshRate().ignore();
}
@@ -176,23 +173,3 @@ Future<void> _init(bool bool, {String? via}) async {
await IconUtils.instance.init();
await LockScreenSettings.instance.init();
}
-
-Future<void> _setupPrivacyScreen() async {
- if (!PlatformUtil.isMobile() || kDebugMode) return;
- final brightness =
- SchedulerBinding.instance.platformDispatcher.platformBrightness;
- bool isInDarkMode = brightness == Brightness.dark;
- await PrivacyScreen.instance.enable(
- iosOptions: const PrivacyIosOptions(
- enablePrivacy: true,
- privacyImageName: "LaunchImage",
- lockTrigger: IosLockTrigger.didEnterBackground,
- ),
- androidOptions: const PrivacyAndroidOptions(
- enableSecure: true,
- ),
- backgroundColor: isInDarkMode ? Colors.black : Colors.white,
- blurEffect:
- isInDarkMode ? PrivacyBlurEffect.dark : PrivacyBlurEffect.extraLight,
- );
-}
diff --git a/auth/lib/ui/settings/lock_screen/lock_screen_options.dart b/auth/lib/ui/settings/lock_screen/lock_screen_options.dart
index 3c24734d6b..e0ec3dd63e 100644
--- a/auth/lib/ui/settings/lock_screen/lock_screen_options.dart
+++ b/auth/lib/ui/settings/lock_screen/lock_screen_options.dart
@@ -16,7 +16,9 @@ import "package:ente_auth/ui/settings/lock_screen/lock_screen_pin.dart";
import "package:ente_auth/ui/tools/app_lock.dart";
import "package:ente_auth/utils/lock_screen_settings.dart";
import "package:ente_auth/utils/navigation_util.dart";
+import "package:ente_auth/utils/platform_util.dart";
import "package:flutter/material.dart";
+import "package:flutter/widgets.dart";
class LockScreenOptions extends StatefulWidget {
const LockScreenOptions({super.key});
@@ -32,10 +34,12 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
bool isPinEnabled = false;
bool isPasswordEnabled = false;
late int autoLockTimeInMilliseconds;
+ bool showAppContent = true;
@override
void initState() {
super.initState();
+ showAppContent = _lockscreenSetting.getShouldShowAppContent();
autoLockTimeInMilliseconds = _lockscreenSetting.getAutoLockTime();
_initializeSettings();
appLock = isPinEnabled ||
@@ -46,9 +50,12 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
Future<void> _initializeSettings() async {
final bool passwordEnabled = await _lockscreenSetting.isPasswordSet();
final bool pinEnabled = await _lockscreenSetting.isPinSet();
+ final bool shouldShowAppContent =
+ _lockscreenSetting.getShouldShowAppContent();
setState(() {
isPasswordEnabled = passwordEnabled;
isPinEnabled = pinEnabled;
+ showAppContent = shouldShowAppContent;
});
}
@@ -115,6 +122,9 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
AppLock.of(context)!.setEnabled(!appLock);
await _configuration.setSystemLockScreen(!appLock);
await _lockscreenSetting.removePinAndPassword();
+ if (appLock == true) {
+ await _lockscreenSetting.shouldShowAppContent(showAppContent: true);
+ }
await _lockscreenSetting.setAppLockType(
appLock ? AppLockUpdateType.none : AppLockUpdateType.device,
);
@@ -142,6 +152,16 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
);
}
+ Future<void> _onShowContent() async {
+ showAppContent = _lockscreenSetting.getShouldShowAppContent();
+ await _lockscreenSetting.shouldShowAppContent(
+ showAppContent: !showAppContent,
+ );
+ setState(() {
+ showAppContent = !showAppContent;
+ });
+ }
+
String _formatTime(Duration duration) {
if (duration.inHours != 0) {
return "in ${duration.inHours} hour${duration.inHours > 1 ? 's' : ''}";
@@ -297,43 +317,56 @@ class _LockScreenOptionsState extends State<LockScreenOptions> {
textAlign: TextAlign.left,
),
),
- const SizedBox(height: 24),
- MenuItemWidget(
- captionedTextWidget: CaptionedTextWidget(
- title: "App content in Task switcher",
- textStyle: textTheme.small.copyWith(
- color: colorTheme.textMuted,
- ),
- ),
- isBottomBorderRadiusRemoved: true,
- alignCaptionedTextToLeft: true,
- menuItemColor: colorTheme.fillFaint,
- ),
- MenuItemWidget(
- captionedTextWidget:
- const CaptionedTextWidget(
- title: "Show Content",
- ),
- alignCaptionedTextToLeft: true,
- isTopBorderRadiusRemoved: true,
- menuItemColor: colorTheme.fillFaint,
- trailingWidget: ToggleSwitchWidget(
- value: () => appLock,
- onChanged: () => _onToggleSwitch(),
- ),
- ),
- Padding(
- padding: const EdgeInsets.only(
- top: 14,
- left: 14,
- right: 12,
- ),
- child: Text(
- "If disabled app content will be displayed in the task switcher",
- style: textTheme.miniFaint,
- textAlign: TextAlign.left,
- ),
- ),
+ PlatformUtil.isMobile()
+ ? Column(
+ children: [
+ const SizedBox(height: 24),
+ MenuItemWidget(
+ captionedTextWidget:
+ CaptionedTextWidget(
+ title:
+ "App content in Task switcher",
+ textStyle:
+ textTheme.small.copyWith(
+ color: colorTheme.textMuted,
+ ),
+ ),
+ isBottomBorderRadiusRemoved: true,
+ alignCaptionedTextToLeft: true,
+ menuItemColor:
+ colorTheme.fillFaint,
+ ),
+ MenuItemWidget(
+ captionedTextWidget:
+ const CaptionedTextWidget(
+ title: "Show Content",
+ ),
+ alignCaptionedTextToLeft: true,
+ isTopBorderRadiusRemoved: true,
+ menuItemColor:
+ colorTheme.fillFaint,
+ trailingWidget:
+ ToggleSwitchWidget(
+ value: () => showAppContent,
+ onChanged: () =>
+ _onShowContent(),
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.only(
+ top: 14,
+ left: 14,
+ right: 12,
+ ),
+ child: Text(
+ "If disabled app content will be displayed in the task switcher",
+ style: textTheme.miniFaint,
+ textAlign: TextAlign.left,
+ ),
+ ),
+ ],
+ )
+ : Container(),
],
)
: Container(),
diff --git a/auth/lib/utils/lock_screen_settings.dart b/auth/lib/utils/lock_screen_settings.dart
index c3fa3daa5e..071887c0b6 100644
--- a/auth/lib/utils/lock_screen_settings.dart
+++ b/auth/lib/utils/lock_screen_settings.dart
@@ -1,9 +1,13 @@
import "dart:convert";
import "dart:typed_data";
+import "dart:ui";
import "package:ente_auth/events/app_lock_update_event.dart";
import "package:ente_crypto_dart/ente_crypto_dart.dart";
+import "package:flutter/material.dart";
+import "package:flutter/scheduler.dart";
import "package:flutter_secure_storage/flutter_secure_storage.dart";
+import "package:privacy_screen/privacy_screen.dart";
import "package:shared_preferences/shared_preferences.dart";
class LockScreenSettings {
@@ -18,6 +22,7 @@ class LockScreenSettings {
static const lastInvalidAttemptTime = "ls_last_invalid_attempt_time";
static const autoLockTime = "ls_auto_lock_time";
static const appLockType = "ls_app_lock_type";
+ static const keyShowAppContent = "ls_show_app_content";
final List<Duration> autoLockDurations = const [
Duration(seconds: 0),
Duration(seconds: 5),
@@ -35,6 +40,29 @@ class LockScreenSettings {
_preferences = await SharedPreferences.getInstance();
}
+ Future<void> shouldShowAppContent({bool showAppContent = true}) async {
+ final brightness =
+ SchedulerBinding.instance.platformDispatcher.platformBrightness;
+ bool isInDarkMode = brightness == Brightness.dark;
+ showAppContent
+ ? PrivacyScreen.instance.disable()
+ : await PrivacyScreen.instance.enable(
+ iosOptions: const PrivacyIosOptions(),
+ androidOptions: const PrivacyAndroidOptions(
+ enableSecure: true,
+ ),
+ backgroundColor: isInDarkMode ? Colors.black : Colors.white,
+ blurEffect: isInDarkMode
+ ? PrivacyBlurEffect.dark
+ : PrivacyBlurEffect.extraLight,
+ );
+ await _preferences.setBool(keyShowAppContent, showAppContent);
+ }
+
+ bool getShouldShowAppContent() {
+ return _preferences.getBool(keyShowAppContent) ?? true;
+ }
+
Future<void> setAppLockType(AppLockUpdateType lockType) async {
switch (lockType) {
case AppLockUpdateType.device: