From 1e868f876e9eed4feea3f49545e0bece5a2e0409 Mon Sep 17 00:00:00 2001 From: Godwin Asuquo <41484542+godilite@users.noreply.github.com> Date: Wed, 17 May 2023 18:34:41 +0300 Subject: [PATCH] CW-352 add enable disable screenshot feature to i os (#931) * Disable ios screen recording * Minor Enhancements --------- Co-authored-by: OmarHatem --- cw_core/lib/set_app_secure_native.dart | 5 +-- ios/Runner/AppDelegate.swift | 39 ++++++++++++++++------ lib/src/screens/settings/privacy_page.dart | 14 ++++---- lib/store/settings_store.dart | 9 ++--- 4 files changed, 40 insertions(+), 27 deletions(-) diff --git a/cw_core/lib/set_app_secure_native.dart b/cw_core/lib/set_app_secure_native.dart index 2f2e9a9c9..09e01556c 100644 --- a/cw_core/lib/set_app_secure_native.dart +++ b/cw_core/lib/set_app_secure_native.dart @@ -2,5 +2,6 @@ import 'package:flutter/services.dart'; const utils = const MethodChannel('com.cake_wallet/native_utils'); -void setIsAppSecureNative(bool isAppSecure) => - utils.invokeMethod('setIsAppSecure', {'isAppSecure': isAppSecure}); +void setIsAppSecureNative(bool isAppSecure) { + utils.invokeMethod('setIsAppSecure', {'isAppSecure': isAppSecure}); +} \ No newline at end of file diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index ec95060d1..401509606 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -15,6 +15,8 @@ import UnstoppableDomainsResolution if #available(iOS 10.0, *) { UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate } + + makeSecure() let controller : FlutterViewController = window?.rootViewController as! FlutterViewController let legacyMigrationChannel = FlutterMethodChannel( @@ -96,22 +98,39 @@ import UnstoppableDomainsResolution result(address) } - + case "setIsAppSecure": + guard let args = call.arguments as? Dictionary, + let isAppSecure = args["isAppSecure"] else { + result(nil) + return + } + + if isAppSecure { + self?.textField.isSecureTextEntry = true + } else { + self?.textField.isSecureTextEntry = false + } + + result(nil) default: result(FlutterMethodNotImplemented) } }) - + GeneratedPluginRegistrant.register(with: self) return super.application(application, didFinishLaunchingWithOptions: launchOptions) } + + private var textField = UITextField() + + private func makeSecure() { + if (!self.window.subviews.contains(textField)) { + self.window.addSubview(textField) + textField.centerYAnchor.constraint(equalTo: self.window.centerYAnchor).isActive = true + textField.centerXAnchor.constraint(equalTo: self.window.centerXAnchor).isActive = true + self.window.layer.superlayer?.addSublayer(textField.layer) + textField.layer.sublayers?.first?.addSublayer(self.window.layer) + } + } - override func applicationWillResignActive(_: UIApplication ) { - self.window?.rootViewController?.view.endEditing(true) - self.window?.isHidden = true; - } - - override func applicationDidBecomeActive(_: UIApplication) { - self.window?.isHidden = false; - } } diff --git a/lib/src/screens/settings/privacy_page.dart b/lib/src/screens/settings/privacy_page.dart index d21ae0ae8..c84bdc8e9 100644 --- a/lib/src/screens/settings/privacy_page.dart +++ b/lib/src/screens/settings/privacy_page.dart @@ -8,7 +8,6 @@ import 'package:cake_wallet/view_model/settings/choices_list_item.dart'; import 'package:cake_wallet/view_model/settings/privacy_settings_view_model.dart'; import 'package:flutter/material.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; -import 'dart:io' show Platform; class PrivacyPage extends BasePage { PrivacyPage(this._privacySettingsViewModel); @@ -49,13 +48,12 @@ class PrivacyPage extends BasePage { onValueChange: (BuildContext _, bool value) { _privacySettingsViewModel.setShouldSaveRecipientAddress(value); }), - if (Platform.isAndroid) - SettingsSwitcherCell( - title: S.current.prevent_screenshots, - value: _privacySettingsViewModel.isAppSecure, - onValueChange: (BuildContext _, bool value) { - _privacySettingsViewModel.setIsAppSecure(value); - }), + SettingsSwitcherCell( + title: S.current.prevent_screenshots, + value: _privacySettingsViewModel.isAppSecure, + onValueChange: (BuildContext _, bool value) { + _privacySettingsViewModel.setIsAppSecure(value); + }), SettingsSwitcherCell( title: S.current.disable_buy, value: _privacySettingsViewModel.disableBuy, diff --git a/lib/store/settings_store.dart b/lib/store/settings_store.dart index 74c86dd76..01723fc6e 100644 --- a/lib/store/settings_store.dart +++ b/lib/store/settings_store.dart @@ -23,7 +23,6 @@ import 'package:cake_wallet/monero/monero.dart'; import 'package:cake_wallet/entities/action_list_display_mode.dart'; import 'package:cake_wallet/entities/fiat_api_mode.dart'; import 'package:cw_core/set_app_secure_native.dart'; -import 'dart:io' show Platform; part 'settings_store.g.dart'; @@ -136,11 +135,11 @@ abstract class SettingsStoreBase with Store { (bool shouldSaveRecipientAddress) => sharedPreferences.setBool( PreferencesKey.shouldSaveRecipientAddressKey, shouldSaveRecipientAddress)); + setIsAppSecureNative(isAppSecure); + reaction((_) => isAppSecure, (bool isAppSecure) { sharedPreferences.setBool(PreferencesKey.isAppSecureKey, isAppSecure); - if (Platform.isAndroid) { setIsAppSecureNative(isAppSecure); - } }); reaction( @@ -153,10 +152,6 @@ abstract class SettingsStoreBase with Store { (bool disableSell) => sharedPreferences.setBool( PreferencesKey.disableSellKey, disableSell)); - if (Platform.isAndroid) { - setIsAppSecureNative(isAppSecure); - } - reaction( (_) => fiatApiMode, (FiatApiMode mode) =>