TheAcharya / MarkerData

The avant-garde Marker extraction application crafted for Final Cut Pro
https://markerdata.theacharya.co
MIT License
27 stars 1 forks source link

Install Location Check #100

Closed IAmVigneswaran closed 4 months ago

IAmVigneswaran commented 4 months ago

@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 of Applications 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.

milanvarady commented 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.

CleanShot 2024-06-01 at 17 40 18

IAmVigneswaran commented 4 months ago

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.

Install_Location_Check
IAmVigneswaran commented 4 months ago

@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.

IAmVigneswaran commented 4 months ago

@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

  1. isApplicationInApplicationsFolder Function: This function checks if the application's bundle path starts with /Applications.
  2. 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.
milanvarady commented 4 months ago

The error message still shows up when it is in applications folder?

Yes I made a mistake in the code, should work now.

IAmVigneswaran commented 4 months ago

@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.

milanvarady commented 4 months ago

@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
IAmVigneswaran commented 4 months ago

Reseting the setting via terminal worked.

Now, it is working as expected! Thank you.