Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ install(PROGRAMS files/dde-lock-loader-wrapper DESTINATION ${CMAKE_INSTALL_BINDI
# 指定greeter,优先级最低,允许被其他应用以更高的配置文件覆盖
install(FILES files/50-deepin.conf DESTINATION ${CMAKE_INSTALL_DATADIR}/lightdm/lightdm.conf.d)
install(PROGRAMS files/pre-greeter DESTINATION ${CMAKE_INSTALL_DATADIR}/dde-session-shell/greeters.d)
if(NOT DISABLE_DSS_SNIPE)
install(PROGRAMS files/select-account-entry-task
DESTINATION ${CMAKE_INSTALL_DATADIR}/dde-session-shell/greeters.d)
endif()

if (DISABLE_DSS_SNIPE)
file(GLOB QM_FILES "translations/*.qm")
Expand Down
21 changes: 21 additions & 0 deletions files/select-account-entry-task
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

config_dir=/usr/share/dde-session-shell/greeters.d/account-entry.conf.d
shopt -s nullglob

cd "$config_dir" || exit 1
files=(*.json)
if (( ${#files[@]} == 0 )); then
exit 1
fi

while IFS= read -r -d '' file; do
checker=$(jq -er '.NeedExecScript | strings | select(startswith("/"))' "./$file") || continue
program=$(jq -er '.ExecPath | strings | select(startswith("/"))' "./$file") || continue
if [[ -f "$checker" && -x "$checker" && -f "$program" && -x "$program" ]] && "$checker" >&2; then
printf '%s\n' "$program"
exit 0
fi
done < <(printf '%s\0' "${files[@]}" | LC_ALL=C sort -z -nr)

exit 1
8 changes: 7 additions & 1 deletion src/app/lightdm-deepin-greeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ int main(int argc, char* argv[])

// 初始化LoginContent
LoginContent::instance()->init(model);
QObject::connect(worker, &GreeterWorker::accountEntryActivated, LoginContent::instance(), &LoginContent::reactivateAccountEntry);
QObject::connect(worker, &GreeterWorker::greeterActiveChanged, LoginContent::instance(), &LoginContent::setGreeterActive);
QObject::connect(LoginContent::instance(), &LoginContent::requestSwitchToUser, worker, &GreeterWorker::switchToUser);
QObject::connect(LoginContent::instance(), &LoginContent::requestSetLayout, worker, &GreeterWorker::setKeyboardLayout);
QObject::connect(LoginContent::instance(), &LoginContent::requestCheckAccount, worker, &GreeterWorker::checkAccount);
Expand All @@ -157,6 +159,10 @@ int main(int argc, char* argv[])
QObject::connect(LoginContent::instance(), &LockContent::passwordChangeUserIsActive, worker, &GreeterWorker::restartResetSessionTimer);
QObject::connect(LoginContent::instance(), &LoginContent::noPasswordLoginChanged, worker, &GreeterWorker::onNoPasswordLoginChanged);

#ifdef ENABLE_DSS_SNIPE
worker->watchSessionActivity();
#endif

// 根据屏幕创建全屏背景窗口
auto createFrame = [&](QPointer<QScreen> screen, int count) -> QWidget * {
LoginWindow *loginFrame = new LoginWindow(model);
Expand All @@ -170,7 +176,7 @@ int main(int argc, char* argv[])
}
loginFrame->setScreen(screen, count <= 0);
QObject::connect(worker, &GreeterWorker::requestUpdateBackground, loginFrame, &LoginWindow::updateBackground);
loginFrame->setVisible(model->visible());
loginFrame->updateLoginVisibility();
return loginFrame;
};

Expand Down
69 changes: 68 additions & 1 deletion src/lightdm-deepin-greeter/greeterworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "signal_bridge.h"

#include <DSysInfo>
#include <QDBusVariant>
#include <QScopedValueRollback>

#ifndef ENABLE_DSS_SNIPE
Expand Down Expand Up @@ -263,7 +264,12 @@ void GreeterWorker::initConnections()
});
connect(m_login1Inter, &DBusLogin1Manager::SessionRemoved, this, [this] {
qCInfo(DDE_SHELL) << "DBus login1 manager session removed";
if (m_model->updateCurrentUser(m_lockInter->CurrentUser())) {
#ifdef ENABLE_DSS_SNIPE
const bool preserveAccountInput = !m_model->userlistVisible() && getDconfigValue("loginPromptInput", false).toBool();
#else
constexpr bool preserveAccountInput = false;
#endif
if (!preserveAccountInput && m_model->updateCurrentUser(m_lockInter->CurrentUser())) {
m_model->updateAuthState(AT_All, AS_Cancel, "Cancel");
destroyAuthentication(m_account);
if (!m_model->currentUser()->isNoPasswordLogin()) {
Expand Down Expand Up @@ -409,6 +415,67 @@ void GreeterWorker::initConnections()
connect(&SignalBridge::ref(), &SignalBridge::requestSendExtraInfo, this, &GreeterWorker::sendExtraInfo);
}

#ifdef ENABLE_DSS_SNIPE
void GreeterWorker::watchSessionActivity()
{
if (!m_login1SessionSelf || !m_login1SessionSelf->isValid())
return;

if (!QDBusConnection::systemBus().connect(m_login1SessionSelf->service(), m_login1SessionSelf->path(),
QStringLiteral("org.freedesktop.DBus.Properties"), QStringLiteral("PropertiesChanged"),
this, SLOT(sessionPropertiesChanged(QString,QVariantMap,QStringList)))) {
qCWarning(DDE_SHELL) << "Failed to watch Greeter session activity" << m_login1SessionSelf->path();
return;
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
}

readSessionActivity();
}

void GreeterWorker::readSessionActivity()
{
// Read the current value directly. The asynchronous session proxy can emit
// ActiveChanged when a property read completes as well as on D-Bus changes.
auto request = QDBusMessage::createMethodCall(m_login1SessionSelf->service(), m_login1SessionSelf->path(),
QStringLiteral("org.freedesktop.DBus.Properties"), QStringLiteral("Get"));
request << QStringLiteral("org.freedesktop.login1.Session") << QStringLiteral("Active");
const QDBusReply<QDBusVariant> reply = QDBusConnection::systemBus().call(request);
if (reply.isValid())
updateSessionActivity(reply.value().variant().toBool());
else
qCWarning(DDE_SHELL) << "Failed to read Greeter session activity:" << reply.error();
}

void GreeterWorker::sessionPropertiesChanged(const QString &interface, const QVariantMap &changed,
const QStringList &invalidated)
{
if (interface != QStringLiteral("org.freedesktop.login1.Session"))
return;

const QString active = QStringLiteral("Active");
const auto value = changed.constFind(active);
if (value != changed.cend())
updateSessionActivity(value->toBool());
else if (invalidated.contains(active))
readSessionActivity();
}

void GreeterWorker::updateSessionActivity(bool active)
{
if (m_sessionActive == active)
return;

const bool reactivated = active && m_sessionActive == false && m_sessionWasActive;
m_sessionActive = active;
m_sessionWasActive |= active;
qCInfo(DDE_SHELL) << "Greeter login1 session active:" << active << "reactivated:" << reactivated;

if (reactivated && !m_model->userlistVisible() && getDconfigValue("loginPromptInput", false).toBool())
emit accountEntryActivated();
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
else
emit greeterActiveChanged(active);
}
#endif

void GreeterWorker::initData()
{
if (isSecurityEnhanceOpen()) {
Expand Down
18 changes: 18 additions & 0 deletions src/lightdm-deepin-greeter/greeterworker.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
using SoundThemePlayerInter = com::deepin::api::SoundThemePlayer;
#endif

#ifdef ENABLE_DSS_SNIPE
#include <optional>
#endif

class GreeterPasswordChange;

class GreeterWorker : public Auth::AuthInterface
Expand All @@ -40,8 +44,13 @@ class GreeterWorker : public Auth::AuthInterface

void switchToUser(std::shared_ptr<User> user) override;
bool isSecurityEnhanceOpen();
#ifdef ENABLE_DSS_SNIPE
void watchSessionActivity();
#endif

signals:
void accountEntryActivated();
void greeterActiveChanged(bool active);
void requestUpdateBackground(const QString &path);
void requestShowPrompt(const QString &prompt);
void requestShowMessage(const QString &message);
Expand All @@ -65,6 +74,10 @@ public slots:
void onNoPasswordLoginChanged(const QString &account, bool noPassword);

private slots:
#ifdef ENABLE_DSS_SNIPE
void sessionPropertiesChanged(const QString &interface, const QVariantMap &changed,
const QStringList &invalidated);
#endif
void onAuthStateChanged(const int type, const int state, const QString &message);
void onReceiptChanged(bool state);
void onCurrentUserChanged(const std::shared_ptr<User> &user);
Expand Down Expand Up @@ -102,6 +115,11 @@ private slots:
void updatePasswordExpiredStateBySPName(const QString &account);
#ifdef ENABLE_DSS_SNIPE
void prepareShutdownSound();
void readSessionActivity();
void updateSessionActivity(bool active);

std::optional<bool> m_sessionActive;
bool m_sessionWasActive = false;
#endif

private:
Expand Down
131 changes: 131 additions & 0 deletions src/lightdm-deepin-greeter/logincontent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#include "logintipswindow.h"
#include "sessionwidget.h"
#include "controlwidget.h"
#include "dconfig_helper.h"

#include <QDir>
#include <QProcess>
#include <QScopedValueRollback>

LoginContent::LoginContent(QWidget *parent)
: LockContent(parent)
Expand Down Expand Up @@ -53,6 +58,129 @@ void LoginContent::init(SessionBaseModel *model)
connect(m_model, &SessionBaseModel::tipsShowed, this, &LoginContent::popTipsFrame);
}

void LoginContent::onSwitchUserRequested()
{
#ifdef ENABLE_DSS_SNIPE
if (beginAccountEntry())
return;
#endif
LockContent::onSwitchUserRequested();
}

void LoginContent::setVisible(bool visible)
{
// FullScreenBackground can show the shared content again while moving it between screens.
LockContent::setVisible(visible && !accountEntryBlocksLogin());
}

bool LoginContent::usesAccountEntry() const
{
if (m_model->userlistVisible() || !m_model->findUserByName(QStringLiteral("...")))
return false;

const QString shellConfig = QStringLiteral("org.deepin.dde.session-shell");
return DConfigHelper::instance()->getConfig(shellConfig, shellConfig, {},
QStringLiteral("loginPromptInput"), false).toBool();
}

bool LoginContent::beginAccountEntry()
{
if (!m_greeterActive || m_taskProcess || m_startingAccountEntry)
return true;

if (!usesAccountEntry())
return false;

const QDir configs(QStringLiteral("/usr/share/dde-session-shell/greeters.d/account-entry.conf.d"));
if (configs.entryList({QStringLiteral("*.json")}, QDir::Files).isEmpty()) {
enterAccountInput();
emit accountEntryVisibilityChanged();
} else {
startAccountEntryTask(QStringLiteral("/usr/share/dde-session-shell/greeters.d/select-account-entry-task"), true);
}
return true;
}

void LoginContent::enterAccountInput()
{
const auto accountEntryUser = m_model->findUserByName(QStringLiteral("..."));
if (!accountEntryUser)
return;

QScopedValueRollback<bool> starting(m_startingAccountEntry, true);
if (m_model->currentUser() != accountEntryUser)
emit requestSwitchToUser(accountEntryUser);
m_model->setCurrentModeState(SessionBaseModel::ModeStatus::PasswordMode);
if (m_showTipsWidget && m_loginTipsWindow->isValid())
pushTipsFrame();
else
pushPasswordFrame();
}

void LoginContent::reactivateAccountEntry()
{
m_greeterActive = true;
if (m_taskProcess)
m_accountEntryPending = true;
else if (beginAccountEntry())
return;
emit accountEntryVisibilityChanged();
}

void LoginContent::setGreeterActive(bool active)
{
m_greeterActive = active;
if (!active) {
m_accountEntryPending = false;
if (m_taskProcess && m_taskProcess->processChannelMode() == QProcess::ForwardedChannels)
m_taskProcess->kill();
}
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
emit accountEntryVisibilityChanged();
}

void LoginContent::startAccountEntryTask(const QString &program, bool selecting)
{
auto *process = new QProcess(this);
process->setProgram(program);
process->setProcessChannelMode(selecting ? QProcess::ForwardedErrorChannel : QProcess::ForwardedChannels);
m_taskProcess = process;

const auto finish = [this, process, selecting](int code, QProcess::ExitStatus status) {
m_taskProcess = nullptr;
process->deleteLater();
if (m_greeterActive && m_accountEntryPending) {
m_accountEntryPending = false;
if (!beginAccountEntry())
emit accountEntryVisibilityChanged();
return;
} else if (m_greeterActive && selecting && status == QProcess::NormalExit && code == 0) {
const QString task = QString::fromUtf8(process->readAllStandardOutput()).trimmed();
if (QDir::isAbsolutePath(task)) {
startAccountEntryTask(task, false);
return;
}
}

if (m_greeterActive)
enterAccountInput();
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
emit accountEntryVisibilityChanged();
};
connect(process, &QProcess::finished, this, [process, selecting, finish](int code, QProcess::ExitStatus status) {
if (status != QProcess::NormalExit || code > (selecting ? 1 : 0))
qCWarning(DDE_SHELL) << "Account entry process exited" << process->program() << status << code;
finish(code, status);
});
connect(process, &QProcess::errorOccurred, this, [process, finish](QProcess::ProcessError error) {
if (error == QProcess::FailedToStart) {
qCWarning(DDE_SHELL) << "Failed to start account entry process:" << process->program() << process->errorString();
finish(-1, QProcess::CrashExit);
}
});

emit accountEntryVisibilityChanged();
process->start();
}

void LoginContent::onCurrentUserChanged(std::shared_ptr<User> user)
{
if (!user.get())
Expand All @@ -64,6 +192,9 @@ void LoginContent::onCurrentUserChanged(std::shared_ptr<User> user)

void LoginContent::onStatusChanged(SessionBaseModel::ModeStatus status)
{
if (m_taskProcess)
return;

qCInfo(DDE_SHELL) << "Status changed, status" << status << ", current status: " << m_currentModeStatus;
switch (status) {
case SessionBaseModel::ModeStatus::SessionMode:
Expand Down
23 changes: 22 additions & 1 deletion src/lightdm-deepin-greeter/logincontent.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2011 - 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2011 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand All @@ -8,6 +8,7 @@
#include "lockcontent.h"
#include "userswiththesamename.h"

class QProcess;
class SessionWidget;
class LoginTipsWindow;

Expand All @@ -21,12 +22,32 @@ class LoginContent : public LockContent
void init(SessionBaseModel *model);
void onCurrentUserChanged(std::shared_ptr<User> user) override;
void onStatusChanged(SessionBaseModel::ModeStatus status) override;
void reactivateAccountEntry();
void setVisible(bool visible) override;
bool usesAccountEntry() const;
void setGreeterActive(bool active);
bool accountEntryBlocksLogin() const { return m_taskProcess || m_startingAccountEntry || !m_greeterActive; }
void pushSessionFrame();
void pushTipsFrame();
void popTipsFrame();
void showUsersWithTheSameName(const QString &nativeUserName, const QString &doMainAccountDetail);

signals:
void accountEntryVisibilityChanged();

protected:
void onSwitchUserRequested() override;

private:
bool beginAccountEntry();
void enterAccountInput();
void startAccountEntryTask(const QString &program, bool selecting);

QProcess *m_taskProcess = nullptr;
bool m_greeterActive = true;
bool m_accountEntryPending = false;
bool m_startingAccountEntry = false;

SessionWidget *m_sessionFrame;
LoginTipsWindow *m_loginTipsWindow;
bool m_showTipsWidget = true;
Expand Down
Loading
Loading