// this is the source code for the binary checked in to the repo.  
// renamed to .txt to make code scanning ignore it 
// TODO:  change CodeQL config to advanced mode in github and make it explicitly ignore this file or figure out how to tell it to build it
// it currently complains that: Exit code was 32 and last log line was: CodeQL detected code written in C/C++ but could not automatically build any of it

#include <stdlib.h>
#include <unistd.h>
#include <libgen.h>
#include <string.h>
#include <stdio.h>
#include <limits.h>
#include <mach-o/dyld.h>

int main(int argc, char *argv[]) {
    char exePath[PATH_MAX];
    uint32_t size = sizeof(exePath);
    if (_NSGetExecutablePath(exePath, &size) != 0) {
        fprintf(stderr, "Failed to get executable path\n");
        return 1;
    }

    char *dir = dirname(exePath);
    char command[2048];

    // Escape quotes inside AppleScript to handle paths with spaces
    // Also activate Terminal to bring it to the foreground
    snprintf(command, sizeof(command),
        "osascript -e 'tell application \"Terminal\"' "
        "-e 'activate' "
        "-e 'do script \"cd \\\"%s/../Resources\\\" && ./inference-app\"' "
        "-e 'end tell'",
        dir);

    return system(command);
}
//compile with: clang -target arm64-apple-macos -o launcher launcher.c