Skip to content

Commit 31389be

Browse files
committed
apply startup auth in maindwindow
1 parent f6882d4 commit 31389be

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/gui/mainwindow.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "settings_widget.h"
77
#include "../utils/logger.h"
88
#include "../core/alpm_wrapper.h"
9+
#include "../core/auth_manager.h"
910
#include <QMenuBar>
1011
#include <QMenu>
1112
#include <QAction>
@@ -19,10 +20,21 @@ MainWindow::MainWindow(QWidget* parent)
1920

2021
// Initialize ALPM before creating widgets that might need it
2122
if (!AlpmWrapper::instance().initialize()) {
22-
QMessageBox::critical(this, "Error",
23+
QMessageBox::critical(this, "Error",
2324
"Failed to initialize package manager. Please check your system configuration.");
2425
Logger::error("Failed to initialize ALPM in MainWindow");
2526
}
27+
28+
// Authenticate once at startup for all privileged operations
29+
if (!AuthManager::instance().authenticate(this)) {
30+
Logger::error("Authentication failed or cancelled");
31+
QMessageBox::critical(this, "Authentication Required",
32+
"This application requires administrator privileges to manage packages.\n"
33+
"The application will now exit.");
34+
// Schedule exit after event loop starts
35+
QMetaObject::invokeMethod(qApp, &QApplication::quit, Qt::QueuedConnection);
36+
return;
37+
}
2638

2739
setupUi();
2840
loadStyleSheet();

0 commit comments

Comments
 (0)