Skip to content

Commit e52d9ed

Browse files
committed
#3371 webappclientservice: fix sending of correct clipboard content
Signed-off-by: Patrizio Bekerle <[email protected]>
1 parent 88ace03 commit e52d9ed

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
(for [#3371](https://github.com/pbek/QOwnNotes/issues/3371))
88
- You need to set the same security token in both instances to be able to
99
send clipboard content
10+
- The tray action will also bring the app to focus, because it can happen that
11+
the app needs to get focus first before the correct clipboard content can be read
1012
- A tooltip for the tray icon was added
1113
- A crash on wayland was fixed when a global shortcut was set
1214

src/mainwindow.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6303,6 +6303,9 @@ void MainWindow::showWindow() {
63036303
setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
63046304
raise(); // for MacOS
63056305

6306+
// Really show the window, by bringing it to focus
6307+
setFocus();
6308+
63066309
// parse the current note for the navigation panel in case it wasn't parsed
63076310
// while the mainwindow was hidden (https://github.com/pbek/QOwnNotes/issues/2110)
63086311
startNavigationParser();
@@ -12484,9 +12487,16 @@ void MainWindow::on_actionManage_Nextcloud_Deck_cards_triggered() {
1248412487
}
1248512488

1248612489
void MainWindow::on_actionSend_clipboard_triggered() {
12487-
if (_webAppClientService->sendClipboard()) {
12488-
showStatusBarMessage(tr("Clipboard sent successfully"), QStringLiteral(""), 3000);
12489-
} else {
12490-
showStatusBarMessage(tr("Failed to send clipboard"), QStringLiteral("⚠️"), 5000);
12491-
}
12490+
// We need to show the window because on some systems the clipboard
12491+
// can't be accessed if the app is not focused
12492+
showWindow();
12493+
12494+
// We need a delay because otherwise the clipboard can't be properly accessed on some systems
12495+
QTimer::singleShot(1000, this, [this] {
12496+
if (_webAppClientService->sendClipboard()) {
12497+
showStatusBarMessage(tr("Clipboard sent successfully"), QStringLiteral(""), 3000);
12498+
} else {
12499+
showStatusBarMessage(tr("Failed to send clipboard"), QStringLiteral("⚠️"), 5000);
12500+
}
12501+
});
1249212502
}

src/services/webappclientservice.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ bool WebAppClientService::keepClipboard() {
9090
} else if (mimeData->hasText()) {
9191
_clipboardMimeType = "text/plain";
9292
_clipboardContent = clipboard->text();
93+
// qDebug() << __func__ << "_clipboardContent: " << _clipboardContent;
9394
} else if (mimeData->hasHtml()) {
9495
_clipboardMimeType = "text/html";
9596
_clipboardContent = clipboard->text();

0 commit comments

Comments
 (0)