Graphical package manager for pacman based on pamac 5.x.x
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.4KB

  1. /*
  2. * pamac-vala
  3. *
  4. * Copyright (C) 2014-2015 Guillaume Benoit <guillaume@manjaro.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a get of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. namespace Pamac {
  20. public class Manager : Gtk.Application {
  21. ManagerWindow manager_window;
  22. bool pamac_run;
  23. public Manager () {
  24. application_id = "org.manjaro.pamac.manager";
  25. flags = ApplicationFlags.FLAGS_NONE;
  26. }
  27. public override void startup () {
  28. // i18n
  29. Intl.textdomain ("pamac");
  30. Intl.setlocale (LocaleCategory.ALL, "");
  31. base.startup ();
  32. pamac_run = check_pamac_running ();
  33. if (pamac_run) {
  34. var msg = new Gtk.MessageDialog (null,
  35. Gtk.DialogFlags.MODAL,
  36. Gtk.MessageType.ERROR,
  37. Gtk.ButtonsType.OK,
  38. dgettext (null, "Pamac is already running"));
  39. msg.run ();
  40. msg.destroy ();
  41. } else {
  42. manager_window = new ManagerWindow (this);
  43. }
  44. }
  45. public override void activate () {
  46. if (!pamac_run) {
  47. manager_window.present ();
  48. while (Gtk.events_pending ()) {
  49. Gtk.main_iteration ();
  50. }
  51. }
  52. }
  53. public override void shutdown () {
  54. base.shutdown ();
  55. if (!pamac_run) {
  56. manager_window.transaction.stop_daemon ();
  57. }
  58. }
  59. bool check_pamac_running () {
  60. Application app;
  61. bool run = false;
  62. app = new Application ("org.manjaro.pamac.updater", 0);
  63. try {
  64. app.register ();
  65. } catch (GLib.Error e) {
  66. stderr.printf ("%s\n", e.message);
  67. }
  68. run = app.get_is_remote ();
  69. if (run) {
  70. return run;
  71. }
  72. app = new Application ("org.manjaro.pamac.install", 0);
  73. try {
  74. app.register ();
  75. } catch (GLib.Error e) {
  76. stderr.printf ("%s\n", e.message);
  77. }
  78. run = app.get_is_remote ();
  79. return run;
  80. }
  81. }
  82. public static int main (string[] args) {
  83. var manager = new Manager ();
  84. return manager.run (args);
  85. }
  86. }