From 90a7432bf9de1f969df7857b9aa539303558be2c Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Thu, 26 Jan 2023 02:05:48 +0200 Subject: [PATCH] - Remove legacy migration from macos - Remove wake lock native code and just use the ready made package --- ios/CakeWallet/wakeLock.swift | 20 ------ ios/Runner.xcodeproj/project.pbxproj | 2 - lib/di.dart | 3 - lib/entities/wake_lock.dart | 21 ------ .../on_wallet_sync_status_change.dart | 9 +-- macos/Flutter/GeneratedPluginRegistrant.swift | 2 + macos/Runner/AppDelegate.swift | 68 ------------------- pubspec_base.yaml | 1 + 8 files changed, 6 insertions(+), 120 deletions(-) delete mode 100644 ios/CakeWallet/wakeLock.swift delete mode 100644 lib/entities/wake_lock.dart diff --git a/ios/CakeWallet/wakeLock.swift b/ios/CakeWallet/wakeLock.swift deleted file mode 100644 index 35f23eafa..000000000 --- a/ios/CakeWallet/wakeLock.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// wakeLock.swift -// Runner -// -// Created by Godwin Asuquo on 1/21/22. -// - -import Foundation -import UIKit - -func enableWakeScreen() -> Bool{ - UIApplication.shared.isIdleTimerDisabled = true - - return true -} - -func disableWakeScreen() -> Bool{ - UIApplication.shared.isIdleTimerDisabled = false - return true -} diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 8d62665c3..81b8dfcc7 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -12,7 +12,6 @@ 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; }; 20ED0868E1BD7E12278C0CB3 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B26E3F56D69167FBB1DC160A /* Pods_Runner.framework */; }; 3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; }; - 5AFFEBFD279AD49C00F906A4 /* wakeLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5AFFEBFC279AD49C00F906A4 /* wakeLock.swift */; }; 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; }; 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; @@ -280,7 +279,6 @@ files = ( 74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */, 1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */, - 5AFFEBFD279AD49C00F906A4 /* wakeLock.swift in Sources */, 0C9D68C9264854B60011B691 /* secRandom.swift in Sources */, 0C44A71A2518EF8000B570ED /* decrypt.swift in Sources */, ); diff --git a/lib/di.dart b/lib/di.dart index 1acdad2dd..fac4d634a 100644 --- a/lib/di.dart +++ b/lib/di.dart @@ -1,6 +1,5 @@ import 'package:cake_wallet/core/yat_service.dart'; import 'package:cake_wallet/entities/parse_address_from_domain.dart'; -import 'package:cake_wallet/entities/wake_lock.dart'; import 'package:cake_wallet/ionia/ionia_anypay.dart'; import 'package:cake_wallet/ionia/ionia_gift_card.dart'; import 'package:cake_wallet/ionia/ionia_tip.dart'; @@ -704,8 +703,6 @@ Future setup( param1: item, param2: unspentCoinsListViewModel)); }); - getIt.registerFactory(() => WakeLock()); - getIt.registerFactory(() => YatService()); getIt.registerFactory(() => AddressResolver(yatService: getIt.get(), diff --git a/lib/entities/wake_lock.dart b/lib/entities/wake_lock.dart deleted file mode 100644 index 99acc65ee..000000000 --- a/lib/entities/wake_lock.dart +++ /dev/null @@ -1,21 +0,0 @@ -import 'package:flutter/services.dart'; - -class WakeLock { - static const _utils = const MethodChannel('com.cake_wallet/native_utils'); - - Future enableWake() async { - try { - await _utils.invokeMethod('enableWakeScreen'); - } on PlatformException catch (_) { - print('Failed enabling screen wakelock'); - } - } - - Future disableWake() async { - try { - await _utils.invokeMethod('disableWakeScreen'); - } on PlatformException catch (_) { - print('Failed enabling screen wakelock'); - } - } -} diff --git a/lib/reactions/on_wallet_sync_status_change.dart b/lib/reactions/on_wallet_sync_status_change.dart index 68bd4b3c2..767bfd7e8 100644 --- a/lib/reactions/on_wallet_sync_status_change.dart +++ b/lib/reactions/on_wallet_sync_status_change.dart @@ -1,6 +1,4 @@ -import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/entities/update_haven_rate.dart'; -import 'package:cake_wallet/entities/wake_lock.dart'; import 'package:cake_wallet/store/dashboard/fiat_conversion_store.dart'; import 'package:cw_core/wallet_type.dart'; import 'package:mobx/mobx.dart'; @@ -9,7 +7,7 @@ import 'package:cw_core/wallet_base.dart'; import 'package:cw_core/balance.dart'; import 'package:cw_core/transaction_info.dart'; import 'package:cw_core/sync_status.dart'; -import 'package:flutter/services.dart'; +import 'package:wakelock/wakelock.dart'; ReactionDisposer? _onWalletSyncStatusChangeReaction; @@ -17,7 +15,6 @@ void startWalletSyncStatusChangeReaction( WalletBase, TransactionInfo> wallet, FiatConversionStore fiatConversionStore) { - final _wakeLock = getIt.get(); _onWalletSyncStatusChangeReaction?.reaction.dispose(); _onWalletSyncStatusChangeReaction = reaction((_) => wallet.syncStatus, (SyncStatus status) async { @@ -30,10 +27,10 @@ void startWalletSyncStatusChangeReaction( } } if (status is SyncingSyncStatus) { - await _wakeLock.enableWake(); + await Wakelock.enable(); } if (status is SyncedSyncStatus || status is FailedSyncStatus) { - await _wakeLock.disableWake(); + await Wakelock.disable(); } } catch(e) { print(e.toString()); diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 068b087fe..745087d97 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -16,6 +16,7 @@ import platform_device_id_macos import share_plus_macos import shared_preferences_foundation import url_launcher_macos +import wakelock_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin")) @@ -29,4 +30,5 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) + WakelockMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockMacosPlugin")) } diff --git a/macos/Runner/AppDelegate.swift b/macos/Runner/AppDelegate.swift index def2979dd..0c8973175 100644 --- a/macos/Runner/AppDelegate.swift +++ b/macos/Runner/AppDelegate.swift @@ -8,54 +8,8 @@ class AppDelegate: FlutterAppDelegate { return true } - var assertionID: IOPMAssertionID = 0 - override func applicationDidFinishLaunching(_ notification: Notification) { let controller : FlutterViewController = mainFlutterWindow?.contentViewController as! FlutterViewController - let legacyMigrationChannel = FlutterMethodChannel( - name: "com.cakewallet.cakewallet/legacy_wallet_migration", - binaryMessenger: controller.engine.binaryMessenger) - legacyMigrationChannel.setMethodCallHandler({ - (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in - - switch call.method { - case "decrypt": - guard let args = call.arguments as? Dictionary, - let data = args["bytes"] as? FlutterStandardTypedData, - let key = args["key"] as? String, - let salt = args["salt"] as? String else { - result(nil) - return - } - - let content = decrypt(data: data.data, key: key, salt: salt) - result(content) - case "read_user_defaults": - guard let args = call.arguments as? Dictionary, - let key = args["key"] as? String, - let type = args["type"] as? String else { - result(nil) - return - } - - var value: Any? - - switch (type) { - case "string": - value = UserDefaults.standard.string(forKey: key) - case "int": - value = UserDefaults.standard.integer(forKey: key) - case "bool": - value = UserDefaults.standard.bool(forKey: key) - default: - break - } - - result(value) - default: - result(FlutterMethodNotImplemented) - } - }) let utilsChannel = FlutterMethodChannel( name: "com.cake_wallet/native_utils", @@ -70,32 +24,10 @@ class AppDelegate: FlutterAppDelegate { } result(secRandom(count: count)) - case "getUnstoppableDomainAddress": - // Not supported on macos - result(nil) - case "enableWakeScreen": - result(self?.enableWakeScreen()) - - case "disableWakeScreen": - result(self?.disableWakeScreen()) default: result(FlutterMethodNotImplemented) } }) } - - - func enableWakeScreen(reason: String = "Disabling display sleep") -> Bool{ - return IOPMAssertionCreateWithName( kIOPMAssertionTypeNoDisplaySleep as CFString, - IOPMAssertionLevel(kIOPMAssertionLevelOn), - reason as CFString, - &assertionID) == kIOReturnSuccess - } - - func disableWakeScreen() -> Bool{ - IOPMAssertionRelease(assertionID) - - return true - } } diff --git a/pubspec_base.yaml b/pubspec_base.yaml index 4bd308abd..6b44fdfac 100644 --- a/pubspec_base.yaml +++ b/pubspec_base.yaml @@ -61,6 +61,7 @@ dependencies: permission_handler: ^10.0.0 device_display_brightness: ^0.0.6 platform_device_id: ^1.0.1 + wakelock: ^0.6.2 cake_backup: git: url: https://github.com/cake-tech/cake_backup.git