From c2cc47184ca2013c0f3f6f429190e271ebbf5147 Mon Sep 17 00:00:00 2001
From: liuxinhao <liuxinhao@kylinsec.com.cn>
Date: Tue, 25 Apr 2023 16:22:48 +0800
Subject: [PATCH 2/2] fix(greeter): user has not logged in to a desktop
 environment,  selects a desktop environment by default
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

- 用户未登录过桌面环境默认选择一个桌面环境
---
 src/lightdm-greeter/frame.cpp | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/lightdm-greeter/frame.cpp b/src/lightdm-greeter/frame.cpp
index 10f1510..6b83247 100644
--- a/src/lightdm-greeter/frame.cpp
+++ b/src/lightdm-greeter/frame.cpp
@@ -408,11 +408,26 @@ void Frame::onUserSelected(const QString& name)
 
     QString userSession = UserManager::getUserLastSession(name);
     KLOG_DEBUG() << "user session:" << name << userSession;
+
     if (!userSession.isEmpty() && m_sessionItemMap.contains(userSession))
     {
+        // 默认选择用户上次进入的桌面环境
         auto sessionItem = m_sessionItemMap[userSession];
         sessionItem->setChecked(true);
     }
+    else if (!m_sessionItemMap.isEmpty())
+    {
+        // 该用户未登录过桌面环境
+        auto kiranSession = m_sessionItemMap.find("kiran");
+        if (kiranSession != m_sessionItemMap.end())
+        {
+            (*kiranSession)->setChecked(true);
+        }
+        else
+        {
+            m_sessionItemMap.first()->setChecked(true);
+        }
+    }
 
     if (name == m_greeter->autologinUserHint())
     {
-- 
2.33.0

