From 68faf9fb4acef599d4496865f576b5f85b15778b Mon Sep 17 00:00:00 2001 From: Tom Taylor Date: Sat, 30 Sep 2023 15:37:54 +0100 Subject: [PATCH] Switched To Using forceTerminate --- README.md | 5 ++-- noTunes.xcodeproj/project.pbxproj | 30 ++++++++++++++++++------ noTunes/AppDelegate.swift | 39 +++++++++++++++---------------- 3 files changed, 45 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 5fe00c1..9081ac9 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ brew install --cask notunes ### Direct Download -[noTunes-3.3.zip](https://github.com/tombonez/noTunes/releases/download/v3.3/noTunes-3.3.zip) +[noTunes-3.4.zip](https://github.com/tombonez/noTunes/releases/download/v3.4/noTunes-3.4.zip) ## Usage @@ -36,7 +36,7 @@ brew install --cask notunes #### Before Ventura: -Navigate to System Preferences -> Users & Groups. Under your user, select "Login Items", click the lock on the bottom left and enter your login password to make changes. Click the plus sign (+) in the main panel and search for noTunes. Select it and click "Add". +Navigate to System Preferences -> Users & Groups. Under your user, select "Login Items", click the lock on the bottom left and enter your login password to make changes. Click the plus sign (+) in the main panel and search for noTunes. Select it and click "Add". #### Ventura and later: @@ -88,6 +88,7 @@ osascript -e 'quit app "noTunes"' ### Set replacement for iTunes / Apple Music Replace `YOUR_MUSIC_APP` with the name of your music app in the following command. + ```bash defaults write digital.twisted.noTunes replacement /Applications/YOUR_MUSIC_APP.app ``` diff --git a/noTunes.xcodeproj/project.pbxproj b/noTunes.xcodeproj/project.pbxproj index 246fd33..795792c 100644 --- a/noTunes.xcodeproj/project.pbxproj +++ b/noTunes.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -97,8 +97,9 @@ E29B3C671E1D97CF00CB67E3 /* Project object */ = { isa = PBXProject; attributes = { + BuildIndependentTargetsInParallel = YES; LastSwiftUpdateCheck = 0820; - LastUpgradeCheck = 1230; + LastUpgradeCheck = 1500; ORGANIZATIONNAME = "Twisted Digital Ltd."; TargetAttributes = { E29B3C6E1E1D97CF00CB67E3 = { @@ -194,9 +195,11 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; COPY_PHASE_STRIP = NO; + DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_NO_COMMON_BLOCKS = YES; @@ -252,9 +255,11 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "-"; COPY_PHASE_STRIP = NO; + DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; @@ -266,7 +271,8 @@ MACOSX_DEPLOYMENT_TARGET = 10.12; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; - SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; }; name = Release; }; @@ -277,11 +283,16 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; + DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = JP6WW46Y42; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = noTunes/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; - MARKETING_VERSION = 3.3; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; + MARKETING_VERSION = 3.4; PRODUCT_BUNDLE_IDENTIFIER = digital.twisted.noTunes; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -297,11 +308,16 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; + DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = JP6WW46Y42; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = noTunes/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; - MARKETING_VERSION = 3.3; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; + MARKETING_VERSION = 3.4; PRODUCT_BUNDLE_IDENTIFIER = digital.twisted.noTunes; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/noTunes/AppDelegate.swift b/noTunes/AppDelegate.swift index 00dbf26..f1e9fcb 100644 --- a/noTunes/AppDelegate.swift +++ b/noTunes/AppDelegate.swift @@ -30,23 +30,25 @@ class AppDelegate: NSObject, NSApplicationDelegate { @objc func statusBarButtonClicked(sender: NSStatusBarButton) { let event = NSApp.currentEvent! - + if event.type == NSEvent.EventType.rightMouseUp { statusItem.menu = statusMenu - statusItem.popUpMenu(statusMenu) + if let menu = statusItem.menu { + menu.popUp(positioning: menu.items.first, at: NSEvent.mouseLocation, in: nil) + } statusItem.menu = nil } else { - if statusItem.image == NSImage(named: "StatusBarButtonImage") { + if statusItem.button?.image == NSImage(named: "StatusBarButtonImage") { self.appIsLaunched() - statusItem.image = NSImage(named: "StatusBarButtonImageActive") + statusItem.button?.image = NSImage(named: "StatusBarButtonImageActive") } else { - statusItem.image = NSImage(named: "StatusBarButtonImage") + statusItem.button?.image = NSImage(named: "StatusBarButtonImage") } } } func applicationDidFinishLaunching(_ aNotification: Notification) { - statusItem.image = NSImage(named: "StatusBarButtonImageActive") + statusItem.button?.image = NSImage(named: "StatusBarButtonImageActive") if let button = statusItem.button { button.action = #selector(self.statusBarButtonClicked(sender:)) @@ -73,28 +75,25 @@ class AppDelegate: NSObject, NSApplicationDelegate { if(runningApp.activationPolicy == .regular) { if(runningApp.bundleIdentifier == "com.apple.iTunes") { - self.terminateProcessWith(Int(runningApp.processIdentifier), runningApp.localizedName!) + runningApp.forceTerminate() } if(runningApp.bundleIdentifier == "com.apple.Music") { - self.terminateProcessWith(Int(runningApp.processIdentifier), runningApp.localizedName!) + runningApp.forceTerminate() } } } } @objc func appWillLaunch(note:Notification) { - if statusItem.image == NSImage(named: "StatusBarButtonImageActive") || defaults.bool(forKey: "hideIcon") { - if let processName:String = note.userInfo?["NSApplicationBundleIdentifier"] as? String { - if let processId = note.userInfo?["NSApplicationProcessIdentifier"] as? Int { - switch processName { - case "com.apple.iTunes": - self.terminateProcessWith(processId, processName) - self.launchReplacement() - case "com.apple.Music": - self.terminateProcessWith(processId, processName) - self.launchReplacement() - default:break - } + if statusItem.button?.image == NSImage(named: "StatusBarButtonImageActive") || defaults.bool(forKey: "hideIcon") { + if let app = note.userInfo?[NSWorkspace.applicationUserInfoKey] as? NSRunningApplication { + if app.bundleIdentifier == "com.apple.Music" { + app.forceTerminate() + self.launchReplacement() + } + else if app.bundleIdentifier == "com.apple.iTunes" { + app.forceTerminate() + self.launchReplacement() } } }