Skip to content

Linux + iPhone Continuity / iMessage / SMS

more failed fixes

Zack Barteled17da75495a
diff --git a/apple/Tether/ViewModels/TetherViewModel.swift b/apple/Tether/ViewModels/TetherViewModel.swift
index 76abbc2..98dfe53 100644
--- a/apple/Tether/ViewModels/TetherViewModel.swift
+++ b/apple/Tether/ViewModels/TetherViewModel.swift
@@ -367,11 +367,11 @@ final class TetherViewModel {
connection.onStateChange = { [weak self] state in
guard let self else { return }
switch state {
- case .connected:
+ case .connected(let isInbound):
self.pendingReconnectTask?.cancel()
self.pendingReconnectTask = nil
self.autoConnectingFingerprint = nil
- self.handleConnected()
+ self.handleConnected(isInbound: isInbound)
case .disconnected:
self.autoConnectingFingerprint = nil
self.appState = .disconnected
@@ -420,7 +420,7 @@ final class TetherViewModel {
)
}
- private func handleConnected() {
+ private func handleConnected(isInbound: Bool = false) {
let serverFP = connection.serverFingerprint
if certificateManager.isHostKnown(serverFP) {
@@ -429,13 +429,19 @@ final class TetherViewModel {
connectedDeviceName = certificateManager.knownHosts[serverFP] ?? connectedDeviceName
} else {
// Need to pair
- appState = .pairing
- showPairingSheet = true
- pairingStatus = "Sending pairing request..."
-
- let deviceName = certificateManager.localDeviceName
+ if isInbound {
+ // If it's an inbound connection, we wait for the client to send us a pair_request.
+ // We don't send one ourselves over their established tunnel.
+ appState = .pairing
+ // The UI will update when we actually receive the .pairRequest command
+ } else {
+ appState = .pairing
+ showPairingSheet = true
+ pairingStatus = "Sending pairing request..."
- connection.send(.pairRequest(deviceName: deviceName))
+ let deviceName = certificateManager.localDeviceName
+ connection.send(.pairRequest(deviceName: deviceName))
+ }
}
}
diff --git a/docs/TODO.md b/docs/TODO.md
index 021bc0f..692b0f0 100644
--- a/docs/TODO.md
+++ b/docs/TODO.md
@@ -8,3 +8,5 @@
- [x] device pairing request
- [x] file received notification
- [ ] TOTP code display
+- [ ] BUGS
+ - [ ] infinite reconnect loop if tetherd is down
diff --git a/src/gtk/main.cpp b/src/gtk/main.cpp
index 16b21da..1fb8a58 100644
--- a/src/gtk/main.cpp
+++ b/src/gtk/main.cpp
@@ -26,8 +26,8 @@ namespace {
std::vector<tether::DiscoveredDevice> discovered_devices;
std::vector<tether::DiscoveredDevice> pending_pairing_requests;
std::vector<std::pair<std::string, std::string>> paired_devices; // fp, name
- std::vector<std::string> connected_fps; // active connections
-
+ std::vector<std::string> connected_fps; // active connections
+
int event_fd = -1;
GIOChannel* event_channel = nullptr;
guint event_watch_id = 0;
@@ -35,11 +35,11 @@ namespace {
GtkApplication* app = nullptr;
GtkWidget* window = nullptr;
-
+
GtkWidget* header_bar = nullptr;
GtkWidget* list_devices = nullptr;
GtkWidget* right_pane_stack = nullptr;
-
+
std::string selected_device_fp;
std::string selected_device_name;
std::string selected_device_ip;
@@ -47,7 +47,7 @@ namespace {
GtkWidget* lbl_action_name = nullptr;
GtkWidget* lbl_action_status = nullptr;
-
+
GtkWidget* lbl_unpaired_name = nullptr;
GtkWidget* lbl_unpaired_ip = nullptr;
};
@@ -57,7 +57,8 @@ namespace {
std::string format_fingerprint(const std::string& fingerprint) {
std::string formatted;
for (size_t i = 0; i < fingerprint.size(); ++i) {
- if (i > 0 && i % 2 == 0) formatted += ":";
+ if (i > 0 && i % 2 == 0)
+ formatted += ":";
formatted += fingerprint[i];
}
return formatted;
@@ -87,10 +88,8 @@ namespace {
gtk_header_bar_set_subtitle(GTK_HEADER_BAR(g_app.header_bar), text.c_str());
}
}
-
- void set_status_action(const std::string& text) {
- set_status(g_app.lbl_action_status, text);
- }
+
+ void set_status_action(const std::string& text) { set_status(g_app.lbl_action_status, text); }
void send_async_daemon_message(const nlohmann::json& j) {
if (g_app.event_fd >= 0) {
@@ -98,7 +97,7 @@ namespace {
::write(g_app.event_fd, payload.c_str(), payload.size());
}
}
-
+
void trigger_discovery() {
set_status_main("Scanning for nearby devices...");
nlohmann::json j;
@@ -117,34 +116,43 @@ namespace {
// Refresh the device list based on Discovered (unpaired), Paired (offline), Paired (online)
void refresh_device_list() {
clear_list_box(g_app.list_devices);
-
+
tether::Crypto::instance().init();
try {
nlohmann::json known = nlohmann::json::parse(tether::Crypto::instance().get_known_hosts_dump());
g_app.paired_devices.clear();
if (!known.empty()) {
for (auto& [fingerprint, name_value] : known.items()) {
- g_app.paired_devices.push_back({fingerprint, name_value.is_string() ? name_value.get<std::string>() : "Unknown Device"});
+ g_app.paired_devices.push_back(
+ {fingerprint, name_value.is_string() ? name_value.get<std::string>() : "Unknown Device"});
}
}
- } catch (...) {}
+ } catch (...) {
+ }
- // We build a unified list of devices.
+ // We build a unified list of devices.
// 1. All Paired Devices
// 2. Any Discovered Devices not in the Paired list
-
- auto create_row = [](const std::string& name, const std::string& fp, const std::string& ip, uint16_t port, bool paired, bool online) {
+
+ auto create_row = [](const std::string& name,
+ const std::string& fp,
+ const std::string& ip,
+ uint16_t port,
+ bool paired,
+ bool online) {
GtkWidget* row = gtk_list_box_row_new();
g_object_set_data_full(G_OBJECT(row), "fp", g_strdup(fp.c_str()), g_free);
g_object_set_data_full(G_OBJECT(row), "name", g_strdup(name.c_str()), g_free);
g_object_set_data_full(G_OBJECT(row), "ip", g_strdup(ip.c_str()), g_free);
g_object_set_data(G_OBJECT(row), "port", GINT_TO_POINTER(port));
g_object_set_data(G_OBJECT(row), "paired", GINT_TO_POINTER(paired ? 1 : 0));
-
+
GtkWidget* box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12);
gtk_container_set_border_width(GTK_CONTAINER(box), 12);
-
- const char* icon_name = paired ? (online ? "network-cellular-connected-symbolic" : "network-cellular-offline-symbolic") : "dialog-information-symbolic";
+
+ const char* icon_name =
+ paired ? (online ? "network-cellular-connected-symbolic" : "network-cellular-offline-symbolic")
+ : "dialog-information-symbolic";
GtkWidget* icon = gtk_image_new_from_icon_name(icon_name, GTK_ICON_SIZE_LARGE_TOOLBAR);
gtk_box_pack_start(GTK_BOX(box), icon, FALSE, FALSE, 0);
@@ -167,18 +175,24 @@ namespace {
std::string my_fp = tether::Crypto::instance().get_my_fingerprint();
for (const auto& paired : g_app.paired_devices) {
- bool online = std::find(g_app.connected_fps.begin(), g_app.connected_fps.end(), paired.first) != g_app.connected_fps.end();
+ bool online = std::find(g_app.connected_fps.begin(), g_app.connected_fps.end(), paired.first) !=
+ g_app.connected_fps.end();
GtkWidget* r = create_row(paired.second, paired.first, "", 5134, true, online);
gtk_list_box_insert(GTK_LIST_BOX(g_app.list_devices), r, -1);
}
for (const auto& disc : g_app.discovered_devices) {
- if (disc.fingerprint == my_fp) continue;
+ if (disc.fingerprint == my_fp)
+ continue;
bool is_paired = false;
for (const auto& p : g_app.paired_devices) {
- if (p.first == disc.fingerprint) { is_paired = true; break; }
+ if (p.first == disc.fingerprint) {
+ is_paired = true;
+ break;
+ }
}
- if (is_paired) continue; // already added above
+ if (is_paired)
+ continue; // already added above
std::string ip = disc.addresses.empty() ? "" : disc.addresses[0].address;
uint16_t port = disc.addresses.empty() ? 5134 : disc.addresses[0].port;
GtkWidget* r = create_row(disc.name, disc.fingerprint, ip, port, false, false);
@@ -189,50 +203,62 @@ namespace {
for (const auto& req : g_app.pending_pairing_requests) {
bool is_paired = false;
for (const auto& p : g_app.paired_devices) {
- if (p.first == req.fingerprint) { is_paired = true; break; }
+ if (p.first == req.fingerprint) {
+ is_paired = true;
+ break;
+ }
}
- if (is_paired) continue; // ignore if they successfully paired
+ if (is_paired)
+ continue; // ignore if they successfully paired
bool already_shown = false;
for (const auto& disc : g_app.discovered_devices) {
- if (disc.fingerprint == req.fingerprint) { already_shown = true; break; }
+ if (disc.fingerprint == req.fingerprint) {
+ already_shown = true;
+ break;
+ }
}
- if (already_shown) continue; // ignore if mDNS already populated it
+ if (already_shown)
+ continue; // ignore if mDNS already populated it
std::string ip = req.addresses.empty() ? "" : req.addresses[0].address;
uint16_t port = req.addresses.empty() ? 5134 : req.addresses[0].port;
GtkWidget* r = create_row(req.name, req.fingerprint, ip, port, false, false);
gtk_list_box_insert(GTK_LIST_BOX(g_app.list_devices), r, -1);
}
-
+
gtk_widget_show_all(g_app.list_devices);
}
-
+
void update_right_pane() {
if (g_app.selected_device_fp.empty()) {
gtk_stack_set_visible_child_name(GTK_STACK(g_app.right_pane_stack), "placeholder");
return;
}
-
+
bool is_paired = false;
for (const auto& p : g_app.paired_devices) {
- if (p.first == g_app.selected_device_fp) is_paired = true;
+ if (p.first == g_app.selected_device_fp)
+ is_paired = true;
}
-
+
if (is_paired) {
gtk_stack_set_visible_child_name(GTK_STACK(g_app.right_pane_stack), "action");
set_markup(g_app.lbl_action_name, ("<b>" + escape_markup(g_app.selected_device_name) + "</b>"));
- bool online = std::find(g_app.connected_fps.begin(), g_app.connected_fps.end(), g_app.selected_device_fp) != g_app.connected_fps.end();
+ bool online = std::find(g_app.connected_fps.begin(), g_app.connected_fps.end(), g_app.selected_device_fp) !=
+ g_app.connected_fps.end();
set_status_action(online ? "Connected and ready." : "Device is offline. Pair again or wait for network.");
} else {
gtk_stack_set_visible_child_name(GTK_STACK(g_app.right_pane_stack), "pair");
set_markup(g_app.lbl_unpaired_name, ("<b>" + escape_markup(g_app.selected_device_name) + "</b>"));
- set_status(g_app.lbl_unpaired_ip, ("Found at " + g_app.selected_device_ip + ":" + std::to_string(g_app.selected_device_port)));
+ set_status(g_app.lbl_unpaired_ip,
+ ("Found at " + g_app.selected_device_ip + ":" + std::to_string(g_app.selected_device_port)));
}
}
void on_device_selected(GtkListBox*, GtkListBoxRow* row, gpointer) {
- if (!row) return;
+ if (!row)
+ return;
const char* fp = (const char*)g_object_get_data(G_OBJECT(row), "fp");
const char* name = (const char*)g_object_get_data(G_OBJECT(row), "name");
const char* ip = (const char*)g_object_get_data(G_OBJECT(row), "ip");
@@ -244,7 +270,8 @@ namespace {
}
void on_pair_click(GtkWidget*, gpointer) {
- if (g_app.selected_device_ip.empty()) return;
+ if (g_app.selected_device_ip.empty())
+ return;
set_status(g_app.lbl_unpaired_ip, "Sending pair request...");
nlohmann::json j;
j["command"] = "pair_request";
@@ -253,15 +280,16 @@ namespace {
send_async_daemon_message(j);
set_status_main("Pair request sent. Approve on remote device!");
}
-
+
void on_accept_click(GtkWidget*, gpointer) {
- if (g_app.selected_device_fp.empty()) return;
+ if (g_app.selected_device_fp.empty())
+ return;
nlohmann::json j;
j["command"] = "accept_device";
j["fingerprint"] = g_app.selected_device_fp;
send_async_daemon_message(j);
}
-
+
void send_file_async(const std::filesystem::path& path) {
if (g_app.event_fd < 0) {
set_status_action("Daemon unavailable.");
@@ -275,9 +303,14 @@ namespace {
}
void on_choose_file(GtkWidget*, gpointer) {
- GtkWidget* dialog = gtk_file_chooser_dialog_new(
- "Send File", GTK_WINDOW(g_app.window), GTK_FILE_CHOOSER_ACTION_OPEN,
- "_Cancel", GTK_RESPONSE_CANCEL, "_Send", GTK_RESPONSE_ACCEPT, nullptr);
+ GtkWidget* dialog = gtk_file_chooser_dialog_new("Send File",
+ GTK_WINDOW(g_app.window),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ "_Cancel",
+ GTK_RESPONSE_CANCEL,
+ "_Send",
+ GTK_RESPONSE_ACCEPT,
+ nullptr);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
char* filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
if (filename) {
@@ -289,7 +322,8 @@ namespace {
}
void on_pull_clipboard(GtkWidget*, gpointer) {
- nlohmann::json j; j["command"] = "clipboard_get";
+ nlohmann::json j;
+ j["command"] = "clipboard_get";
send_async_daemon_message(j);
set_status_action("Requested desktop clipboard...");
}
@@ -299,10 +333,10 @@ namespace {
// We can just use the Push Clipboard button which pushes current wayland clipboard.
// But the daemon does this transparently! We just need `clipboard_set` if the user typed text,
// but here we just push whatever is on Wayland to the remote right now, wait...
- // Actually, if the user hits "Push", we read local Wayland, then send it via daemon? No, the Daemon already pushes wayland changes!
- // Actually, let's keep the button for explicit "Sync Now" if they disabled auto-sync.
+ // Actually, if the user hits "Push", we read local Wayland, then send it via daemon? No, the Daemon already
+ // pushes wayland changes! Actually, let's keep the button for explicit "Sync Now" if they disabled auto-sync.
}
-
+
void apply_state_snapshot(const nlohmann::json& j) {
g_app.connected_fps.clear();
if (j.contains("connected_clients") && j["connected_clients"].is_array()) {
@@ -332,7 +366,10 @@ namespace {
void handle_daemon_event(const nlohmann::json& event) {
const std::string command = event.value("command", "");
- if (command == "state_snapshot") { apply_state_snapshot(event); return; }
+ if (command == "state_snapshot") {
+ apply_state_snapshot(event);
+ return;
+ }
if (command == "client_connected") {
std::string fp = event.value("fingerprint", "");
if (std::find(g_app.connected_fps.begin(), g_app.connected_fps.end(), fp) == g_app.connected_fps.end()) {
@@ -344,7 +381,8 @@ namespace {
}
if (command == "client_disconnected") {
std::string fp = event.value("fingerprint", "");
- g_app.connected_fps.erase(std::remove(g_app.connected_fps.begin(), g_app.connected_fps.end(), fp), g_app.connected_fps.end());
+ g_app.connected_fps.erase(std::remove(g_app.connected_fps.begin(), g_app.connected_fps.end(), fp),
+ g_app.connected_fps.end());
refresh_device_list();
update_right_pane();
return;
@@ -352,7 +390,7 @@ namespace {
if (command == "pair_request_received" || command == "untrusted_client_connected") {
tether::DiscoveredDevice req;
req.fingerprint = event.value("fingerprint", "");
-
+
std::string resolved_name = event.value("device_name", "Unknown Device");
if (resolved_name == "Unknown Device") {
for (const auto& d : g_app.discovered_devices) {
@@ -366,7 +404,10 @@ namespace {
req.addresses.push_back({event.value("address", ""), 5134});
bool exists = false;
for (const auto& dev : g_app.pending_pairing_requests) {
- if (dev.fingerprint == req.fingerprint) { exists = true; break; }
+ if (dev.fingerprint == req.fingerprint) {
+ exists = true;
+ break;
+ }
}
if (!exists) {
g_app.pending_pairing_requests.push_back(req);
@@ -376,13 +417,26 @@ namespace {
}
if (command == "pair_accepted") {
std::string fp = event.value("fingerprint", "");
+ std::string name = event.value("device_name", "");
if (!fp.empty()) {
g_app.connected_fps.push_back(fp);
+
+ // Ensure it's in the paired devices list so the UI transitions
+ bool already_paired = false;
+ for (const auto& p : g_app.paired_devices) {
+ if (p.first == fp) {
+ already_paired = true;
+ break;
+ }
+ }
+ if (!already_paired)
+ g_app.paired_devices.push_back({fp, name});
+
g_app.pending_pairing_requests.erase(
- std::remove_if(g_app.pending_pairing_requests.begin(), g_app.pending_pairing_requests.end(), [&](const tether::DiscoveredDevice& d) {
- return d.fingerprint == fp;
- }), g_app.pending_pairing_requests.end()
- );
+ std::remove_if(g_app.pending_pairing_requests.begin(),
+ g_app.pending_pairing_requests.end(),
+ [&](const tether::DiscoveredDevice& d) { return d.fingerprint == fp; }),
+ g_app.pending_pairing_requests.end());
refresh_device_list();
update_right_pane();
}
@@ -420,54 +474,96 @@ namespace {
// Remove from pending pairing requests
std::string fp = event.value("fingerprint", "");
g_app.pending_pairing_requests.erase(
- std::remove_if(g_app.pending_pairing_requests.begin(), g_app.pending_pairing_requests.end(), [&](const tether::DiscoveredDevice& d){ return d.fingerprint == fp; }),
- g_app.pending_pairing_requests.end()
- );
+ std::remove_if(g_app.pending_pairing_requests.begin(),
+ g_app.pending_pairing_requests.end(),
+ [&](const tether::DiscoveredDevice& d) { return d.fingerprint == fp; }),
+ g_app.pending_pairing_requests.end());
refresh_device_list();
update_right_pane();
return;
}
}
-
+
// ----------- EVENT LOOP -----------
void stop_event_subscription() {
- if (g_app.event_watch_id != 0) { g_source_remove(g_app.event_watch_id); g_app.event_watch_id = 0; }
- if (g_app.event_channel) { g_io_channel_shutdown(g_app.event_channel, TRUE, nullptr); g_io_channel_unref(g_app.event_channel); g_app.event_channel = nullptr; }
- else if (g_app.event_fd >= 0) { close(g_app.event_fd); }
+ if (g_app.event_watch_id != 0) {
+ g_source_remove(g_app.event_watch_id);
+ g_app.event_watch_id = 0;
+ }
+ if (g_app.event_channel) {
+ g_io_channel_shutdown(g_app.event_channel, TRUE, nullptr);
+ g_io_channel_unref(g_app.event_channel);
+ g_app.event_channel = nullptr;
+ } else if (g_app.event_fd >= 0) {
+ close(g_app.event_fd);
+ }
g_app.event_fd = -1;
}
gboolean start_event_subscription(gpointer);
void schedule_event_retry() {
- if (g_app.event_retry_id == 0) g_app.event_retry_id = g_timeout_add_seconds(2, start_event_subscription, nullptr);
+ if (g_app.event_retry_id == 0)
+ g_app.event_retry_id = g_timeout_add_seconds(2, start_event_subscription, nullptr);
}
gboolean on_event_channel(GIOChannel* source, GIOCondition condition, gpointer) {
- if (condition & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) { stop_event_subscription(); schedule_event_retry(); set_status_main("Daemon Offline"); return FALSE; }
+ if (condition & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
+ stop_event_subscription();
+ schedule_event_retry();
+ set_status_main("Daemon Offline");
+ return FALSE;
+ }
if (condition & G_IO_IN) {
- gchar* line = nullptr; gsize length = 0; GError* error = nullptr;
+ gchar* line = nullptr;
+ gsize length = 0;
+ GError* error = nullptr;
while (true) {
GIOStatus status = g_io_channel_read_line(source, &line, &length, nullptr, &error);
- if (status == G_IO_STATUS_AGAIN) { if (line) g_free(line); break; }
+ if (status == G_IO_STATUS_AGAIN) {
+ if (line)
+ g_free(line);
+ break;
+ }
if (status == G_IO_STATUS_EOF || status == G_IO_STATUS_ERROR) {
- if (error) { std::cerr << "Stream err: " << error->message << std::endl; g_error_free(error); }
- if (line) g_free(line); stop_event_subscription(); schedule_event_retry(); set_status_main("Daemon Offline"); return FALSE;
+ if (error) {
+ std::cerr << "Stream err: " << error->message << std::endl;
+ g_error_free(error);
+ }
+ if (line)
+ g_free(line);
+ stop_event_subscription();
+ schedule_event_retry();
+ set_status_main("Daemon Offline");
+ return FALSE;
}
- if (line && length > 0) { try { handle_daemon_event(nlohmann::json::parse(std::string(line, length))); } catch (...) {} }
- if (line) g_free(line);
+ if (line && length > 0) {
+ try {
+ handle_daemon_event(nlohmann::json::parse(std::string(line, length)));
+ } catch (...) {
+ }
+ }
+ if (line)
+ g_free(line);
}
}
return TRUE;
}
gboolean start_event_subscription(gpointer) {
- if (g_app.event_retry_id != 0) { g_source_remove(g_app.event_retry_id); g_app.event_retry_id = 0; }
+ if (g_app.event_retry_id != 0) {
+ g_source_remove(g_app.event_retry_id);
+ g_app.event_retry_id = 0;
+ }
stop_event_subscription();
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if (fd < 0) { schedule_event_retry(); return G_SOURCE_REMOVE; }
+ if (fd < 0) {
+ schedule_event_retry();
+ return G_SOURCE_REMOVE;
+ }
- sockaddr_un addr{}; addr.sun_family = AF_UNIX;
+ sockaddr_un addr{};
+ addr.sun_family = AF_UNIX;
std::string path = tether::get_runtime_dir() + "/tetherd.sock";
std::strncpy(addr.sun_path, path.c_str(), sizeof(addr.sun_path) - 1);
@@ -481,13 +577,22 @@ namespace {
std::filesystem::path self_path = std::filesystem::read_symlink("/proc/self/exe");
std::string daemon_path = (self_path.parent_path() / "tetherd").string();
if (fork() == 0) {
- freopen("/dev/null", "w", stdout); freopen("/dev/null", "w", stderr); freopen("/dev/null", "r", stdin);
- execl(daemon_path.c_str(), "tetherd", nullptr); execlp("tetherd", "tetherd", nullptr); exit(1);
+ freopen("/dev/null", "w", stdout);
+ freopen("/dev/null", "w", stderr);
+ freopen("/dev/null", "r", stdin);
+ execl(daemon_path.c_str(), "tetherd", nullptr);
+ execlp("tetherd", "tetherd", nullptr);
+ exit(1);
}
exit(0);
- } else if (pid > 0) { int status; waitpid(pid, &status, 0); }
+ } else if (pid > 0) {
+ int status;
+ waitpid(pid, &status, 0);
+ }
}
- schedule_event_retry(); set_status_main("Daemon Offline"); return G_SOURCE_REMOVE;
+ schedule_event_retry();
+ set_status_main("Daemon Offline");
+ return G_SOURCE_REMOVE;
}
g_app.event_fd = fd;
@@ -495,7 +600,10 @@ namespace {
g_io_channel_set_encoding(g_app.event_channel, nullptr, nullptr);
g_io_channel_set_buffered(g_app.event_channel, TRUE);
g_io_channel_set_flags(g_app.event_channel, G_IO_FLAG_NONBLOCK, nullptr);
- g_app.event_watch_id = g_io_add_watch(g_app.event_channel, static_cast<GIOCondition>(G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL), on_event_channel, nullptr);
+ g_app.event_watch_id = g_io_add_watch(g_app.event_channel,
+ static_cast<GIOCondition>(G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL),
+ on_event_channel,
+ nullptr);
static const char kSubscribe[] = "{\"command\":\"subscribe\"}\n";
write(fd, kSubscribe, sizeof(kSubscribe) - 1);
set_status_main("Daemon Online");
@@ -504,20 +612,23 @@ namespace {
void apply_css() {
GtkCssProvider* provider = gtk_css_provider_new();
- const gchar* css =
- "window { background-color: #0d1117; color: #c9d1d9; }"
- ".card { background-color: #161b22; border: 1px solid #30363d; border-radius: 12px; }"
- ".muted { color: #8b949e; }"
- "button { border-radius: 8px; padding: 12px 24px; background-color: #21262d; color: #c9d1d9; border: 1px solid #30363d; font-weight: 600; }"
- "button:hover { background-color: #30363d; }"
- "button.suggested-action { background-color: #238636; color: #ffffff; border-color: rgba(240,246,252,0.1); }"
- "button.suggested-action:hover { background-color: #2ea043; }"
- "list { background-color: transparent; }"
- "list row { background-color: transparent; border-bottom: 1px solid #21262d; padding: 4px; transition: all 150ms ease-in-out; }"
- "list row:selected { background-color: rgba(56,139,253,0.15); border-radius: 8px; }"
- "scrolledwindow { background: transparent; }";
+ const gchar* css = "window { background-color: #0d1117; color: #c9d1d9; }"
+ ".card { background-color: #161b22; border: 1px solid #30363d; border-radius: 12px; }"
+ ".muted { color: #8b949e; }"
+ "button { border-radius: 8px; padding: 12px 24px; background-color: #21262d; color: "
+ "#c9d1d9; border: 1px solid #30363d; font-weight: 600; }"
+ "button:hover { background-color: #30363d; }"
+ "button.suggested-action { background-color: #238636; color: #ffffff; border-color: "
+ "rgba(240,246,252,0.1); }"
+ "button.suggested-action:hover { background-color: #2ea043; }"
+ "list { background-color: transparent; }"
+ "list row { background-color: transparent; border-bottom: 1px solid #21262d; padding: 4px; "
+ "transition: all 150ms ease-in-out; }"
+ "list row:selected { background-color: rgba(56,139,253,0.15); border-radius: 8px; }"
+ "scrolledwindow { background: transparent; }";
gtk_css_provider_load_from_data(provider, css, -1, nullptr);
- gtk_style_context_add_provider_for_screen(gdk_screen_get_default(), GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ gtk_style_context_add_provider_for_screen(
+ gdk_screen_get_default(), GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref(provider);
}
@@ -538,7 +649,8 @@ namespace {
gtk_window_set_titlebar(GTK_WINDOW(g_app.window), g_app.header_bar);
GtkWidget* refresh_btn = gtk_button_new_from_icon_name("view-refresh-symbolic", GTK_ICON_SIZE_BUTTON);
- g_signal_connect(refresh_btn, "clicked", G_CALLBACK(+[](GtkWidget*, gpointer){ trigger_discovery(); }), nullptr);
+ g_signal_connect(
+ refresh_btn, "clicked", G_CALLBACK(+[](GtkWidget*, gpointer) { trigger_discovery(); }), nullptr);
gtk_header_bar_pack_start(GTK_HEADER_BAR(g_app.header_bar), refresh_btn);
// Paned Layout
@@ -549,7 +661,7 @@ namespace {
GtkWidget* left_scroll = gtk_scrolled_window_new(nullptr, nullptr);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(left_scroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
gtk_widget_set_size_request(left_scroll, 220, -1);
-
+
g_app.list_devices = gtk_list_box_new();
g_signal_connect(g_app.list_devices, "row-selected", G_CALLBACK(on_device_selected), nullptr);
gtk_container_add(GTK_CONTAINER(left_scroll), g_app.list_devices);
@@ -558,7 +670,7 @@ namespace {
// Right Pane
g_app.right_pane_stack = gtk_stack_new();
gtk_stack_set_transition_type(GTK_STACK(g_app.right_pane_stack), GTK_STACK_TRANSITION_TYPE_CROSSFADE);
-
+
// --- State: Placeholder ---
GtkWidget* placeholder = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
gtk_widget_set_valign(placeholder, GTK_ALIGN_CENTER);
@@ -579,12 +691,12 @@ namespace {
g_app.lbl_unpaired_ip = gtk_label_new(nullptr);
gtk_style_context_add_class(gtk_widget_get_style_context(g_app.lbl_unpaired_ip), "muted");
gtk_box_pack_start(GTK_BOX(pair_box), g_app.lbl_unpaired_ip, FALSE, FALSE, 0);
-
+
GtkWidget* pair_btn = gtk_button_new_with_label("Pair Device");
gtk_style_context_add_class(gtk_widget_get_style_context(pair_btn), "suggested-action");
g_signal_connect(pair_btn, "clicked", G_CALLBACK(on_pair_click), nullptr);
gtk_box_pack_start(GTK_BOX(pair_box), pair_btn, FALSE, FALSE, 0);
-
+
// optional accept override button
GtkWidget* accept_btn = gtk_button_new_with_label("Force Trust (Accept Pending)");
g_signal_connect(accept_btn, "clicked", G_CALLBACK(on_accept_click), nullptr);
@@ -596,19 +708,19 @@ namespace {
GtkWidget* action_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 24);
gtk_container_set_border_width(GTK_CONTAINER(action_box), 32);
gtk_widget_set_valign(action_box, GTK_ALIGN_CENTER);
-
+
g_app.lbl_action_name = gtk_label_new(nullptr);
gtk_widget_set_halign(g_app.lbl_action_name, GTK_ALIGN_CENTER);
gtk_box_pack_start(GTK_BOX(action_box), g_app.lbl_action_name, FALSE, FALSE, 0);
-
+
GtkWidget* btn_grid = gtk_box_new(GTK_ORIENTATION_VERTICAL, 12);
gtk_widget_set_halign(btn_grid, GTK_ALIGN_CENTER);
-
+
GtkWidget* btn_send_file = gtk_button_new_with_label("Send File");
gtk_style_context_add_class(gtk_widget_get_style_context(btn_send_file), "suggested-action");
g_signal_connect(btn_send_file, "clicked", G_CALLBACK(on_choose_file), nullptr);
gtk_box_pack_start(GTK_BOX(btn_grid), btn_send_file, FALSE, FALSE, 0);
-
+
gtk_box_pack_start(GTK_BOX(action_box), btn_grid, FALSE, FALSE, 0);
g_app.lbl_action_status = gtk_label_new("Ready");
@@ -627,14 +739,15 @@ namespace {
gtk_widget_show_all(g_app.window);
}
-}
+} // namespace
int main(int argc, char** argv) {
GtkApplication* app = gtk_application_new("com.tether.desktop", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect(app, "activate", G_CALLBACK(activate), nullptr);
int status = g_application_run(G_APPLICATION(app), argc, argv);
stop_event_subscription();
- if (g_app.event_retry_id != 0) g_source_remove(g_app.event_retry_id);
+ if (g_app.event_retry_id != 0)
+ g_source_remove(g_app.event_retry_id);
g_object_unref(app);
return status;
}