From 208456ffb7bb9f142f8f8a8d1eba5e13f358f48a Mon Sep 17 00:00:00 2001 From: Archie McKay Date: Wed, 14 Sep 2022 18:53:26 +1000 Subject: [PATCH 1/6] Added some comments to main.swift to make it easier to understand what's going on --- main.swift | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/main.swift b/main.swift index d905f4a..7c867bd 100755 --- a/main.swift +++ b/main.swift @@ -6,18 +6,19 @@ import Cocoa +// Function to spawn a child process that can be used to update @discardableResult func shell(_ args: [String]) -> Int32 { - let task = Process() + let task = Process() // The new child process let isDark = UserDefaults.standard.string(forKey: "AppleInterfaceStyle") == "Dark" - var env = ProcessInfo.processInfo.environment - env["DARKMODE"] = isDark ? "1" : "0" - task.environment = env + var env = ProcessInfo.processInfo.environment // Get the current processes environment variables + env["DARKMODE"] = isDark ? "1" : "0" // Append the DARKMODE environment variable to env + task.environment = env // Set the child processes enivronment variables to the current processes environment variables plus DARKMODE task.launchPath = "/usr/bin/env" task.arguments = args task.standardError = FileHandle.standardError task.standardOutput = FileHandle.standardOutput - task.launch() + task.launch() // Spawn the child process with the new environment variables task.waitUntilExit() return task.terminationStatus } @@ -25,13 +26,15 @@ func shell(_ args: [String]) -> Int32 { let args = Array(CommandLine.arguments.suffix(from: 1)) shell(args) +// Add an observer for dark mode or light mode being set DistributedNotificationCenter.default.addObserver( forName: Notification.Name("AppleInterfaceThemeChangedNotification"), object: nil, queue: nil) { (notification) in - shell(args) + shell(args) } +// Add an observer to check whether dark/light mode has been updated since the device last went to sleep NSWorkspace.shared.notificationCenter.addObserver( forName: NSWorkspace.didWakeNotification, object: nil, From 8b9ab23ee03116ec66404618f86b0e7ad0b3341e Mon Sep 17 00:00:00 2001 From: Archie McKay <45909641+awmkay@users.noreply.github.com> Date: Thu, 15 Sep 2022 00:28:53 +1000 Subject: [PATCH 2/6] Update main.swift Co-authored-by: Bouke van der Bijl --- main.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.swift b/main.swift index 7c867bd..5613bd5 100755 --- a/main.swift +++ b/main.swift @@ -11,7 +11,7 @@ import Cocoa func shell(_ args: [String]) -> Int32 { let task = Process() // The new child process let isDark = UserDefaults.standard.string(forKey: "AppleInterfaceStyle") == "Dark" - var env = ProcessInfo.processInfo.environment // Get the current processes environment variables + var env = ProcessInfo.processInfo.environment // Get the current processes environment variables env["DARKMODE"] = isDark ? "1" : "0" // Append the DARKMODE environment variable to env task.environment = env // Set the child processes enivronment variables to the current processes environment variables plus DARKMODE task.launchPath = "/usr/bin/env" From b7fda607601061dca7c8df9c8822bafb588cf24f Mon Sep 17 00:00:00 2001 From: Archie McKay <45909641+awmkay@users.noreply.github.com> Date: Thu, 15 Sep 2022 00:28:59 +1000 Subject: [PATCH 3/6] Update main.swift Co-authored-by: Bouke van der Bijl --- main.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.swift b/main.swift index 5613bd5..f51ea89 100755 --- a/main.swift +++ b/main.swift @@ -13,7 +13,7 @@ func shell(_ args: [String]) -> Int32 { let isDark = UserDefaults.standard.string(forKey: "AppleInterfaceStyle") == "Dark" var env = ProcessInfo.processInfo.environment // Get the current processes environment variables env["DARKMODE"] = isDark ? "1" : "0" // Append the DARKMODE environment variable to env - task.environment = env // Set the child processes enivronment variables to the current processes environment variables plus DARKMODE + task.environment = env // Set the child processes environment variables to the current processes environment variables plus DARKMODE task.launchPath = "/usr/bin/env" task.arguments = args task.standardError = FileHandle.standardError From 2a76d61e345255106db454d3b5a13b5a95e4284d Mon Sep 17 00:00:00 2001 From: Archie McKay <45909641+awmkay@users.noreply.github.com> Date: Thu, 15 Sep 2022 00:29:06 +1000 Subject: [PATCH 4/6] Update main.swift Co-authored-by: Bouke van der Bijl --- main.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.swift b/main.swift index f51ea89..cbac209 100755 --- a/main.swift +++ b/main.swift @@ -12,7 +12,7 @@ func shell(_ args: [String]) -> Int32 { let task = Process() // The new child process let isDark = UserDefaults.standard.string(forKey: "AppleInterfaceStyle") == "Dark" var env = ProcessInfo.processInfo.environment // Get the current processes environment variables - env["DARKMODE"] = isDark ? "1" : "0" // Append the DARKMODE environment variable to env + env["DARKMODE"] = isDark ? "1" : "0" // Append the DARKMODE environment variable to env task.environment = env // Set the child processes environment variables to the current processes environment variables plus DARKMODE task.launchPath = "/usr/bin/env" task.arguments = args From a3ba178321e619ab4bdfe7e65db9b30e202afc15 Mon Sep 17 00:00:00 2001 From: Archie McKay <45909641+awmkay@users.noreply.github.com> Date: Thu, 15 Sep 2022 00:29:13 +1000 Subject: [PATCH 5/6] Update main.swift Co-authored-by: Bouke van der Bijl --- main.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.swift b/main.swift index cbac209..b2da159 100755 --- a/main.swift +++ b/main.swift @@ -9,7 +9,7 @@ import Cocoa // Function to spawn a child process that can be used to update @discardableResult func shell(_ args: [String]) -> Int32 { - let task = Process() // The new child process + let task = Process() // The new child process let isDark = UserDefaults.standard.string(forKey: "AppleInterfaceStyle") == "Dark" var env = ProcessInfo.processInfo.environment // Get the current processes environment variables env["DARKMODE"] = isDark ? "1" : "0" // Append the DARKMODE environment variable to env From cda2fc2d68ebe22aac8d4fe8e6448656a406e7be Mon Sep 17 00:00:00 2001 From: Archie McKay <45909641+awmkay@users.noreply.github.com> Date: Thu, 15 Sep 2022 00:29:19 +1000 Subject: [PATCH 6/6] Update main.swift Co-authored-by: Bouke van der Bijl --- main.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.swift b/main.swift index b2da159..bcdc99a 100755 --- a/main.swift +++ b/main.swift @@ -18,7 +18,7 @@ func shell(_ args: [String]) -> Int32 { task.arguments = args task.standardError = FileHandle.standardError task.standardOutput = FileHandle.standardOutput - task.launch() // Spawn the child process with the new environment variables + task.launch() // Spawn the child process with the new environment variables task.waitUntilExit() return task.terminationStatus }