mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-08-15 18:43:59 +00:00
Merge pull request #747 from oluijks/user-display-name
HostService: add user display name and use it in UI
This commit is contained in:
@@ -2,6 +2,7 @@ import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Services.Pam
|
||||
import qs.Commons
|
||||
import qs.Services.System
|
||||
|
||||
Scope {
|
||||
id: root
|
||||
@@ -40,7 +41,7 @@ Scope {
|
||||
PamContext {
|
||||
id: pam
|
||||
config: "login"
|
||||
user: Quickshell.env("USER")
|
||||
user: HostService.displayName
|
||||
|
||||
onPamMessage: {
|
||||
Logger.i("LockContext", "PAM message:", message, "isError:", messageIsError, "responseRequired:", responseRequired)
|
||||
|
||||
@@ -15,6 +15,7 @@ import qs.Services.Location
|
||||
import qs.Services.Media
|
||||
import qs.Services.Compositor
|
||||
import qs.Services.UI
|
||||
import qs.Services.System
|
||||
import qs.Widgets
|
||||
import qs.Widgets.AudioSpectrum
|
||||
|
||||
@@ -336,7 +337,7 @@ Loader {
|
||||
|
||||
// Welcome back + Username on one line
|
||||
NText {
|
||||
text: I18n.tr("lock-screen.welcome-back") + " " + (Quickshell.env("USER").charAt(0).toUpperCase() + Quickshell.env("USER").slice(1)) + "!"
|
||||
text: I18n.tr("lock-screen.welcome-back") + " " + HostService.displayName + "!"
|
||||
pointSize: Style.fontSizeXXL
|
||||
font.weight: Font.Medium
|
||||
color: Color.mOnSurface
|
||||
|
||||
@@ -7,6 +7,7 @@ import Quickshell.Widgets
|
||||
import qs.Commons
|
||||
import qs.Modules.Panels.ControlCenter.Cards
|
||||
import qs.Modules.Panels.Settings
|
||||
import qs.Services.System
|
||||
import qs.Services.UI
|
||||
import qs.Widgets
|
||||
|
||||
@@ -37,7 +38,7 @@ NBox {
|
||||
Layout.fillWidth: true
|
||||
spacing: Style.marginXXS
|
||||
NText {
|
||||
text: Quickshell.env("USER") || "user"
|
||||
text: HostService.displayName
|
||||
font.weight: Style.fontWeightBold
|
||||
font.capitalization: Font.Capitalize
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ ColumnLayout {
|
||||
|
||||
NTextInputButton {
|
||||
label: I18n.tr("settings.general.profile.picture.label", {
|
||||
"user": Quickshell.env("USER" || "User")
|
||||
"user": HostService.displayName
|
||||
})
|
||||
description: I18n.tr("settings.general.profile.picture.description")
|
||||
text: Settings.data.general.avatarImage
|
||||
|
||||
@@ -14,6 +14,28 @@ Singleton {
|
||||
property bool isNixOS: false
|
||||
property bool isReady: false
|
||||
|
||||
// User info
|
||||
readonly property string username: (Quickshell.env("USER") || "")
|
||||
readonly property string envRealName: (Quickshell.env("NOCTALIA_REALNAME") || "")
|
||||
property string realName: ""
|
||||
|
||||
readonly property string displayName: {
|
||||
// Explicit override
|
||||
if (envRealName && envRealName.length > 0)
|
||||
return envRealName
|
||||
|
||||
// Name from getent
|
||||
if (realName && realName.length > 0)
|
||||
return realName
|
||||
|
||||
// Fallback: capitalized $USER
|
||||
if (username && username.length > 0)
|
||||
return username.charAt(0).toUpperCase() + username.slice(1)
|
||||
|
||||
// Last resort: placeholder
|
||||
return "User"
|
||||
}
|
||||
|
||||
function init() {
|
||||
Logger.i("HostService", "Service started")
|
||||
}
|
||||
@@ -111,4 +133,22 @@ Singleton {
|
||||
stdout: StdioCollector {}
|
||||
stderr: StdioCollector {}
|
||||
}
|
||||
|
||||
// Resolve GECOS real name once on startup
|
||||
Process {
|
||||
id: realNameProcess
|
||||
command: ["sh", "-c", "getent passwd \"$USER\" | cut -d: -f5 | cut -d, -f1"]
|
||||
running: true
|
||||
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
const name = String(text || "").trim()
|
||||
if (name.length > 0) {
|
||||
root.realName = name
|
||||
Logger.i("HostService", "resolved real name", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
stderr: StdioCollector {}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user