diff --git a/RocketFuel/AppDelegate.h b/RocketFuel/AppDelegate.h index a205001..01fc294 100644 --- a/RocketFuel/AppDelegate.h +++ b/RocketFuel/AppDelegate.h @@ -1,7 +1,7 @@ /*! * @class AppDelegate * @brief The Application Delegate. - * @version 1.1.0 + * @version 1.1.1 * @author Ardalan Samimi * @copyright Saturn Five */ @@ -9,5 +9,6 @@ - (NSNumber *)isActive; - (void)toggleRocketFuel; +- (void)activateWithDuration:(NSInteger)duration; @end diff --git a/RocketFuel/AppDelegate.m b/RocketFuel/AppDelegate.m index 9341955..d2cf9d0 100644 --- a/RocketFuel/AppDelegate.m +++ b/RocketFuel/AppDelegate.m @@ -45,6 +45,14 @@ - (void)toggleRocketFuel { } } +- (void)activateWithDuration:(NSInteger)duration { + if (!_statusItemController) { + [self loadStatusItemController]; + } + + [self.statusItemController requestActivationForDuration:duration]; +} + - (NSNumber *)isActive { BOOL state = self.statusItemController.isActive; return [NSNumber numberWithBool:state]; diff --git a/RocketFuel/Info.plist b/RocketFuel/Info.plist index 3f946fd..82fc229 100644 --- a/RocketFuel/Info.plist +++ b/RocketFuel/Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.3.2 + 1.3.3 CFBundleSignature RkFl CFBundleVersion - 020F + 022F LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) LSUIElement diff --git a/RocketFuel/RFAppleScript.h b/RocketFuel/RFAppleScript.h index fc1c1e7..00516a4 100644 --- a/RocketFuel/RFAppleScript.h +++ b/RocketFuel/RFAppleScript.h @@ -1,7 +1,7 @@ /*! * @class RFAppleScript * @brief This class adds ability to receive commands from an Apple Script. - * @version 1.0.0 + * @version 1.0.1 * @author Ardalan Samimi * @copyright Saturn Five */ diff --git a/RocketFuel/RFAppleScript.m b/RocketFuel/RFAppleScript.m index caee61a..3936bf6 100644 --- a/RocketFuel/RFAppleScript.m +++ b/RocketFuel/RFAppleScript.m @@ -16,6 +16,16 @@ - (void)toggle { [appDelegate toggleRocketFuel]; } +- (void)duration { + NSInteger duration = [self.directParameter integerValue]; + if (!duration) { + duration = 1; + } + + AppDelegate *appDelegate = NSApplication.sharedApplication.delegate; + [appDelegate activateWithDuration:duration]; +} + - (id)performDefaultImplementation { SEL commandName = NSSelectorFromString(self.commandDescription.commandName); // Was it a valid command? @@ -25,6 +35,8 @@ - (id)performDefaultImplementation { func(self, commandName); } + + return NO; } diff --git a/RocketFuel/RFStatusItemController.h b/RocketFuel/RFStatusItemController.h index 9b0a94d..7cf9b64 100644 --- a/RocketFuel/RFStatusItemController.h +++ b/RocketFuel/RFStatusItemController.h @@ -1,13 +1,14 @@ /*! * @class Status Item Controller * @brief Manages the status item and the menu. - * @version 2.2.0 + * @version 2.3.0 * @author Ardalan Samimi * @copyright Saturn Five */ @interface RFStatusItemController : NSObject @property (nonatomic, readonly, getter = isActive) BOOL active; +- (void)requestActivationForDuration:(NSInteger)duration; - (void)requestActivation; - (void)requestTermination; diff --git a/RocketFuel/RFStatusItemController.m b/RocketFuel/RFStatusItemController.m index 03e4e0b..1405a5e 100644 --- a/RocketFuel/RFStatusItemController.m +++ b/RocketFuel/RFStatusItemController.m @@ -212,6 +212,11 @@ - (void)requestActivation { [self.rocketFuel toggleSleepMode]; } +- (void)requestActivationForDuration:(NSInteger)duration { + duration = duration * 60; + [self.rocketFuel activateWithDuration:duration]; +} + #pragma mark MISC METHODS - (BOOL)isMenuDark { diff --git a/RocketFuel/RocketFuel.h b/RocketFuel/RocketFuel.h index 1098f45..2a01de4 100644 --- a/RocketFuel/RocketFuel.h +++ b/RocketFuel/RocketFuel.h @@ -9,7 +9,7 @@ /*! * @class RocketFuel * @brief The RocketFuel Object. - * @version 1.2.0 + * @version 1.3.0 * @author Ardalan Samimi * @copyright Saturn Five */ diff --git a/RocketFuel/RocketFuel.m b/RocketFuel/RocketFuel.m index 6265bba..d62be30 100644 --- a/RocketFuel/RocketFuel.m +++ b/RocketFuel/RocketFuel.m @@ -13,6 +13,7 @@ @interface RocketFuel () @property (nonatomic) NSTask *task; @property (nonatomic) NSString *path; @property (nonatomic) NSArray *arguments; +@property (nonatomic, getter = shouldRelaunch) BOOL relaunch; @end @@ -36,28 +37,34 @@ - (void)toggleSleepMode { if (_task) { [self terminate]; } else { - [self launch]; + [self activate]; } } -- (void)launch { +- (void)activate { [self task]; __weak typeof(self) weakSelf = self; [_task setTerminationHandler:^(NSTask * _Nonnull task) { [weakSelf postTerminationCleanup]; + if (weakSelf.shouldRelaunch) { + [weakSelf activate]; + weakSelf.relaunch = NO; + } }]; } - (void)activateWithDuration:(NSInteger)duration { self.duration = duration; + self.relaunch = YES; + if (_task) { [self terminate]; // Make sure the post termination cleanup method is called. // Termination handler of NSTask does not always do that. [self postTerminationCleanup]; + } else { + [self activate]; } - - [self launch]; } - (void)terminate { @@ -69,9 +76,11 @@ - (void)terminate { } - (void)postTerminationCleanup { - _task = nil; - _arguments = nil; - self.active = self.isActive; + if (_task) { + _task = nil; + _arguments = nil; + self.active = self.isActive; + } } - (BOOL)active { diff --git a/RocketFuel/RocketFuel.sdef b/RocketFuel/RocketFuel.sdef index 4fcd612..26b5f09 100644 --- a/RocketFuel/RocketFuel.sdef +++ b/RocketFuel/RocketFuel.sdef @@ -11,5 +11,9 @@ + + + + \ No newline at end of file