main.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "MainWindow.hpp"
  2. #include <gtkmm/application.h>
  3. #include <gtk/gtk.h>
  4. #include <iostream>
  5. #include <cstdlib>
  6. #include <sys/stat.h>
  7. #include <string>
  8. int main(int argc, char *argv[]) {
  9. // --- Environment Hijack for Fontconfig ---
  10. const char* user = std::getenv("USER");
  11. std::string safe_cache_dir = std::string("/tmp/gnome-vault-cache-") + (user ? user : "default");
  12. mkdir(safe_cache_dir.c_str(), 0777);
  13. setenv("XDG_CACHE_HOME", safe_cache_dir.c_str(), 1);
  14. // Set Program Name for WmClass / Task Bar
  15. g_set_prgname("gnomesettingsvault");
  16. g_set_application_name("GnomeSettingsVault");
  17. if (!gtk_init_check(&argc, &argv)) {
  18. std::cerr << "Bloody hell: GTK failed to initialize." << std::endl;
  19. return 1;
  20. }
  21. try {
  22. // Application ID also helps define the WmClass
  23. auto app = Gtk::Application::create(argc, argv, "org.gnome.settingsvault");
  24. MainWindow window;
  25. return app->run(window);
  26. } catch (const Glib::Error& ex) {
  27. std::cerr << "GTK Error: " << ex.what() << std::endl;
  28. return 1;
  29. } catch (const std::exception& ex) {
  30. std::cerr << "Standard Exception: " << ex.what() << std::endl;
  31. return 1;
  32. }
  33. }