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
This commit is contained in:
Akemi 2017-02-01 21:42:58 +01:00
parent fdd1ef6028
commit a5b97104cf
4 changed files with 9 additions and 52 deletions

View File

@ -173,7 +173,7 @@
</dict>
</array>
<key>CFBundleExecutable</key>
<string>mpv</string>
<string>mpv-wrapper.sh</string>
<key>CFBundleIconFile</key>
<string>icon</string>
<key>CFBundleIdentifier</key>

View File

@ -0,0 +1,3 @@
#!/bin/bash
export MPVBUNDLE="true"
$SHELL -l -c "$(dirname "$0")/mpv --player-operation-mode=pseudo-gui"

View File

@ -1 +0,0 @@
player-operation-mode=pseudo-gui

View File

@ -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 {