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.

95 lines
2.4KB

  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. [DBus (name = "org.manjaro.pamac")]
  21. interface Daemon : Object {
  22. public abstract void start_refresh (bool force) throws IOError;
  23. [DBus (no_reply = true)]
  24. public abstract void quit () throws IOError;
  25. public signal void refresh_finished (bool success);
  26. }
  27. }
  28. Pamac.Daemon pamac_daemon;
  29. MainLoop loop;
  30. bool check_pamac_running () {
  31. Application app;
  32. bool run = false;
  33. app = new Application ("org.manjaro.pamac.manager", 0);
  34. try {
  35. app.register ();
  36. } catch (GLib.Error e) {
  37. stderr.printf ("%s\n", e.message);
  38. }
  39. run = app.get_is_remote ();
  40. if (run) {
  41. return run;
  42. }
  43. app = new Application ("org.manjaro.pamac.updater", 0);
  44. try {
  45. app.register ();
  46. } catch (GLib.Error e) {
  47. stderr.printf ("%s\n", e.message);
  48. }
  49. run = app.get_is_remote ();
  50. if (run) {
  51. return run;
  52. }
  53. app = new Application ("org.manjaro.pamac.install", 0);
  54. try {
  55. app.register ();
  56. } catch (GLib.Error e) {
  57. stderr.printf ("%s\n", e.message);
  58. }
  59. run = app.get_is_remote ();
  60. return run;
  61. }
  62. void on_refresh_finished () {
  63. if (!check_pamac_running ()) {
  64. try {
  65. pamac_daemon.quit ();
  66. } catch (IOError e) {
  67. stderr.printf ("IOError: %s\n", e.message);
  68. }
  69. }
  70. loop.quit ();
  71. }
  72. int main () {
  73. var pamac_config = new Pamac.Config ("/etc/pamac.conf");
  74. // if refresh period is 0, just exit
  75. if (pamac_config.refresh_period != 0) {
  76. if (!check_pamac_running ()) {
  77. try {
  78. pamac_daemon = Bus.get_proxy_sync (BusType.SYSTEM, "org.manjaro.pamac", "/org/manjaro/pamac");
  79. pamac_daemon.refresh_finished.connect (on_refresh_finished);
  80. pamac_daemon.start_refresh (false);
  81. loop = new MainLoop ();
  82. loop.run ();
  83. } catch (IOError e) {
  84. stderr.printf ("IOError: %s\n", e.message);
  85. }
  86. }
  87. }
  88. return 0;
  89. }