Skip to content

Commit

Permalink
osx: fix bundle on macOS High Sierra (10.13)
Browse files Browse the repository at this point in the history
Apple slightly changed the App bundle mechanism which broke wrapper
scripts that invoke the actual binary. it caused the bundle to always
open a new instance of mpv instead of reusing the currently running one.

just removing the wrapper script would lead to several regressions, so
it was replaced with a symlink to the bundle binary. detection if mpv
was started from the bundle was replaced by comparing the execution name
of the binary, eg the name of the symlink "mpv-bundle". additionally,
because we load a standard config from the Resources folder of the
bundle again, we prevent that config from being loaded if mpv wasn't
started via the bundle. the psn argument has to be removed manually
again.

the ability of loading your standard shell environment has been removed
with the wrapper. a substitution will be added with another commit. as a
side effect this fixes an issues when zsh was used with common NodeJS
configuration scripts.

Fixes #4926 #4866
  • Loading branch information
Akemi committed Oct 3, 2017
1 parent 0c04ce5 commit 77021cf
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
6 changes: 6 additions & 0 deletions TOOLS/osxbundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def apply_plist_template(plist_file, version):
for line in fileinput.input(plist_file, inplace=1):
print (line.rstrip().replace('${VERSION}', version))

def create_bundle_symlink(binary_name, symlink_name):
os.symlink(os.path.basename(binary_name),
os.path.join(target_directory(binary_name), symlink_name))

def bundle_version():
if os.path.exists('VERSION'):
x = open('VERSION')
Expand Down Expand Up @@ -69,6 +73,8 @@ def main():
copy_bundle(binary_name)
print("> copying binary")
copy_binary(binary_name)
print("> create bundle symlink")
create_bundle_symlink(binary_name, "mpv-bundle")
print("> generating Info.plist")
apply_plist_template(target_plist(binary_name), version)

Expand Down
2 changes: 1 addition & 1 deletion TOOLS/osxbundle/mpv.app/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
</dict>
</array>
<key>CFBundleExecutable</key>
<string>mpv-wrapper.sh</string>
<string>mpv-bundle</string>
<key>CFBundleIconFile</key>
<string>icon</string>
<key>CFBundleIdentifier</key>
Expand Down
13 changes: 0 additions & 13 deletions TOOLS/osxbundle/mpv.app/Contents/MacOS/mpv-wrapper.sh

This file was deleted.

1 change: 1 addition & 0 deletions TOOLS/osxbundle/mpv.app/Contents/Resources/mpv.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
player-operation-mode=pseudo-gui
25 changes: 20 additions & 5 deletions osdep/macosx_application.m
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,26 @@ static void macosx_redirect_output_to_logfile(const char *filename)
[pool release];
}

static bool bundle_started_from_finder()
static bool bundle_started_from_finder(char **argv)
{
NSDictionary *env = [[NSProcessInfo processInfo] environment];
NSString *is_bundle = [env objectForKey:@"MPVBUNDLE"];
NSString *binary_path = [NSString stringWithUTF8String:argv[0]];
return [binary_path hasSuffix:@"mpv-bundle"];
}

static bool is_psn_argument(char *arg_to_check)
{
NSString *arg = [NSString stringWithUTF8String:arg_to_check];
return [arg hasPrefix:@"-psn_"];
}

static void setup_bundle(int *argc, char *argv[])
{
if (*argc > 1 && is_psn_argument(argv[1])) {
*argc = 1;
argv[1] = NULL;
}

return is_bundle ? [is_bundle boolValue] : false;
setenv("MPVBUNDLE", "true", 1);
}

int cocoa_main(int argc, char *argv[])
Expand All @@ -260,7 +274,8 @@ int cocoa_main(int argc, char *argv[])
ctx.argc = &argc;
ctx.argv = &argv;

if (bundle_started_from_finder()) {
if (bundle_started_from_finder(argv)) {
setup_bundle(&argc, argv);
macosx_redirect_output_to_logfile("mpv");
init_cocoa_application(true);
} else {
Expand Down
2 changes: 1 addition & 1 deletion osdep/path-macosx.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

const char *mp_get_platform_path_osx(void *talloc_ctx, const char *type)
{
if (strcmp(type, "osxbundle") == 0) {
if (strcmp(type, "osxbundle") == 0 && getenv("MPVBUNDLE")) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *path = [[NSBundle mainBundle] resourcePath];
char *res = talloc_strdup(talloc_ctx, [path UTF8String]);
Expand Down

0 comments on commit 77021cf

Please sign in to comment.