feat(launch): start desktops without the login screen
The greeter only starts the session its own selector points at, so an installed environment with no open session could not be reached from the tool. Starting one needs a one-shot autologin drop-in, a display manager restart and a guaranteed cleanup, all as root: keep that in a small pkexec helper so the CLI and the GTK window stay unprivileged.
This commit is contained in:
11 files changed
+709
-38
No files matched your search
+94
-17
@@ -5,11 +5,12 @@
|
||||
|
||||
#include "desktop-catalog.h"
|
||||
#include "session-catalog.h"
|
||||
#include "session-launcher.h"
|
||||
#include "session-switcher.h"
|
||||
|
||||
namespace {
|
||||
|
||||
enum class RowMode { Install, SwitchTo, Greeter };
|
||||
enum class RowMode { Install, SwitchTo, Greeter, Launch };
|
||||
|
||||
struct RowWidgets {
|
||||
const fws::DesktopProfile* profile = nullptr;
|
||||
@@ -72,6 +73,9 @@ private:
|
||||
case RowMode::Greeter:
|
||||
self->askGreeter(*row.profile);
|
||||
break;
|
||||
case RowMode::Launch:
|
||||
self->askLaunch(*row.profile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,6 +129,21 @@ private:
|
||||
self->goToGreeter(true);
|
||||
}
|
||||
|
||||
static void onLaunchChosen(GObject* source, GAsyncResult* result, gpointer data) {
|
||||
auto* self = static_cast<ManagerWindow*>(data);
|
||||
GError* error = nullptr;
|
||||
const int response =
|
||||
gtk_alert_dialog_choose_finish(GTK_ALERT_DIALOG(source), result, &error);
|
||||
if (error != nullptr) {
|
||||
g_error_free(error);
|
||||
return;
|
||||
}
|
||||
if (response != 1 || self->launchProfile_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
self->startLaunch(*self->launchProfile_);
|
||||
}
|
||||
|
||||
void buildWindow(GtkApplication* application) {
|
||||
window_ = gtk_application_window_new(application);
|
||||
gtk_window_set_title(GTK_WINDOW(window_), "FWS DeskManager");
|
||||
@@ -149,8 +168,8 @@ private:
|
||||
gtk_window_set_child(GTK_WINDOW(window_), root);
|
||||
|
||||
GtkWidget* intro = gtk_label_new(
|
||||
"Installez un environnement puis basculez dessus sans redémarrer. "
|
||||
"La bascule instantanée nécessite une session déjà ouverte pour cet environnement.");
|
||||
"Installez un environnement puis lancez-le sans passer par l'ecran de connexion : "
|
||||
"la session precedente est fermee au profit de la nouvelle.");
|
||||
gtk_label_set_wrap(GTK_LABEL(intro), TRUE);
|
||||
gtk_label_set_xalign(GTK_LABEL(intro), 0.0F);
|
||||
gtk_widget_add_css_class(intro, "dim-label");
|
||||
@@ -291,23 +310,41 @@ private:
|
||||
gtk_widget_add_css_class(row.action, "suggested-action");
|
||||
row.mode = RowMode::SwitchTo;
|
||||
} else {
|
||||
// The greeter opens on the session it remembered, not on the one
|
||||
// this row points at, so the entry to pick is named right here.
|
||||
const std::string entry = fws::greeterSessionName(row.profile->sessionNames);
|
||||
if (entry.empty()) {
|
||||
// Without a display manager that supports one-shot autologin,
|
||||
// the greeter stays the only way in.
|
||||
std::string reason;
|
||||
if (fws::canStartWithoutGreeter(reason)) {
|
||||
gtk_label_set_markup(GTK_LABEL(row.status),
|
||||
"<span foreground='#26a269'>Installé</span> · aucune session");
|
||||
"<span foreground='#26a269'>Installé</span> · aucune "
|
||||
"session");
|
||||
gtk_button_set_label(GTK_BUTTON(row.action), "Lancer");
|
||||
gtk_widget_set_tooltip_text(
|
||||
row.action,
|
||||
"Démarrer l'environnement sans écran de connexion : la session "
|
||||
"actuelle sera fermée.");
|
||||
gtk_widget_add_css_class(row.action, "suggested-action");
|
||||
row.mode = RowMode::Launch;
|
||||
} else {
|
||||
gchar* markup = g_markup_printf_escaped(
|
||||
"<span foreground='#26a269'>Installé</span> · aucune session · choisir "
|
||||
"« %s » au greeter",
|
||||
entry.c_str());
|
||||
gtk_label_set_markup(GTK_LABEL(row.status), markup);
|
||||
g_free(markup);
|
||||
// The greeter opens on the session it remembered, not on the one
|
||||
// this row points at, so the entry to pick is named right here.
|
||||
const std::string entry = fws::greeterSessionName(row.profile->sessionNames);
|
||||
if (entry.empty()) {
|
||||
gtk_label_set_markup(GTK_LABEL(row.status),
|
||||
"<span foreground='#26a269'>Installé</span> · "
|
||||
"aucune session");
|
||||
} else {
|
||||
gchar* markup = g_markup_printf_escaped(
|
||||
"<span foreground='#26a269'>Installé</span> · aucune session · "
|
||||
"choisir « %s » au greeter",
|
||||
entry.c_str());
|
||||
gtk_label_set_markup(GTK_LABEL(row.status), markup);
|
||||
g_free(markup);
|
||||
}
|
||||
gtk_button_set_label(GTK_BUTTON(row.action), "Écran de connexion");
|
||||
gtk_widget_set_tooltip_text(row.action, nullptr);
|
||||
gtk_widget_add_css_class(row.action, "destructive-action");
|
||||
row.mode = RowMode::Greeter;
|
||||
}
|
||||
gtk_button_set_label(GTK_BUTTON(row.action), "Écran de connexion");
|
||||
gtk_widget_add_css_class(row.action, "destructive-action");
|
||||
row.mode = RowMode::Greeter;
|
||||
}
|
||||
|
||||
gtk_widget_set_sensitive(row.action, selfBusy() ? FALSE : TRUE);
|
||||
@@ -471,6 +508,44 @@ private:
|
||||
setStatus("Retour à l'écran de connexion impossible.");
|
||||
}
|
||||
|
||||
// Starting a session replaces the current one, so the decision is explicit
|
||||
// before polkit asks for the password.
|
||||
void askLaunch(const fws::DesktopProfile& profile) {
|
||||
launchProfile_ = &profile;
|
||||
const std::string message =
|
||||
"Lancer " + profile.name +
|
||||
" sans passer par l'ecran de connexion ?\n\nLa session courante sera fermee : "
|
||||
"les applications non enregistrees seront perdues. L'authentification est "
|
||||
"demandee par polkit.";
|
||||
GtkAlertDialog* dialog = gtk_alert_dialog_new("%s", message.c_str());
|
||||
const char* buttons[] = {"Annuler", "Lancer et fermer", nullptr};
|
||||
gtk_alert_dialog_set_buttons(dialog, buttons);
|
||||
gtk_alert_dialog_set_cancel_button(dialog, 0);
|
||||
gtk_alert_dialog_set_default_button(dialog, 1);
|
||||
gtk_alert_dialog_choose(dialog, GTK_WINDOW(window_), nullptr,
|
||||
&ManagerWindow::onLaunchChosen, this);
|
||||
g_object_unref(dialog);
|
||||
}
|
||||
|
||||
void startLaunch(const fws::DesktopProfile& profile) {
|
||||
setStatus("Lancement de " + profile.name + " sans écran de connexion…");
|
||||
setBusy(true, "Lancement de " + profile.name + "…");
|
||||
flushPendingEvents();
|
||||
|
||||
// Blocks while the display manager restarts and autologins; the window is
|
||||
// then closed with the session it belongs to.
|
||||
const fws::LaunchOutcome outcome = fws::launchDesktop(profile);
|
||||
if (!outcome.ok) {
|
||||
setBusy(false, "Échec du lancement de " + profile.name + ".");
|
||||
showError(outcome.error);
|
||||
refreshRows();
|
||||
return;
|
||||
}
|
||||
|
||||
setBusy(false, profile.name + " a démarré ; la session précédente se ferme.");
|
||||
refreshRows();
|
||||
}
|
||||
|
||||
void showError(const std::string& message) {
|
||||
GtkAlertDialog* dialog = gtk_alert_dialog_new("%s", message.c_str());
|
||||
gtk_alert_dialog_show(dialog, GTK_WINDOW(window_));
|
||||
@@ -506,6 +581,8 @@ private:
|
||||
std::vector<RowWidgets> rows_;
|
||||
GSubprocess* pending_ = nullptr;
|
||||
bool busy_ = false;
|
||||
// Filled by askLaunch(): the profile the pending dialog starts.
|
||||
const fws::DesktopProfile* launchProfile_ = nullptr;
|
||||
// Filled by askGreeter(): the greeter entry to name once it is on screen.
|
||||
std::string greeterEntry_;
|
||||
bool greeterIsCurrent_ = false;
|
||||
|
||||
Reference in new issue
Block a user