mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-22 19:49:22 +00:00
Merge pull request #244 from cake-tech/CW-8-keep-screen-on-while-wallet-synchronization
Cw 8 keep screen on while wallet synchronization
This commit is contained in:
commit
712a5cfa43
8 changed files with 125 additions and 52 deletions
|
@ -13,6 +13,7 @@ import android.os.AsyncTask;
|
|||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.unstoppabledomains.resolution.DomainResolution;
|
||||
import com.unstoppabledomains.resolution.Resolution;
|
||||
|
@ -39,6 +40,14 @@ public class MainActivity extends FlutterFragmentActivity {
|
|||
|
||||
try {
|
||||
switch (call.method) {
|
||||
case "enableWakeScreen":
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
handler.post(() -> result.success(true));
|
||||
break;
|
||||
case "disableWakeScreen":
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
handler.post(() -> result.success(true));
|
||||
break;
|
||||
case "sec_random":
|
||||
int count = call.argument("count");
|
||||
SecureRandom random = new SecureRandom();
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.os.AsyncTask;
|
|||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.unstoppabledomains.resolution.DomainResolution;
|
||||
import com.unstoppabledomains.resolution.Resolution;
|
||||
|
@ -39,6 +40,14 @@ public class MainActivity extends FlutterFragmentActivity {
|
|||
|
||||
try {
|
||||
switch (call.method) {
|
||||
case "enableWakeScreen":
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
handler.post(() -> result.success(true));
|
||||
break;
|
||||
case "disableWakeScreen":
|
||||
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
handler.post(() -> result.success(true));
|
||||
break;
|
||||
case "sec_random":
|
||||
int count = call.argument("count");
|
||||
SecureRandom random = new SecureRandom();
|
||||
|
|
20
ios/CakeWallet/wakeLock.swift
Normal file
20
ios/CakeWallet/wakeLock.swift
Normal file
|
@ -0,0 +1,20 @@
|
|||
//
|
||||
// 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
|
||||
}
|
|
@ -12,6 +12,7 @@
|
|||
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 */; };
|
||||
|
@ -28,6 +29,7 @@
|
|||
20F67A1B2C2FCB2A3BB048C1 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
|
||||
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
|
||||
501EA9286675DC8636978EA4 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
|
||||
5AFFEBFC279AD49C00F906A4 /* wakeLock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = wakeLock.swift; sourceTree = "<group>"; };
|
||||
61CAA8652B54F23356F7592A /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
|
||||
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
|
||||
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
|
@ -68,6 +70,7 @@
|
|||
children = (
|
||||
0C44A7192518EF8000B570ED /* decrypt.swift */,
|
||||
0C9D68C8264854B60011B691 /* secRandom.swift */,
|
||||
5AFFEBFC279AD49C00F906A4 /* wakeLock.swift */,
|
||||
);
|
||||
path = CakeWallet;
|
||||
sourceTree = "<group>";
|
||||
|
@ -277,6 +280,7 @@
|
|||
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 */,
|
||||
);
|
||||
|
|
|
@ -96,6 +96,12 @@ import UnstoppableDomainsResolution
|
|||
|
||||
result(address)
|
||||
}
|
||||
case "enableWakeScreen":
|
||||
result(enableWakeScreen())
|
||||
|
||||
case "disableWakeScreen":
|
||||
result(disableWakeScreen())
|
||||
|
||||
default:
|
||||
result(FlutterMethodNotImplemented)
|
||||
}
|
||||
|
|
98
lib/di.dart
98
lib/di.dart
|
@ -1,3 +1,4 @@
|
|||
import 'package:cake_wallet/entities/wake_lock.dart';
|
||||
import 'package:cake_wallet/monero/monero.dart';
|
||||
import 'package:cake_wallet/bitcoin/bitcoin.dart';
|
||||
import 'package:cw_core/unspent_coins_info.dart';
|
||||
|
@ -192,8 +193,8 @@ Future setup(
|
|||
getIt.registerSingleton<ExchangeTemplateStore>(
|
||||
ExchangeTemplateStore(templateSource: _exchangeTemplates));
|
||||
getIt.registerSingleton<YatStore>(YatStore(
|
||||
appStore: getIt.get<AppStore>(),
|
||||
secureStorage: getIt.get<FlutterSecureStorage>())
|
||||
appStore: getIt.get<AppStore>(),
|
||||
secureStorage: getIt.get<FlutterSecureStorage>())
|
||||
..init());
|
||||
|
||||
final secretStore =
|
||||
|
@ -237,11 +238,9 @@ Future setup(
|
|||
type: type, language: language);
|
||||
});
|
||||
|
||||
getIt.registerFactory<WalletAddressListViewModel>(
|
||||
() => WalletAddressListViewModel(
|
||||
appStore: getIt.get<AppStore>(),
|
||||
yatStore: getIt.get<YatStore>()
|
||||
));
|
||||
getIt.registerFactory<WalletAddressListViewModel>(() =>
|
||||
WalletAddressListViewModel(
|
||||
appStore: getIt.get<AppStore>(), yatStore: getIt.get<YatStore>()));
|
||||
|
||||
getIt.registerFactory(() => BalanceViewModel(
|
||||
appStore: getIt.get<AppStore>(),
|
||||
|
@ -323,8 +322,7 @@ Future setup(
|
|||
getIt.get<AppStore>().wallet,
|
||||
getIt.get<AppStore>().settingsStore,
|
||||
getIt.get<SendTemplateStore>(),
|
||||
getIt.get<FiatConversionStore>()
|
||||
));
|
||||
getIt.get<FiatConversionStore>()));
|
||||
|
||||
getIt.registerFactory<SendViewModel>(() => SendViewModel(
|
||||
getIt.get<AppStore>().wallet,
|
||||
|
@ -336,9 +334,8 @@ Future setup(
|
|||
getIt.registerFactory(
|
||||
() => SendPage(sendViewModel: getIt.get<SendViewModel>()));
|
||||
|
||||
getIt.registerFactory(
|
||||
() => SendTemplatePage(
|
||||
sendTemplateViewModel: getIt.get<SendTemplateViewModel>()));
|
||||
getIt.registerFactory(() => SendTemplatePage(
|
||||
sendTemplateViewModel: getIt.get<SendTemplateViewModel>()));
|
||||
|
||||
getIt.registerFactory(() => WalletListViewModel(
|
||||
_walletInfoSource,
|
||||
|
@ -471,9 +468,11 @@ Future setup(
|
|||
case WalletType.monero:
|
||||
return monero.createMoneroWalletService(_walletInfoSource);
|
||||
case WalletType.bitcoin:
|
||||
return bitcoin.createBitcoinWalletService(_walletInfoSource, _unspentCoinsInfoSource);
|
||||
return bitcoin.createBitcoinWalletService(
|
||||
_walletInfoSource, _unspentCoinsInfoSource);
|
||||
case WalletType.litecoin:
|
||||
return bitcoin.createLitecoinWalletService(_walletInfoSource, _unspentCoinsInfoSource);
|
||||
return bitcoin.createLitecoinWalletService(
|
||||
_walletInfoSource, _unspentCoinsInfoSource);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
@ -507,13 +506,13 @@ Future setup(
|
|||
getIt
|
||||
.registerFactoryParam<TransactionDetailsViewModel, TransactionInfo, void>(
|
||||
(TransactionInfo transactionInfo, _) {
|
||||
final wallet = getIt.get<AppStore>().wallet;
|
||||
return TransactionDetailsViewModel(
|
||||
transactionInfo: transactionInfo,
|
||||
transactionDescriptionBox: _transactionDescriptionBox,
|
||||
wallet: wallet,
|
||||
settingsStore: getIt.get<SettingsStore>());
|
||||
});
|
||||
final wallet = getIt.get<AppStore>().wallet;
|
||||
return TransactionDetailsViewModel(
|
||||
transactionInfo: transactionInfo,
|
||||
transactionDescriptionBox: _transactionDescriptionBox,
|
||||
wallet: wallet,
|
||||
settingsStore: getIt.get<SettingsStore>());
|
||||
});
|
||||
|
||||
getIt.registerFactoryParam<TransactionDetailsPage, TransactionInfo, void>(
|
||||
(TransactionInfo transactionInfo, _) => TransactionDetailsPage(
|
||||
|
@ -574,23 +573,21 @@ Future setup(
|
|||
return PreOrderPage(buyViewModel: getIt.get<BuyViewModel>());
|
||||
});
|
||||
|
||||
getIt.registerFactoryParam<BuyWebViewPage, List, void>(
|
||||
(List args, _) {
|
||||
final url = args.first as String;
|
||||
final buyViewModel = args[1] as BuyViewModel;
|
||||
getIt.registerFactoryParam<BuyWebViewPage, List, void>((List args, _) {
|
||||
final url = args.first as String;
|
||||
final buyViewModel = args[1] as BuyViewModel;
|
||||
|
||||
return BuyWebViewPage(buyViewModel: buyViewModel,
|
||||
ordersStore: getIt.get<OrdersStore>(), url: url);
|
||||
});
|
||||
return BuyWebViewPage(
|
||||
buyViewModel: buyViewModel,
|
||||
ordersStore: getIt.get<OrdersStore>(),
|
||||
url: url);
|
||||
});
|
||||
|
||||
getIt.registerFactoryParam<OrderDetailsViewModel, Order, void>(
|
||||
(order, _) {
|
||||
final wallet = getIt.get<AppStore>().wallet;
|
||||
getIt.registerFactoryParam<OrderDetailsViewModel, Order, void>((order, _) {
|
||||
final wallet = getIt.get<AppStore>().wallet;
|
||||
|
||||
return OrderDetailsViewModel(
|
||||
wallet: wallet,
|
||||
orderForDetails: order);
|
||||
});
|
||||
return OrderDetailsViewModel(wallet: wallet, orderForDetails: order);
|
||||
});
|
||||
|
||||
getIt.registerFactoryParam<OrderDetailsPage, Order, void>((Order order, _) =>
|
||||
OrderDetailsPage(getIt.get<OrderDetailsViewModel>(param1: order)));
|
||||
|
@ -603,31 +600,28 @@ Future setup(
|
|||
final wallet = getIt.get<AppStore>().wallet;
|
||||
|
||||
return UnspentCoinsListViewModel(
|
||||
wallet: wallet,
|
||||
unspentCoinsInfo: _unspentCoinsInfoSource);
|
||||
wallet: wallet, unspentCoinsInfo: _unspentCoinsInfoSource);
|
||||
});
|
||||
|
||||
getIt.registerFactory(() => UnspentCoinsListPage(
|
||||
unspentCoinsListViewModel: getIt.get<UnspentCoinsListViewModel>()
|
||||
));
|
||||
unspentCoinsListViewModel: getIt.get<UnspentCoinsListViewModel>()));
|
||||
|
||||
getIt.registerFactoryParam<UnspentCoinsDetailsViewModel,
|
||||
UnspentCoinsItem, UnspentCoinsListViewModel>((item, model) =>
|
||||
UnspentCoinsDetailsViewModel(
|
||||
unspentCoinsItem: item,
|
||||
unspentCoinsListViewModel: model));
|
||||
getIt.registerFactoryParam<UnspentCoinsDetailsViewModel, UnspentCoinsItem,
|
||||
UnspentCoinsListViewModel>(
|
||||
(item, model) => UnspentCoinsDetailsViewModel(
|
||||
unspentCoinsItem: item, unspentCoinsListViewModel: model));
|
||||
|
||||
getIt.registerFactoryParam<UnspentCoinsDetailsPage, List, void>(
|
||||
(List args, _) {
|
||||
final item = args.first as UnspentCoinsItem;
|
||||
final unspentCoinsListViewModel = args[1] as UnspentCoinsListViewModel;
|
||||
(List args, _) {
|
||||
final item = args.first as UnspentCoinsItem;
|
||||
final unspentCoinsListViewModel = args[1] as UnspentCoinsListViewModel;
|
||||
|
||||
return UnspentCoinsDetailsPage(
|
||||
unspentCoinsDetailsViewModel:
|
||||
getIt.get<UnspentCoinsDetailsViewModel>(
|
||||
param1: item,
|
||||
param2: unspentCoinsListViewModel));
|
||||
return UnspentCoinsDetailsPage(
|
||||
unspentCoinsDetailsViewModel: getIt.get<UnspentCoinsDetailsViewModel>(
|
||||
param1: item, param2: unspentCoinsListViewModel));
|
||||
});
|
||||
|
||||
getIt.registerFactory(() => WakeLock());
|
||||
|
||||
_isSetupFinished = true;
|
||||
}
|
||||
|
|
21
lib/entities/wake_lock.dart
Normal file
21
lib/entities/wake_lock.dart
Normal file
|
@ -0,0 +1,21 @@
|
|||
import 'package:flutter/services.dart';
|
||||
|
||||
class WakeLock {
|
||||
static const _utils = const MethodChannel('com.cake_wallet/native_utils');
|
||||
|
||||
Future<void> enableWake() async {
|
||||
try {
|
||||
await _utils.invokeMethod<String>('enableWakeScreen');
|
||||
} on PlatformException catch (_) {
|
||||
print('Failed enabling screen wakelock');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> disableWake() async {
|
||||
try {
|
||||
await _utils.invokeMethod<String>('disableWakeScreen');
|
||||
} on PlatformException catch (_) {
|
||||
print('Failed enabling screen wakelock');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,9 +1,12 @@
|
|||
import 'package:cake_wallet/di.dart';
|
||||
import 'package:cake_wallet/entities/wake_lock.dart';
|
||||
import 'package:mobx/mobx.dart';
|
||||
import 'package:cw_core/transaction_history.dart';
|
||||
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';
|
||||
|
||||
ReactionDisposer _onWalletSyncStatusChangeReaction;
|
||||
|
||||
|
@ -11,11 +14,18 @@ void startWalletSyncStatusChangeReaction(
|
|||
WalletBase<Balance, TransactionHistoryBase<TransactionInfo>,
|
||||
TransactionInfo>
|
||||
wallet) {
|
||||
final _wakeLock = getIt.get<WakeLock>();
|
||||
_onWalletSyncStatusChangeReaction?.reaction?.dispose();
|
||||
_onWalletSyncStatusChangeReaction =
|
||||
reaction((_) => wallet.syncStatus, (SyncStatus status) async {
|
||||
if (status is ConnectedSyncStatus) {
|
||||
await wallet.startSync();
|
||||
}
|
||||
if (status is SyncingSyncStatus) {
|
||||
await _wakeLock.enableWake();
|
||||
}
|
||||
if (status is SyncedSyncStatus || status is FailedSyncStatus) {
|
||||
await _wakeLock.disableWake();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue