Skip to content
Open
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
96 changes: 96 additions & 0 deletions docs/IOS-024-toasts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
name: IOS-024
description: "Rex Go shows a short message in a glass toast at the top of the screen, in place of alerts that have only OK, and uses it for uploads and a Notifications row. Use when you change Toast.swift, an alert in the list or the terminal, or the upload feedback."
metadata:
created: "2026-11-24"
updated: "2026-11-25"
---

# IOS-024: Toasts

Status: proposed. The code is written. It is not yet compiled or run on a device.

This doc adds one toast to Rex Go. The toast replaces the alerts that have only an OK button. It also gives the uploads a visible result. It follows the same changes on the desktop and the web client.

## Problem

- **An alert for a small failure.** A failed rename or a failed new tab opens a modal alert with only OK. The user must tap OK before the next action. The alert hides the screen where the failure matters.
- **Uploads show no result.** Add Photo and Add File show a spinner on the key bar. A failure opens an alert. A success shows nothing, and the user does not know where the file went.
- **Notifications have no row in Settings.** The first notification asks for permission once. A user who said no cannot find the way to turn them on again.

## Goal

- One toast shows at a time. It shows over every screen of the app, including the terminal.
- A failure shows as an error toast with the title and the reason in one line.
- An upload shows Uploading, then Uploaded. A failed upload shows the error with Retry.
- Settings shows if notifications are on, and gives the way to turn them on.

## Non-goals

- Alerts that offer a choice stay alerts. Examples are Folder Not Found with Close Project, the questions about the speech model, and the rename fields.
- The toast does not queue. A new toast replaces the old one.
- The desktop and the web client have their own toasts.
- The toast does not take the focus. It has no gesture other than the swipe up.

## Design

### Behavior

**The toast.** A glass capsule shows at the top centre, under the safe area. In a terminal it shows at the bottom centre instead, above the key bar and the pane bar, where the Reconnecting note shows: at the top it would cover the terminal's header. It has two kinds.

| Kind | Content | Stays |
| --- | --- | --- |
| Status | An SF Symbol and one line. The error variant has `exclamationmark.circle.fill` in the system red. | 4 s. 1 s more for each 20 characters past 40. 8 s at most. |
| Progress | A spinner and one line. It becomes its result in the same place. The result can have a button, such as Retry. | While the work runs. Then 3 s for a success. An error with a button stays until the user uses it or closes it. |

- A line has one row. A longer line ends in an ellipsis. VoiceOver reads the full line.
- A swipe toward its edge dismisses the toast: up at the top, down in a terminal. The toast follows the finger.
- Only one place shows the toast: the latest screen that has one. A sheet shows it over a terminal, the terminal over the list.
- A new toast replaces the old one. The old toast ends first.
- Under Reduce Motion, the toast cross-fades for 150 ms. It does not move.
- VoiceOver gets one announcement for each text the toast shows. The toast never takes the focus. A progress that turns into its result announces the result.
- A progress that the user closed, or a new toast replaced, shows its result only when the result is an error. The user must hear of a failure.

**Failures (I4).** The alerts with only OK become error toasts. The text is the title, a colon and the first line of the reason. The reason is cut at 120 characters. The cases are in `HostSection.swift` (the new session and tab, the changes of a tab, a project, a session and the quick launchers), `TerminalScreen.swift` (split, close, new tab, Folder Not Found with only OK) and `HostListView.swift` (make and move a project).

**Uploads (I5).** The toast shows "Uploading <name>", or "Uploading <n> files" for more than one file. It becomes "Uploaded" for 3 s. The toast does not name a folder. The server answers a stream upload (`upload_begin` and the `rex.data.bytes.v1` stream) with no path. It types the path into the terminal and closes the stream. Only the HTTP upload of `/api/upload` answers a path, and the app does not use it. A failure turns the toast into "Can't Upload: <reason>" with Retry. Retry sends only the files that are staged and not yet sent. The server types each file's path as the file arrives, so a file sent twice is typed twice. The staged files go when the toast ends with no Retry. A failure while the files stage has no Retry: the folder goes, and the user picks again. The spinner on the key bar stays.

