Compare commits

...

7 Commits

Author SHA1 Message Date
Lea Anthony
d498423ec2 v2.0.0-alpha.48 2021-03-09 22:28:07 +11:00
Mat Ryer
66ce84973c fixes for machines running TouchBar addresses https://github.com/matryer/xbar/issues/610 2021-03-09 11:24:46 +00:00
Lea Anthony
55e6a0f312 v2.0.0-alpha.47 2021-03-07 16:24:20 +11:00
Lea Anthony
81e83fdf18 Ensure modifiers are lowercase when parsing 2021-03-07 16:21:30 +11:00
Lea Anthony
f9b79d24f8 Guard against nil url messages 2021-03-06 15:51:06 +11:00
Lea Anthony
0599a47bfe v2.0.0-alpha.46 2021-03-06 15:43:44 +11:00
Lea Anthony
817c55d318 Support base64 images in tray 2021-03-06 15:43:11 +11:00
5 changed files with 29 additions and 12 deletions

View File

@@ -1,3 +1,3 @@
package main package main
var version = "v2.0.0-alpha.45" var version = "v2.0.0-alpha.48"

View File

@@ -1166,26 +1166,28 @@ void getURL(id self, SEL selector, id event, id replyEvent) {
void createDelegate(struct Application *app) { void createDelegate(struct Application *app) {
// Define delegate // Define delegate
Class delegateClass = objc_allocateClassPair((Class) c("NSObject"), "AppDelegate", 0); Class appDelegate = objc_allocateClassPair((Class) c("NSResponder"), "AppDelegate", 0);
bool resultAddProtoc = class_addProtocol(delegateClass, objc_getProtocol("NSApplicationDelegate")); class_addProtocol(appDelegate, objc_getProtocol("NSTouchBarProvider"));
class_addMethod(delegateClass, s("applicationShouldTerminateAfterLastWindowClosed:"), (IMP) no, "c@:@");
class_addMethod(delegateClass, s("applicationWillFinishLaunching:"), (IMP) willFinishLaunching, "v@:@"); class_addMethod(appDelegate, s("applicationShouldTerminateAfterLastWindowClosed:"), (IMP) no, "c@:@");
class_addMethod(appDelegate, s("applicationWillFinishLaunching:"), (IMP) willFinishLaunching, "v@:@");
// All Menu Items use a common callback // All Menu Items use a common callback
class_addMethod(delegateClass, s("menuItemCallback:"), (IMP)menuItemCallback, "v@:@"); class_addMethod(appDelegate, s("menuItemCallback:"), (IMP)menuItemCallback, "v@:@");
// If there are URL Handlers, register the callback method // If there are URL Handlers, register the callback method
if( app->hasURLHandlers ) { if( app->hasURLHandlers ) {
class_addMethod(delegateClass, s("getUrl:withReplyEvent:"), (IMP) getURL, "i@:@@"); class_addMethod(appDelegate, s("getUrl:withReplyEvent:"), (IMP) getURL, "i@:@@");
} }
// Script handler // Script handler
class_addMethod(delegateClass, s("userContentController:didReceiveScriptMessage:"), (IMP) messageHandler, "v@:@@"); class_addMethod(appDelegate, s("userContentController:didReceiveScriptMessage:"), (IMP) messageHandler, "v@:@@");
objc_registerClassPair(delegateClass); objc_registerClassPair(appDelegate);
// Create delegate // Create delegate
id delegate = msg((id)delegateClass, s("new")); id delegate = msg((id)appDelegate, s("new"));
objc_setAssociatedObject(delegate, "application", (id)app, OBJC_ASSOCIATION_ASSIGN); objc_setAssociatedObject(delegate, "application", (id)app, OBJC_ASSOCIATION_ASSIGN);
// If there are URL Handlers, register a listener for them // If there are URL Handlers, register a listener for them
@@ -1195,7 +1197,7 @@ void createDelegate(struct Application *app) {
} }
// Theme change listener // Theme change listener
class_addMethod(delegateClass, s("themeChanged:"), (IMP) themeChanged, "v@:@@"); class_addMethod(appDelegate, s("themeChanged:"), (IMP) themeChanged, "v@:@@");
// Get defaultCenter // Get defaultCenter
id defaultCenter = msg(c("NSDistributedNotificationCenter"), s("defaultCenter")); id defaultCenter = msg(c("NSDistributedNotificationCenter"), s("defaultCenter"));

View File

@@ -82,8 +82,18 @@ void UpdateTrayIcon(TrayMenu *trayMenu) {
} }
id trayImage = hashmap_get(&trayIconCache, trayMenu->icon, strlen(trayMenu->icon)); id trayImage = hashmap_get(&trayIconCache, trayMenu->icon, strlen(trayMenu->icon));
// If we don't have the image in the icon cache then assume it's base64 encoded image data
if (trayImage == NULL) {
id data = ALLOC("NSData");
id imageData = msg(data, s("initWithBase64EncodedString:options:"), str(trayMenu->icon), 0);
trayImage = ALLOC("NSImage");
msg(trayImage, s("initWithData:"), imageData);
}
msg(statusBarButton, s("setImagePosition:"), trayMenu->trayIconPosition); msg(statusBarButton, s("setImagePosition:"), trayMenu->trayIconPosition);
msg(statusBarButton, s("setImage:"), trayImage); msg(statusBarButton, s("setImage:"), trayImage);
} }
void ShowTrayMenu(TrayMenu* trayMenu) { void ShowTrayMenu(TrayMenu* trayMenu) {

View File

@@ -68,6 +68,10 @@ func (u *URL) Start() error {
u.wg.Done() u.wg.Done()
return return
case urlMessage := <-u.urlChannel: case urlMessage := <-u.urlChannel:
// Guard against nil messages
if urlMessage == nil {
continue
}
messageType := strings.TrimPrefix(urlMessage.Topic(), "url:") messageType := strings.TrimPrefix(urlMessage.Topic(), "url:")
switch messageType { switch messageType {
case "handler": case "handler":

View File

@@ -30,7 +30,8 @@ var modifierMap = map[string]Modifier{
} }
func parseModifier(text string) (*Modifier, error) { func parseModifier(text string) (*Modifier, error) {
result, valid := modifierMap[text] lowertext := strings.ToLower(text)
result, valid := modifierMap[lowertext]
if !valid { if !valid {
return nil, fmt.Errorf("'%s' is not a valid modifier", text) return nil, fmt.Errorf("'%s' is not a valid modifier", text)
} }