Skip to content

Commit

Permalink
Cleanup session-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
lenemter committed Jan 28, 2025
1 parent 74bab8b commit 5ebddf2
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 56 deletions.
4 changes: 4 additions & 0 deletions session-manager/SessionManager.vala
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2025 elementary, Inc. (https://elementary.io)
*/

[DBus (name="org.gnome.SessionManager")]
public class GreeterSessionManager.GnomeSessionManager : GLib.Object {
Expand Down
68 changes: 38 additions & 30 deletions session-manager/SettingsDaemon.vala
Original file line number Diff line number Diff line change
@@ -1,41 +1,49 @@
public class GreeterSessionManager.SettingsDaemon : Object {
private GreeterSessionManager.GnomeSessionManager session_manager;
/*
* SPDX-License-Identifier: GPL-3.0-or-later
* SPDX-FileCopyrightText: 2011 Canonical Ltd
* 2025 elementary, Inc. (https://elementary.io)
*/

public class GreeterSessionManager.SettingsDaemon : GLib.Object {
private const string[] DAEMONS = {
"gsd-a11y-settings",
"gsd-color",
"gsd-media-keys",
"gsd-sound",
"gsd-power",
"gsd-xsettings"
};

private SubprocessSupervisor[] supervisors = {};

public void start () {
construct {
/* Pretend to be GNOME session */
session_manager = new GnomeSessionManager ();
GLib.Bus.own_name (BusType.SESSION, "org.gnome.SessionManager", BusNameOwnerFlags.NONE,
(c) => {
try {
c.register_object ("/org/gnome/SessionManager", session_manager);
} catch (Error e) {
warning ("Failed to register /org/gnome/SessionManager: %s", e.message);
}
},
() => {
warning ("Acquired org.gnome.SessionManager");
start_settings_daemon ();
},
() => warning ("Failed to acquire name org.gnome.SessionManager"));
GLib.Bus.own_name (
BusType.SESSION, "org.gnome.SessionManager", BusNameOwnerFlags.NONE,
(connection) => {
try {
connection.register_object ("/org/gnome/SessionManager", new GnomeSessionManager ());
} catch (Error e) {
critical ("Failed to register /org/gnome/SessionManager: %s", e.message);
}
},
() => {
debug ("Acquired org.gnome.SessionManager");
start_settings_daemon ();
},
() => {
critical ("Lost org.gnome.SessionManager");
}
);
}

private void start_settings_daemon () {
warning ("All bus names acquired, starting gnome-settings-daemon");

string[] daemons = {
"gsd-a11y-settings",
"gsd-color",
"gsd-media-keys",
"gsd-sound",
"gsd-power",
"gsd-xsettings"
};
debug ("All bus names acquired, starting gnome-settings-daemon");

foreach (var daemon in daemons) {
foreach (unowned var daemon in DAEMONS) {
try {
supervisors += new SubprocessSupervisor ({Constants.GSD_DIR + daemon});
} catch (GLib.Error e) {
supervisors += new SubprocessSupervisor ({ Constants.GSD_DIR + daemon });
} catch (Error e) {
critical ("Could not start %s: %s", daemon, e.message);
}
}
Expand Down
38 changes: 14 additions & 24 deletions session-manager/SubprocessSupervisor.vala
Original file line number Diff line number Diff line change
@@ -1,47 +1,37 @@
/*
* Copyright 2018 elementary, Inc. (https://elementary.io)
*
* 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 2 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 copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*
* SPDX-License-Identifier: GPL-2.0-or-later
* SPDX-FileCopyrightText: 2018, 2025 elementary, Inc. (https://elementary.io)
* Authors: Corentin Noël <corentin@elementary.io>
*/

public class GreeterSessionManager.SubprocessSupervisor : GLib.Object {
public signal void spawned (GLib.Subprocess subprocess);
public string[] exec { get; construct; }

private GLib.Subprocess? subprocess = null;

private GLib.Subprocess subprocess;
private string[] exec;
public SubprocessSupervisor (string[] exec) throws GLib.Error {
this.exec = exec;
Object (exec: exec);
}

construct {
ensure_run.begin ();
}

~SubprocessSupervisor () {
exec = {};
subprocess.force_exit ();
if (subprocess != null) {
subprocess.force_exit ();
}
}

private async void ensure_run () {
try {
subprocess = new GLib.Subprocess.newv (exec, GLib.SubprocessFlags.STDIN_INHERIT | GLib.SubprocessFlags.STDERR_MERGE);

if (!yield subprocess.wait_check_async ()) {
ensure_run.begin ();
}
} catch (Error e) {
critical (e.message);
critical ("Couldn't create subprocess: %s", e.message);
}
}
}
3 changes: 1 addition & 2 deletions session-manager/main.vala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
public class GreeterSessionManager.Application : GLib.Object {
public static int main (string[] args) {
var settings_daemon = new SettingsDaemon ();
settings_daemon.start ();
new SettingsDaemon ();

var loop = new GLib.MainLoop (GLib.MainContext.default (), true);
loop.run ();
Expand Down

0 comments on commit 5ebddf2

Please sign in to comment.