From 3e1ca9134030b44a4c1ad63686d3e4ab7da869f1 Mon Sep 17 00:00:00 2001 From: Rundong Du Date: Wed, 28 Jul 2021 15:33:48 -0700 Subject: [PATCH] Fixed macOS notifications --- .../lib/src/daemon/macos/alerter_notifications.dart | 3 ++- taqo_client/macos/TaqoLauncher/AppDelegate.swift | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pal_event_server/lib/src/daemon/macos/alerter_notifications.dart b/pal_event_server/lib/src/daemon/macos/alerter_notifications.dart index 2ab8f511..1543970f 100644 --- a/pal_event_server/lib/src/daemon/macos/alerter_notifications.dart +++ b/pal_event_server/lib/src/daemon/macos/alerter_notifications.dart @@ -47,7 +47,8 @@ Future cancel(int id) async { } _notifications.remove(id); - await Process.run(_alerterBinary, ['-remove', '$id']); + await Process.start(_alerterBinary, ['-remove', '$id'], + mode: ProcessStartMode.inheritStdio); } Future notify(int id, String title, String body, {int timeout = 0}) async { diff --git a/taqo_client/macos/TaqoLauncher/AppDelegate.swift b/taqo_client/macos/TaqoLauncher/AppDelegate.swift index 16419b26..417136c3 100644 --- a/taqo_client/macos/TaqoLauncher/AppDelegate.swift +++ b/taqo_client/macos/TaqoLauncher/AppDelegate.swift @@ -13,6 +13,7 @@ // limitations under the License. import Cocoa +import Darwin @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { @@ -32,9 +33,17 @@ class AppDelegate: NSObject, NSApplicationDelegate { NSLog("Launching taqo_daemon at") NSLog(taqoDaemon.absoluteString) + // Create a pseudo tty as the stdin of taqo_daemon, so that when taqo_daemon calls + // alerter, alerter won't read an empty message from the stdin. + let fd = posix_openpt(O_RDWR) + grantpt(fd) + unlockpt(fd) + let pty = FileHandle.init(forUpdatingAtPath: String.init(cString: ptsname(fd))) + let task = Process() task.executableURL = URL(fileURLWithPath: taqoDaemon.absoluteString) task.arguments = [] + task.standardInput = pty do { try task.run() } catch {