App.vala 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using Gtk;
  2. namespace Publicate {
  3. public class PpubViewerApplication : Adw.Application {
  4. public PpubViewerApplication() {
  5. Object(application_id: "nz.barrow.billy.publicate", flags: GLib.ApplicationFlags.HANDLES_OPEN);
  6. }
  7. protected override void activate () {
  8. // Absolutely janky fix for whatever is causing the keyboard shortcuts not to show up in menus
  9. var window = new ViewerWindow(this);
  10. window.destroy ();
  11. window = new ViewerWindow(this);
  12. add_window (window);
  13. window.present ();
  14. }
  15. protected override void open (File[] files, string hint) {
  16. foreach (var file in files) {
  17. var window = new ViewerWindow(this);
  18. window.present ();
  19. window.load_ppub.begin(file);
  20. }
  21. }
  22. }
  23. int main (string[] argv) {
  24. seed();
  25. // Create a new application
  26. var app = new PpubViewerApplication();
  27. return app.run (argv);
  28. }
  29. string get_publicate_path() {
  30. return Environment.get_home_dir () + "/.publicate";
  31. }
  32. void seed() {
  33. if(!FileUtils.test (get_publicate_path(), FileTest.EXISTS)) {
  34. DirUtils.create (get_publicate_path (), 0600);
  35. }
  36. if(!FileUtils.test (get_publicate_path() + "/credentials", FileTest.EXISTS)) {
  37. DirUtils.create (get_publicate_path() + "/credentials", 0600);
  38. }
  39. if(!FileUtils.test (get_publicate_path() + "/collections", FileTest.EXISTS)) {
  40. DirUtils.create (get_publicate_path() + "/collections", 0600);
  41. }
  42. if(!FileUtils.test (get_publicate_path() + "/collections.config", FileTest.EXISTS)) {
  43. var template = "{\"collections\": []}";
  44. FileUtils.set_contents (get_publicate_path() + "/collections.config", template, template.length);
  45. }
  46. }
  47. }