main.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. // --- THE HIJACK: Force Fontconfig to use a writable /tmp directory ---
  10. // This stops Pango from shitting the bed on headless/restrictive servers
  11. const char* user = std::getenv("USER");
  12. std::string safe_cache_dir = std::string("/tmp/gnome-vault-cache-") + (user ? user : "default");
  13. // Create the temporary directory (0777 gives it wide open permissions)
  14. mkdir(safe_cache_dir.c_str(), 0777);
  15. // Forcibly inject this into the environment before GTK boots
  16. setenv("XDG_CACHE_HOME", safe_cache_dir.c_str(), 1);
  17. // --- Standard GTK Initialization ---
  18. if (!gtk_init_check(&argc, &argv)) {
  19. std::cerr << "Bloody hell: GTK failed to initialize." << std::endl;
  20. std::cerr << "Your X11/Wayland display is either missing or rejecting the connection." << std::endl;
  21. std::cerr << "If you are on SSH, ensure you used 'ssh -X' and your local X server is running." << std::endl;
  22. return 1;
  23. }
  24. try {
  25. auto app = Gtk::Application::create(argc, argv, "org.gnome.vault");
  26. MainWindow window;
  27. return app->run(window);
  28. } catch (const Glib::Error& ex) {
  29. std::cerr << "GTK Error: " << ex.what() << std::endl;
  30. return 1;
  31. } catch (const std::exception& ex) {
  32. std::cerr << "Standard Exception: " << ex.what() << std::endl;
  33. return 1;
  34. }
  35. }