Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh keyword #48

Merged
merged 3 commits into from
Jan 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions App/BitBar/ExecutablePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@interface ExecutablePlugin : Plugin

@property (nonatomic, strong) NSTimer *lineCycleTimer;
@property (nonatomic, strong) NSTimer *refreshTimer;

- (BOOL) refreshContentByExecutingCommand;

Expand Down
19 changes: 14 additions & 5 deletions App/BitBar/ExecutablePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,24 @@ - (BOOL) refreshContentByExecutingCommand {
// success
self.lastCommandWasError = NO;
return YES;

}

-(void)performRefreshNow:(NSMenuItem*)menuItem{
self.content = @"Updating ...";
self.errorContent = @"";
[self rebuildMenuForStatusItem:self.statusItem];
self.currentLine = -1;
[self cycleLines];
[self.manager pluginDidUdpdateItself:self];
[self refresh];
}

-(BOOL)refresh {


[self.lineCycleTimer invalidate];
self.lineCycleTimer = nil;

[self.refreshTimer invalidate];
self.refreshTimer = nil;

// execute command
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{
[self refreshContentByExecutingCommand];
Expand Down Expand Up @@ -90,7 +99,7 @@ -(BOOL)refresh {
[self.manager pluginDidUdpdateItself:self];

// schedule next refresh
[NSTimer scheduledTimerWithTimeInterval:[self.refreshIntervalSeconds doubleValue] target:self selector:@selector(refresh) userInfo:nil repeats:NO];
_refreshTimer = [NSTimer scheduledTimerWithTimeInterval:[self.refreshIntervalSeconds doubleValue] target:self selector:@selector(refresh) userInfo:nil repeats:NO];

});
});
Expand Down
8 changes: 7 additions & 1 deletion App/BitBar/Plugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ - (NSMenuItem*) buildMenuItemWithParams:(NSDictionary *)params {

NSString * title = [params objectForKey:@"title"];
SEL sel = params[@"href"] ? @selector(performMenuItemHREFAction:)
: params[@"bash"] ? @selector(performMenuItemOpenTerminalAction:) : nil;
: params[@"bash"] ? @selector(performMenuItemOpenTerminalAction:)
: params[@"refresh"] ? @selector(performRefreshNow:):
nil;

NSMenuItem * item = [NSMenuItem.alloc initWithTitle:title action:sel keyEquivalent:@""];
if (sel) {
Expand Down Expand Up @@ -103,6 +105,10 @@ - (NSDictionary*) dictionaryForLine:(NSString *)line {
return params;
}

-(void)performRefreshNow:(NSMenuItem*)menuItem {
NSLog(@"Nothing to refresh in this plugin");
}

- (void) performMenuItemHREFAction:(NSMenuItem *)menuItem {

[NSWorkspace.sharedWorkspace openURL:[NSURL URLWithString:menuItem.representedObject[@"href"]]];
Expand Down
1 change: 1 addition & 0 deletions Plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ If you want to contribute, please send us a pull request and we'll add it to our
* `size=..` to change their text size. eg. `size=12`
* `bash=..` to make the dropdown run a given script terminal with your script e.g. `bash="/Users/user/BitBar_Plugins/scripts/nginx.restart.sh --verbose"`
* `terminal=..` if need to start bash script without open Terminal may be true or false
* `refresh=..` to make the dropdown items refresh the plugin it belongs to
* If you're writing scripts, ensure it has a shebang at the top.
* You can add to `PATH` by including something like `export PATH='/usr/local/bin:/usr/bin:$PATH'` in your plugin script.

Expand Down