From de891265c7089b2684a6c2f57988703ce13b2c52 Mon Sep 17 00:00:00 2001 From: Youngjin Cheon Date: Tue, 28 Nov 2017 21:56:44 +1100 Subject: [PATCH] Added toggle function to custom url action. [How to use] open keepingyouawake:///toggle --- KeepingYouAwake/KYAAppController.m | 3 +++ .../StatusItemController/KYAStatusItemController.h | 5 +++++ .../StatusItemController/KYAStatusItemController.m | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/KeepingYouAwake/KYAAppController.m b/KeepingYouAwake/KYAAppController.m index 1527fb6e..e3d72a26 100644 --- a/KeepingYouAwake/KYAAppController.m +++ b/KeepingYouAwake/KYAAppController.m @@ -385,6 +385,9 @@ - (void)configureEventHandler [KYAEventHandler.defaultHandler registerActionNamed:@"deactivate" block:^(KYAEvent *event) { [weakSelf terminateTimer]; }]; + [KYAEventHandler.defaultHandler registerActionNamed:@"toggle" block:^(KYAEvent *event) { + [self.statusItemController toggle]; + }]; } #pragma mark - KYAStatusItemControllerDelegate diff --git a/KeepingYouAwake/StatusItemController/KYAStatusItemController.h b/KeepingYouAwake/StatusItemController/KYAStatusItemController.h index dfb7c951..0e616ce6 100644 --- a/KeepingYouAwake/StatusItemController/KYAStatusItemController.h +++ b/KeepingYouAwake/StatusItemController/KYAStatusItemController.h @@ -17,6 +17,11 @@ NS_ASSUME_NONNULL_BEGIN */ @interface KYAStatusItemController : NSObject +/** + Toggle + */ +- (void)toggle; + /** The underlying system status bar item. */ diff --git a/KeepingYouAwake/StatusItemController/KYAStatusItemController.m b/KeepingYouAwake/StatusItemController/KYAStatusItemController.m index 18cd87a0..1bb35081 100644 --- a/KeepingYouAwake/StatusItemController/KYAStatusItemController.m +++ b/KeepingYouAwake/StatusItemController/KYAStatusItemController.m @@ -52,6 +52,11 @@ - (void)configureStatusItem self.activeAppearanceEnabled = NO; } +- (void)toggle +{ + [self toggleStatus:nil]; +} + - (void)toggleStatus:(id)sender { KYA_AUTO delegate = self.delegate;