Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
34f76be
Run CI for the master branch
Wavesonics Nov 15, 2026
6b5f54b
Install a pinned periphery release in CI
Wavesonics Nov 15, 2026
0a74e72
Classify server lines and frame long lines safely
Wavesonics Nov 15, 2026
b4bfc77
Address review of server line handling
Wavesonics Nov 15, 2026
dbe4518
Request, cache and show application icons
Wavesonics Nov 15, 2026
69f5edb
Address review of icon requests and caching
Wavesonics Nov 15, 2026
adeb447
Upload test diagnostics when CI tests fail
Wavesonics Nov 15, 2026
ba0a3f8
Document the v8 icon support
Wavesonics Nov 15, 2026
1952e66
Clarify the v8 icon notes in the contributor docs
Wavesonics Nov 15, 2026
98e6628
Record status changes in the reconnect state test
Wavesonics Nov 15, 2026
d661c23
Address review of the docs and the reconnect test
Wavesonics Nov 15, 2026
40128b5
Show session details under the application name
Wavesonics Nov 15, 2026
dab79d2
Address review of session details
Wavesonics Nov 15, 2026
aad99ac
Address second review of session details
Wavesonics Nov 15, 2026
1e87ba2
Restore a blank line in MainViewModel
Wavesonics Nov 15, 2026
a614609
Speak protocol version 8 only
Wavesonics Nov 15, 2026
f0b6f68
Address review of the version 8 change
Wavesonics Nov 15, 2026
ce30995
Fix the split-read framing test input
Wavesonics Nov 15, 2026
a9d26d6
Make the remaining server copy platform neutral
Wavesonics Nov 15, 2026
55b4b27
Test the reference full state and point docs to the version 8 spec
Wavesonics Nov 16, 2026
2dbcbd8
Test the version mismatch flow in the view model
Wavesonics Nov 16, 2026
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
33 changes: 30 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ name: CI

on:
push:
branches: [main]
branches: [main, master]
pull_request:
branches: [main]
branches: [main, master]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
Expand All @@ -20,6 +24,20 @@ jobs:
- name: Run tests
run: bundle exec fastlane test

