mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-07-26 00:05:34 -04:00
macOS: Fix hiding window after using database unlock dialog
* Properly hide window after Browser Integration and Auto-Type unlock, if needed * Fix #4904
This commit is contained in:
parent
8ebd1ab4f4
commit
9b63e6a289
4 changed files with 59 additions and 9 deletions
|
@ -35,6 +35,7 @@
|
||||||
#include "core/ListDeleter.h"
|
#include "core/ListDeleter.h"
|
||||||
#include "core/Resources.h"
|
#include "core/Resources.h"
|
||||||
#include "core/Tools.h"
|
#include "core/Tools.h"
|
||||||
|
#include "gui/MainWindow.h"
|
||||||
#include "gui/MessageBox.h"
|
#include "gui/MessageBox.h"
|
||||||
|
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
|
@ -51,6 +52,7 @@ AutoType::AutoType(QObject* parent, bool test)
|
||||||
, m_pluginLoader(new QPluginLoader(this))
|
, m_pluginLoader(new QPluginLoader(this))
|
||||||
, m_plugin(nullptr)
|
, m_plugin(nullptr)
|
||||||
, m_executor(nullptr)
|
, m_executor(nullptr)
|
||||||
|
, m_windowState(WindowState::Normal)
|
||||||
, m_windowForGlobal(0)
|
, m_windowForGlobal(0)
|
||||||
{
|
{
|
||||||
// prevent crash when the plugin has unresolved symbols
|
// prevent crash when the plugin has unresolved symbols
|
||||||
|
@ -227,6 +229,7 @@ void AutoType::executeAutoTypeActions(const Entry* entry, QWidget* hideWindow, c
|
||||||
"KeePassXC."));
|
"KeePassXC."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
macUtils()->raiseLastActiveWindow();
|
macUtils()->raiseLastActiveWindow();
|
||||||
m_plugin->hideOwnWindow();
|
m_plugin->hideOwnWindow();
|
||||||
#else
|
#else
|
||||||
|
@ -286,6 +289,18 @@ void AutoType::startGlobalAutoType()
|
||||||
{
|
{
|
||||||
m_windowForGlobal = m_plugin->activeWindow();
|
m_windowForGlobal = m_plugin->activeWindow();
|
||||||
m_windowTitleForGlobal = m_plugin->activeWindowTitle();
|
m_windowTitleForGlobal = m_plugin->activeWindowTitle();
|
||||||
|
#ifdef Q_OS_MACOS
|
||||||
|
m_windowState = WindowState::Normal;
|
||||||
|
if (getMainWindow()) {
|
||||||
|
if (getMainWindow()->isMinimized()) {
|
||||||
|
m_windowState = WindowState::Minimized;
|
||||||
|
}
|
||||||
|
if (getMainWindow()->isHidden()) {
|
||||||
|
m_windowState = WindowState::Hidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
emit globalAutoTypeTriggered();
|
emit globalAutoTypeTriggered();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,9 +347,12 @@ void AutoType::performGlobalAutoType(const QList<QSharedPointer<Database>>& dbLi
|
||||||
.append(m_windowTitleForGlobal));
|
.append(m_windowTitleForGlobal));
|
||||||
msgBox->setIcon(QMessageBox::Information);
|
msgBox->setIcon(QMessageBox::Information);
|
||||||
msgBox->setStandardButtons(QMessageBox::Ok);
|
msgBox->setStandardButtons(QMessageBox::Ok);
|
||||||
msgBox->show();
|
#ifdef Q_OS_MACOS
|
||||||
msgBox->raise();
|
m_plugin->raiseOwnWindow();
|
||||||
msgBox->activateWindow();
|
Tools::wait(200);
|
||||||
|
#endif
|
||||||
|
msgBox->exec();
|
||||||
|
restoreWindowState();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_inGlobalAutoTypeDialog.unlock();
|
m_inGlobalAutoTypeDialog.unlock();
|
||||||
|
@ -361,8 +379,23 @@ void AutoType::performGlobalAutoType(const QList<QSharedPointer<Database>>& dbLi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AutoType::restoreWindowState()
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
if (getMainWindow()) {
|
||||||
|
if (m_windowState == WindowState::Minimized) {
|
||||||
|
getMainWindow()->showMinimized();
|
||||||
|
} else if (m_windowState == WindowState::Hidden) {
|
||||||
|
getMainWindow()->hideWindow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void AutoType::performAutoTypeFromGlobal(AutoTypeMatch match)
|
void AutoType::performAutoTypeFromGlobal(AutoTypeMatch match)
|
||||||
{
|
{
|
||||||
|
restoreWindowState();
|
||||||
|
|
||||||
m_plugin->raiseWindow(m_windowForGlobal);
|
m_plugin->raiseWindow(m_windowForGlobal);
|
||||||
executeAutoTypeActions(match.entry, nullptr, match.sequence, m_windowForGlobal);
|
executeAutoTypeActions(match.entry, nullptr, match.sequence, m_windowForGlobal);
|
||||||
|
|
||||||
|
@ -380,6 +413,7 @@ void AutoType::autoTypeRejectedFromGlobal()
|
||||||
m_windowForGlobal = 0;
|
m_windowForGlobal = 0;
|
||||||
m_windowTitleForGlobal.clear();
|
m_windowTitleForGlobal.clear();
|
||||||
|
|
||||||
|
restoreWindowState();
|
||||||
emit autotypeRejected();
|
emit autotypeRejected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,13 @@ private slots:
|
||||||
void unloadPlugin();
|
void unloadPlugin();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
enum WindowState
|
||||||
|
{
|
||||||
|
Normal,
|
||||||
|
Minimized,
|
||||||
|
Hidden
|
||||||
|
};
|
||||||
|
|
||||||
explicit AutoType(QObject* parent = nullptr, bool test = false);
|
explicit AutoType(QObject* parent = nullptr, bool test = false);
|
||||||
~AutoType() override;
|
~AutoType() override;
|
||||||
void loadPlugin(const QString& pluginPath);
|
void loadPlugin(const QString& pluginPath);
|
||||||
|
@ -86,6 +93,7 @@ private:
|
||||||
bool windowMatchesTitle(const QString& windowTitle, const QString& resolvedTitle);
|
bool windowMatchesTitle(const QString& windowTitle, const QString& resolvedTitle);
|
||||||
bool windowMatchesUrl(const QString& windowTitle, const QString& resolvedUrl);
|
bool windowMatchesUrl(const QString& windowTitle, const QString& resolvedUrl);
|
||||||
bool windowMatches(const QString& windowTitle, const QString& windowPattern);
|
bool windowMatches(const QString& windowTitle, const QString& windowPattern);
|
||||||
|
void restoreWindowState();
|
||||||
|
|
||||||
QMutex m_inAutoType;
|
QMutex m_inAutoType;
|
||||||
QMutex m_inGlobalAutoTypeDialog;
|
QMutex m_inGlobalAutoTypeDialog;
|
||||||
|
@ -98,6 +106,7 @@ private:
|
||||||
static AutoType* m_instance;
|
static AutoType* m_instance;
|
||||||
|
|
||||||
QString m_windowTitleForGlobal;
|
QString m_windowTitleForGlobal;
|
||||||
|
WindowState m_windowState;
|
||||||
WId m_windowForGlobal;
|
WId m_windowForGlobal;
|
||||||
|
|
||||||
Q_DISABLE_COPY(AutoType)
|
Q_DISABLE_COPY(AutoType)
|
||||||
|
|
|
@ -64,6 +64,7 @@ BrowserService::BrowserService()
|
||||||
: QObject()
|
: QObject()
|
||||||
, m_browserHost(new BrowserHost)
|
, m_browserHost(new BrowserHost)
|
||||||
, m_dialogActive(false)
|
, m_dialogActive(false)
|
||||||
|
, m_bringToFrontRequested(false)
|
||||||
, m_prevWindowState(WindowState::Normal)
|
, m_prevWindowState(WindowState::Normal)
|
||||||
, m_keepassBrowserUUID(Tools::hexToUuid("de887cc3036343b8974b5911b8816224"))
|
, m_keepassBrowserUUID(Tools::hexToUuid("de887cc3036343b8974b5911b8816224"))
|
||||||
{
|
{
|
||||||
|
@ -109,6 +110,8 @@ bool BrowserService::openDatabase(bool triggerUnlock)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (triggerUnlock) {
|
if (triggerUnlock) {
|
||||||
|
m_bringToFrontRequested = true;
|
||||||
|
updateWindowState();
|
||||||
emit requestUnlock();
|
emit requestUnlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -751,7 +754,7 @@ QList<Entry*> BrowserService::confirmEntries(QList<Entry*>& pwEntriesToConfirm,
|
||||||
}
|
}
|
||||||
|
|
||||||
m_dialogActive = true;
|
m_dialogActive = true;
|
||||||
bool wasAppActive = qApp->activeWindow() == getMainWindow()->window();
|
updateWindowState();
|
||||||
BrowserAccessControlDialog accessControlDialog;
|
BrowserAccessControlDialog accessControlDialog;
|
||||||
|
|
||||||
connect(m_currentDatabaseWidget, SIGNAL(databaseLocked()), &accessControlDialog, SLOT(reject()));
|
connect(m_currentDatabaseWidget, SIGNAL(databaseLocked()), &accessControlDialog, SLOT(reject()));
|
||||||
|
@ -796,11 +799,7 @@ QList<Entry*> BrowserService::confirmEntries(QList<Entry*>& pwEntriesToConfirm,
|
||||||
#ifdef Q_OS_MAC
|
#ifdef Q_OS_MAC
|
||||||
// Re-hide the application if it wasn't visible before
|
// Re-hide the application if it wasn't visible before
|
||||||
// only affects macOS because dialogs force the main window to show
|
// only affects macOS because dialogs force the main window to show
|
||||||
if (!wasAppActive) {
|
|
||||||
hideWindow();
|
hideWindow();
|
||||||
}
|
|
||||||
#else
|
|
||||||
Q_UNUSED(wasAppActive);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_dialogActive = false;
|
m_dialogActive = false;
|
||||||
|
@ -1247,6 +1246,13 @@ void BrowserService::databaseLocked(DatabaseWidget* dbWidget)
|
||||||
void BrowserService::databaseUnlocked(DatabaseWidget* dbWidget)
|
void BrowserService::databaseUnlocked(DatabaseWidget* dbWidget)
|
||||||
{
|
{
|
||||||
if (dbWidget) {
|
if (dbWidget) {
|
||||||
|
#ifdef Q_OS_MAC
|
||||||
|
if (m_bringToFrontRequested) {
|
||||||
|
m_bringToFrontRequested = false;
|
||||||
|
hideWindow();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
QJsonObject msg;
|
QJsonObject msg;
|
||||||
msg["action"] = QString("database-unlocked");
|
msg["action"] = QString("database-unlocked");
|
||||||
m_browserHost->sendClientMessage(msg);
|
m_browserHost->sendClientMessage(msg);
|
||||||
|
|
|
@ -154,6 +154,7 @@ private:
|
||||||
QHash<QString, QSharedPointer<BrowserAction>> m_browserClients;
|
QHash<QString, QSharedPointer<BrowserAction>> m_browserClients;
|
||||||
|
|
||||||
bool m_dialogActive;
|
bool m_dialogActive;
|
||||||
|
bool m_bringToFrontRequested;
|
||||||
WindowState m_prevWindowState;
|
WindowState m_prevWindowState;
|
||||||
QUuid m_keepassBrowserUUID;
|
QUuid m_keepassBrowserUUID;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue