pamac-classic/src/manager.vala

97 lines
2.4 KiB
Vala
Raw Normal View History

2014-10-22 13:44:02 -03:00
/*
* pamac-vala
*
2015-03-04 11:55:36 -03:00
* Copyright (C) 2014-2015 Guillaume Benoit <guillaume@manjaro.org>
2014-10-22 13:44:02 -03:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a get of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Pamac {
public class Manager : Gtk.Application {
ManagerWindow manager_window;
2014-11-03 17:04:44 -03:00
bool pamac_run;
2014-10-22 13:44:02 -03:00
public Manager () {
application_id = "org.manjaro.pamac.manager";
flags = ApplicationFlags.FLAGS_NONE;
}
public override void startup () {
// i18n
Intl.textdomain ("pamac");
Intl.setlocale (LocaleCategory.ALL, "");
base.startup ();
2014-11-03 17:04:44 -03:00
pamac_run = check_pamac_running ();
if (pamac_run) {
var msg = new Gtk.MessageDialog (null,
Gtk.DialogFlags.MODAL,
Gtk.MessageType.ERROR,
Gtk.ButtonsType.OK,
dgettext (null, "Pamac is already running"));
msg.run ();
msg.destroy ();
2015-03-04 11:55:36 -03:00
} else {
2014-11-03 17:04:44 -03:00
manager_window = new ManagerWindow (this);
2015-03-04 11:55:36 -03:00
}
2014-10-22 13:44:02 -03:00
}
public override void activate () {
2016-02-02 05:28:07 -03:00
if (!pamac_run) {
2014-11-03 17:04:44 -03:00
manager_window.present ();
2015-03-04 11:55:36 -03:00
while (Gtk.events_pending ()) {
2014-11-16 07:31:44 -03:00
Gtk.main_iteration ();
2015-03-04 11:55:36 -03:00
}
2014-11-16 07:31:44 -03:00
}
2014-10-22 13:44:02 -03:00
}
public override void shutdown () {
base.shutdown ();
2016-02-02 05:28:07 -03:00
if (!pamac_run) {
2014-11-03 17:04:44 -03:00
manager_window.transaction.stop_daemon ();
2015-03-04 11:55:36 -03:00
}
2014-11-03 17:04:44 -03:00
}
bool check_pamac_running () {
Application app;
bool run = false;
app = new Application ("org.manjaro.pamac.updater", 0);
try {
app.register ();
} catch (GLib.Error e) {
stderr.printf ("%s\n", e.message);
}
run = app.get_is_remote ();
2015-03-04 11:55:36 -03:00
if (run) {
2014-11-03 17:04:44 -03:00
return run;
}
app = new Application ("org.manjaro.pamac.install", 0);
try {
app.register ();
} catch (GLib.Error e) {
stderr.printf ("%s\n", e.message);
}
run = app.get_is_remote ();
return run;
2014-10-22 13:44:02 -03:00
}
}
public static int main (string[] args) {
var manager = new Manager ();
return manager.run (args);
}
}