Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ New icons must keep the same visual weight and 16px grid.

- **QR**: decorative placeholder in mocks, deterministic pseudo QR, white background, rounded corners, foreground `#1a1813` (dark mode `#0e0c09`). **Replace with a real QR code in implementation**, but keep size, radius, white background, and padding.
- **CopyPill**: `field` rounded bar. Left side is a mono address with middle ellipsis and a full-address hover tooltip. Right side has copy (green check for 1.3s after success) and open-in-browser buttons; expand/collapse appears only when the full address does not fit on one line. Expanded addresses wrap without a fixed row height.
- File tickets and the home drop zone use `Scan to access on the same Wi-Fi`. Text captions reflect direction: `Scan to view text on the same Wi-Fi`, `Scan to send text to this Mac on the same Wi-Fi`, or `Scan to view or send text on the same Wi-Fi` when both channels are active.
- File tickets show the QR code's network scope beneath the code. Text captions reflect direction: `Scan to view text`, `Scan to send text to this Mac`, or `Scan to view or send text`, followed by the network scope.
- **Share address list**: one bordered list below the QR code, with thin dividers between Local Network, Internet, and Tailscale, in that order. Local IP remains visible while internet sharing is active. Collapse the hostname by default behind a narrow, softly faded Gaussian-blurred preview at the bottom of the LAN addresses, with a centered chevron. Keep it below the URL row with a small gap. The expanded list retains a centered collapse chevron. Clicking an address row selects its QR code. Each row has a label and separate expand, copy, and browser-open controls. Highlight the selected QR entry with `accentSoft`. Enabling a network preserves the current QR selection; disabling or losing the selected entry chooses the first available address, preferring LAN.
- Internet title, access hint, connection dot, and Switch share one line. Online = green, connecting = amber, failed/offline = red; status text is available through hover and accessibility only. Show the actual share link rather than the relay configuration address. Label the public address “Using Relay Service | domain”. Truncate a long domain before the other elements. Show a green verification seal only for the exact host share.fairydog.net; keep the seal visible. Retain actionable errors and a yellow warning with an alert icon: the relay can read shared content, so use a trusted relay.
- Tailscale has one Switch for both MagicDNS and IP addresses. Hide the entire group and its Settings control when Tailscale is not detected. Turning it off keeps the group header and hides its addresses.
- Access-code presentation is a share-level setting. Place a Share Link / Access Code segmented selector above the QR code. Reserve an equal-height row immediately below it for the share-link hint or access code, keeping the QR position stable when switching modes. LAN/Tailscale display their origins in access-code mode while QR codes retain their authenticated URLs; public links retain their relay credentials.

---

Expand Down Expand Up @@ -201,7 +205,7 @@ Browser navigation to `.md(.markdown)` / `.json(.geojson)` / `.csv(.tsv)` render

Screen sections, top to bottom:

1. **QR card**: service running with URL -> QRCard (172x172, padding 18, radius 14) + direction-specific caption + CopyPill. When the service is idle, show one line: `Share text or enable receiving to show the QR code`, without an empty-state card. Preserve the network warning when offline.
1. **QR card**: service running with URL -> QRCard (172x172, padding 18, radius 14) + direction-specific caption + network scope + shared address list. The Internet group contains the optional internet text-receive Switch; it appears only on Text Transfer. When idle, show `Share text or enable receiving to show the QR code` and keep the network controls available. Preserve the network warning when offline.
2. **Send text card**: `surface` radius 16, padding 16, `line` border. `Send` section label -> `PlainTextEditor` (`field`, radius 12, **mono 13**, min-height 118, placeholder `Enter or paste text`, compatible with Chinese IME, accent caret) -> PrimaryBtn "Share" or "Update"; show "Withdraw" GhostBtn when already shared.
3. **Receive text row**: `surface` radius 14, padding 14. Title + Switch, with no persistent helper copy. Opt-in and off by default.
4. **Inbox card**: visible only when receiving is enabled or messages exist. Header = accent status dot + title + unread badge + Clear action. List shows up to 12 items, then a count. Each row has TextGlyph, source device/IP and relative time, text preview up to 3 selectable lines, copy success check, and delete button.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The QR code points to something like `http://192.168.x.x:8080/?t=<random-token>`

### Remote browser sharing

