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.

94 lines
2.3KB

  1. /*
  2. * pamac-vala
  3. *
  4. * Copyright (C) 2014-2016 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. class Updater : Gtk.Application {
  21. UpdaterWindow updater_window;
  22. bool pamac_run;
  23. public Updater () {
  24. application_id = "org.manjaro.pamac.updater";
  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. updater_window = new UpdaterWindow (this);
  43. }
  44. }
  45. public override void activate () {
  46. if (!pamac_run) {
  47. updater_window.present ();
  48. }
  49. }
  50. public override void shutdown () {
  51. base.shutdown ();
  52. if (!pamac_run) {
  53. updater_window.transaction.stop_daemon ();
  54. }
  55. }
  56. bool check_pamac_running () {
  57. Application app;
  58. bool run = false;
  59. app = new Application ("org.manjaro.pamac.manager", 0);
  60. try {
  61. app.register ();
  62. } catch (GLib.Error e) {
  63. stderr.printf ("%s\n", e.message);
  64. }
  65. run = app.get_is_remote ();
  66. if (run) {
  67. return run;
  68. }
  69. app = new Application ("org.manjaro.pamac.install", 0);
  70. try {
  71. app.register ();
  72. } catch (GLib.Error e) {
  73. stderr.printf ("%s\n", e.message);
  74. }
  75. run = app.get_is_remote ();
  76. return run;
  77. }
  78. }
  79. static int main (string[] args) {
  80. var updater = new Updater ();
  81. return updater.run (args);
  82. }
  83. }