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.

105 lines
2.6KB

  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. public class Installer: Gtk.Application {
  21. Transaction transaction;
  22. bool pamac_run;
  23. public Installer () {
  24. application_id = "org.manjaro.pamac.install";
  25. flags |= ApplicationFlags.HANDLES_OPEN;
  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. transaction = new Pamac.Transaction (null);
  43. transaction.finished.connect (on_transaction_finished);
  44. this.hold ();
  45. }
  46. }
  47. public override void activate () {
  48. if (!pamac_run) {
  49. print ("\nError: Path(s) of tarball(s) to install is needed\n");
  50. transaction.stop_daemon ();
  51. this.release ();
  52. }
  53. }
  54. public override void open (File[] files, string hint) {
  55. if (!pamac_run) {
  56. foreach (unowned File file in files) {
  57. transaction.to_load.add (file.get_path ());
  58. }
  59. transaction.run ();
  60. }
  61. }
  62. bool check_pamac_running () {
  63. Application app;
  64. bool run = false;
  65. app = new Application ("org.manjaro.pamac.manager", 0);
  66. try {
  67. app.register ();
  68. } catch (GLib.Error e) {
  69. stderr.printf ("%s\n", e.message);
  70. }
  71. run = app.get_is_remote ();
  72. if (run) {
  73. return run;
  74. }
  75. app = new Application ("org.manjaro.pamac.updater", 0);
  76. try {
  77. app.register ();
  78. } catch (GLib.Error e) {
  79. stderr.printf ("%s\n", e.message);
  80. }
  81. run = app.get_is_remote ();
  82. return run;
  83. }
  84. void on_transaction_finished () {
  85. transaction.stop_daemon ();
  86. this.release ();
  87. }
  88. public static int main (string[] args) {
  89. var installer = new Installer();
  90. return installer.run (args);
  91. }
  92. }
  93. }