Choose files or send text, then click Internet Sharing → Connect and send the link to a visitor. The built-in service is `https://share.fairydog.net`; first use registers an independent device credential in Keychain. Keep your Mac online. Public connections use HTTPS/WSS, and the relay can read shared content. Remote files are read-only; receiving text over the internet is separate and off by default. LAN permissions remain independent. For self-hosting, enter your Server address and administrator-issued enrollment key in Settings → Network. See the [internet-sharing plan](docs/REMOTE_SHARING_PLAN.md).
Choose files or send text, then turn on Internet in the address list and send that group’s share link to a visitor. LAN, Internet, and detected Tailscale entries share one list; click an address row to change the scan entry. The built-in service is `https://share.fairydog.net`; first use registers an independent device credential in Keychain. Keep your Mac online. Public connections use HTTPS/WSS, and the relay can read shared content. Remote files are read-only; receiving text over the internet is separate and off by default. LAN permissions remain independent. For self-hosting, enter your Server address in Settings → Network. An administrator-issued enrollment key is required unless the Server enables automatic registration with `--registration`, in which case you can leave it blank. See the [Client connection guide](website/server/connect-client.md).

## Terminal usage

Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

### 远程浏览器分享

选择文件或发送文本后,点击「互联网分享 → 连接」,把链接发给访问者。App 内置默认服务 `https://share.fairydog.net`,首次启用自动注册,凭据存入 Keychain;Mac 需保持在线。公网使用 HTTPS/WSS,中继可读取内容。远程文件只读,远程收文本独立且默认关闭,局域网权限不受影响。自托管用户可在「设置 → 网络」填写服务器地址和管理员配对码。详见[互联网分享方案](docs/REMOTE_SHARING_PLAN.md)。
选择文件或发送文本后,开启地址列表中的「互联网」开关,把该组的分享链接发给访问者。局域网、互联网和 Tailscale 地址在同一列表中;点击某条地址切换扫码入口。App 内置默认服务 `https://share.fairydog.net`,首次启用自动注册,凭据存入 Keychain;Mac 需保持在线。公网使用 HTTPS/WSS,中继可读取内容。远程文件只读,远程收文本独立且默认关闭,局域网权限不受影响。自托管用户在「设置 → 网络」填写服务器地址;默认需要管理员提供的配对码,Server 通过 `--registration` 开放自动注册后可留空。详见[连接 Client](website/server/connect-client.md)。

## 终端用法

