Skip to content

Linux + iPhone Continuity / iMessage / SMS

feat(gtk): bluetooth pairing flow

Zack Bartel23d086ba4b48
diff --git a/Makefile b/Makefile
index f743413..a928501 100644
--- a/Makefile
+++ b/Makefile
@@ -45,6 +45,16 @@ fmt:
extension:
@./extension/build.sh
+.PHONY: reset reset-wifi reset-bt
+reset:
+ @./scripts/tether-reset.sh all
+
+reset-wifi:
+ @./scripts/tether-reset.sh wifi
+
+reset-bt:
+ @./scripts/tether-reset.sh bt
+
clean:
rm -rf build
rm -f compile_commands.json
diff --git a/README.md b/README.md
index 7cd4d0a..3d98774 100644
--- a/README.md
+++ b/README.md
@@ -139,7 +139,27 @@ make install
```
3. Bluetooth pair via GUI or CLI (for Messages and Notifications):
- (TODO: Bluetooth pairing instructions)
+
+ Check that your machine has the Bluetooth features first.
+ This sets the Bluetooth adapter class to "A/V Hands-Free" instead of "Computer"
+
+ ```bash
+ ./scripts/bt-probe.sh --set-class
+ ```
+
+ Then, in the GTK app, pick your iPhone under BLUETOOTH on the Devices page
+ and press "Pair over Bluetooth". Confirm the code on both the iPhone and
+ Linux. Afterwards the iPhone offers "Show Message Notifications" and "Sync
+ Contacts" under Settings > Bluetooth > (i) for this computer. Enable these, both are needed.
+ They can take a few minutes to appear. "Show iPhone Permissions" in the same pane can re-advertise so they show up again.
+
+ or
+
+ ```bash
+ tether --bt-devices # find the iPhone's address
+ tether --bt-pair <address>
+ tether --bt-connection # what is up, and what is not
+ ```
## Roadmap
diff --git a/scripts/tether-reset.sh b/scripts/tether-reset.sh
new file mode 100755
index 0000000..d78f83d
--- /dev/null
+++ b/scripts/tether-reset.sh
@@ -0,0 +1,125 @@
+#!/usr/bin/env bash
+# Delete Tether's pairing state so the next pair starts from nothing.
+#
+# tether-reset.sh wifi mTLS keys, known hosts, pending pair requests
+# tether-reset.sh bt the BlueZ bond, Bluetooth config, contacts, messages
+# tether-reset.sh all both, plus the daemon log
+#
+# Paths are spelled out rather than derived from XDG_CONFIG_HOME/XDG_DATA_HOME
+# because the daemon itself builds them from $HOME; following the spec here
+# would delete files nothing ever wrote.
+
+set -uo pipefail
+
+scope=${1:-}
+assume_yes=0
+dry_run=0
+for arg in "${@:2}"; do
+ case $arg in
+ -y|--yes) assume_yes=1 ;;
+ -n|--dry-run) dry_run=1 ;;
+ *) echo "unknown option: $arg" >&2; exit 2 ;;
+ esac
+done
+
+case $scope in
+ wifi|bt|all) ;;
+ *) echo "usage: $0 {wifi|bt|all} [-y] [--dry-run]" >&2; exit 2 ;;
+esac
+
+red=$'\e[31m'; grn=$'\e[32m'; ylw=$'\e[33m'; dim=$'\e[2m'; rst=$'\e[0m'
+[[ -t 1 ]] || { red=; grn=; ylw=; dim=; rst=; }
+
+config="$HOME/.config/tether"
+share="$HOME/.local/share/tether"
+state="${XDG_STATE_HOME:-$HOME/.local/state}/tether"
+runtime="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/tether"
+
+wifi_paths=(
+ "$config/cert.pem"
+ "$config/key.pem"
+ "$config/known_hosts.json"
+ "$runtime/pending_pairs.json"
+)
+bt_paths=(
+ "$config/bluetooth.json"
+ "$config/groups.json"
+ "$share/contacts.json"
+ "$share/messages.ndjson"
+)
+
+paths=()
+[[ $scope == wifi || $scope == all ]] && paths+=("${wifi_paths[@]}")
+[[ $scope == bt || $scope == all ]] && paths+=("${bt_paths[@]}")
+[[ $scope == all ]] && paths+=("$state/tetherd.log")
+
+# The bond lives in BlueZ, not in any of the files above. Read the address before
+# bluetooth.json is deleted.
+bond_address=""
+if [[ $scope == bt || $scope == all ]] && [[ -f $config/bluetooth.json ]]; then
+ bond_address=$(sed -n 's/.*"device_address"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' \
+ "$config/bluetooth.json" | head -n 1)
+fi
+
+echo "Resetting: $scope"
+echo
+for p in "${paths[@]}"; do
+ if [[ -e $p ]]; then
+ printf ' %sremove%s %s\n' "$ylw" "$rst" "$p"
+ else
+ printf ' %sabsent%s %s\n' "$dim" "$rst" "$p"
+ fi
+done
+[[ -n $bond_address ]] && printf ' %sremove%s BlueZ bond %s\n' "$ylw" "$rst" "$bond_address"
+pgrep -x tetherd >/dev/null && printf ' %sstop%s tetherd\n' "$ylw" "$rst"
+echo
+
+if (( dry_run )); then
+ echo "${dim}dry run: nothing was deleted${rst}"
+ exit 0
+fi
+
+if (( ! assume_yes )); then
+ read -r -p "Delete these? [y/N] " reply
+ [[ $reply == [yY] ]] || { echo "aborted"; exit 1; }
+ echo
+fi
+
+# The daemon rewrites known_hosts.json, bluetooth.json and the journal as it runs,
+# so it has to be gone before anything is deleted or the reset partially undoes
+# itself.
+if pgrep -x tetherd >/dev/null; then
+ pkill -x tetherd
+ for _ in $(seq 20); do
+ pgrep -x tetherd >/dev/null || break
+ sleep 0.25
+ done
+ pgrep -x tetherd >/dev/null && pkill -9 -x tetherd
+ printf ' %s✓%s stopped tetherd\n' "$grn" "$rst"
+fi
+
+if [[ -n $bond_address ]]; then
+ if bluetoothctl remove "$bond_address" >/dev/null 2>&1; then
+ printf ' %s✓%s removed BlueZ bond %s\n' "$grn" "$rst" "$bond_address"
+ else
+ printf ' %s!%s could not remove BlueZ bond %s (already gone?)\n' "$ylw" "$rst" "$bond_address"
+ fi
+fi
+
+for p in "${paths[@]}"; do
+ [[ -e $p ]] || continue
+ if rm -f "$p"; then
+ printf ' %s✓%s %s\n' "$grn" "$rst" "$p"
+ else
+ printf ' %s✗%s %s\n' "$red" "$rst" "$p"
+ fi
+done
+
+echo
+echo "Done. The iPhone side cannot be cleared from here:"
+if [[ $scope == bt || $scope == all ]]; then
+ echo " - Settings > Bluetooth > (i) next to this computer > Forget This Device"
+fi
+if [[ $scope == wifi || $scope == all ]]; then
+ echo " - Tether iOS app: remove this computer from its paired devices"
+fi
diff --git a/src/core/src/net.cpp b/src/core/src/net.cpp
index ca9f9cc..9c99191 100644
--- a/src/core/src/net.cpp
+++ b/src/core/src/net.cpp
@@ -258,6 +258,7 @@ namespace tether {
nlohmann::json status;
status["command"] = "bt_status";
status["available"] = bluetooth::g_bluez != nullptr && bluetooth::g_bluez->running();
+ status["device_address"] = bluetooth::load_config().device_address;
if (!bluetooth::g_bluez) {
status["capability"] = nullptr;
status["adapters"] = nlohmann::json::array();
diff --git a/src/gtk/daemon_client.cpp b/src/gtk/daemon_client.cpp
index 48f1250..2ef1e4f 100644
--- a/src/gtk/daemon_client.cpp
+++ b/src/gtk/daemon_client.cpp
@@ -52,6 +52,8 @@ namespace tether::ui {
stop_event_subscription();
schedule_event_retry();
set_status_main("Daemon Offline");
+ set_route_status(Route::WiFi, false, "The Tether daemon is not running.");
+ set_route_status(Route::Bluetooth, false, "The Tether daemon is not running.");
if (g_on_disconnect)
g_on_disconnect();
}
@@ -154,6 +156,8 @@ namespace tether::ui {
}
schedule_event_retry();
set_status_main("Daemon Offline");
+ set_route_status(Route::WiFi, false, "The Tether daemon is not running.");
+ set_route_status(Route::Bluetooth, false, "The Tether daemon is not running.");
return G_SOURCE_REMOVE;
}
@@ -174,6 +178,8 @@ namespace tether::ui {
// status, but ask anyway: an older daemon will not, and a view whose
// composer is gated on that status stays shut until it arrives.
daemon_send({{"command", "bt_connection"}});
+ daemon_send({{"command", "bt_status"}});
+ daemon_send({{"command", "bt_list_devices"}});
set_status_main("Daemon Online");
return G_SOURCE_REMOVE;
}
diff --git a/src/gtk/devices_view.cpp b/src/gtk/devices_view.cpp
index 6409b38..cca2875 100644
--- a/src/gtk/devices_view.cpp
+++ b/src/gtk/devices_view.cpp
@@ -19,6 +19,11 @@ namespace tether::ui {
std::vector<std::pair<std::string, std::string>> paired_devices; // fp, name
std::vector<std::string> connected_fps; // active connections
+ // The Bluetooth route
+ std::vector<nlohmann::json> bt_devices;
+ nlohmann::json bt_status = nlohmann::json::object();
+ nlohmann::json bt_connection = nlohmann::json::object();
+
GtkWidget* list_devices = nullptr;
GtkWidget* right_pane_stack = nullptr;
@@ -33,14 +38,160 @@ namespace tether::ui {
GtkWidget* lbl_unpaired_name = nullptr;
GtkWidget* lbl_unpaired_ip = nullptr;
+
+ std::string selected_bt_address;
+ std::string selected_bt_name;
+
+ GtkWidget* lbl_bt_name = nullptr;
+ GtkWidget* lbl_bt_mode = nullptr;
+ GtkWidget* lbl_bt_link = nullptr;
+ GtkWidget* lbl_bt_messages = nullptr;
+ GtkWidget* lbl_bt_contacts = nullptr;
+ GtkWidget* lbl_bt_notifications = nullptr;
+ GtkWidget* lbl_bt_reason = nullptr;
+ GtkWidget* lbl_bt_progress = nullptr;
+ GtkWidget* btn_bt_pair = nullptr;
+ GtkWidget* btn_bt_solicit = nullptr;
+ GtkWidget* btn_bt_unpair = nullptr;
+
+ GtkWidget* lbl_welcome_wifi = nullptr;
+ GtkWidget* lbl_welcome_bt = nullptr;
};
DevicesState g_devices;
void set_status_action(const std::string& text) { set_text(g_devices.lbl_action_status, text); }
+ const nlohmann::json* find_bt_device(const std::string& address) {
+ for (const auto& device : g_devices.bt_devices) {
+ if (device.value("address", "") == address)
+ return &device;
+ }
+ return nullptr;
+ }
+
+ // The daemon supervises one iPhone at a time, so the live profile status
+ // describes whichever Bluetooth device is bonded, not the one merely
+ // selected in the list.
+ bool is_supervised_bt_device(const std::string& address) {
+ if (address.empty())
+ return false;
+ const std::string supervised = g_devices.bt_status.value("device_address", "");
+ return !supervised.empty() && supervised == address;
+ }
+
+ void set_capability_row(GtkWidget* label, const std::string& title, bool ok, const std::string& note) {
+ std::string markup = std::string(ok ? "\u2713" : "\u2717") + " <b>" + escape_markup(title) + "</b>";
+ if (!note.empty())
+ markup += " <span size='small'>" + escape_markup(note) + "</span>";
+ set_markup(label, markup);
+ }
+
+ void update_welcome_pane() {
+ const bool wifi_ok = !g_devices.connected_fps.empty();
+ set_text(g_devices.lbl_welcome_wifi, wifi_ok ? "Connected." : "Not connected yet.");
+
+ const bool bt_ok =
+ g_devices.bt_connection.value("map_open", false) || g_devices.bt_connection.value("ancs_ready", false);
+ std::string bt_note = "Not connected yet.";
+ if (bt_ok)
+ bt_note = "Connected.";
+ else if (!g_devices.bt_status.empty() && !g_devices.bt_status.value("available", false))
+ bt_note = "Bluetooth is unavailable on this machine.";
+ set_text(g_devices.lbl_welcome_bt, bt_note);
+ }
+
+ void update_bt_pane() {
+ const std::string address = g_devices.selected_bt_address;
+ const nlohmann::json* device = find_bt_device(address);
+ const bool paired = device && device->value("paired", false);
+ const bool supervised = is_supervised_bt_device(address);
+ const bool available = g_devices.bt_status.value("available", false);
+
+ set_markup(g_devices.lbl_bt_name, "<b>" + escape_markup(g_devices.selected_bt_name) + "</b>");
+
+ std::string mode;
+ if (!g_devices.bt_status.empty()) {
+ const nlohmann::json capability = g_devices.bt_status.value("capability", nlohmann::json());
+ if (!available || capability.is_null()) {
+ mode = "Bluetooth is unavailable on this machine.";
+ } else if (capability.value("mode", "") == "full") {
+ mode = "Full mode \u2014 messages, contacts, and notifications.";
+ } else if (capability.value("mode", "") == "compatibility") {
+ mode = "Compatibility mode \u2014 messages and contacts, no notification mirroring.";
+ } else {
+ mode = "This machine cannot carry the Bluetooth features.";
+ }
+ // The reasons name what is missing (adapter class, LE roles, BlueZ
+ // version) and are the only place that detail surfaces outside the CLI.
+ if (!capability.is_null() && capability.contains("reasons")) {
+ for (const auto& reason : capability["reasons"]) {
+ if (reason.is_string())
+ mode += "\n" + reason.get<std::string>();
+ }
+ }
+ }
+ set_text(g_devices.lbl_bt_mode, mode);
+
+ // Only the supervised bond has live profile state; anything else can
+ // report what BlueZ knows and no more.
+ const nlohmann::json& connection = g_devices.bt_connection;
+ const bool classic = supervised ? connection.value("classic_connected", false)
+ : (device && device->value("classic_connected", false));
+ const bool le =
+ supervised ? connection.value("le_connected", false) : (device && device->value("le_connected", false));
+ const bool map_open = supervised && connection.value("map_open", false);
+ const bool pbap_open = supervised && connection.value("pbap_open", false);
+ const bool ancs_ready = supervised && connection.value("ancs_ready", false);
+
+ set_capability_row(g_devices.lbl_bt_link,
+ "Link",
+ classic || le,
+ std::string("BR/EDR ") + (classic ? "on" : "off") + ", LE " + (le ? "on" : "off"));
+
+ const std::string map_error = connection.value("map_error", "none");
+ const std::string pbap_error = connection.value("pbap_error", "none");
+ set_capability_row(
+ g_devices.lbl_bt_messages, "Messages", map_open, map_open || map_error == "none" ? "" : map_error);
+ set_capability_row(
+ g_devices.lbl_bt_contacts, "Contacts", pbap_open, pbap_open || pbap_error == "none" ? "" : pbap_error);
+ set_capability_row(g_devices.lbl_bt_notifications,
+ "Notifications",
+ ancs_ready,
+ ancs_ready ? "" : connection.value("ancs_reason", ""));
+
+ // The daemon's reasons name the actual next step, so they are shown
+ // verbatim rather than replaced with something vaguer.
+ std::string reason;
+ if (!paired) {
+ reason = "Not paired over Bluetooth yet.";
+ } else if (!supervised) {
+ reason = "Tether is not using this device. Pair it to select it.";
+ } else {
+ reason = connection.value("profile_reason", "");
+ if (reason.empty())
+ reason = connection.value("link_reason", "");
+ }
+ set_text(g_devices.lbl_bt_reason, reason);
+
+ gtk_widget_set_visible(g_devices.btn_bt_pair, available && (!paired || !supervised));
+ gtk_widget_set_visible(g_devices.btn_bt_unpair, available && paired);
+ // Re-soliciting only helps when the phone is withholding a profile,
+ // not when the link itself is down or nothing is bonded.
+ gtk_widget_set_visible(g_devices.btn_bt_solicit,
+ available && supervised &&
+ (map_error == "forbidden" || map_error == "no_record" || !ancs_ready));
+ }
+
void update_right_pane() {
+ if (!g_devices.selected_bt_address.empty()) {
+ gtk_stack_set_visible_child_name(GTK_STACK(g_devices.right_pane_stack), "bluetooth");
+ update_bt_pane();
+ return;
+ }
+
if (g_devices.selected_device_fp.empty()) {
+ update_welcome_pane();
gtk_stack_set_visible_child_name(GTK_STACK(g_devices.right_pane_stack), "placeholder");
return;
}
@@ -75,6 +226,17 @@ namespace tether::ui {
void on_device_selected(GtkListBox*, GtkListBoxRow* row, gpointer) {
if (!row)
return;
+
+ const char* bt_address = (const char*)g_object_get_data(G_OBJECT(row), "bt_address");
+ g_devices.selected_bt_address = bt_address ? bt_address : "";
+ if (!g_devices.selected_bt_address.empty()) {
+ const char* bt_name = (const char*)g_object_get_data(G_OBJECT(row), "name");
+ g_devices.selected_bt_name = bt_name ? bt_name : "";
+ g_devices.selected_device_fp.clear();
+ update_right_pane();
+ 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");
@@ -106,6 +268,51 @@ namespace tether::ui {
daemon_send(j);
}
+ void on_bt_pair_click(GtkWidget*, gpointer) {
+ if (g_devices.selected_bt_address.empty())
+ return;
+ if (!daemon_send({{"command", "bt_pair"}, {"address", g_devices.selected_bt_address}})) {
+ set_text(g_devices.lbl_bt_progress, "Could not reach the Tether daemon.");
+ return;
+ }
+ gtk_widget_set_sensitive(g_devices.btn_bt_pair, FALSE);
+ set_text(g_devices.lbl_bt_progress, "Pairing\u2026 confirm the prompt on the iPhone.");
+ }
+
+ void on_bt_unpair_click(GtkWidget*, gpointer) {
+ if (g_devices.selected_bt_address.empty())
+ return;
+
+ GtkWidget* dialog = gtk_message_dialog_new(GTK_WINDOW(main_window()),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_OK_CANCEL,
+ "Remove the Bluetooth pairing with %s?",
+ g_devices.selected_bt_name.c_str());
+ gtk_message_dialog_format_secondary_text(
+ GTK_MESSAGE_DIALOG(dialog),
+ "Also delete this computer from the iPhone's Bluetooth settings before pairing again, "
+ "or the phone will keep the stale bond.");
+ const bool confirmed = gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK;
+ gtk_widget_destroy(dialog);
+ if (!confirmed)
+ return;
+
+ daemon_send({{"command", "bt_unpair"}, {"address", g_devices.selected_bt_address}});
+ set_text(g_devices.lbl_bt_progress, "Removing the pairing\u2026");
+ }
+
+ // The advertisement that makes iOS reveal its Messages and Contacts
+ // permission toggles expires a few minutes after pairing. Without this the
+ // only way back to those toggles is to remove the bond and pair again.
+ void on_bt_solicit_click(GtkWidget*, gpointer) {
+ if (!daemon_send({{"command", "bt_solicit"}})) {
+ set_text(g_devices.lbl_bt_progress, "Could not reach the Tether daemon.");
+ return;
+ }
+ set_text(g_devices.lbl_bt_progress, "Asking the iPhone to show its Bluetooth permissions\u2026");
+ }
+
void send_file_async(const std::filesystem::path& path) {
if (!daemon_connected()) {
set_status_action("Daemon unavailable.");
@@ -137,6 +344,14 @@ namespace tether::ui {
gtk_widget_destroy(dialog);
}
+ void update_wifi_indicator() {
+ const bool connected = !g_devices.connected_fps.empty();
+ set_route_status(Route::WiFi,
+ connected,
+ connected ? "Clipboard, files, and OTP are connected."
+ : "No paired iPhone is connected. Open the Tether app on the phone.");
+ }
+
void apply_state_snapshot(const nlohmann::json& j) {
g_devices.connected_fps.clear();
if (j.contains("connected_clients") && j["connected_clients"].is_array()) {
@@ -162,15 +377,17 @@ namespace tether::ui {
}
}
devices_view_refresh();
+ update_wifi_indicator();
}
} // namespace
void devices_view_trigger_discovery() {
set_status_main("Scanning for nearby devices...");
- nlohmann::json j;
- j["command"] = "discover";
- daemon_send(j);
+ // Refresh means both routes: mDNS for Wi-Fi peers, BlueZ for Bluetooth.
+ daemon_send({{"command", "discover"}});
+ daemon_send({{"command", "bt_status"}});
+ daemon_send({{"command", "bt_list_devices"}});
}
// Refresh the device list based on Discovered (unpaired), Paired (offline), Paired (online)
@@ -232,6 +449,39 @@ namespace tether::ui {
return row;
};
+ auto create_bt_row = [](const nlohmann::json& device) {
+ const std::string address = device.value("address", "");
+ const std::string name = device.value("name", "").empty() ? address : device.value("name", "");
+ const bool paired = device.value("paired", false);
+ const bool connected = device.value("connected", false);
+
+ GtkWidget* row = gtk_list_box_row_new();
+ g_object_set_data_full(G_OBJECT(row), "bt_address", g_strdup(address.c_str()), g_free);
+ g_object_set_data_full(G_OBJECT(row), "name", g_strdup(name.c_str()), g_free);
+
+ GtkWidget* box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12);
+ gtk_container_set_border_width(GTK_CONTAINER(box), 12);
+
+ GtkWidget* icon = gtk_image_new_from_icon_name(
+ connected ? "bluetooth-active-symbolic" : "bluetooth-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR);
+ gtk_box_pack_start(GTK_BOX(box), icon, FALSE, FALSE, 0);
+
+ GtkWidget* labels = gtk_box_new(GTK_ORIENTATION_VERTICAL, 2);
+ GtkWidget* title = gtk_label_new(nullptr);
+ gtk_label_set_markup(GTK_LABEL(title), ("<b>" + escape_markup(name) + "</b>").c_str());
+ gtk_label_set_xalign(GTK_LABEL(title), 0.0);
+ gtk_box_pack_start(GTK_BOX(labels), title, FALSE, FALSE, 0);
+
+ GtkWidget* subtitle = gtk_label_new(connected ? "Connected" : (paired ? "Paired" : "Nearby (Tap to Pair)"));
+ gtk_label_set_xalign(GTK_LABEL(subtitle), 0.0);
+ gtk_style_context_add_class(gtk_widget_get_style_context(subtitle), "muted");
+ gtk_box_pack_start(GTK_BOX(labels), subtitle, FALSE, FALSE, 0);
+
+ gtk_box_pack_start(GTK_BOX(box), labels, TRUE, TRUE, 0);
+ gtk_container_add(GTK_CONTAINER(row), box);
+ return row;
+ };
+
auto create_header_row = [](const std::string& title_text) {
GtkWidget* row = gtk_list_box_row_new();
gtk_list_box_row_set_selectable(GTK_LIST_BOX_ROW(row), FALSE);
@@ -328,6 +578,23 @@ namespace tether::ui {
gtk_list_box_insert(GTK_LIST_BOX(g_devices.list_devices), r, -1);
}
+ // ponytail: iPhones, plus whatever Tether is actually bonded to. Every
+ // other paired thing BlueZ knows about -- headphones, controllers,
+ // keyboards -- is noise on this page. Widen the filter only if someone
+ // needs to pair a phone that does not look like an iPhone.
+ std::vector<GtkWidget*> bt_rows;
+ for (const auto& device : g_devices.bt_devices) {
+ if (!device.value("iphone", false) && !is_supervised_bt_device(device.value("address", "")))
+ continue;
+ bt_rows.push_back(create_bt_row(device));
+ }
+
+ if (!bt_rows.empty()) {
+ gtk_list_box_insert(GTK_LIST_BOX(g_devices.list_devices), create_header_row("BLUETOOTH"), -1);
+ for (auto* r : bt_rows)
+ gtk_list_box_insert(GTK_LIST_BOX(g_devices.list_devices), r, -1);
+ }
+
gtk_widget_show_all(g_devices.list_devices);
}
@@ -345,6 +612,7 @@ namespace tether::ui {
}
devices_view_refresh();
update_right_pane();
+ update_wifi_indicator();
return true;
}
if (command == "client_disconnected") {
@@ -354,6 +622,7 @@ namespace tether::ui {
g_devices.connected_fps.end());
devices_view_refresh();
update_right_pane();
+ update_wifi_indicator();
return true;
}
if (command == "pair_request_received" || command == "untrusted_client_connected") {
@@ -438,6 +707,52 @@ namespace tether::ui {
set_status_action("Desktop Clipboard Sync triggered.");
return true;
}
+ if (command == "bt_status") {
+ g_devices.bt_status = event;
+ devices_view_refresh();
+ update_right_pane();
+ return true;
+ }
+ if (command == "bt_devices") {
+ g_devices.bt_devices.clear();
+ if (event.contains("devices") && event["devices"].is_array()) {
+ for (const auto& device : event["devices"])
+ g_devices.bt_devices.push_back(device);
+ }
+ devices_view_refresh();
+ update_right_pane();
+ return true;
+ }
+ if (command == "bt_connection_changed") {
+ g_devices.bt_connection = event;
+ const bool connected = event.value("map_open", false) || event.value("ancs_ready", false);
+ std::string detail = event.value("profile_reason", "");
+ if (detail.empty())
+ detail = event.value("link_reason", "");
+ if (detail.empty() && connected)
+ detail = "Messages and notifications are connected.";
+ set_route_status(Route::Bluetooth, connected, detail);
+ update_right_pane();
+ // A status broadcast, not a command this view owns: the Messages and
+ // Notifications views need the same event.
+ return false;
+ }
+ if (command == "bt_solicit_result") {
+ set_text(g_devices.lbl_bt_progress, event.value("message", ""));
+ return false;
+ }
+ if (command == "bt_pair_progress") {
+ set_text(g_devices.lbl_bt_progress, event.value("step", "") + " " + event.value("detail", ""));
+ return true;
+ }
+ if (command == "bt_pair_result" || command == "bt_unpair_result") {
+ gtk_widget_set_sensitive(g_devices.btn_bt_pair, TRUE);
+ set_text(g_devices.lbl_bt_progress, event.value("message", ""));
+ // The bond and the supervised device both just changed.
+ daemon_send({{"command", "bt_status"}});
+ daemon_send({{"command", "bt_list_devices"}});
+ return true;
+ }
return false;
}
@@ -458,17 +773,143 @@ namespace tether::ui {
g_devices.right_pane_stack = gtk_stack_new();
gtk_stack_set_transition_type(GTK_STACK(g_devices.right_pane_stack), GTK_STACK_TRANSITION_TYPE_CROSSFADE);
- // Placeholder
- GtkWidget* placeholder = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
+ // Placeholder, which on a machine with nothing paired is the first thing
+ // anyone sees: it explains both routes rather than saying "select a device".
+ GtkWidget* placeholder = gtk_box_new(GTK_ORIENTATION_VERTICAL, 24);
+ gtk_container_set_border_width(GTK_CONTAINER(placeholder), 24);
gtk_widget_set_valign(placeholder, GTK_ALIGN_CENTER);
- gtk_widget_set_halign(placeholder, GTK_ALIGN_CENTER);
- GtkWidget* p_icon = gtk_image_new_from_icon_name("computer-symbolic", GTK_ICON_SIZE_DIALOG);
- gtk_box_pack_start(GTK_BOX(placeholder), p_icon, FALSE, FALSE, 0);
- GtkWidget* p_lbl = gtk_label_new("Select a device to start");
- gtk_style_context_add_class(gtk_widget_get_style_context(p_lbl), "muted");
- gtk_box_pack_start(GTK_BOX(placeholder), p_lbl, FALSE, FALSE, 0);
+
+ GtkWidget* welcome_title = gtk_label_new(nullptr);
+ gtk_label_set_markup(GTK_LABEL(welcome_title), "<big><b>Connect your iPhone</b></big>");
+ gtk_box_pack_start(GTK_BOX(placeholder), welcome_title, FALSE, FALSE, 0);
+
+ // A plain box cannot reflow, and the two blocks do not both fit in a narrow
+ // window. A flow box drops to a single column instead of clipping.
+ GtkWidget* routes = gtk_flow_box_new();
+ gtk_flow_box_set_selection_mode(GTK_FLOW_BOX(routes), GTK_SELECTION_NONE);
+ gtk_flow_box_set_min_children_per_line(GTK_FLOW_BOX(routes), 1);
+ gtk_flow_box_set_max_children_per_line(GTK_FLOW_BOX(routes), 2);
+ gtk_flow_box_set_column_spacing(GTK_FLOW_BOX(routes), 24);
+ gtk_flow_box_set_row_spacing(GTK_FLOW_BOX(routes), 16);
+ gtk_flow_box_set_homogeneous(GTK_FLOW_BOX(routes), TRUE);
+ gtk_widget_set_halign(routes, GTK_ALIGN_CENTER);
+
+ auto build_route_block =
+ [](const char* icon_name, const char* title, const char* steps, GtkWidget** status_out) {
+ GtkWidget* block = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
+ gtk_widget_set_valign(block, GTK_ALIGN_START);
+
+ GtkWidget* heading = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
+ gtk_box_pack_start(
+ GTK_BOX(heading), gtk_image_new_from_icon_name(icon_name, GTK_ICON_SIZE_BUTTON), FALSE, FALSE, 0);
+ GtkWidget* heading_label = gtk_label_new(nullptr);
+ gtk_label_set_markup(GTK_LABEL(heading_label), title);
+ gtk_label_set_xalign(GTK_LABEL(heading_label), 0.0);
+ gtk_box_pack_start(GTK_BOX(heading), heading_label, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(block), heading, FALSE, FALSE, 0);
+
+ GtkWidget* steps_label = gtk_label_new(steps);
+ gtk_label_set_xalign(GTK_LABEL(steps_label), 0.0);
+ gtk_label_set_line_wrap(GTK_LABEL(steps_label), TRUE);
+ gtk_label_set_max_width_chars(GTK_LABEL(steps_label), 28);
+ gtk_box_pack_start(GTK_BOX(block), steps_label, FALSE, FALSE, 0);
+
+ *status_out = gtk_label_new("");
+ gtk_label_set_xalign(GTK_LABEL(*status_out), 0.0);
+ gtk_label_set_line_wrap(GTK_LABEL(*status_out), TRUE);
+ gtk_label_set_max_width_chars(GTK_LABEL(*status_out), 30);
+ gtk_style_context_add_class(gtk_widget_get_style_context(*status_out), "muted");
+ gtk_box_pack_start(GTK_BOX(block), *status_out, FALSE, FALSE, 0);
+ return block;
+ };
+
+ gtk_container_add(GTK_CONTAINER(routes),
+ build_route_block("network-wireless-signal-excellent-symbolic",
+ "<b>Wi-Fi</b>\nclipboard, files, OTP",
+ "1. Open the Tether app on the iPhone\n"
+ "2. It finds this computer by itself\n"
+ "3. Approve on both ends",
+ &g_devices.lbl_welcome_wifi));
+
+ gtk_container_add(GTK_CONTAINER(routes),
+ build_route_block("bluetooth-active-symbolic",
+ "<b>Bluetooth</b>\nmessages, notifications",
+ "1. Pick the iPhone under BLUETOOTH\n"
+ "2. Press Pair over Bluetooth\n"
+ "3. Grant the two toggles on the phone",
+ &g_devices.lbl_welcome_bt));
+
+ gtk_box_pack_start(GTK_BOX(placeholder), routes, FALSE, FALSE, 0);
+
+ // One button for both routes: scanning is what refreshes either list.
+ GtkWidget* welcome_scan = gtk_button_new_with_label("Scan for devices");
+ gtk_widget_set_halign(welcome_scan, GTK_ALIGN_CENTER);
+ g_signal_connect(welcome_scan,
+ "clicked",
+ G_CALLBACK(+[](GtkWidget*, gpointer) { devices_view_trigger_discovery(); }),
+ nullptr);
+ gtk_box_pack_start(GTK_BOX(placeholder), welcome_scan, FALSE, FALSE, 0);
gtk_stack_add_named(GTK_STACK(g_devices.right_pane_stack), placeholder, "placeholder");
+ // Bluetooth
+ GtkWidget* bt_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 16);
+ gtk_container_set_border_width(GTK_CONTAINER(bt_box), 32);
+ gtk_widget_set_valign(bt_box, GTK_ALIGN_CENTER);
+
+ g_devices.lbl_bt_name = gtk_label_new(nullptr);
+ gtk_label_set_xalign(GTK_LABEL(g_devices.lbl_bt_name), 0.0);
+ gtk_box_pack_start(GTK_BOX(bt_box), g_devices.lbl_bt_name, FALSE, FALSE, 0);
+
+ g_devices.lbl_bt_mode = gtk_label_new(nullptr);
+ gtk_label_set_xalign(GTK_LABEL(g_devices.lbl_bt_mode), 0.0);
+ gtk_label_set_line_wrap(GTK_LABEL(g_devices.lbl_bt_mode), TRUE);
+ gtk_style_context_add_class(gtk_widget_get_style_context(g_devices.lbl_bt_mode), "muted");
+ gtk_box_pack_start(GTK_BOX(bt_box), g_devices.lbl_bt_mode, FALSE, FALSE, 0);
+
+ GtkWidget* capabilities = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
+ for (GtkWidget** label : {&g_devices.lbl_bt_link,
+ &g_devices.lbl_bt_messages,
+ &g_devices.lbl_bt_contacts,
+ &g_devices.lbl_bt_notifications}) {
+ *label = gtk_label_new(nullptr);
+ gtk_label_set_xalign(GTK_LABEL(*label), 0.0);
+ gtk_label_set_line_wrap(GTK_LABEL(*label), TRUE);
+ gtk_box_pack_start(GTK_BOX(capabilities), *label, FALSE, FALSE, 0);
+ }
+ gtk_box_pack_start(GTK_BOX(bt_box), capabilities, FALSE, FALSE, 0);
+
+ g_devices.lbl_bt_reason = gtk_label_new(nullptr);
+ gtk_label_set_xalign(GTK_LABEL(g_devices.lbl_bt_reason), 0.0);
+ gtk_label_set_line_wrap(GTK_LABEL(g_devices.lbl_bt_reason), TRUE);
+ gtk_style_context_add_class(gtk_widget_get_style_context(g_devices.lbl_bt_reason), "muted");
+ gtk_box_pack_start(GTK_BOX(bt_box), g_devices.lbl_bt_reason, FALSE, FALSE, 0);
+
+ GtkWidget* bt_buttons = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
+ g_devices.btn_bt_pair = gtk_button_new_with_label("Pair over Bluetooth");
+ gtk_style_context_add_class(gtk_widget_get_style_context(g_devices.btn_bt_pair), "suggested-action");
+ g_signal_connect(g_devices.btn_bt_pair, "clicked", G_CALLBACK(on_bt_pair_click), nullptr);
+ gtk_box_pack_start(GTK_BOX(bt_buttons), g_devices.btn_bt_pair, FALSE, FALSE, 0);
+
+ g_devices.btn_bt_solicit = gtk_button_new_with_label("Show iPhone Permissions");
+ gtk_widget_set_tooltip_text(g_devices.btn_bt_solicit,
+ "Re-advertise so the iPhone shows its Show Message Notifications and "
+ "Sync Contacts toggles under Settings > Bluetooth > (i).");
+ g_signal_connect(g_devices.btn_bt_solicit, "clicked", G_CALLBACK(on_bt_solicit_click), nullptr);
+ gtk_box_pack_start(GTK_BOX(bt_buttons), g_devices.btn_bt_solicit, FALSE, FALSE, 0);
+
+ g_devices.btn_bt_unpair = gtk_button_new_with_label("Unpair");
+ g_signal_connect(g_devices.btn_bt_unpair, "clicked", G_CALLBACK(on_bt_unpair_click), nullptr);
+ gtk_box_pack_start(GTK_BOX(bt_buttons), g_devices.btn_bt_unpair, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(bt_box), bt_buttons, FALSE, FALSE, 0);
+
+ g_devices.lbl_bt_progress = gtk_label_new(nullptr);
+ gtk_label_set_xalign(GTK_LABEL(g_devices.lbl_bt_progress), 0.0);
+ gtk_label_set_line_wrap(GTK_LABEL(g_devices.lbl_bt_progress), TRUE);
+ gtk_style_context_add_class(gtk_widget_get_style_context(g_devices.lbl_bt_progress), "muted");
+ gtk_box_pack_start(GTK_BOX(bt_box), g_devices.lbl_bt_progress, FALSE, FALSE, 0);
+
+ gtk_stack_add_named(GTK_STACK(g_devices.right_pane_stack), bt_box, "bluetooth");
+
// Pair
GtkWidget* pair_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 16);
gtk_widget_set_valign(pair_box, GTK_ALIGN_CENTER);
diff --git a/src/gtk/main.cpp b/src/gtk/main.cpp
index 0cfa594..497286d 100644
--- a/src/gtk/main.cpp
+++ b/src/gtk/main.cpp
@@ -59,11 +59,16 @@ namespace {
gtk_header_bar_set_custom_title(GTK_HEADER_BAR(header_bar), switcher);
g_signal_connect(stack, "notify::visible-child-name", G_CALLBACK(on_visible_view_changed), nullptr);
- gtk_container_add(GTK_CONTAINER(window), stack);
+
+ GtkWidget* root = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+ gtk_box_pack_start(GTK_BOX(root), stack, TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(root), create_route_bar(), FALSE, FALSE, 0);
+ gtk_container_add(GTK_CONTAINER(window), root);
// One feed, dispatched to whichever view owns the event; the views never
// hold the socket themselves.
daemon_client_on_disconnect([] { messages_view_handle_disconnect(); });
+
daemon_client_start([](const nlohmann::json& event) {
if (devices_view_handle_event(event))
return;
@@ -75,11 +80,6 @@ namespace {
devices_view_trigger_discovery();
devices_view_refresh();
- // Bluetooth connection status is requested by the client on every
- // subscription, including reconnects, so there is nothing to ask for
- // here: doing it once from this point would be lost whenever the daemon
- // had to be autostarted and no socket existed yet.
-
gtk_widget_show_all(window);
gtk_stack_set_visible_child_name(GTK_STACK(stack), "devices");
}
diff --git a/src/gtk/messages_view.cpp b/src/gtk/messages_view.cpp
index 46c32ea..8197e4b 100644
--- a/src/gtk/messages_view.cpp
+++ b/src/gtk/messages_view.cpp
@@ -550,7 +550,7 @@ namespace tether::ui {
}
if (command == "bt_connection_changed") {
update_connection(event);
- return true;
+ return false;
}
if (command == "bt_message") {
// A new message changes both the thread list and, when it lands in
diff --git a/src/gtk/ui_util.cpp b/src/gtk/ui_util.cpp
index 8d01ac3..e541d5b 100644
--- a/src/gtk/ui_util.cpp
+++ b/src/gtk/ui_util.cpp
@@ -6,6 +6,19 @@ namespace tether::ui {
GtkWidget* g_window = nullptr;
GtkWidget* g_header_bar = nullptr;
+ struct RouteIndicator {
+ GtkWidget* box = nullptr;
+ GtkWidget* icon = nullptr;
+ GtkWidget* label = nullptr;
+ const char* name = nullptr;
+ const char* icon_ok = nullptr;
+ const char* icon_off = nullptr;
+ };
+
+ RouteIndicator g_routes[2];
+
+ RouteIndicator& indicator(Route route) { return g_routes[route == Route::WiFi ? 0 : 1]; }
+
constexpr const char* STYLE = R"CSS(
.muted {
opacity: 0.62;
@@ -31,6 +44,14 @@ namespace tether::ui {
border: 1px dashed alpha(@theme_selected_fg_color, 0.55);
}
+.tether-route-bar {
+ border-top: 1px solid alpha(@theme_fg_color, 0.12);
+}
+
+.tether-route-off {
+ opacity: 0.5;
+}
+
.tether-badge {
background-color: @theme_selected_bg_color;
color: @theme_selected_fg_color;
@@ -95,4 +116,55 @@ namespace tether::ui {
}
}
+ GtkWidget* create_route_bar() {
+ GtkWidget* bar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 16);
+ gtk_container_set_border_width(GTK_CONTAINER(bar), 6);
+ gtk_style_context_add_class(gtk_widget_get_style_context(bar), "tether-route-bar");
+
+ auto build = [](RouteIndicator& route, const char* name, const char* icon_ok, const char* icon_off) {
+ route.icon_ok = icon_ok;
+ route.icon_off = icon_off;
+ route.name = name;
+ route.box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 6);
+ route.icon = gtk_image_new_from_icon_name(icon_off, GTK_ICON_SIZE_MENU);
+ gtk_box_pack_start(GTK_BOX(route.box), route.icon, FALSE, FALSE, 0);
+ route.label = gtk_label_new(nullptr);
+ gtk_label_set_ellipsize(GTK_LABEL(route.label), PANGO_ELLIPSIZE_END);
+ gtk_box_pack_start(GTK_BOX(route.box), route.label, FALSE, FALSE, 0);
+ };
+
+ build(indicator(Route::WiFi),
+ "Wi-Fi",
+ "network-wireless-signal-excellent-symbolic",
+ "network-wireless-offline-symbolic");
+ build(indicator(Route::Bluetooth), "Bluetooth", "bluetooth-active-symbolic", "bluetooth-disabled-symbolic");
+
+ gtk_box_pack_start(GTK_BOX(bar), indicator(Route::WiFi).box, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(bar), indicator(Route::Bluetooth).box, FALSE, FALSE, 0);
+
+ set_route_status(Route::WiFi, false, "Waiting for the Tether daemon.");
+ set_route_status(Route::Bluetooth, false, "Waiting for the Tether daemon.");
+ return bar;
+ }
+
+ void set_route_status(Route route, bool ok, const std::string& detail) {
+ RouteIndicator& r = indicator(route);
+ if (!r.box)
+ return;
+
+ gtk_image_set_from_icon_name(GTK_IMAGE(r.icon), ok ? r.icon_ok : r.icon_off, GTK_ICON_SIZE_MENU);
+ GtkStyleContext* context = gtk_widget_get_style_context(r.box);
+ if (ok)
+ gtk_style_context_remove_class(context, "tether-route-off");
+ else
+ gtk_style_context_add_class(context, "tether-route-off");
+
+ const std::string state = std::string(r.name) + ": " + (ok ? "connected" : "not connected");
+ set_text(r.label, state);
+ // The reason can be a sentence or two, which would push the other route
+ // off the strip, so it lives in the tooltip. The Devices page shows it
+ // in full.
+ gtk_widget_set_tooltip_text(r.box, detail.empty() ? state.c_str() : (state + "\n" + detail).c_str());
+ }
+
} // namespace tether::ui
diff --git a/src/gtk/ui_util.hpp b/src/gtk/ui_util.hpp
index e4e4200..688ec58 100644
--- a/src/gtk/ui_util.hpp
+++ b/src/gtk/ui_util.hpp
@@ -20,6 +20,22 @@ namespace tether::ui {
void set_main_window(GtkWidget* window);
GtkWidget* main_window();
void set_header_bar(GtkWidget* bar);
+
+ // Transient text: what the app is doing right now. Route state belongs in
+ // the indicators below, which nothing else overwrites.
void set_status_main(const std::string& text);
+ // The two independent ways the phone is reached. Both are always visible so
+ // "clipboard works but messages do not" is readable at a glance.
+ enum class Route { WiFi, Bluetooth };
+
+ // Builds the status strip carrying both indicators. Call once; the caller
+ // packs the returned widget at the bottom of the window. It does not go in
+ // the header bar, which the view switcher already fills.
+ GtkWidget* create_route_bar();
+
+ // "detail" becomes the tooltip. The daemon's reason strings name the actual
+ // next step, so they are passed through verbatim rather than summarised.
+ void set_route_status(Route route, bool ok, const std::string& detail);
+
} // namespace tether::ui