**Notifications (G4).** Settings has a Notifications row. The app reads the system's state when Settings appears and when the app becomes active.

| State | The row shows |
| --- | --- |
| Allowed or provisional | "On" |
| Not asked yet | A Turn On button. It asks for permission. |
| Denied | The Open Settings button, and the note "Notifications are off". The button opens the notification page of the Settings app. |

**Delete Space.** Delete Space keeps its confirm alert, by the owner's decision. It has no toast and no Undo.

### Model

- `Toasts` (`Toast.swift`) holds the one `current` toast. It is observable. The terminal's UIKit views and the SwiftUI screens use the same `Toasts.shared`, so no view needs plumbing.
- A toast has an optional button and an optional `commit`. `commit` runs once when the toast ends in any way but its button, as the tidy-up of a failed upload's Retry toast. The button runs when the user presses it.
- A timer ends only its own toast. A timer of a replaced toast does nothing.
- A sheet with its own host counts in `sheetHosts`. The root's host does not show the toast while a sheet's host does, so the toast shows once.

### Code

| File | Change |
| --- | --- |
| `ios/GoRex/Views/Toast.swift` | `Toast`, `Toasts`, the `toastHost()` modifier and the views. |
| `ios/GoRex/GoRexApp.swift` | `toastHost()` after `promptSheet`. |
| `HostSection.swift`, `TerminalScreen.swift`, `HostListView.swift` | Error toasts. The `failure` state and its alerts go. |
| `TerminalView+Upload.swift` | The progress toast, the result and Retry. |
| `SettingsView.swift`, `Notifier.swift` | The Notifications row. `Notifier.requestAuthorization()` is the question that `post` asked already. |
| `ios/GoRexTests/ToastTests.swift` | Tests of the toast model. |

A sheet is a view of its own, so the toast of the root is under it. The quick launchers sheet has its own host (`sheetToastHost()`). The other sheets raise no toast. A system alert or the photo picker also covers the toast. This is an open limit.

## Decisions

1. **A new toast replaces the old one.** A queue makes a late message. A user who does a second action does not need the message of the first.
2. **The toast does not name the upload folder.** The stream upload's answer has no path. A guess is worse than no name. A name needs a change of the server's stream, or a change to the HTTP upload. Both are outside this doc.

## Tests