Expand Down
97 changes: 64 additions & 33 deletions Sources/LocalShare/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@ final class AppState: ObservableObject {
@Published var sharedItems: [URL] = [] // 当前分享的项:0=空、1=单项、N=多选
@Published var sharedIsFile = false // 仅单项有意义:true=单个文件,false=单个文件夹
@Published var sharedDetail: String? // 人类可读元数据:文件→大小,文件夹/多选→项数
@Published var sharedText: String? // 当前广播的一段文本(nil=未分享文本);与 sharedItems 正交
@Published var sharedText: String? { // 当前广播的一段文本(nil=未分享文本);与 sharedItems 正交
didSet { restoreQRSelection() }
}
@Published var textDraft = "" // 文本编辑器草稿(重启回填、再次编辑用);与 sharedText 解耦
@Published private(set) var autoStopMinutes = ShareAutoStop.defaultMinutes // 0 = never
@Published private(set) var customAutoStopMinutes = ShareAutoStop.defaultMinutes
@Published private(set) var autoStopAt: Date?
@Published var isRunning = false
@Published var isRunning = false {
didSet { restoreQRSelection() }
}
@Published var port: in_port_t = 0 // 实际绑定端口(可能因占用回退而异于 configuredPort)
@Published var interfaces: [NetworkInterface] = []
@Published var selectedInterface: NetworkInterface?
@Published var selectedInterface: NetworkInterface? {
didSet { restoreQRSelection() }
}
@Published var lastError: String?
@Published var viewerCount = 0 // 最近 45s 内活跃的访客设备数(FileServer 在线感知)
@Published var viewers: [ViewerInfo] = [] // 在线访客明细(设备名 / 完整 IP),最近活跃在前
Expand All @@ -44,7 +50,9 @@ final class AppState: ObservableObject {
@Published var permission = Permission() // read 常开;add 可切(仅单文件夹分享);edit/del 未开放
@Published var configuredPort: in_port_t = 8080 // 用户期望端口(设置页可改,持久化)
@Published var recents: [RecentShare] = [] // 最近分享(持久化)
@Published var screen: Screen = .share // 屏幕路由(默认落功能主页)
@Published var screen: Screen = .share { // 屏幕路由(默认落功能主页)
didSet { restoreQRSelection() }
}
@Published var wideLayout = false // 当前窗口是否使用宽屏内容布局(仅会话内)
@Published var selectedSettingsCategory: SettingsCategory = .network // 设置页分类(仅会话内)
@Published var appearance: AppearancePref = .system // 外观:跟随系统 / 浅色 / 深色(持久化)
Expand All @@ -54,16 +62,27 @@ final class AppState: ObservableObject {
@Published var textInboxEnabled = false // 「允许收文本」闸门(默认关,持久化;不限分享形态)
@Published var persistReceivedText = false // 「记住收到的文本」(默认关,持久化)
@Published var accessCodeEnabled = false // 电脑间手输入口:网址 + 短码(默认关,持久化)
@Published var tailscaleAccessEnabled = false // Tailscale 入站闸门(默认关,持久化)
@Published private(set) var tailscaleStatus: TailscaleStatus?
@Published var tailscaleAccessEnabled = false { // Tailscale 入站闸门(默认关,持久化)
didSet { restoreQRSelection() }
}
@Published private(set) var tailscaleStatus: TailscaleStatus? {
didSet { restoreQRSelection() }
}
@Published private(set) var selectedAddressKind: ShareAddress.Kind = .localIP
@Published var cliStatus: CLIInstaller.Status = .notInstalled // 命令行工具安装状态
@Published var remoteSettings = RemoteSettings()
@Published var remoteEnrollmentKey = "" // 仅用于首次配对;成功后不落盘
@Published private(set) var remoteAccessEnabled = false
@Published private(set) var remoteTextInboxEnabled = false
@Published private(set) var remoteAccessEnabled = false {
didSet { restoreQRSelection() }
}
@Published private(set) var remoteTextInboxEnabled = false {
didSet { restoreQRSelection() }
}
@Published private(set) var remoteStatus: RemoteAgent.Status = .disconnected
@Published private(set) var remotePaired = false
@Published private(set) var remoteShareBaseURL: String?
@Published private(set) var remoteShareBaseURL: String? {
didSet { restoreQRSelection() }
}
@Published private(set) var remoteError: String?

// GUI 进程仅构造一次,init 末尾自登记;AppDelegate 的 open 事件回调经它触达状态。
Expand Down Expand Up @@ -215,55 +234,66 @@ final class AppState: ObservableObject {
return makeURL(base: base, authenticated: false)
}

private var primaryHost: String? {
selectedInterface?.ip ?? (tailscaleAccessEnabled ? tailscaleStatus?.ipv4 : nil)
var selectedShareAddress: ShareAddress? {
shareAddresses.first { $0.kind == selectedAddressKind } ?? shareAddresses.first
}

var primaryURL: String? {
if let remoteURL { return remoteURL }
guard isRunning, port != 0, let host = primaryHost else { return nil }
return makeURL(host: host)
selectedShareAddress?.qrURL
}

// 票据上的手输入口:默认仍显示/复制完整 token URL;访问码模式只给 origin,浏览器再经 /ls/join
// 输入短码。二维码始终使用 primaryURL,不因展示模式降低安全性或增加扫码步骤。
var presentedURL: String? {
if let remoteURL { return remoteURL }
guard isRunning, port != 0, let host = primaryHost else { return nil }
return makePresentedURL(host: host)
selectedShareAddress?.url
}

var presentedAccessCode: String? {
isRunning && remoteURL == nil && accessCodeEnabled ? accessCode : nil
isRunning && accessCodeEnabled ? accessCode : nil
}

var qrImage: NSImage? {
guard let primaryURL else { return nil }
return QRCode.image(for: primaryURL)
}

// 主地址之外的入口统一收在折叠区。访问码模式下它们只显示 origin,与主地址共用一枚短码;
// 普通模式则保留当前分享路径和 token。Tailscale 两项只在用户显式开放且检测到时出现。
var otherAddresses: [ShareAddress] {
guard isRunning, port != 0, remoteURL == nil else { return [] }
// 三种网络同时列出;启用网络不改变用户选中的二维码入口。
var shareAddresses: [ShareAddress] {
guard isRunning, port != 0 else { return [] }
var result: [ShareAddress] = []
if selectedInterface != nil, let hostname = NetworkInfo.localHostName(), hostname != primaryHost {
if let host = selectedInterface?.ip {
result.append(ShareAddress(kind: .localIP, scope: .localNetwork,
url: makePresentedURL(host: host), qrURL: makeURL(host: host)))
}
if selectedInterface != nil, let hostname = NetworkInfo.localHostName() {
result.append(ShareAddress(kind: .localHostname, scope: .localNetwork,
url: makePresentedURL(host: hostname)))
url: makePresentedURL(host: hostname), qrURL: makeURL(host: hostname)))
}
if let remoteURL {
result.append(ShareAddress(kind: .publicRelay, scope: .publicInternet, url: remoteURL))
}
if tailscaleAccessEnabled, let status = tailscaleStatus {
if let dnsName = status.dnsName, dnsName != primaryHost {
if let dnsName = status.dnsName {
result.append(ShareAddress(kind: .tailscaleMagicDNS, scope: .tailscale,
url: makePresentedURL(host: dnsName)))
}
if status.ipv4 != primaryHost {
result.append(ShareAddress(kind: .tailscaleIP, scope: .tailscale,
url: makePresentedURL(host: status.ipv4)))
url: makePresentedURL(host: dnsName), qrURL: makeURL(host: dnsName)))
}
result.append(ShareAddress(kind: .tailscaleIP, scope: .tailscale,
url: makePresentedURL(host: status.ipv4), qrURL: makeURL(host: status.ipv4)))
}
return result
}

func selectShareAddress(_ kind: ShareAddress.Kind) {
guard shareAddresses.contains(where: { $0.kind == kind }) else { return }
selectedAddressKind = kind
}

private func restoreQRSelection() {
guard !shareAddresses.contains(where: { $0.kind == selectedAddressKind }) else { return }
let kind = shareAddresses.first?.kind ?? .localIP
if kind != selectedAddressKind { selectedAddressKind = kind }
}

private func makePresentedURL(host: String) -> String {
accessCodeEnabled ? "http://\(host):\(port)" : makeURL(host: host)
}
Expand Down Expand Up @@ -320,14 +350,15 @@ final class AppState: ObservableObject {
localBaseURL: localShareBaseURL, localToken: token,
deviceName: Host.current().localizedName ?? "Mac", lang: lang,
localRelayToken: server?.remoteRequestToken ?? "", receivingText: remoteTextInboxEnabled,
automaticRegistration: remoteSettings.usesDefaultService)
automaticRegistration: enrollmentKey.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty)
}

func pairRemote(enrollmentKey: String) async -> String? {
guard let serverURL = remoteSettings.serverURL else { return L.remoteConfigHint(lang) }
do {
try await remoteAgent.pair(serverURL: serverURL, enrollmentKey: enrollmentKey,
deviceName: Host.current().localizedName ?? "Mac", lang: lang)
deviceName: Host.current().localizedName ?? "Mac", lang: lang,
automaticRegistration: enrollmentKey.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty)
remotePaired = remoteAgent.isPaired(for: remoteSettings.serverURL)
remoteEnrollmentKey = ""
remoteError = nil
Expand Down Expand Up @@ -390,7 +421,7 @@ final class AppState: ObservableObject {
remoteAgent.connect(serverURL: serverURL, enrollmentKey: "", localBaseURL: localShareBaseURL,
localToken: token, deviceName: Host.current().localizedName ?? "Mac", lang: lang,
localRelayToken: server?.remoteRequestToken ?? "", receivingText: remoteTextInboxEnabled,
automaticRegistration: remoteSettings.usesDefaultService)
automaticRegistration: true)
}

private func startNetworkMonitoring() {
Expand Down
2 changes: 1 addition & 1 deletion Sources/LocalShare/AutoStopSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,6 @@ struct AutoStopDeadline: View {
formatter.dateStyle = .short
formatter.timeStyle = .short
let date = formatter.string(from: deadline)
return state.lang == .zh ? "\(date) 关闭分享" : "Stops \(date)"
return state.lang == .zh ? "将于 \(date) 自动关闭分享" : "Sharing will stop automatically at \(date)"
}
}
Loading
Loading