Skip to content

Commit

Permalink
1.3.3 (022F)
Browse files Browse the repository at this point in the history
Changes:
* Fixed time preset bug in issue #3
* Added applescript command for activating RF with duration.
  • Loading branch information
pkrll committed Nov 2, 2015
1 parent ab77b93 commit b9ff04e
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 13 deletions.
3 changes: 2 additions & 1 deletion RocketFuel/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/*!
* @class AppDelegate
* @brief The Application Delegate.
* @version 1.1.0
* @version 1.1.1
* @author Ardalan Samimi
* @copyright Saturn Five
*/
@interface AppDelegate : NSObject <NSApplicationDelegate>

- (NSNumber *)isActive;
- (void)toggleRocketFuel;
- (void)activateWithDuration:(NSInteger)duration;

@end
8 changes: 8 additions & 0 deletions RocketFuel/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions RocketFuel/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.3.2</string>
<string>1.3.3</string>
<key>CFBundleSignature</key>
<string>RkFl</string>
<key>CFBundleVersion</key>
<string>020F</string>
<string>022F</string>
<key>LSMinimumSystemVersion</key>
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
<key>LSUIElement</key>
Expand Down
2 changes: 1 addition & 1 deletion RocketFuel/RFAppleScript.h
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down
12 changes: 12 additions & 0 deletions RocketFuel/RFAppleScript.m
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -25,6 +35,8 @@ - (id)performDefaultImplementation {
func(self, commandName);
}



return NO;
}

Expand Down
3 changes: 2 additions & 1 deletion RocketFuel/RFStatusItemController.h
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
5 changes: 5 additions & 0 deletions RocketFuel/RFStatusItemController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion RocketFuel/RocketFuel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/*!
* @class RocketFuel
* @brief The RocketFuel Object.
* @version 1.2.0
* @version 1.3.0
* @author Ardalan Samimi
* @copyright Saturn Five
*/
Expand Down
23 changes: 16 additions & 7 deletions RocketFuel/RocketFuel.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions RocketFuel/RocketFuel.sdef
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@
<command name="toggle" code="rkfltogl" description="Activate/deactivate Rocket Fuel.">
<cocoa class="RFAppleScript"/>
</command>
<command name="duration" code="rkfldura" description="Activate Rocket Fuel for a certain amount of time (in minutes).">
<cocoa class="RFAppleScript"/>
<direct-parameter name="minutes" description="Amount of time in minutes Rocket Fuel should stay active. Defaults to 1 if no argument is given." code="rkfldupa" type="text"></direct-parameter>
</command>
</suite>
</dictionary>

0 comments on commit b9ff04e

Please sign in to comment.