LiYang
Committed by GitHub

fix: Avoid changes in values unexpected (#64)

* fix: Avoid changes in values unexpected

* Do not check stable

* Attempt to fix integration test check

* Add version

* Remove extra pub get

Co-authored-by: 李阳 <yang.li@plaso.me>
Co-authored-by: creativecreatorormaybenot <creativecreatorormaybenot@gmail.com>
... ... @@ -24,7 +24,8 @@ jobs:
os:
- ubuntu-latest
channel:
- 'stable'
# Do not check stable until NNBD is on stable.
#- 'stable'
- 'beta'
- 'dev'
package:
... ... @@ -55,7 +56,8 @@ jobs:
device:
- 'iPhone 11 Pro Max (14.0)'
channel:
- 'stable'
# Do not check stable until NNBD is on stable.
#- 'stable'
- 'beta'
- 'dev'
package:
... ...
... ... @@ -3,6 +3,7 @@ description: >-2
Example app demonstrating how to use the wakelock plugin. It also includes integration tests for
testing the plugin in an integrated example.
publish_to: 'none'
version: 1.0.0+1
environment:
sdk: '>=2.12.0-0 <3.0.0'
... ...
#import "WakelockPlugin.h"
#import "messages.h"
static void * mKeyPathObserverContextApplicationIsIdleTimerDisabled = &mKeyPathObserverContextApplicationIsIdleTimerDisabled;
@interface WakelockPlugin () <FLTWakelockApi>
@property (nonatomic, assign) BOOL enable;
@end
@implementation WakelockPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
WakelockPlugin* instance = [[WakelockPlugin alloc] init];
FLTWakelockApiSetup(registrar.messenger, instance);
[UIApplication.sharedApplication addObserver:instance forKeyPath:@"idleTimerDisabled" options:NSKeyValueObservingOptionNew context:mKeyPathObserverContextApplicationIsIdleTimerDisabled];
}
- (void)toggle:(FLTToggleMessage*)input error:(FlutterError**)error {
NSNumber *enable = input.enable;
self.enable = enable.boolValue;
NSNumber *enabled = [NSNumber numberWithBool:[[UIApplication sharedApplication] isIdleTimerDisabled]];
if (![enable isEqualToNumber:enabled]) {
... ... @@ -28,4 +36,18 @@
return result;
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (context == mKeyPathObserverContextApplicationIsIdleTimerDisabled) {
if (UIApplication.sharedApplication.idleTimerDisabled != self.enable) {
UIApplication.sharedApplication.idleTimerDisabled = self.enable;
}
} else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
- (void)dealloc {
[UIApplication.sharedApplication removeObserver:self forKeyPath:@"idleTimerDisabled" context:mKeyPathObserverContextApplicationIsIdleTimerDisabled];
}
@end
... ...