Skip to content

Commit

Permalink
Check clipboard wnen app is activated on Mac
Browse files Browse the repository at this point in the history
  • Loading branch information
deXol committed May 9, 2024
1 parent 3a49c75 commit 93ca4fc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/CredentialsManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,14 @@ void CredentialsManagement::saveChanges()
emit wantSaveMemMode();
}

void CredentialsManagement::onMainWindowActivated()
{
if (wsClient->get_memMgmtMode() && wsClient->isMPBLE())
{
onClipboardDataChanged();
}
}

void CredentialsManagement::keyPressEvent(QKeyEvent *event)
{
QWidget::keyPressEvent(event);
Expand Down Expand Up @@ -1995,6 +2003,17 @@ void CredentialsManagement::onClipboardDataChanged()
QClipboard *clipboard = QGuiApplication::clipboard();

QImage clipImage = clipboard->image();
static QImage lastImage;
if (clipImage == lastImage)
{
// Only process image from clipboard one time.
return;
}
else
{
lastImage = clipImage;
}

if (!clipImage.isNull() && !m_processingQRImage)
{
m_processingQRImage = true;
Expand Down
1 change: 1 addition & 0 deletions src/CredentialsManagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class CredentialsManagement : public QWidget
public slots:
bool confirmDiscardUneditedCredentialChanges(const QModelIndex &proxyIndex = {});
void saveChanges();
void onMainWindowActivated();

protected:
virtual void keyPressEvent(QKeyEvent *event) override;
Expand Down
14 changes: 14 additions & 0 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ MainWindow::MainWindow(WSClient *client, DbMasterController *mc, QWidget *parent
}
});

#ifdef Q_OS_MAC
// For Mac clipboard changed event is not working when app is in background,
// so need to check the clipboard content when window is activated.
connect(this, &MainWindow::mainWindowActivated,
ui->widgetCredentials, &CredentialsManagement::onMainWindowActivated);
#endif

ui->pushButtonExportFile->setStyleSheet(CSS_BLUE_BUTTON);
ui->pushButtonImportFile->setStyleSheet(CSS_BLUE_BUTTON);
ui->pushButtonSettingsReset->setStyleSheet(CSS_BLUE_BUTTON);
Expand Down Expand Up @@ -805,6 +812,13 @@ void MainWindow::changeEvent(QEvent *event)
ui->retranslateUi(this);
retranslateUi();
}
if (event->type() == QEvent::ActivationChange)
{
if (isActiveWindow())
{
emit mainWindowActivated();
}
}
QMainWindow::changeEvent(event);
}

Expand Down
1 change: 1 addition & 0 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class MainWindow : public QMainWindow
void windowCloseRequested();
void iconChangeRequested();
void saveMMMChanges();
void mainWindowActivated();

public slots:
void wantImportDatabase();
Expand Down

0 comments on commit 93ca4fc

Please sign in to comment.