hertg / lightdm-neon

:art: A customizable theme for web-greeter in a nostalgic but modern neon look
https://hertg.github.io/lightdm-neon/
GNU General Public License v3.0
133 stars 2 forks source link

[FEATURE] Automatic detection of environment session #18

Closed D3vil0p3r closed 5 months ago

D3vil0p3r commented 11 months ago

Currently, when this theme is applied at the installation of a OS (so before the installation of previous Display Managers or themes), the theme does not recognize the desktop environment session and the "window" icon at bottom-left is without any string. I'm using GNOME, so I have the following possible sessions: gnome (that is wayland), gnome-wayland (same as before) and gnome-xorg (Xorg session, the one I use more): image

A newbie that does not know the concept of "sessions", if try to insert a password, get a popup window saying: image

So the user must be aware of the functionality of the "window" icon, clicking there and selecting the right session: image

Is there a way for the theme to automatically set one of the available sessions and provide a config file to set it programmatically?

Usually the session files are stored in /usr/share/xsessions for Xorg and /usr/share/wayland-sessions for Wayland.

D3vil0p3r commented 11 months ago

I note that it can be satisfied by filling user-session field in /etc/lightdm/lightdm.conf. If you confirm this, I can close the issue.

hertg commented 11 months ago

Yes, it will select the default session that was configured in the lightdm config, if there isn't any, it should select the first session in the session list returned from the lightdm api... unless there's something wrong with this code. https://github.com/hertg/lightdm-neon/blob/6644299558197a2e3aaa115f0df5ec0bb2c34773/src/main.ts#L17-L24

Do you get any errors in the javascript console?

D3vil0p3r commented 11 months ago

No, I dont get errors. It works well. I tested on a fresh machine. I close the ticket.

D3vil0p3r commented 10 months ago

Hello @hertg Sorry if I reopen the issue. The user-session can work well, but in reality the code seems to not retrieve the first available session. I tested it again in a clean environment with MATE desktop env and the icon on bottom-left remains empty on first run. Maybe it does not take the first session in the session list...

If I run the piece of code above you posted in typescript, I get:

/usr/lib/node_modules/ts-node/src/index.ts:859
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
lightdm.ts:1:32 - error TS2304: Cannot find name 'window'.

1  let default_session: string = window.lightdm.default_session;
                                 ~~~~~~
lightdm.ts:3:7 - error TS2304: Cannot find name 'window'.

