summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authorAkemi <der.richter@gmx.de>2017-09-29 18:17:32 +0200
committerAkemi <der.richter@gmx.de>2017-10-03 11:30:56 +0200
commit77021cf6fe6a1813b832c8927c288e958b6f6845 (patch)
tree85c5e6d0b230337541edb0b05c9fa7465daf5f51 /osdep
parent0c04ce5f0d9c4fb7311edf0ae7bdf1eef0f61235 (diff)
downloadmpv-77021cf6fe6a1813b832c8927c288e958b6f6845.tar.bz2
mpv-77021cf6fe6a1813b832c8927c288e958b6f6845.tar.xz
osx: fix bundle on macOS High Sierra (10.13)
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
Diffstat (limited to 'osdep')
-rw-r--r--osdep/macosx_application.m25
-rw-r--r--osdep/path-macosx.m2
2 files changed, 21 insertions, 6 deletions
diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m
index 0379491d79..b42cba5c37 100644
--- a/osdep/macosx_application.m
+++ b/osdep/macosx_application.m
@@ -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[])
@@ -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 {
diff --git a/osdep/path-macosx.m b/osdep/path-macosx.m
index 73abb0d305..8a5a704e49 100644
--- a/osdep/path-macosx.m
+++ b/osdep/path-macosx.m
@@ -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]);