From a5b97104cff358beebdb7ed1e96f7ab441295afa Mon Sep 17 00:00:00 2001 From: Akemi Date: Wed, 1 Feb 2017 21:42:58 +0100 Subject: osx: improve bundle handling we have two problems here. first when mpv is started from the bundle it uses its own environment variables and possibly can't find for example the youtube-dl binary for our youtube-dl hook. second we couldn't reliable determine when mpv was started from the bundle, which led to the pseudo-gui usage even when the binary was invoked from a shell. to prevent this we will wrap the bundle binary with a shell script, which will only be called when we start mpv from the bundle. this way we can get the same environment variables, like $PATH, for our bundle and additional we can set the pseudo-gui only when started through this script. it is also possible to detect the bundle usage properly and accurately through the usage of another environment var. Fixes #2061 --- osdep/macosx_application.m | 55 +++++----------------------------------------- 1 file changed, 5 insertions(+), 50 deletions(-) (limited to 'osdep') diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m index bd48398965..d7cdf4b832 100644 --- a/osdep/macosx_application.m +++ b/osdep/macosx_application.m @@ -310,53 +310,12 @@ static void macosx_redirect_output_to_logfile(const char *filename) [pool release]; } -static void get_system_version(int* major, int* minor, int* bugfix) +static bool bundle_started_from_finder() { - static dispatch_once_t once_token; - static int s_major = 0; - static int s_minor = 0; - static int s_bugfix = 0; - dispatch_once(&once_token, ^{ - NSString *version_plist = - @"/System/Library/CoreServices/SystemVersion.plist"; - NSString *version_string = - [NSDictionary dictionaryWithContentsOfFile:version_plist] - [@"ProductVersion"]; - NSArray* versions = [version_string componentsSeparatedByString:@"."]; - int count = [versions count]; - if (count >= 1) - s_major = [versions[0] intValue]; - if (count >= 2) - s_minor = [versions[1] intValue]; - if (count >= 3) - s_bugfix = [versions[2] intValue]; - }); - *major = s_major; - *minor = s_minor; - *bugfix = s_bugfix; -} + NSDictionary *env = [[NSProcessInfo processInfo] environment]; + NSString *is_bundle = [env objectForKey:@"MPVBUNDLE"]; -static bool is_psn_argument(char *psn_arg_to_check) -{ - NSString *psn_arg = [NSString stringWithUTF8String:psn_arg_to_check]; - return [psn_arg hasPrefix:@"-psn_"]; -} - -static bool bundle_started_from_finder(int argc, char **argv) -{ - bool bundle_detected = [[NSBundle mainBundle] bundleIdentifier]; - int major, minor, bugfix; - get_system_version(&major, &minor, &bugfix); - bool without_psn = bundle_detected && argc==1; - bool with_psn = bundle_detected && argc==2 && is_psn_argument(argv[1]); - - if ((major == 10) && (minor >= 9)) { - // Looks like opening quarantined files from the finder inserts the - // -psn argument while normal files do not. Hurr. - return with_psn || without_psn; - } else { - return with_psn; - } + return is_bundle ? [is_bundle boolValue] : false; } int cocoa_main(int argc, char *argv[]) @@ -368,11 +327,7 @@ int cocoa_main(int argc, char *argv[]) ctx.argc = &argc; ctx.argv = &argv; - if (bundle_started_from_finder(argc, argv)) { - if (argc > 1) { - argc = 1; // clears out -psn argument if present - argv[1] = NULL; - } + if (bundle_started_from_finder()) { macosx_redirect_output_to_logfile("mpv"); init_cocoa_application(true); } else { -- cgit v1.2.3