Try to start _writer on-demand on macOS (#1739).
authorCarl Hetherington <cth@carlh.net>
Sat, 2 May 2020 19:37:14 +0000 (21:37 +0200)
committerCarl Hetherington <cth@carlh.net>
Sat, 2 May 2020 19:37:14 +0000 (21:37 +0200)
platform/osx/make_dmg.sh
src/tools/dcpomatic_disk.cc
src/tools/dcpomatic_disk_writer.cc

index b4a4488df2c80b48e6f3e3f7e38bc1596390a337..1cff3b5bbafd9579e10e4709d68efc88ee977189 100644 (file)
@@ -537,16 +537,21 @@ cat > $pkgroot/Library/LaunchDaemons/com.dcpomatic.disk.writer.plist <<EOF
         <key>DYLD_LIBRARY_PATH</key>
         <string><![CDATA[/Library/Application Support/com.dcpomatic]]></string>
     </dict>
-    <key>KeepAlive</key>
-    <true/>
-    <key>RunAtLoad</key>
-    <true/>
-    <key>Debug</key>
-    <true/>
     <key>StandardOutPath</key>
     <string>/var/log/dcpomatic_disk_writer_out.log</string>
     <key>StandardErrorPath</key>
     <string>/var/log/dcpomatic_disk_writer_err.log</string>
+    <key>LaunchEvents</key>
+    <dict>
+        <key>com.apple.notifyd.matching</key>
+        <dict>
+            <key>com.dcpomatic.disk.writer.start</key>
+            <dict>
+                <key>Notification</key>
+                <string>com.dcpomatic.disk.writer.start</string>
+            </dict>
+        </dict>
+    </dict>
 </dict>
 </plist>
 EOF
index 6f72bfed0e749b672e5d1208afb560b3fbbfa3f7..b2678ce42a788409480ad110f80f20085d704055 100644 (file)
@@ -42,6 +42,7 @@
 #endif
 #ifdef DCPOMATIC_OSX
 #include <ApplicationServices/ApplicationServices.h>
+#include <notify.h>
 #endif
 
 using std::string;
@@ -132,7 +133,10 @@ public:
                _writer = new boost::process::child (disk_writer_path());
 #endif
 
-               /* _writer is always running on macOS at the moment */
+#ifdef DCPOMATIC_OSX
+               LOG_DISK_NC("Sending notification to writer daemon");
+               notify_post ("com.dcpomatic.disk.writer.start");
+#endif
        }
 
        ~DOMFrame ()
index 66f34794347e3fd6885e2ae012cca2278b76944c..d5599f25b5af2d15dd65c15fcfe47b9e03d894fa 100644 (file)
@@ -48,6 +48,7 @@ extern "C" {
 extern "C" {
 #include <lwext4/file_dev.h>
 }
+#include <xpc/xpc.h>
 #endif
 
 #ifdef DCPOMATIC_LINUX
@@ -520,6 +521,13 @@ main ()
        LOG_DISK_NC("dcpomatic_disk_writer started");
 #endif
 
+#ifdef DCPOMATIC_OSX
+       /* I *think* this confumes the notifyd event that we used to start the process, so we only
+        * get started once per notification.
+        */
+        xpc_set_event_stream_handler("com.apple.notifyd.matching", DISPATCH_TARGET_QUEUE_DEFAULT, ^(xpc_object_t event) {});
+#endif
+
        try {
                nanomsg = new Nanomsg (false);
        } catch (runtime_error& e) {