- `ToastTests` use a clock that the test owns. They check the lifetimes, the replacement, the stale timer, the progress that becomes its result, and Retry.
- A device check is open: the toast over the terminal, the swipe up, VoiceOver, Reduce Motion, and the upload.
1 change: 1 addition & 0 deletions ios/GoRex/GoRexApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ struct GoRexApp: App {
.environment(spaces)
.promptSheet(store)
.sshHostKeyAlert()
.toastHost()
.preferredColorScheme(ScreenStyle.shared.terminal ?? Self.colorScheme(scheme))
.background { SystemScheme().accessibilityHidden(true) }
.onAppear(perform: Self.startGhostty)
Expand Down
100 changes: 90 additions & 10 deletions ios/GoRex/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
"sourceLanguage": "en",
"version": "1.0",
"strings": {
"%@: %@": {
"localizations": {
"zh-Hans": {
"stringUnit": {
"state": "translated",
"value": "%@:%@"
}
}
}
},
"%lld Images, New": {
"localizations": {
"en": {
Expand Down Expand Up @@ -280,6 +290,16 @@
}
}
},
"Can't Upload: %@": {
"localizations": {
"zh-Hans": {
"stringUnit": {
"state": "translated",
"value": "无法上传:%@"
}
}
}
},
"Choose": {
"localizations": {
"zh-Hans": {
Expand Down Expand Up @@ -420,6 +440,26 @@
}
}
},
"Notifications are off": {
"localizations": {
"zh-Hans": {
"stringUnit": {
"state": "translated",
"value": "通知已关闭"
}
}
}
},
"On": {
"localizations": {
"zh-Hans": {
"stringUnit": {
"state": "translated",
"value": "开"
}
}
}
},
"Only the first 2000 folders are shown.": {
"localizations": {
"zh-Hans": {
Expand All @@ -430,6 +470,16 @@
}
}
},
"Open Settings": {
"localizations": {
"zh-Hans": {
"stringUnit": {
"state": "translated",
"value": "打开设置"
}
}
}
},
"Opening File": {
"localizations": {
"zh-Hans": {
Expand Down Expand Up @@ -550,16 +600,6 @@
}
}
},
"Can't Upload": {
"localizations": {
"zh-Hans": {
"stringUnit": {
"state": "translated",
"value": "无法上传"
}
}
}
},
"Cancel": {
"localizations": {
"zh-Hans": {
Expand Down Expand Up @@ -1560,6 +1600,16 @@
}
}
},
"Turn On": {
"localizations": {
"zh-Hans": {
"stringUnit": {
"state": "translated",
"value": "开启"
}
}
}
},
"Type a path and press Go, or tap a folder below to open it.": {
"localizations": {
"zh-Hans": {
Expand Down Expand Up @@ -1620,6 +1670,16 @@
}
}
},
"Uploaded": {
"localizations": {
"zh-Hans": {
"stringUnit": {
"state": "translated",
"value": "已上传"
}
}
}
},
"Uploaded, Not Pasted": {
"localizations": {
"zh-Hans": {
Expand All @@ -1630,6 +1690,26 @@
}
}
},
"Uploading %@": {
"localizations": {
"zh-Hans": {
"stringUnit": {
"state": "translated",
"value": "正在上传 %@"
}
}
}
},
"Uploading %lld files": {
"localizations": {
"zh-Hans": {
"stringUnit": {
"state": "translated",
"value": "正在上传 %lld 个文件"
}
}
}
},
"Use": {
"localizations": {
"zh-Hans": {
Expand Down
8 changes: 7 additions & 1 deletion ios/GoRex/Notifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,18 @@ final class Notifier: NSObject, UNUserNotificationCenterDelegate {
Task {
let center = UNUserNotificationCenter.current()
if await center.notificationSettings().authorizationStatus == .notDetermined {
_ = try? await center.requestAuthorization(options: [.alert, .sound])
await requestAuthorization()
}
try? await center.add(request)
}
}

/// Asks the user to allow notifications; whether they are allowed.
@discardableResult
func requestAuthorization() async -> Bool {
(try? await UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound])) ?? false
}

// The answers below use the completion handlers, not the async forms: for
// those, the bridge calls the handler on whatever thread the task resumes
// on, and UIKit asserts the main thread right after it, taking the app's
Expand Down
11 changes: 11 additions & 0 deletions ios/GoRex/Rex/Upload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ enum Upload {
try await stream.waitForClose()
}

/// Sends each of files that is not in sent, in order, and adds it to
/// sent once it is up. A failure at one file leaves those before it in
/// sent, so a second call sends the rest only: the server types each
/// file's path as it arrives, and a file sent twice would be typed twice.
static func sendEach(_ files: [URL], sent: inout Set<URL>, _ send: (URL) async throws -> Void) async throws {
for f in files where !sent.contains(f) {
try await send(f)
sent.insert(f)
}
}

/// A photo's file name: the name the library suggests, as IMG_1234, with
/// the extension of the file it gave, upper case as the camera's are.
nonisolated static func photoName(suggested: String?, file: URL) -> String {
Expand Down
61 changes: 51 additions & 10 deletions ios/GoRex/Terminal/TerminalView+Upload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import UniformTypeIdentifiers
/// files, or files picked, go into the temporary folder of the server's
/// machine (Upload), and their paths are pasted, as the app pastes those of
/// files dropped on a pane of a host. The keyboard comes back as the picker
/// closes, if it was up; ⌘ spins while the files go up, and an alert tells
/// of one that failed.
/// closes, if it was up; ⌘ spins while the files go up, and a toast tells
/// how it went: Uploading, then Uploaded, or the error with Retry
/// (docs/IOS-024-toasts.md).
extension TerminalView: UIDocumentPickerDelegate {
func addPhoto() {
// Once: the picker may be up, or going.
Expand Down Expand Up @@ -54,23 +55,67 @@ extension TerminalView: UIDocumentPickerDelegate {
}

/// Sends the files that files puts into a folder of its own, one after
/// another, and removes the folder.
/// another. The folder goes when the files are sent, or when the
/// failure's toast ends with no Retry.
private func upload(_ files: @escaping (URL) async throws -> [URL]) {
let dir = FileManager.default.temporaryDirectory.appending(path: "Uploads").appending(path: UUID().uuidString)
send(files, into: dir, staged: nil)
}

/// One try. A toast shows it: Uploading, then Uploaded. A failure
/// turns it into the error with Retry, which stays until used or
/// closed. Retry sends the files staged and not yet sent, so it needs
/// no picker again, and a file that went up is not typed twice. The
/// toast does not name the folder: the server's answer to a stream
/// upload has no path (docs/IOS-024-toasts.md).
private func send(_ files: @escaping (URL) async throws -> [URL], into dir: URL, staged: [URL]?, sent: Set<URL> = []) {
bar.uploading += 1
Task {
var list = staged
var done = sent
var toast: UUID?
do {
for f in try await files(dir) {
if list == nil { list = try await files(dir) }
let names = (list ?? []).filter { !done.contains($0) }
toast = Toasts.shared.progress(names.count == 1
? String(localized: "Uploading \(names[0].lastPathComponent)")
: String(localized: "Uploading \(names.count) files"))
try await Upload.sendEach(names, sent: &done) { f in
try await session.host.upload(f, block: session.block, session: session.session)
}
Toasts.shared.settle(toast, with: Toast(kind: .status, text: String(localized: "Uploaded"), seconds: 3))
await Self.remove(dir)
} catch {
failed(error)
let text = String(localized: "Can't Upload: \(Toast.oneLine(error.localizedDescription))")
// A staging that failed part-way left sources moved and
// copies half made: a retry of it would fail again. The
// folder goes, and the error has no Retry; the user picks
// again.
guard let kept = list else {
await Self.remove(dir)
Toasts.shared.settle(toast, with: Toast(kind: .error, text: text, seconds: Toast.lifetime(text)))
bar.uploading -= 1
return
}
let keptDone = done
let retry = Toast.Choice(label: String(localized: "Retry")) { [weak self] in
if let self {
self.send(files, into: dir, staged: kept, sent: keptDone)
} else {
Task { await Self.remove(dir) }
}
}
Toasts.shared.settle(toast, with: Toast(kind: .error, text: text, button: retry, seconds: nil,
commit: { Task { await Self.remove(dir) } }))
}
await Task.detached { try? FileManager.default.removeItem(at: dir) }.value
bar.uploading -= 1
}
}

nonisolated private static func remove(_ dir: URL) async {
await Task.detached { try? FileManager.default.removeItem(at: dir) }.value
}

/// Copies a photo's original file into dir, named as the library
/// names it.
private static func photo(_ p: NSItemProvider, into dir: URL) async throws -> URL {
Expand All @@ -91,10 +136,6 @@ extension TerminalView: UIDocumentPickerDelegate {
}
}

private func failed(_ error: Error) {
alert(String(localized: "Can't Upload"), error.localizedDescription)
}

/// Tells of a problem; the keyboard comes back once it is read, if it
/// was up.
func alert(_ title: String, _ message: String) {
Expand Down
Loading