Skip to content

Commit

Permalink
Switched To Using forceTerminate
Browse files Browse the repository at this point in the history
  • Loading branch information
tombonez committed Sep 30, 2023
1 parent 8d0a20b commit 68faf9f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 29 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ 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

### Set noTunes to launch at startup

#### 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:

Expand Down Expand Up @@ -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
```
Expand Down
30 changes: 23 additions & 7 deletions noTunes.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -97,8 +97,9 @@
E29B3C671E1D97CF00CB67E3 /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastSwiftUpdateCheck = 0820;
LastUpgradeCheck = 1230;
LastUpgradeCheck = 1500;
ORGANIZATIONNAME = "Twisted Digital Ltd.";
TargetAttributes = {
E29B3C6E1E1D97CF00CB67E3 = {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
};
Expand All @@ -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 = "";
Expand All @@ -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 = "";
Expand Down
39 changes: 19 additions & 20 deletions noTunes/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:))
Expand All @@ -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()
}
}
}
Expand Down

0 comments on commit 68faf9f

Please sign in to comment.