Skip to content

Instantly share code, notes, and snippets.

@cmsj
Created January 4, 2015 20:08
Show Gist options
  • Save cmsj/0eb94eb86ffb495c34bc to your computer and use it in GitHub Desktop.
Save cmsj/0eb94eb86ffb495c34bc to your computer and use it in GitHub Desktop.
diff --git a/Hammerspoon/MJConsoleWindowController.m b/Hammerspoon/MJConsoleWindowController.m
index ea234d0..985fb24 100644
--- a/Hammerspoon/MJConsoleWindowController.m
+++ b/Hammerspoon/MJConsoleWindowController.m
@@ -84,7 +84,9 @@ typedef NS_ENUM(NSUInteger, MJReplLineType) {
NSDictionary* attrs = @{NSFontAttributeName: [NSFont fontWithName:@"Menlo" size:12.0], NSForegroundColorAttributeName: color};
NSAttributedString* attrstr = [[NSAttributedString alloc] initWithString:str attributes:attrs];
- [[self.outputView textStorage] appendAttributedString:attrstr];
+ [[self.outputView textStorage] performSelectorOnMainThread:@selector(appendAttributedString:)
+ withObject:attrstr
+ waitUntilDone:YES];
}
- (NSString*) run:(NSString*)command {
diff --git a/extensions/keycodes/internal.m b/extensions/keycodes/internal.m
index 3fd307d..fb9e3a6 100644
--- a/extensions/keycodes/internal.m
+++ b/extensions/keycodes/internal.m
@@ -171,6 +171,12 @@ int keycodes_cachemap(lua_State* L) {
@implementation MJKeycodesObserver
+- (void) _inputSourceChanged:(NSNotification*)__unused note {
+ [self performSelectorOnMainThread:@selector(inputSourceChanged:)
+ withObject:nil
+ waitUntilDone:YES];
+}
+
- (void) inputSourceChanged:(NSNotification*)__unused note {
lua_rawgeti(self.L, LUA_REGISTRYINDEX, self.ref);
lua_call(self.L, 0, 0);
@@ -178,7 +184,7 @@ int keycodes_cachemap(lua_State* L) {
- (void) start {
[[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(inputSourceChanged:)
+ selector:@selector(_inputSourceChanged:)
name:NSTextInputContextKeyboardSelectionDidChangeNotification
object:nil];
}
diff --git a/extensions/screen/watcher.m b/extensions/screen/watcher.m
index 77b4af8..646fc97 100644
--- a/extensions/screen/watcher.m
+++ b/extensions/screen/watcher.m
@@ -40,6 +40,12 @@ static NSMutableIndexSet* screenHandlers;
@end
@implementation MJScreenWatcher
+- (void) _screensChanged:(id __unused)bla {
+ [self performSelectorOnMainThread:@selector(screensChanged:)
+ withObject:nil
+ waitUntilDone:YES];
+}
+
- (void) screensChanged:(id __unused)bla {
lua_State* L = self.L;
lua_getglobal(L, "debug"); lua_getfield(L, -1, "traceback"); lua_remove(L, -2);
@@ -100,7 +106,7 @@ static int screen_watcher_start(lua_State* L) {
screenwatcher->registryHandle = store_udhandler(L, screenHandlers, 1);
[[NSNotificationCenter defaultCenter] addObserver:(__bridge id)screenwatcher->obj
- selector:@selector(screensChanged:)
+ selector:@selector(_screensChanged:)
name:NSApplicationDidChangeScreenParametersNotification
object:nil];
diff --git a/extensions/wifi/watcher.m b/extensions/wifi/watcher.m
index f403293..929b67c 100644
--- a/extensions/wifi/watcher.m
+++ b/extensions/wifi/watcher.m
@@ -48,6 +48,12 @@ static NSMutableIndexSet* wifiHandlers;
return self;
}
+- (void) _ssidChanged:(id __unused)bla {
+ [self performSelectorOnMainThread:@selector(ssidChanged:)
+ withObject:nil
+ waitUntilDone:YES];
+}
+
- (void) ssidChanged:(id __unused)bla {
lua_State* L = self.L;
lua_getglobal(L, "debug"); lua_getfield(L, -1, "traceback"); lua_remove(L, -2);
@@ -116,7 +122,7 @@ static int wifi_watcher_start(lua_State* L) {
wifiwatcher->registryHandle = store_udhandler(L, wifiHandlers, 1);
[[NSNotificationCenter defaultCenter] addObserver:(__bridge id)wifiwatcher->obj
- selector:@selector(ssidChanged:)
+ selector:@selector(_ssidChanged:)
name:CWSSIDDidChangeNotification
object:nil];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment