diff options
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/macosx_application.h | 1 | ||||
-rw-r--r-- | osdep/macosx_application.m | 23 | ||||
-rw-r--r-- | osdep/macosx_application_objc.h | 2 |
3 files changed, 15 insertions, 11 deletions
diff --git a/osdep/macosx_application.h b/osdep/macosx_application.h index 8202093aed..c48d1154a0 100644 --- a/osdep/macosx_application.h +++ b/osdep/macosx_application.h @@ -32,6 +32,5 @@ typedef enum { // multithreaded wrapper for mpv_main int cocoa_main(mpv_main_fn mpv_main, int argc, char *argv[]); void cocoa_register_menu_item_action(MPMenuKey key, void* action); -void terminate_cocoa_application(void); #endif /* MPV_MACOSX_APPLICATION */ diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m index 3691e922a5..2ff3386f76 100644 --- a/osdep/macosx_application.m +++ b/osdep/macosx_application.m @@ -29,6 +29,10 @@ #define MPV_PROTOCOL @"mpv://" +// Whether the NSApplication singleton was created. If this is false, we are +// running in libmpv mode, and cocoa_main() was never called. +static bool application_instantiated; + static pthread_t playback_thread_id; @interface Application () @@ -53,11 +57,17 @@ static pthread_t playback_thread_id; - (void)setAppleMenu:(NSMenu *)aMenu; @end -Application *mpv_shared_app(void) +static Application *mpv_shared_app(void) { return (Application *)[Application sharedApplication]; } +static void terminate_cocoa_application(void) +{ + [NSApp hide:NSApp]; + [NSApp terminate:NSApp]; +} + @implementation Application @synthesize menuItems = _menu_items; @synthesize openCount = _open_count; @@ -247,12 +257,6 @@ struct playback_thread_ctx { char ***argv; }; -void terminate_cocoa_application(void) -{ - [NSApp hide:NSApp]; - [NSApp terminate:NSApp]; -} - static void cocoa_run_runloop(void) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; @@ -274,7 +278,8 @@ static void *playback_thread(void *ctx_obj) void cocoa_register_menu_item_action(MPMenuKey key, void* action) { - [NSApp registerSelector:(SEL)action forKey:key]; + if (application_instantiated) + [NSApp registerSelector:(SEL)action forKey:key]; } static void init_cocoa_application(bool regular) @@ -359,6 +364,8 @@ static bool bundle_started_from_finder(int argc, char **argv) int cocoa_main(mpv_main_fn mpv_main, int argc, char *argv[]) { @autoreleasepool { + application_instantiated = true; + struct playback_thread_ctx ctx = {0}; ctx.mpv_main = mpv_main; ctx.argc = &argc; diff --git a/osdep/macosx_application_objc.h b/osdep/macosx_application_objc.h index 0f18952c7e..4741a14a64 100644 --- a/osdep/macosx_application_objc.h +++ b/osdep/macosx_application_objc.h @@ -27,5 +27,3 @@ @property(nonatomic, retain) NSArray *files; @property(nonatomic, assign) size_t openCount; @end - -Application *mpv_shared_app(void); |