3   if (window.lightdm.sessions.length > 0) {
        ~~~~~~
lightdm.ts:4:22 - error TS2304: Cannot find name 'window'.

4    default_session = window.lightdm.sessions[0].key;
                       ~~~~~~

    at createTSError (/usr/lib/node_modules/ts-node/src/index.ts:859:12)
    at reportTSError (/usr/lib/node_modules/ts-node/src/index.ts:863:19)
    at getOutput (/usr/lib/node_modules/ts-node/src/index.ts:1077:36)
    at Object.compile (/usr/lib/node_modules/ts-node/src/index.ts:1433:41)
    at Module.m._compile (/usr/lib/node_modules/ts-node/src/index.ts:1617:30)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Object.require.extensions.<computed> [as .ts] (/usr/lib/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1023:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12) {
  diagnosticCodes: [ 2304, 2304, 2304 ]
}

I'm running it on my Linux terminal by NodeJS.

hertg commented 10 months ago

I don't fully understand what code you executed, and where.

Can you fully reproduce the issue on your machine? If so, could you enable debug mode in web-greeter by setting the following config:

# /etc/lightdm/web-greeter.yml
greeter:
    debug_mode: True

After that, once you are back to the login screen (through log out, or reboot), press F12 and open the javascript console. Do you see any errors there?

D3vil0p3r commented 10 months ago

I'm using it in a Virtual Machine (VMware Workstation), I enabled the debug mode and when I am at login page and I press F12, nothing happens, I cannot get the javascript console. Or maybe it is not clear for me how to run the debug of it.

UPDATE: I got it by right-click by mouse -> Inspect -> clicking on Console.

D3vil0p3r commented 10 months ago

@hertg I run it, and in my console I see the following messages: image

MATE session exists, indeed if I click on the bottom-left button, I get: image

So, it is not able to set session as this existing MATE session.

UPDATE: going deep to the elements, I expanded lightdm QObject -> __propertyCache__ -> 28 -> 0 that is the one containing the session value and I see:

image

So it reports This session logs you into MATE but, as you can see on bottom-left of the image, that icon is without MATE. If I try to login directly without manually selecting MATE, it does not login, and I get the popup window LightDM couldn't start session.

D3vil0p3r commented 10 months ago

I'm continuing further tests. I note this happens only for some desktop environments. For example, it occurs for MATE, KDE Plasma, Cinnamon and Bspwm. Now I tested XFCE, Hyprland and GNOME and it is able to recognize them at first boot. I will check more involved environments.

hertg commented 10 months ago

What's the content of your /etc/lightdm/lightdm.conf? On my machine, I see that there is a line that's commented out:

#user-session=default

Your console output (default session is 'default') looks like your lightdm config might have this line in it. Now, I don't know what values are allowed for this setting, my understanding was that you'd set that value to something like xfce or gnome. But is the value default actually a valid setting?

I'll ping @JezerM, maybe they have some insight on what is happening here.

hertg commented 10 months ago

If you cannot login, when the session is set to 'default', clearly it seems to be an issue to call

window.lightdm?.start_session('default');

which is what's effectively happening here: https://github.com/hertg/lightdm-neon/blob/13e7675089983e87514f9d418ccb9a1f0a931d0e/src/signals.ts#L33C22-L33C22

@JezerM, is that a problem? Should I convert a value of 'default' to null when calling window.lightdm?.start_session()?

JezerM commented 10 months ago

If I remember correctly, the "default" session in "lightdm.conf" should select the last session the user logged in with (or a session that is exactly called "default").

And yeah, you shouldn't use "default" in lightdm.start_session(), it's better to set it as null.

D3vil0p3r commented 10 months ago

I tested several environments cited above and I see that the issue occurs for the following ones:

MATE, KDE Plasma, Cinnamon and Bspwm

hertg commented 10 months ago

@D3vil0p3r Could you build the theme yourself and test the following patch to see if it resolves your issue?

diff --git a/src/main.ts b/src/main.ts
index c391916..6204940 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -14,16 +14,37 @@ function initGreeter() {
        target: document.body,
        props: {}
    });
-   let default_session: string = window.lightdm.default_session;
-   if (!default_session) {
-       if (window.lightdm.sessions.length > 0) {
-           default_session = window.lightdm.sessions[0].key;
-       } else {
-           console.warn("no session found to choose from?");
-       }
-   }
-   console.debug(`default_session is '${default_session}'`);
+
+   let default_session: string = computeDefaultSession();
+   console.debug(`session being used is '${default_session}'`);
    selectedSession.update(_ => default_session);
 };
+
+function computeDefaultSession(): string {
+    let from_config = window.lightdm.default_session;
+
+    if (from_config) {
+        if (window.lightdm.sessions.find(k => k.key === from_config)) {
+            console.debug(`default session '${from_config}' configured, using it`);
+            return from_config;
+        } else {
+            if (window.lightdm.sessions.length > 0) {
+                console.warn(`default session '${from_config}' not found, using first session`);
+                return window.lightdm.sessions[0].key;
+            } else {
+                console.warn(`default session '${from_config}' not found, but also no sessions available to fallback to, attempting to use it anyway`)
+                return from_config;
+            }
+        }
+    }
+
+    if (window.lightdm.sessions.length > 0) {
+        console.debug("no default session configured, using first session");
+        return window.lightdm.sessions[0].key;
+    } else {
+        console.warn("no default session configured, and no sessions available to fallback to, using 'null'");
+        return null;
+    }
+}

-window.addEventListener("GreeterReady", initGreeter);
\ No newline at end of file
+window.addEventListener("GreeterReady", initGreeter);
D3vil0p3r commented 10 months ago

I confirm that code fixed the issue. I tested MATE and Bspwm and now they are shown at first boot with this theme. Thank you so much!

hertg commented 10 months ago

will be closed once #20 is merged

hertg commented 5 months ago

closed via #20