From 374d38961ce21d83ac3fab5fd002b0ed30cdddb5 Mon Sep 17 00:00:00 2001
From: barracuda156 <vital.had@gmail.com>
Date: Sun, 31 Mar 2024 05:44:38 +0800
Subject: [PATCH] Revert "macos: Fix gst_macos_main() terminating whole process
 before returning a value"

This reverts commit ffdec6bc2b4af5ddc6c52c7a6bff51949426b984.
Also makes 1815061e26db11c5e8cef35e7b5e3e3fb9eb7017 conditional to fix 10.5.
---
 subprojects/gstreamer/gst/gstmacos.m | 61 ++--------------------------
 1 file changed, 3 insertions(+), 58 deletions(-)

diff --git subprojects/gstreamer/gst/gstmacos.m subprojects/gstreamer/gst/gstmacos.m
index dbdb1a70a3..b930bbb0f6 100644
--- gst/gstmacos.m
+++ gst/gstmacos.m
@@ -1,5 +1,6 @@
 #include "gstmacos.h"
 #include <Cocoa/Cocoa.h>
+#include <AvailabilityMacros.h>
 
 typedef struct _ThreadArgs ThreadArgs;
 
@@ -9,40 +10,11 @@
   char **argv;
   gpointer user_data;
   gboolean is_simple;
-  GMutex nsapp_mutex;
-  GCond nsapp_cond;
-  gboolean nsapp_running;
 };
 
-@interface GstCocoaApplicationDelegate : NSObject <NSApplicationDelegate>
-@property (assign) GMutex *nsapp_mutex;
-@property (assign) GCond *nsapp_cond;
-@property (assign) gboolean *nsapp_running;
-@end
-
-@implementation GstCocoaApplicationDelegate
-
-- (void)applicationDidFinishLaunching:(NSNotification *)notification
-{
-  g_mutex_lock (self.nsapp_mutex);
-  *self.nsapp_running = TRUE;
-  g_cond_signal (self.nsapp_cond);
-  g_mutex_unlock (self.nsapp_mutex);
-}
-
-@end
-
 int
 gst_thread_func (ThreadArgs *args)
 {
-  /* Only proceed once NSApp is running, otherwise we could
-   * attempt to call [NSApp: stop] before it's even started. */
-  g_mutex_lock (&args->nsapp_mutex);
-  while (!args->nsapp_running) {
-    g_cond_wait (&args->nsapp_cond, &args->nsapp_mutex);
-  }
-  g_mutex_unlock (&args->nsapp_mutex);
-
   int ret;
   if (args->is_simple) {
     ret = ((GstMainFuncSimple) args->main_func) (args->user_data);
@@ -50,20 +22,7 @@
     ret = ((GstMainFunc) args->main_func) (args->argc, args->argv, args->user_data);
   }
 
-  /* Post a message so we'll break out of the message loop */
-  NSEvent *event = [NSEvent otherEventWithType: NSEventTypeApplicationDefined
-                       location: NSZeroPoint
-                  modifierFlags: 0
-                      timestamp: 0
-                   windowNumber: 0
-                        context: nil
-                        subtype: NSEventSubtypeApplicationActivated
-                          data1: 0
-                          data2: 0];
-
-  [NSApp stop:nil];
-  [NSApp postEvent:event atStart:YES];
-
+  [NSApp terminate: nil];
   return ret;
 }
 
@@ -71,33 +30,16 @@
 run_main_with_nsapp (ThreadArgs args)
 {
   GThread *gst_thread;
-  GstCocoaApplicationDelegate* delegate;
-  int result;
-
-  g_mutex_init (&args.nsapp_mutex);
-  g_cond_init (&args.nsapp_cond);
-  args.nsapp_running = FALSE;
 
   [NSApplication sharedApplication];
-  delegate = [[GstCocoaApplicationDelegate alloc] init];
-  delegate.nsapp_mutex = &args.nsapp_mutex;
-  delegate.nsapp_cond = &args.nsapp_cond;
-  delegate.nsapp_running = &args.nsapp_running;
-  [NSApp setDelegate:delegate];
-
-  /* This lets us show an icon in the dock and correctly focus opened windows */
+#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
   if ([NSApp activationPolicy] == NSApplicationActivationPolicyProhibited) {
     [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
   }
-
+#endif
   gst_thread = g_thread_new ("macos-gst-thread", (GThreadFunc) gst_thread_func, &args);
   [NSApp run];
-  result = GPOINTER_TO_INT (g_thread_join (gst_thread));
-
-  g_mutex_clear (&args.nsapp_mutex);
-  g_cond_clear (&args.nsapp_cond);
-
-  return result;
+  return GPOINTER_TO_INT (g_thread_join (gst_thread));
 }
 
 /**
