Skip to content

Linux + iPhone Continuity / iMessage / SMS

feat(ios): open url from ShareSheet on Linux

Zack Bartelc481de8db6f4
diff --git a/apple/TetherFramework/Sources/TetherFramework/SharePayload.swift b/apple/TetherFramework/Sources/TetherFramework/SharePayload.swift
index 0df3dd2..d1d0b9f 100644
--- a/apple/TetherFramework/Sources/TetherFramework/SharePayload.swift
+++ b/apple/TetherFramework/Sources/TetherFramework/SharePayload.swift
@@ -12,6 +12,9 @@ public enum SharePayload: Sendable {
/// Send text to the Linux Wayland clipboard (`clipboard_set`).
case clipboard(String)
+ /// Open an http(s) link in the Linux default browser (`open_url`).
+ case openUrl(String)
+
/// Send an OTP/2FA code to the tetherd vault (`new_otp`).
/// - Parameters:
/// - code: The OTP digits or secret string.
diff --git a/apple/TetherFramework/Sources/TetherFramework/ShareSender.swift b/apple/TetherFramework/Sources/TetherFramework/ShareSender.swift
index f52d7dd..db73f77 100644
--- a/apple/TetherFramework/Sources/TetherFramework/ShareSender.swift
+++ b/apple/TetherFramework/Sources/TetherFramework/ShareSender.swift
@@ -83,6 +83,11 @@ public actor ShareSender {
try? await Task.sleep(for: .milliseconds(300))
sendResult = .success(())
+ case .openUrl(let url):
+ connection.send(.openUrl(url))
+ try? await Task.sleep(for: .milliseconds(300))
+ sendResult = .success(())
+
case .otp(let code, let source):
connection.send(.newOtp(code, source: source))
try? await Task.sleep(for: .milliseconds(300))
diff --git a/apple/TetherFramework/Sources/TetherFramework/TetherMessage.swift b/apple/TetherFramework/Sources/TetherFramework/TetherMessage.swift
index b587b6f..f7f11fe 100644
--- a/apple/TetherFramework/Sources/TetherFramework/TetherMessage.swift
+++ b/apple/TetherFramework/Sources/TetherFramework/TetherMessage.swift
@@ -14,6 +14,7 @@ public enum TetherCommand: String, Codable, Sendable {
// Client → Daemon
case clipboardSet = "clipboard_set"
case clipboardGet = "clipboard_get"
+ case openUrl = "open_url"
case fileStart = "file_start"
case fileChunk = "file_chunk"
case fileEnd = "file_end"
@@ -118,6 +119,11 @@ extension TetherMessage {
TetherMessage(command: TetherCommand.clipboardSet.rawValue, content: text)
}
+ // Create an `open_url` message; tetherd opens only http(s) links.
+ public static func openUrl(_ url: String) -> TetherMessage {
+ TetherMessage(command: TetherCommand.openUrl.rawValue, content: url)
+ }
+
// Create a `clipboard_get` request.
public static func clipboardGet() -> TetherMessage {
TetherMessage(command: TetherCommand.clipboardGet.rawValue)
diff --git a/apple/TetherShareExtension/ShareViewController.swift b/apple/TetherShareExtension/ShareViewController.swift
index e912452..651a4ca 100644
--- a/apple/TetherShareExtension/ShareViewController.swift
+++ b/apple/TetherShareExtension/ShareViewController.swift
@@ -330,6 +330,16 @@ private struct ShareSheetView: View {
private func singleItemActions(for item: SharedItem) -> some View {
switch item {
case .text(let text):
+ if let url = Self.webURL(text) {
+ ActionButton(
+ icon: "safari",
+ label: "Open on Desktop",
+ subtitle: url.host() ?? "Opens in your default browser",
+ color: .blue
+ ) {
+ perform(.openUrl(url.absoluteString))
+ }
+ }
ActionButton(
icon: "clipboard",
label: "Send to Clipboard",
@@ -359,6 +369,18 @@ private struct ShareSheetView: View {
}
}
+ /// The text as an http(s) link with a host, or nil when it is anything else
+ /// (prose, a sentence containing a link, mailto:, tel:).
+ private static func webURL(_ text: String) -> URL? {
+ let trimmed = text.trimmingCharacters(in: .whitespacesAndNewlines)
+ guard !trimmed.contains(where: \.isWhitespace),
+ let url = URL(string: trimmed),
+ let scheme = url.scheme?.lowercased(), scheme == "http" || scheme == "https",
+ url.host() != nil
+ else { return nil }
+ return url
+ }
+
// MARK: Content Preview
@ViewBuilder
@@ -503,6 +525,7 @@ private struct ShareSheetView: View {
private func successMessage(for payload: SharePayload) -> String {
switch payload {
case .clipboard: return "Sent to clipboard ✓"
+ case .openUrl: return "Opened on desktop ✓"
case .otp: return "OTP stored in vault ✓"
case .file(_, let name): return "\(name) sent ✓"
}
diff --git a/docs/PROTOCOL.md b/docs/PROTOCOL.md
index 73b8fbc..1201ef4 100644
--- a/docs/PROTOCOL.md
+++ b/docs/PROTOCOL.md
@@ -32,6 +32,22 @@ The clipboard capabilities allow seamless copying and pasting between the Host (
---
+### `open_url` (Client -> Daemon)
+
+**Description**: Sent by a paired device (iPhone Share Extension) to open a web link in the Host's default browser.
+
+**Payload**:
+```json
+{
+ "command": "open_url",
+ "content": "https://example.com/article"
+}
+```
+
+**Daemon Behavior**: Accepted only over the paired mTLS connection. The URL must parse, use `http` or `https`, and have a host; anything else is logged and ignored. Valid links are opened with the default URI handler.
+
+---
+
### `clipboard_updated` (Daemon -> Clients)
**Description**: Broadcasted from the daemon to *all connected active clients* when the Host's clipboard text natively changes (e.g., when the user highlights and presses `Ctrl-C` in a desktop app).
diff --git a/src/core/src/net.cpp b/src/core/src/net.cpp
index 08d9541..f2ac29c 100644
--- a/src/core/src/net.cpp
+++ b/src/core/src/net.cpp
@@ -112,6 +112,36 @@ namespace tether {
return "";
}
+ // Opens a link from a paired device in the default browser. Only http(s) with a
+ // host is accepted so a peer can never reach file:, custom-scheme or other handlers.
+ static void open_web_url(const std::string& url) {
+ if (url.size() > 8192) {
+ debug::log(WARN, "open_url: rejected oversized URL");
+ return;
+ }
+ GUri* uri = g_uri_parse(url.c_str(), G_URI_FLAGS_NONE, nullptr);
+ if (!uri) {
+ debug::log(WARN, "open_url: rejected unparsable URL");
+ return;
+ }
+ const char* host = g_uri_get_host(uri);
+ const char* scheme = g_uri_get_scheme(uri);
+ if (!host || !*host || (g_ascii_strcasecmp(scheme, "http") != 0 && g_ascii_strcasecmp(scheme, "https") != 0)) {
+ debug::log(WARN, "open_url: rejected non-web URL with scheme '{}'", scheme ? scheme : "");
+ g_uri_unref(uri);
+ return;
+ }
+ // Launch the re-serialized parse, not the raw input.
+ char* normalized = g_uri_to_string(uri);
+ g_uri_unref(uri);
+ GError* error = nullptr;
+ if (!g_app_info_launch_default_for_uri(normalized, nullptr, &error)) {
+ debug::log(ERR, "open_url: failed to open '{}': {}", normalized, error ? error->message : "unknown");
+ g_clear_error(&error);
+ }
+ g_free(normalized);
+ }
+
static nlohmann::json make_otp_event(const Otp& otp) {
nlohmann::json event;
event["command"] = "otp_available";
@@ -2004,6 +2034,9 @@ namespace tether {
bc["command"] = "clipboard_updated";
bc["content"] = content;
broadcast_message(bc.dump(), client_fd);
+ } else if (j.contains("command") && j["command"] == "open_url" && j.contains("content") &&
+ j["content"].is_string()) {
+ open_web_url(j["content"].get<std::string>());
} else if (j.contains("command") && j["command"] == "clipboard_get") {
if (g_wayland) {
nlohmann::json resp;