From c47e930caa977d43605a47c6cc3d244b8e2565b5 Mon Sep 17 00:00:00 2001 From: Guillaume Louel <37544189+glouel@users.noreply.github.com> Date: Wed, 12 Jul 2023 15:44:34 +0200 Subject: [PATCH] Fix for CPU usage under Sonoma --- Aerial.xcodeproj/project.pbxproj | 8 +++--- Aerial/Source/Views/AerialView.swift | 37 ++++++++++++++++++++++------ 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Aerial.xcodeproj/project.pbxproj b/Aerial.xcodeproj/project.pbxproj index e58e7dc0..abad80e8 100644 --- a/Aerial.xcodeproj/project.pbxproj +++ b/Aerial.xcodeproj/project.pbxproj @@ -3241,7 +3241,7 @@ CODE_SIGN_IDENTITY = "Developer ID Application"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 3.2.7beta2; + CURRENT_PROJECT_VERSION = 3.2.7beta3; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = 3L54M5L5KK; ENABLE_HARDENED_RUNTIME = YES; @@ -3249,7 +3249,7 @@ INSTALL_PATH = "$(HOME)/Library/Screen Savers"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.13; - MARKETING_VERSION = 3.2.7beta2; + MARKETING_VERSION = 3.2.7beta3; PRODUCT_BUNDLE_IDENTIFIER = com.johncoates.Aerial; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -3270,7 +3270,7 @@ CODE_SIGN_IDENTITY = "Developer ID Application"; CODE_SIGN_STYLE = Manual; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 3.2.7beta2; + CURRENT_PROJECT_VERSION = 3.2.7beta3; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = 3L54M5L5KK; ENABLE_HARDENED_RUNTIME = YES; @@ -3278,7 +3278,7 @@ INSTALL_PATH = "$(HOME)/Library/Screen Savers"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.13; - MARKETING_VERSION = 3.2.7beta2; + MARKETING_VERSION = 3.2.7beta3; OTHER_CODE_SIGN_FLAGS = "--timestamp"; PRODUCT_BUNDLE_IDENTIFIER = com.johncoates.Aerial; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Aerial/Source/Views/AerialView.swift b/Aerial/Source/Views/AerialView.swift index d54767f2..9b33739d 100644 --- a/Aerial/Source/Views/AerialView.swift +++ b/Aerial/Source/Views/AerialView.swift @@ -534,7 +534,10 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate { DistributedNotificationCenter.default.addObserver(self, selector: #selector(AerialView.willStop(_:)), name: Notification.Name("com.apple.screensaver.willstop"), object: nil) - + DistributedNotificationCenter.default.addObserver(self, + selector: #selector(AerialView.screenIsUnlocked(_:)), + name: Notification.Name("com.apple.screenIsUnlocked"), object: nil) + Music.instance.setup() } @@ -550,15 +553,33 @@ final class AerialView: ScreenSaverView, CAAnimationDelegate { } } - @objc func willStop(_ aNotification: Notification) { - debugLog("🖼️ 📢📢📢 willStop") - if !Aerial.helper.underCompanion { - if let player = player { - player.pause() + @objc func screenIsUnlocked(_ aNotification: Notification) { + if #available(macOS 14.0, *) { + debugLog("🖼️ 📢📢📢 ☢️sonoma☢️ workaround screenIsUnlocked") + if !Aerial.helper.underCompanion { + if let player = player { + player.pause() + } + self.stopAnimation() + } else { + player?.play() } - self.stopAnimation() + } + } + + @objc func willStop(_ aNotification: Notification) { + if #available(macOS 14.0, *) { + debugLog("🖼️ 📢📢📢 🖼️ 📢📢📢 ☢️sonoma☢️ workaround IGNORING willStop") } else { - player?.play() + debugLog("🖼️ 📢📢📢 willStop") + if !Aerial.helper.underCompanion { + if let player = player { + player.pause() + } + self.stopAnimation() + } else { + player?.play() + } } }