# The console output is condensed by xcbeautify; keep the raw log, the result
# bundle and any crash reports so failures can be diagnosed.
- name: Upload test diagnostics
if: failure()
uses: actions/upload-artifact@v4
with:
name: test-diagnostics
path: |
~/Library/Logs/scan
~/Library/Developer/Xcode/DerivedData/*/Logs/Test/*.xcresult
~/Library/Logs/DiagnosticReports
if-no-files-found: ignore
retention-days: 7

periphery:
runs-on: macos-latest
steps:
Expand All @@ -30,8 +48,17 @@ jobs:
ruby-version: '3.3'
bundler-cache: true

# The periphery Homebrew tap's cask fails on current Homebrew, so install a
# pinned release binary instead.
- name: Install periphery
run: brew install peripheryapp/periphery/periphery
env:
PERIPHERY_VERSION: '3.8.0'
run: |
curl -fsSL -o "$RUNNER_TEMP/periphery.zip" \
"https://github.com/peripheryapp/periphery/releases/download/${PERIPHERY_VERSION}/periphery-${PERIPHERY_VERSION}.zip"
unzip -q "$RUNNER_TEMP/periphery.zip" -d "$RUNNER_TEMP/periphery"
echo "$RUNNER_TEMP/periphery" >> "$GITHUB_PATH"
"$RUNNER_TEMP/periphery/periphery" version

- name: Scan for dead code
run: bundle exec fastlane periphery
70 changes: 61 additions & 9 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ PCVolumeControl is an iOS application that allows users to remotely control appl
- **Platform**: iOS 17+ Swift app using SwiftUI
- **Architecture Pattern**: MVVM (Model-View-ViewModel)
- **Networking**: TCP socket communication using Apple's Network framework
- **Protocol**: JSON-based protocol (version 7) for client-server communication
- **Protocol**: JSON-based protocol (version 8) for client-server communication

## Key Components

Expand Down Expand Up @@ -58,7 +58,8 @@ The project uses [periphery](https://github.com/peripheryapp/periphery) to detec

In CI this runs as the `periphery` fastlane lane (`bundle exec fastlane periphery`),
which adds `--strict` so the scan exits non-zero on findings. The
`.github/workflows/ci.yml` workflow runs it on every push and pull request.
`.github/workflows/ci.yml` workflow runs it, with a pinned periphery release, on
pushes to and pull requests against `master` (and `main`).

Configuration lives in the committed `.periphery.yml`; `periphery scan` reads it
automatically. A clean run reports `No unused code detected.`. Notes:
Expand All @@ -84,13 +85,64 @@ automatically. A clean run reports `No unused code detected.`. Notes:

## Protocol

The app communicates with the PC server using a JSON protocol:

- **Server → Client**: Sends `FullState` with all devices and sessions information
- **Client → Server**: Sends updates for:
- Default device changes
- Master volume/mute changes
- Individual application volume/mute changes
The app speaks protocol version 8 only, a JSON protocol with one message per line:

- **Server → Client**: full states (all devices and the default device's sessions) and
icon replies to the client's own icon requests
- **Client → Server**: updates for the default device, master volume/mute and session
volume/mute, and `iconRequest` for application icons

The canonical spec is `docs/PROTOCOL.md` in the PcVolumeControlServer repo; sample
messages are in `examples/` of the PcVolumeControlProtocol repo. This app does not work
with the original C# PcVolumeControlWindows server (version 7).
Paths below are relative to `PcVolumeControl/`.

### Version and ids

- Every outgoing message carries `protocolVersion` 8 (`WireProtocol.version` in
`models/ServerLine.swift`). A full state with another version throws
`ProtocolVersionMismatch`, checked before the rest of the state is decoded; the view
model then disconnects (no reconnect) and shows a localised message saying whether the
server (lower number) or the app (higher number) needs updating.
- Session ids are opaque. A session update is sent with the current state's
`defaultDevice.deviceId`, the device whose sessions the app shows.
- mDNS discovery does not read TXT records (servers advertise `protocol=8`); a server of
another version shows up in the list and is rejected with the message above when
connecting, which tells the user what to update instead of hiding the server.

### Lines and icons

- Lines are classified in `models/ServerLine.swift`: `defaultDevice` means a full
state, `icon` means an icon reply, anything else is ignored. Not every line is a
full state. A full state that cannot be decoded ends the stream, which goes through
the normal connection-lost and reconnect path (so a server that keeps sending one
makes the app reconnect repeatedly).
- `datasources/LineFramer.swift` frames the byte stream; icon lines can be several
hundred KiB.
- Sessions may carry an `iconId` (`[a-z0-9]{1,64}`, content-derived). Every server
answers `iconRequest`; one that serves no icons never sends an `iconId`.
- `usecases/IconRequestPlanner.swift` decides what to request: at most 32 ids per
`iconRequest`, at most 64 outstanding, outstanding ids reset when the connection
drops or the app goes to the background (both end the stream). Ids without a usable
image (`notFound` or any other `error`, missing or bad data, a PNG that does not
decode) are not asked for again until the user connects anew.
- `repos/IconRepository.swift` is the entry point for icons: an actor that decodes
PNGs off the main thread and keeps a bounded memory cache over
`datasources/IconDiskCacheDataSource.swift` (Caches/AppIcons, not thread-safe, used
only through the actor). Both are keyed by icon id and requested pixel size.
- Rows show `views/SessionIconView.swift`: the icon, or a placeholder of the same size.

### Session details

- A session may carry an optional `detail` (one line, at most 120 characters), such as a
browser tab title, that tells apart sessions with the same `name`. It is shown
whenever present; servers may be configured never to send it.
- It is display text only. Aliases, saved order and anything else remembered about a
session keep keying on the session `id`; outgoing updates never include it.
- `SessionCell` shows it under the name (or alias) in a smaller, dimmer style on one
line, truncated at the tail. Every row reserves that line, so heights do not change
when a detail appears, changes (up to once a second) or disappears; it is not
animated, and VoiceOver reads it after the name.

## Related Resources

Expand Down
39 changes: 24 additions & 15 deletions Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"About" : {

},
"Adjust the volume of every application on your Windows PC remotely. Turn the game down without leaving voice chat behind." : {
"Adjust the volume of every application on your PC remotely. Turn the game down without leaving voice chat behind." : {
"comment" : "A description of the main feature of the app.",
"isCommentAutoGenerated" : true
},
Expand Down Expand Up @@ -98,8 +98,8 @@
"Done" : {

},
"Download PcVolumeControlWindows releases on GitHub" : {
"comment" : "A link that, when tapped, directs the user to the GitHub releases page for the PcVolumeControlWindows app.",
"Download PcVolumeControlServer releases on GitHub" : {
"comment" : "A link that, when tapped, directs the user to the GitHub releases page for the PcVolumeControlServer app.",
"isCommentAutoGenerated" : true
},
"Edit Custom Name" : {
Expand All @@ -110,6 +110,9 @@
},
"Enter a custom name for \"%@\"" : {

},
"Enter a custom name for \"%@\" (%@)" : {

},
"Enter new name" : {

Expand All @@ -133,7 +136,7 @@
"Leave" : {

},
"Make sure this device and PC are on the same network, the server is allowed through Windows Firewall, and no VPN is active on either device. VPNs often block local discovery." : {
"Make sure this device and PC are on the same network, the PC's firewall allows TCP port 3000 and mDNS (UDP 5353), and no VPN is active on either device. VPNs often block local discovery." : {
"comment" : "A description of troubleshooting steps for connecting to the server.",
"isCommentAutoGenerated" : true
},
Expand Down Expand Up @@ -181,14 +184,14 @@
"comment" : "A description of how to connect to the PcVolumeControl server.",
"isCommentAutoGenerated" : true
},
"On your Windows PC, download the latest installer from GitHub." : {
"On your PC (Windows or Linux), download the latest release from GitHub." : {
"comment" : "A step in the guide that instructs the user to download the latest installer from GitHub.",
"isCommentAutoGenerated" : true
},
"Opens a picker to choose the active output device" : {

},
"Opens the Windows server setup guide" : {
"Opens the server setup guide" : {
"comment" : "A hint that appears when hovering over the button to",
"isCommentAutoGenerated" : true
},
Expand All @@ -203,12 +206,12 @@
"comment" : "The accessibility label for the app logo.",
"isCommentAutoGenerated" : true
},
"PcVolumeControl needs a small, free server running on your Windows PC. Set it up once and this app can find it automatically." : {
"comment" : "A description of the purpose of the Windows server.",
"PcVolumeControl needs a small, free server running on your PC. Set it up once and this app can find it automatically." : {
"comment" : "A description of the purpose of the server.",
"isCommentAutoGenerated" : true
},
"PcVolumeControlWindows releases" : {
"comment" : "A link label that, when tapped, takes the user to the GitHub releases page for the PcVolumeControlWindows repository.",
"PcVolumeControlServer releases" : {
"comment" : "A link label that, when tapped, takes the user to the GitHub releases page for the PcVolumeControlServer repository.",
"isCommentAutoGenerated" : true
},
"Please enter a valid TCP port (1-65535)" : {
Expand Down Expand Up @@ -239,8 +242,8 @@
"comment" : "A button that, when pressed, replays the introductory tour.",
"isCommentAutoGenerated" : true
},
"Run the installer, then start the server. If Windows Firewall asks, click Allow so the server can accept connections on private networks." : {
"comment" : "A step in the guide that instructs the user to run the installer and start the server, with a note about Windows Firewall.",
"Install the server as its README describes, then start it. On Windows, if Windows Firewall asks, click Allow so the server can accept connections on private networks." : {
"comment" : "A step in the guide that instructs the user to install and start the server, with a note about Windows Firewall.",
"isCommentAutoGenerated" : true
},
"Save" : {
Expand Down Expand Up @@ -288,7 +291,7 @@
"isCommentAutoGenerated" : true
},
"Share the download link to open on your PC" : {
"comment" : "A button that allows the user to share the download link to open the PcVolumeControlWindows installer on their PC.",
"comment" : "A button that allows the user to share the download link to open the PcVolumeControlServer installer on their PC.",
"isCommentAutoGenerated" : true
},
"Show me how to set it up" : {
Expand All @@ -299,11 +302,17 @@
"comment" : "A button that lets a user skip the first-launch welcome tour.",
"isCommentAutoGenerated" : true
},
"The server window shows your PC's IP address and port. The default port is 3000." : {
"The server's Status page shows your PC's IP address and port. The default port is 3000." : {
"comment" : "A description of how to find the IP address and port of the server.",
"isCommentAutoGenerated" : true
},
"This app talks to the PcVolumeControl server, a small program that runs on your Windows PC." : {
"This PC server is newer than this app (protocol version %lld). Update PcVolumeControl on this device to connect to it." : {
"comment" : "Error shown when the server speaks a newer protocol version than the app."
},
"This PC server is too old (protocol version %lld). Install the latest PcVolumeControlServer on your PC to use this version of the app." : {
"comment" : "Error shown when the server speaks an older protocol version than the app."
},
"This app talks to the PcVolumeControl server, a small program that runs on your PC." : {
"comment" : "A description of how the app interacts with the server.",
"isCommentAutoGenerated" : true
},
Expand Down
80 changes: 80 additions & 0 deletions PcVolumeControl/datasources/IconDiskCacheDataSource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import Foundation

protocol IconDiskCacheDataSourceProtocol {
func load(id: String, size: Int) -> Data?
func store(_ png: Data, id: String, size: Int)
}

/// Icon PNGs on disk, one file per icon id and requested pixel size, bounded by file
/// count. When the bound is exceeded the least recently used files are evicted down to
/// three quarters of it. Invalid ids are never turned into paths. Not thread-safe: use
/// from one isolation domain.
final class IconDiskCacheDataSource: IconDiskCacheDataSourceProtocol {
private let directory: URL
private let maxEntries: Int
// Counted from the directory on first store, then maintained; eviction recounts.
private var entryCount: Int?

init(
directory: URL = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0]
.appendingPathComponent("AppIcons", isDirectory: true),
maxEntries: Int = 256
) {
self.directory = directory
self.maxEntries = maxEntries
}

func load(id: String, size: Int) -> Data? {
guard let url = fileURL(for: id, size: size), let data = try? Data(contentsOf: url) else { return nil }
// The modification date doubles as the last-used date for eviction.
try? FileManager.default.setAttributes([.modificationDate: Date()], ofItemAtPath: url.path)
return data
}

func store(_ png: Data, id: String, size: Int) {
guard let url = fileURL(for: id, size: size) else { return }
let isNewFile = !FileManager.default.fileExists(atPath: url.path)
do {
try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true)
try png.write(to: url, options: .atomic)
} catch {
appLog("Failed to cache icon \(id): \(error)")
return
}
let count = entryCount.map { $0 + (isNewFile ? 1 : 0) } ?? cachedFiles().count
entryCount = count
if count > maxEntries {
evict()
}
}

private func fileURL(for id: String, size: Int) -> URL? {
guard IconId.isValid(id) else { return nil }
return directory.appendingPathComponent("\(id)_\(size).png", isDirectory: false)
}

private func cachedFiles() -> [URL] {
(try? FileManager.default.contentsOfDirectory(
at: directory,
includingPropertiesForKeys: [.contentModificationDateKey],
options: .skipsHiddenFiles
)) ?? []
}

private func evict() {
let files = cachedFiles()
let keep = maxEntries * 3 / 4
let byLastUse = files
.map { url in
(url, (try? url.resourceValues(forKeys: [.contentModificationDateKey]))?.contentModificationDate ?? .distantPast)
}
.sorted { $0.1 < $1.1 }
var removed = 0
for (url, _) in byLastUse.prefix(max(files.count - keep, 0)) {
if (try? FileManager.default.removeItem(at: url)) != nil {
removed += 1
}
}
entryCount = files.count - removed
}
}
53 changes: 53 additions & 0 deletions PcVolumeControl/datasources/LineFramer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import Foundation

/// Splits a byte stream into newline-terminated lines, independent of how the bytes
/// were chunked by the socket. A trailing `\r` is dropped and blank lines are skipped.
/// A line longer than `maxLineLength` is discarded up to its terminator so one bad
/// line cannot grow the buffer without bound or end the stream.
struct LineFramer {
/// Icon replies can be several hundred KiB; the protocol requires accepting at least 1 MiB.
static let defaultMaxLineLength = 4 * 1024 * 1024

private let maxLineLength: Int
private var buffer: [UInt8] = []
// Bytes at the front of `buffer` already searched for a newline.
private var searchedCount = 0
private var discardingOverlongLine = false

init(maxLineLength: Int = LineFramer.defaultMaxLineLength) {
self.maxLineLength = maxLineLength
}

/// Appends `chunk` and returns every line it completes, in order.
mutating func append(_ chunk: Data) -> [Data] {
buffer.append(contentsOf: chunk)

var lines: [Data] = []
var lineStart = 0
var searchFrom = searchedCount
while let newline = buffer[searchFrom...].firstIndex(of: 0x0A) {
if discardingOverlongLine {
discardingOverlongLine = false
} else {
var lineEnd = newline
if lineEnd > lineStart, buffer[lineEnd - 1] == 0x0D {
lineEnd -= 1
}
if lineEnd > lineStart, lineEnd - lineStart <= maxLineLength {
lines.append(Data(buffer[lineStart..<lineEnd]))
}
}
lineStart = newline + 1
searchFrom = lineStart
}

buffer.removeFirst(lineStart)
searchedCount = buffer.count
if buffer.count > maxLineLength {
buffer.removeAll()
searchedCount = 0
discardingOverlongLine = true
}
return lines
}
}
Loading
Loading