/*
 * GnomeSettingsVault - A high-integrity GNOME configuration backup utility.
 * Copyright (C) 2026 Nicole Portas, nicole@equalmass.com
 */

#include "MainWindow.hpp"
#include <gtkmm/application.h>
#include <gtk/gtk.h>
#include <iostream>
#include <cstdlib>
#include <sys/stat.h>
#include <string>

int main(int argc, char *argv[]) {
    const char* user = std::getenv("USER");
    std::string safe_cache_dir = std::string("/tmp/gnome-vault-cache-") + (user ? user : "default");
    mkdir(safe_cache_dir.c_str(), 0777);
    setenv("XDG_CACHE_HOME", safe_cache_dir.c_str(), 1);

    const std::string app_id = "gnome-vault"; 
    g_set_prgname(app_id.c_str());
    g_set_application_name("GnomeSettingsVault");

    if (!gtk_init_check(&argc, &argv)) {
        std::cerr << "Bloody hell: GTK failed to initialize." << std::endl;
        return 1;
    }

    try {
        auto app = Gtk::Application::create(argc, argv, "com.equalmass.gnomevault");
        MainWindow window;
        return app->run(window);
    } catch (const Glib::Error& ex) {
        std::cerr << "GTK Error: " << ex.what() << std::endl;
        return 1;
    } catch (const std::exception& ex) {
        std::cerr << "Standard Exception: " << ex.what() << std::endl;
        return 1;
    }
}
