Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion boringNotch/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -21159,4 +21159,4 @@
}
},
"version" : "1.0"
}
}
58 changes: 57 additions & 1 deletion boringNotch/boringNotchApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

setupDragDetectors()

checkForApplicationsFolder() // added check call here

if coordinator.firstLaunch {
DispatchQueue.main.async {
Expand Down Expand Up @@ -626,4 +628,58 @@ class AppDelegate: NSObject, NSApplicationDelegate {
onboardingWindowController?.window?.makeKeyAndOrderFront(nil)
onboardingWindowController?.window?.orderFrontRegardless()
}
}

private func checkForApplicationsFolder() {
// Define Application folders paths
let systemAppsPath = "/Applications"
let userAppsPath = NSHomeDirectory() + "/Applications"

// Get path of executable
let appPath = Bundle.main.bundlePath

// Check if the app is already in either Applications folder
if !appPath.hasPrefix(systemAppsPath) && !appPath.hasPrefix(userAppsPath) {

// Alert move is recommended
let alertMove = NSAlert()
alertMove.messageText = "Move to Applications folder?"
alertMove.informativeText = "Boring Notch works best when run from your Applications folder. Would you like to move it there now?"
alertMove.alertStyle = .informational
alertMove.addButton(withTitle: "Move")
alertMove.addButton(withTitle: "Keep in Place")

// Move application if selected
if alertMove.runModal() == .alertFirstButtonReturn {
moveSelfToApplications(appPath: appPath)
}
}
}

private func moveSelfToApplications(appPath: String) {
// Retrieve app name at runtime
let appName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String
?? Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String
?? "BoringNotch" // Default to BoringNotch if no name was found

// Run script to move application and relaunch
let scripts = """
tell application "Finder"
set appPath to POSIX file "\(appPath)" as alias
set targetPath to POSIX file "/Applications" as alias
move appPath to targetPath with replacing
end tell
tell application "\(appName)" to activate
"""

// Error handling
var error: NSDictionary?
if let scriptObject = NSAppleScript(source: scripts) {
scriptObject.executeAndReturnError(&error)
}

if error != nil {
// Handle error if script fails
print("Error moving app: \(String(describing: error))")
}
}
}