Skip to content

Linux + iPhone Continuity / iMessage / SMS

feat: otp "Copy Code" button on notifications

Zack Bartelbf36bdcc12dd
diff --git a/po/cs.po b/po/cs.po
index 5d9b937..31ce2b7 100644
--- a/po/cs.po
+++ b/po/cs.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: tether\n"
"Report-Msgid-Bugs-To: [email protected]\n"
-"POT-Creation-Date: 2026-08-27 20:41-0700\n"
+"POT-Creation-Date: 2026-08-28 16:06-0700\n"
"PO-Revision-Date: 2026-08-23\n"
"Last-Translator: Tether project\n"
"Language-Team: Czech\n"
@@ -882,6 +882,11 @@ msgstr "Otevřít složku"
msgid "Reply"
msgstr "Odpovědět"
+#: src/daemon/notification.cpp
+#, fuzzy
+msgid "Copy Code"
+msgstr "Kopírovat příkazy"
+
#: src/gtk/daemon_client.cpp
msgid "Daemon Offline"
msgstr "Démon je offline"
diff --git a/po/de.po b/po/de.po
index 9cb5fd2..52ac45d 100644
--- a/po/de.po
+++ b/po/de.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: tether\n"
"Report-Msgid-Bugs-To: [email protected]\n"
-"POT-Creation-Date: 2026-08-27 20:41-0700\n"
+"POT-Creation-Date: 2026-08-28 16:06-0700\n"
"PO-Revision-Date: 2026-08-22\n"
"Last-Translator: Tether project\n"
"Language-Team: German\n"
@@ -901,6 +901,11 @@ msgstr "Ordner öffnen"
msgid "Reply"
msgstr "Antworten"
+#: src/daemon/notification.cpp
+#, fuzzy
+msgid "Copy Code"
+msgstr "Befehle kopieren"
+
#: src/gtk/daemon_client.cpp
msgid "Daemon Offline"
msgstr "Daemon offline"
diff --git a/po/es.po b/po/es.po
index a6f5660..28188a8 100644
--- a/po/es.po
+++ b/po/es.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: tether\n"
"Report-Msgid-Bugs-To: [email protected]\n"
-"POT-Creation-Date: 2026-08-27 20:41-0700\n"
+"POT-Creation-Date: 2026-08-28 16:06-0700\n"
"PO-Revision-Date: 2026-08-22\n"
"Last-Translator: Tether project\n"
"Language-Team: Spanish\n"
@@ -894,6 +894,11 @@ msgstr "Abrir carpeta"
msgid "Reply"
msgstr "Responder"
+#: src/daemon/notification.cpp
+#, fuzzy
+msgid "Copy Code"
+msgstr "Copiar comandos"
+
#: src/gtk/daemon_client.cpp
msgid "Daemon Offline"
msgstr "Daemon desconectado"
diff --git a/po/fr.po b/po/fr.po
index 638bb02..f189976 100644
--- a/po/fr.po
+++ b/po/fr.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: tether\n"
"Report-Msgid-Bugs-To: [email protected]\n"
-"POT-Creation-Date: 2026-08-27 20:41-0700\n"
+"POT-Creation-Date: 2026-08-28 16:06-0700\n"
"PO-Revision-Date: 2026-08-22\n"
"Last-Translator: Tether project\n"
"Language-Team: French\n"
@@ -899,6 +899,11 @@ msgstr "Ouvrir le dossier"
msgid "Reply"
msgstr "Répondre"
+#: src/daemon/notification.cpp
+#, fuzzy
+msgid "Copy Code"
+msgstr "Copier les commandes"
+
#: src/gtk/daemon_client.cpp
msgid "Daemon Offline"
msgstr "Démon hors ligne"
diff --git a/po/it.po b/po/it.po
index 0b3d047..525be2e 100644
--- a/po/it.po
+++ b/po/it.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: tether\n"
"Report-Msgid-Bugs-To: [email protected]\n"
-"POT-Creation-Date: 2026-08-27 20:41-0700\n"
+"POT-Creation-Date: 2026-08-28 16:06-0700\n"
"PO-Revision-Date: 2026-08-23\n"
"Last-Translator: Tether project\n"
"Language-Team: Italian\n"
@@ -893,6 +893,11 @@ msgstr "Apri cartella"
msgid "Reply"
msgstr "Rispondi"
+#: src/daemon/notification.cpp
+#, fuzzy
+msgid "Copy Code"
+msgstr "Copia i comandi"
+
#: src/gtk/daemon_client.cpp
msgid "Daemon Offline"
msgstr "Daemon offline"
diff --git a/po/ja.po b/po/ja.po
index bb39ad4..ef0c2d2 100644
--- a/po/ja.po
+++ b/po/ja.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: tether\n"
"Report-Msgid-Bugs-To: [email protected]\n"
-"POT-Creation-Date: 2026-08-27 20:41-0700\n"
+"POT-Creation-Date: 2026-08-28 16:06-0700\n"
"PO-Revision-Date: 2026-08-23\n"
"Last-Translator: Tether project\n"
"Language-Team: Japanese\n"
@@ -865,6 +865,11 @@ msgstr "フォルダを開く"
msgid "Reply"
msgstr "返信"
+#: src/daemon/notification.cpp
+#, fuzzy
+msgid "Copy Code"
+msgstr "コマンドをコピー"
+
#: src/gtk/daemon_client.cpp
msgid "Daemon Offline"
msgstr "デーモンはオフライン"
diff --git a/po/ko.po b/po/ko.po
index 00674d5..ccb6bf7 100644
--- a/po/ko.po
+++ b/po/ko.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: tether\n"
"Report-Msgid-Bugs-To: [email protected]\n"
-"POT-Creation-Date: 2026-08-27 20:41-0700\n"
+"POT-Creation-Date: 2026-08-28 16:06-0700\n"
"PO-Revision-Date: 2026-08-23\n"
"Last-Translator: Tether project\n"
"Language-Team: Korean\n"
@@ -859,6 +859,11 @@ msgstr "폴더 열기"
msgid "Reply"
msgstr "답장"
+#: src/daemon/notification.cpp
+#, fuzzy
+msgid "Copy Code"
+msgstr "명령 복사"
+
#: src/gtk/daemon_client.cpp
msgid "Daemon Offline"
msgstr "데몬 오프라인"
diff --git a/po/nl.po b/po/nl.po
index 2e9767a..1058be5 100644
--- a/po/nl.po
+++ b/po/nl.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: tether\n"
"Report-Msgid-Bugs-To: [email protected]\n"
-"POT-Creation-Date: 2026-08-27 20:41-0700\n"
+"POT-Creation-Date: 2026-08-28 16:06-0700\n"
"PO-Revision-Date: 2026-08-23\n"
"Last-Translator: Tether project\n"
"Language-Team: Dutch\n"
@@ -888,6 +888,11 @@ msgstr "Map openen"
msgid "Reply"
msgstr "Antwoorden"
+#: src/daemon/notification.cpp
+#, fuzzy
+msgid "Copy Code"
+msgstr "Opdrachten kopiëren"
+
#: src/gtk/daemon_client.cpp
msgid "Daemon Offline"
msgstr "Daemon offline"
diff --git a/po/pl.po b/po/pl.po
index 3c693ad..0be3e51 100644
--- a/po/pl.po
+++ b/po/pl.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: tether\n"
"Report-Msgid-Bugs-To: [email protected]\n"
-"POT-Creation-Date: 2026-08-27 20:41-0700\n"
+"POT-Creation-Date: 2026-08-28 16:06-0700\n"
"PO-Revision-Date: 2026-08-23\n"
"Last-Translator: Tether project\n"
"Language-Team: Polish\n"
@@ -891,6 +891,11 @@ msgstr "Otwórz folder"
msgid "Reply"
msgstr "Odpowiedz"
+#: src/daemon/notification.cpp
+#, fuzzy
+msgid "Copy Code"
+msgstr "Kopiuj polecenia"
+
#: src/gtk/daemon_client.cpp
msgid "Daemon Offline"
msgstr "Demon offline"
diff --git a/po/pt_BR.po b/po/pt_BR.po
index 57fec9a..61af4ce 100644
--- a/po/pt_BR.po
+++ b/po/pt_BR.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: tether\n"
"Report-Msgid-Bugs-To: [email protected]\n"
-"POT-Creation-Date: 2026-08-27 20:41-0700\n"
+"POT-Creation-Date: 2026-08-28 16:06-0700\n"
"PO-Revision-Date: 2026-08-23\n"
"Last-Translator: Tether project\n"
"Language-Team: Brazilian Portuguese\n"
@@ -888,6 +888,11 @@ msgstr "Abrir pasta"
msgid "Reply"
msgstr "Responder"
+#: src/daemon/notification.cpp
+#, fuzzy
+msgid "Copy Code"
+msgstr "Copiar comandos"
+
#: src/gtk/daemon_client.cpp
msgid "Daemon Offline"
msgstr "Daemon offline"
diff --git a/po/ru.po b/po/ru.po
index 6a31148..951c185 100644
--- a/po/ru.po
+++ b/po/ru.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: tether\n"
"Report-Msgid-Bugs-To: [email protected]\n"
-"POT-Creation-Date: 2026-08-27 20:41-0700\n"
+"POT-Creation-Date: 2026-08-28 16:06-0700\n"
"PO-Revision-Date: 2026-08-23\n"
"Last-Translator: Tether project\n"
"Language-Team: Russian\n"
@@ -890,6 +890,11 @@ msgstr "Открыть папку"
msgid "Reply"
msgstr "Ответить"
+#: src/daemon/notification.cpp
+#, fuzzy
+msgid "Copy Code"
+msgstr "Скопировать команды"
+
#: src/gtk/daemon_client.cpp
msgid "Daemon Offline"
msgstr "Демон не в сети"
diff --git a/po/sv.po b/po/sv.po
index 2ac2235..3bc4709 100644
--- a/po/sv.po
+++ b/po/sv.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: tether\n"
"Report-Msgid-Bugs-To: [email protected]\n"
-"POT-Creation-Date: 2026-08-27 20:41-0700\n"
+"POT-Creation-Date: 2026-08-28 16:06-0700\n"
"PO-Revision-Date: 2026-08-23\n"
"Last-Translator: Tether project\n"
"Language-Team: Swedish\n"
@@ -877,6 +877,11 @@ msgstr "Öppna mapp"
msgid "Reply"
msgstr "Svara"
+#: src/daemon/notification.cpp
+#, fuzzy
+msgid "Copy Code"
+msgstr "Kopiera kommandon"
+
#: src/gtk/daemon_client.cpp
msgid "Daemon Offline"
msgstr "Demonen är offline"
diff --git a/po/tether.pot b/po/tether.pot
index 4d51d3c..1a786df 100644
--- a/po/tether.pot
+++ b/po/tether.pot
@@ -6,9 +6,9 @@
#, fuzzy
msgid ""
msgstr ""
-"Project-Id-Version: tether 0.2.14\n"
+"Project-Id-Version: tether 0.2.15\n"
"Report-Msgid-Bugs-To: [email protected]\n"
-"POT-Creation-Date: 2026-08-27 20:41-0700\n"
+"POT-Creation-Date: 2026-08-28 16:06-0700\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -791,6 +791,10 @@ msgstr ""
msgid "Reply"
msgstr ""
+#: src/daemon/notification.cpp
+msgid "Copy Code"
+msgstr ""
+
#: src/gtk/daemon_client.cpp
msgid "Daemon Offline"
msgstr ""
diff --git a/po/tr.po b/po/tr.po
index fc1e1bd..2a2934e 100644
--- a/po/tr.po
+++ b/po/tr.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: tether\n"
"Report-Msgid-Bugs-To: [email protected]\n"
-"POT-Creation-Date: 2026-08-27 20:41-0700\n"
+"POT-Creation-Date: 2026-08-28 16:06-0700\n"
"PO-Revision-Date: 2026-08-23\n"
"Last-Translator: Tether project\n"
"Language-Team: Turkish\n"
@@ -876,6 +876,11 @@ msgstr "Klasörü aç"
msgid "Reply"
msgstr "Yanıtla"
+#: src/daemon/notification.cpp
+#, fuzzy
+msgid "Copy Code"
+msgstr "Komutları kopyala"
+
#: src/gtk/daemon_client.cpp
msgid "Daemon Offline"
msgstr "Arka plan hizmeti çevrimdışı"
diff --git a/po/uk.po b/po/uk.po
index b2b38a4..2203b8d 100644
--- a/po/uk.po
+++ b/po/uk.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: tether\n"
"Report-Msgid-Bugs-To: [email protected]\n"
-"POT-Creation-Date: 2026-08-27 20:41-0700\n"
+"POT-Creation-Date: 2026-08-28 16:06-0700\n"
"PO-Revision-Date: 2026-08-23\n"
"Last-Translator: Tether project\n"
"Language-Team: Ukrainian\n"
@@ -887,6 +887,11 @@ msgstr "Відкрити теку"
msgid "Reply"
msgstr "Відповісти"
+#: src/daemon/notification.cpp
+#, fuzzy
+msgid "Copy Code"
+msgstr "Скопіювати команди"
+
#: src/gtk/daemon_client.cpp
msgid "Daemon Offline"
msgstr "Демон не в мережі"
diff --git a/po/zh_CN.po b/po/zh_CN.po
index 0f168c1..f0ae8e4 100644
--- a/po/zh_CN.po
+++ b/po/zh_CN.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: tether\n"
"Report-Msgid-Bugs-To: [email protected]\n"
-"POT-Creation-Date: 2026-08-27 20:41-0700\n"
+"POT-Creation-Date: 2026-08-28 16:06-0700\n"
"PO-Revision-Date: 2026-08-23\n"
"Last-Translator: Tether project\n"
"Language-Team: Simplified Chinese\n"
@@ -838,6 +838,11 @@ msgstr "打开文件夹"
msgid "Reply"
msgstr "回复"
+#: src/daemon/notification.cpp
+#, fuzzy
+msgid "Copy Code"
+msgstr "复制命令"
+
#: src/gtk/daemon_client.cpp
msgid "Daemon Offline"
msgstr "守护进程离线"
diff --git a/src/core/include/tether/event_loop.hpp b/src/core/include/tether/event_loop.hpp
index 75c0821..6f8d164 100644
--- a/src/core/include/tether/event_loop.hpp
+++ b/src/core/include/tether/event_loop.hpp
@@ -3,6 +3,8 @@
#include <atomic>
#include <functional>
#include <map>
+#include <mutex>
+#include <vector>
namespace tether {
@@ -20,6 +22,10 @@ namespace tether {
// Add a file descriptor to be watched for EPOLLIN
bool addFd(int fd, Callback cb);
+ // Queue a function to run on the loop thread. The only member safe to call
+ // from another thread.
+ void post(std::function<void()> fn);
+
// Remove a file descriptor from being watched
bool removeFd(int fd);
@@ -30,9 +36,14 @@ namespace tether {
void stop();
private:
+ void drain_posts();
+
int epoll_fd_;
+ int post_fd_ = -1;
std::atomic<bool> running_;
std::map<int, Callback> callbacks_;
+ std::mutex post_mutex_;
+ std::vector<std::function<void()>> posted_;
};
} // namespace tether
diff --git a/src/core/src/event_loop.cpp b/src/core/src/event_loop.cpp
index 16bec01..705754f 100644
--- a/src/core/src/event_loop.cpp
+++ b/src/core/src/event_loop.cpp
@@ -1,6 +1,8 @@
#include "tether/event_loop.hpp"
+#include <cstdint>
#include <stdexcept>
#include <sys/epoll.h>
+#include <sys/eventfd.h>
#include <tether/log.hpp>
#include <unistd.h>
@@ -11,15 +13,53 @@ namespace tether {
if (epoll_fd_ < 0) {
throw std::runtime_error("Failed to create epoll file descriptor");
}
+
+ post_fd_ = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
+ if (post_fd_ < 0) {
+ close(epoll_fd_);
+ throw std::runtime_error("Failed to create eventfd");
+ }
+ addFd(post_fd_, [this](int) { drain_posts(); });
}
EpollEventLoop::~EpollEventLoop() {
stop();
+ if (post_fd_ >= 0) {
+ close(post_fd_);
+ }
if (epoll_fd_ >= 0) {
close(epoll_fd_);
}
}
+ void EpollEventLoop::post(std::function<void()> fn) {
+ if (!fn)
+ return;
+ {
+ std::lock_guard<std::mutex> lock(post_mutex_);
+ posted_.push_back(std::move(fn));
+ }
+ uint64_t one = 1;
+ if (write(post_fd_, &one, sizeof(one)) < 0) {
+ debug::log(ERR, "Failed to wake the event loop for a posted task");
+ }
+ }
+
+ void EpollEventLoop::drain_posts() {
+ uint64_t ticks = 0;
+ ssize_t ignored = read(post_fd_, &ticks, sizeof(ticks));
+ (void)ignored;
+
+ std::vector<std::function<void()>> batch;
+ {
+ std::lock_guard<std::mutex> lock(post_mutex_);
+ batch.swap(posted_);
+ }
+ for (auto& fn : batch) {
+ fn();
+ }
+ }
+
bool EpollEventLoop::addFd(int fd, Callback cb) {
struct epoll_event ev;
ev.events = EPOLLIN;
diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp
index aeb74be..cc16eea 100644
--- a/src/daemon/main.cpp
+++ b/src/daemon/main.cpp
@@ -140,6 +140,14 @@ int main(int argc, char** argv) {
}
tether::g_file_manager = &file_mgr;
+ notifier.set_copy_handler([&loop](const std::string& code) {
+ // libnotify dispatches actions on its own thread; the clipboard belongs to the loop.
+ loop.post([code] {
+ if (tether::g_wayland)
+ tether::g_wayland->copy_to_clipboard(code);
+ });
+ });
+
if (notifier_ready) {
int mdns_warn_fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
if (mdns_warn_fd >= 0) {
@@ -177,8 +185,11 @@ int main(int argc, char** argv) {
event["command"] = "bt_message";
tether::broadcast_local_event(event.dump(-1, ' ', false, nlohmann::json::error_handler_t::replace));
- if (!backfill && !message.outgoing)
- tether::otp_publish(tether::otp_extract(message.body));
+ std::string otp;
+ if (!backfill && !message.outgoing) {
+ otp = tether::otp_extract(message.body);
+ tether::otp_publish(otp);
+ }
// ANCS deliberately shows no popup for Messages, because MAP is the
// copy whose read state stays in sync with the phone. This is that popup.
@@ -199,7 +210,8 @@ int main(int argc, char** argv) {
message.body,
tether::bluetooth::ancs::icon_candidates(as_notification),
false,
- message.thread_key});
+ message.thread_key,
+ otp});
});
if (bluez.start()) {
tether::bluetooth::g_bluez = &bluez;
@@ -236,8 +248,9 @@ int main(int argc, char** argv) {
static_cast<int64_t>(std::time(nullptr)));
}
- tether::otp_publish(tether::otp_extract(notification.title + "\n" + notification.subtitle + "\n" +
- notification.body));
+ const std::string otp = tether::otp_extract(notification.title + "\n" + notification.subtitle +
+ "\n" + notification.body);
+ tether::otp_publish(otp);
nlohmann::json event = tether::bluetooth::ancs::to_json(notification);
event["command"] = "bt_notification";
@@ -255,7 +268,9 @@ int main(int argc, char** argv) {
title.empty() ? "iPhone" : title,
body,
tether::bluetooth::ancs::icon_candidates(notification),
- notification.silent});
+ notification.silent,
+ "",
+ otp});
},
[](uint32_t uid) {
nlohmann::json event;
diff --git a/src/daemon/notification.cpp b/src/daemon/notification.cpp
index 1b59e10..00dc22d 100644
--- a/src/daemon/notification.cpp
+++ b/src/daemon/notification.cpp
@@ -6,6 +6,7 @@
#include <glib.h>
#include <libnotify/notify.h>
+#include <functional>
#include <mutex>
#include <string>
#include <tether/log.hpp>
@@ -99,6 +100,9 @@ namespace tether {
std::string payload;
};
+ // Set once during startup, before any notification exists.
+ std::function<void(const std::string&)> g_copy_handler;
+
void free_request(gpointer data) { delete static_cast<NotificationRequest*>(data); }
void free_action_data(gpointer data) { delete static_cast<NotificationActionData*>(data); }
@@ -139,6 +143,12 @@ namespace tether {
}
}
+ void on_copy_code_action(NotifyNotification*, char*, gpointer user_data) {
+ auto* action = static_cast<NotificationActionData*>(user_data);
+ if (action && g_copy_handler)
+ g_copy_handler(action->payload);
+ }
+
void on_reply_action(NotifyNotification*, char*, gpointer user_data) {
if (auto* action = static_cast<NotificationActionData*>(user_data))
open_gui_thread(action->payload);
@@ -219,9 +229,11 @@ namespace tether {
set_identity(notification, spec->app_name);
notify_notification_set_urgency(notification, spec->quiet ? NOTIFY_URGENCY_LOW : NOTIFY_URGENCY_NORMAL);
- const bool has_actions = !spec->reply_thread.empty();
- if (has_actions) {
+ const bool has_actions = !spec->reply_thread.empty() || !spec->otp_code.empty();
+ if (has_actions)
g_signal_connect(notification, "closed", G_CALLBACK(on_notification_closed), nullptr);
+
+ if (!spec->reply_thread.empty()) {
notify_notification_add_action(notification,
"default",
"default",
@@ -236,6 +248,15 @@ namespace tether {
free_action_data);
}
+ if (!spec->otp_code.empty()) {
+ notify_notification_add_action(notification,
+ "copy-code",
+ _("Copy Code"),
+ on_copy_code_action,
+ new NotificationActionData{spec->otp_code},
+ free_action_data);
+ }
+
GError* error = nullptr;
if (!notify_notification_show(notification, &error)) {
debug::log(ERR, "Failed to show notification: {}", error ? error->message : "unknown");
@@ -306,6 +327,10 @@ namespace tether {
return true;
}
+ void DesktopNotifier::set_copy_handler(std::function<void(const std::string&)> handler) {
+ g_copy_handler = std::move(handler);
+ }
+
void DesktopNotifier::notify(const NotificationSpec& spec) {
if (!impl_ || !impl_->initialized) {
return;
diff --git a/src/daemon/notification.hpp b/src/daemon/notification.hpp
index 6c99750..7d2c6f2 100644
--- a/src/daemon/notification.hpp
+++ b/src/daemon/notification.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <filesystem>
+#include <functional>
#include <memory>
#include <string>
#include <vector>
@@ -17,6 +18,8 @@ namespace tether {
std::vector<std::string> icons;
bool quiet = false;
std::string reply_thread;
+ // OTP found in this notification, or empty. Non-empty adds a copy action.
+ std::string otp_code;
};
class DesktopNotifier {
@@ -28,6 +31,11 @@ namespace tether {
DesktopNotifier& operator=(const DesktopNotifier&) = delete;
bool init();
+
+ // Where the "Copy Code" action sends the code. Called on the notifier's
+ // own thread, so the handler is responsible for any thread hop it needs.
+ void set_copy_handler(std::function<void(const std::string&)> handler);
+
void notify_file_arrived(const std::filesystem::path& path);
void notify(const NotificationSpec& spec);
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 8242a70..0a19bcd 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -14,6 +14,7 @@ add_executable(tether_test
test_journal.cpp
test_crypto.cpp
test_discovery.cpp
+ test_event_loop.cpp
test_display_width.cpp
test_file_transfer.cpp
test_log.cpp
diff --git a/test/test_event_loop.cpp b/test/test_event_loop.cpp
new file mode 100644
index 0000000..b4d60ee
--- /dev/null
+++ b/test/test_event_loop.cpp
@@ -0,0 +1,41 @@
+#include <gtest/gtest.h>
+#include <tether/event_loop.hpp>
+
+#include <atomic>
+#include <thread>
+
+using namespace tether;
+
+TEST(EventLoopTest, RunsPostedWorkOnTheLoopThread) {
+ EpollEventLoop loop;
+ std::atomic<int> ran{0};
+ std::thread::id loop_thread;
+
+ std::thread poster([&] {
+ loop.post([&] { ++ran; });
+ loop.post([&] {
+ ++ran;
+ loop_thread = std::this_thread::get_id();
+ loop.stop();
+ });
+ });
+
+ loop.run();
+ poster.join();
+
+ EXPECT_EQ(ran.load(), 2);
+ EXPECT_EQ(loop_thread, std::this_thread::get_id());
+}
+
+TEST(EventLoopTest, RunsWorkPostedBeforeRun) {
+ EpollEventLoop loop;
+ bool ran = false;
+
+ loop.post([&] {
+ ran = true;
+ loop.stop();
+ });
+ loop.run();
+
+ EXPECT_TRUE(ran);
+}