Closed IAmVigneswaran closed 4 months ago
I added an alert. Most features of Marker Data will still work if it's not in the Applications folder so I rewrote the alert message to reflect this better. We can change it if you don't like it.
Thanks for adding this location check alert message! I would prefer for the message to sound a little strict.
I changed the message. Just want to ensure users are running application in the correct location before, sending us any bug reports and issues.
@milanvarady The error message still shows up when it is in applications folder? I understand that we need to click on "Don't show again". Would it be possible to hide the message when it is running from applications folder? Cause, if the user is running Marker Data for the first time from applications folder, technically they should not see the message.
@milanvarady
From ChatGPT -
Sample code
import Foundation
func isApplicationInApplicationsFolder() -> Bool {
let applicationPath = Bundle.main.bundlePath
return applicationPath.hasPrefix("/Applications")
}
import SwiftUI
@main
struct YourApp: App {
@State private var showAlert = false
var body: some Scene {
WindowGroup {
ContentView()
.onAppear {
if !isApplicationInApplicationsFolder() {
showAlert = true
}
}
.alert(isPresented: $showAlert) {
Alert(
title: Text("Install Location Warning"),
message: Text("Marker Data must be installed in the Applications folder to run correctly. Please move the application to the Applications folder and try again."),
dismissButton: .default(Text("OK")) {
NSApplication.shared.terminate(nil)
}
)
}
}
}
func isApplicationInApplicationsFolder() -> Bool {
let applicationPath = Bundle.main.bundlePath
return applicationPath.hasPrefix("/Applications")
}
}
Explanation
- isApplicationInApplicationsFolder Function: This function checks if the application's bundle path starts with /Applications.
- SwiftUI App:
- State Variable:
@State private var showAlert = false
is used to manage the visibility of the alert.- onAppear Modifier: When the ContentView appears, it checks the installation path.
- Alert: If the application is not in the Applications folder, an alert is shown with a message, and the application terminates when the user clicks "OK".
Notes
- Termination: The application will terminate when the user dismisses the alert. This ensures the user takes action to move the application to the correct location.
- User Experience: This approach provides a clear message to the user about the required installation location, ensuring they can take the appropriate action.
The error message still shows up when it is in applications folder?
Yes I made a mistake in the code, should work now.
@milanvarady I just tested with the latest build.
Now the error message does not even show up when running the app outside of applications folder.
@IAmVigneswaran It works for me, I have tested it in several locations. Did you click "Don't show again"? This will mute the alert for all versions of the app. To reset the setting, paste this into the terminal:
defaults write co.theacharya.MarkerData ignoreInstallLocation 0
Reseting the setting via terminal worked.
Now, it is working as expected! Thank you.
@milanvarady Would it be possible to add install location check for Marker Data?
Marker Data should be installed into
Applications
folder. If for some reason, user tries to run the app outside ofApplications
we would have an error prompt?Error: Invalid Installation Location
Marker Data must be installed in the Applications folder to run correctly. Please move the application to the Applications folder and try again.
Thank you.