Skip to content
Closed
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
2 changes: 1 addition & 1 deletion Phone/Sources/About/AboutLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class AboutModel {
/// Yab's community: the group chat on X the site's changelog links to (the Mac's Links.community).
static let community = URL(string: "https://x.com/i/chat/group_join/g2108389056413618447/Tmr5OvF8Rx")!
static let copyright = "© 2026 Serafim Korablev"
static let line = "Yes, another one. A small, quiet browser for your iPhone."
static let line = "Yes, another one. A small, quiet browser for your \(DeviceWord.name)."
static var version: String { "Version \(SettingsStore.version()) (\(SettingsStore.build()))" }

/// Shown at once, for named states and tests.
Expand Down
8 changes: 4 additions & 4 deletions Phone/Sources/Answers/ChatBackend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ struct AskContext: Sendable {
var parts: [String] = []
let previous = history.filter { $0.role == .you || $0.role == .answer }.suffix(8)
if !previous.isEmpty {
parts.append("Earlier conversation on this iPhone:\n" + previous.map {
parts.append("Earlier conversation on this \(DeviceWord.name):\n" + previous.map {
"\($0.role == .you ? "You" : "Assistant"): \(String($0.plain.prefix(2000)))"
}.joined(separator: "\n"))
}
if let page {
parts.append("Page on this iPhone:\nTitle: \(page.title)\nURL: \(page.address)\nPage text:\n\(String(page.text.prefix(12000)))")
parts.append("Page on this \(DeviceWord.name):\nTitle: \(page.title)\nURL: \(page.address)\nPage text:\n\(String(page.text.prefix(12000)))")
}
guard !parts.isEmpty else { return question }
parts.insert("Question: " + question, at: 0)
Expand Down Expand Up @@ -63,8 +63,8 @@ final class Answerers {
case unavailable, interrupted
var errorDescription: String? {
switch self {
case .unavailable: "Apple Intelligence isn't available on this iPhone. Enable it in Settings, then ask again. This question stayed on this iPhone."
case .interrupted: "This iPhone couldn't answer. Ask again, or choose Your Mac for public page questions in Settings. This question stayed on this iPhone."
case .unavailable: "Apple Intelligence isn't available on this \(DeviceWord.name). Enable it in Settings, then ask again. This question stayed on this \(DeviceWord.name)."
case .interrupted: "This \(DeviceWord.name) couldn't answer. Ask again, or choose Your Mac for public page questions in Settings. This question stayed on this \(DeviceWord.name)."
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Phone/Sources/Answers/OnDeviceModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class OnDeviceModel: ChatBackend {

func answer(_ context: AskContext) async throws -> String {
let session = LanguageModelSession(instructions: """
You answer questions about the web page a person has open in Yab, a browser on their iPhone. \
You answer questions about the web page a person has open in Yab, a browser on their \(DeviceWord.name). \
Answer from the page's words in two or three plain sentences, in the language of the question. \
No headings, lists or markup. If the page doesn't say, say so in one sentence.
""")
Expand Down
2 changes: 1 addition & 1 deletion Phone/Sources/App/AppActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ extension AppModel {
Motion.nowGone.run {
saved = self.tasks.markLiveSeen(snapshot)
if !saved {
self.say("Couldn’t save read status on this iPhone", glyph: .macbook)
self.say("Couldn’t save read status on this \(DeviceWord.name)", glyph: .macbook)
}
}
return saved
Expand Down
1 change: 1 addition & 0 deletions Phone/Sources/App/AppModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ final class AppModel {
return self.browser.tab(tab.id)
}
pages.onOpenLink = { [weak self] url, source, opening in self?.openHeldLink(url, from: source, as: opening) }
pages.canOpenLinkBeside = { [weak self] source in self?.canOpenLinkBeside(source) ?? false }
pages.onCloseWindowFrom = { [weak self] id, source in
guard let self, self.browser.tab(id) != nil else { return }
// A background completion never takes focus from another page.
Expand Down
146 changes: 134 additions & 12 deletions Phone/Sources/App/BrowserKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,36 @@ let keysLog = Logger(subsystem: "dev.serafim.fast.iphone", category: "keys")
/// an iPad lists them, and ⌘W is the tab's: the system's Close Window, which
/// closes a single-window app outright, is taken out of the menu.
enum BrowserKey: Hashable, Sendable {
case newTab, openLocation, closeTab, reopenTab
case newTab, newPrivateTab, openLocation, closeTab, reopenTab
case reload, back, forward, find
case nextTab, previousTab, toggleSidebar
case nextTab, previousTab, toggleSidebar, settings
/// The Mac's ⇧⌘S: tabs in the sidebar or across the top; Safari's ⇧⌘\ for All Tabs.
case toggleTabsInSidebar, allTabs
/// The Mac's View and File keys for the page.
case zoomIn, zoomOut, actualSize, stop, reader, copyLink, print
/// ⌘1 to ⌘8 the tab at that place, ⌘9 the last one.
case tab(Int)

static let all: [BrowserKey] = [.newTab, .openLocation, .closeTab, .reopenTab,
.reload, .back, .forward, .find, .nextTab, .previousTab, .toggleSidebar]
static let all: [BrowserKey] = [.newTab, .newPrivateTab, .openLocation, .closeTab, .reopenTab,
.reload, .back, .forward, .find, .nextTab, .previousTab, .toggleSidebar, .settings,
.toggleTabsInSidebar, .allTabs,
.zoomIn, .zoomOut, .actualSize, .stop, .reader, .copyLink, .print]
+ (1...9).map { .tab($0) }

var title: String {
switch self {
case .newTab: "New Tab"
case .newPrivateTab: "New Private Tab"
case .settings: "Settings…"
case .toggleTabsInSidebar: "Show Tabs in Sidebar"
case .allTabs: "Show All Tabs"
case .zoomIn: "Zoom In"
case .zoomOut: "Zoom Out"
case .actualSize: "Actual Size"
case .stop: "Stop Loading"
case .reader: "Show Reader"
case .copyLink: "Copy Link"
case .print: "Print…"
case .openLocation: "Open Location"
case .closeTab: "Close Tab"
case .reopenTab: "Reopen Closed Tab"
Expand All @@ -40,6 +57,18 @@ enum BrowserKey: Hashable, Sendable {
switch self {
case .newTab, .reopenTab: "t"
case .openLocation: "l"
case .newPrivateTab: "n"
case .settings: ","
case .toggleTabsInSidebar: "s"
case .allTabs: "\\"
// ⌘= is ⌘+ on the keyboard, as Safari's Zoom In.
case .zoomIn: "="
case .zoomOut: "-"
case .actualSize: "0"
case .stop: "."
case .reader: "r"
case .copyLink: "c"
case .print: "p"
case .closeTab: "w"
case .reload: "r"
case .back: "["
Expand All @@ -53,7 +82,7 @@ enum BrowserKey: Hashable, Sendable {

var modifiers: UIKeyModifierFlags {
switch self {
case .reopenTab: [.command, .shift]
case .reopenTab, .newPrivateTab, .toggleTabsInSidebar, .allTabs, .reader, .copyLink: [.command, .shift]
case .nextTab: .control
case .previousTab: [.control, .shift]
default: .command
Expand Down Expand Up @@ -89,6 +118,10 @@ enum BrowserKey: Hashable, Sendable {
static let viewMenu = UIMenu.Identifier("dev.serafim.fast.iphone.keys.view")
static let historyMenu = UIMenu.Identifier("dev.serafim.fast.iphone.keys.history")
static let tabsMenu = UIMenu.Identifier("dev.serafim.fast.iphone.keys.switch")
static let settingsMenu = UIMenu.Identifier("dev.serafim.fast.iphone.keys.settings")
static let pageMenu = UIMenu.Identifier("dev.serafim.fast.iphone.keys.page")
static let printMenu = UIMenu.Identifier("dev.serafim.fast.iphone.keys.print")
static let copyMenu = UIMenu.Identifier("dev.serafim.fast.iphone.keys.copy")

/// File holds the tabs, View Reload, History Back and Forward, Window
/// the tab switching, Edit Find on Page: where Safari keeps them.
Expand All @@ -106,19 +139,34 @@ enum BrowserKey: Hashable, Sendable {
// The system's Find would reach only a focused web view, not the tab in front.
builder.remove(menu: .find)

let tabs = inline(filesMenu, [.newTab, .openLocation, .closeTab, .reopenTab])
// Settings where the Mac keeps it, in the app's own menu under About.
let settings = inline(settingsMenu, [.settings])
if builder.menu(for: .preferences) != nil { builder.replace(menu: .preferences, with: settings) }
else if builder.menu(for: .about) != nil { builder.insertSibling(settings, afterMenu: .about) }
else if builder.menu(for: .application) != nil { builder.insertChild(settings, atStartOfMenu: .application) }

let tabs = inline(filesMenu, [.newTab, .newPrivateTab, .openLocation, .closeTab, .reopenTab])
if builder.menu(for: .file) != nil { builder.insertChild(tabs, atStartOfMenu: .file) }
else { builder.insertSibling(UIMenu(title: "File", children: [tabs]), afterMenu: .application) }

let printing = inline(printMenu, [.print])
if builder.menu(for: .file) != nil { builder.insertChild(printing, atEndOfMenu: .file) }

let find = inline(findMenu, [.find])
if builder.menu(for: .edit) != nil { builder.insertChild(find, atEndOfMenu: .edit) }
if builder.menu(for: .edit) != nil {
builder.insertChild(inline(copyMenu, [.copyLink]), atEndOfMenu: .edit)
builder.insertChild(find, atEndOfMenu: .edit)
}
else { builder.insertSibling(UIMenu(title: "Edit", children: [find]), afterMenu: .file) }

let reload = inline(viewMenu, [.reload, .toggleSidebar])
if builder.menu(for: .view) != nil { builder.insertChild(reload, atStartOfMenu: .view) }
let reload = inline(viewMenu, [.reload, .stop, .toggleSidebar, .toggleTabsInSidebar, .allTabs])
if builder.menu(for: .view) != nil {
builder.insertChild(reload, atStartOfMenu: .view)
builder.insertChild(inline(pageMenu, [.reader, .zoomIn, .zoomOut, .actualSize]), atEndOfMenu: .view)
}

var history: [BrowserKey] = [.back, .forward]
if builder.menu(for: .view) == nil { history.insert(contentsOf: [.reload, .toggleSidebar], at: 0) }
if builder.menu(for: .view) == nil { history.insert(contentsOf: [.reload, .toggleSidebar, .toggleTabsInSidebar, .allTabs], at: 0) }
let historyTop = UIMenu(title: "History", identifier: historyMenu, children: history.map(\.command))
let after: UIMenu.Identifier = builder.menu(for: .view) != nil ? .view : .edit
builder.insertSibling(historyTop, afterMenu: after)
Expand All @@ -135,12 +183,24 @@ extension AppModel {
/// puts it away.
func mayUse(_ key: BrowserKey) -> Bool {
if privateContentBlocked || privateLock.presentsPrompt { return false }
// Always ours, Settings up or not: a ⌘, we turn down goes to the
// system's own Settings item, which leaves Yab for the Settings app.
if key == .settings { return true }
if surfaces.settings || surfaces.join || surfaces.chat != nil { return false }
if surfaces.coversChrome { return key == .closeTab && surfaces.field != nil }
return offers(key)
}

/// Whether the key has something to do for the browser as it is, with
/// nothing over it: the field asks this of the commands it offers.
func offers(_ key: BrowserKey) -> Bool {
let tab = browser.tab
switch key {
case .newTab: return true
case .toggleSidebar: return workspace.tabletControls
case .newTab, .newPrivateTab, .settings: return true
case .toggleSidebar, .toggleTabsInSidebar: return workspace.tabletControls
case .allTabs, .zoomIn, .zoomOut, .actualSize, .copyLink, .print: return tab != nil
case .stop: return tab != nil && currentPageState.isLoading
case .reader: return tab != nil && (currentPageState.readerAvailable || currentPageState.readerEnabled)
case .openLocation, .reload, .find: return tab != nil
case .closeTab: return tab != nil
case .reopenTab: return backStack.closed != nil
Expand All @@ -155,7 +215,21 @@ extension AppModel {
guard mayUse(key) else { return }
switch key {
case .newTab: openNewTab()
case .newPrivateTab: openNewTab(privately: true)
case .settings:
// Taken but idle while something covers the browser (mayUse).
guard !surfaces.settings, !surfaces.join, surfaces.chat == nil, !surfaces.coversChrome else { return }
openSettingsFromSpaces(at: nil)
case .toggleSidebar: workspace.sidebarShown.toggle()
case .toggleTabsInSidebar: workspace.preferences.tabsInSidebar.toggle()
case .allTabs: TabStack.of(self).openGallery()
case .zoomIn: pageMenuZoom(1)
case .zoomOut: pageMenuZoom(-1)
case .actualSize: pageMenuZoom(0)
case .stop: if let id = browser.tab?.id { pages.stop(id) }
case .reader: pageMenuReader()
case .copyLink: if let tab = browser.tab { copyLink(of: tab) }
case .print: printPage()
case .openLocation: Motion.fieldOpen.run { surfaces.openField(.address) }
case .closeTab:
if surfaces.field != nil { field.close(); return }
Expand Down Expand Up @@ -186,3 +260,51 @@ extension AppModel {
if let closed { backStack.offer(closed) }
}
}

extension BrowserKey {
/// Kept out of the field: a tab by place, the field itself, Find (the
/// field's own On This Page row) and Settings (its own row).
var commandable: Bool {
switch self {
case .tab, .nextTab, .previousTab, .openLocation, .find, .settings: false
default: true
}
}

/// Other words the field knows a command by.
var aliases: [String] {
switch self {
case .newPrivateTab: ["private", "incognito"]
case .reopenTab: ["reopen", "undo close"]
case .reload: ["refresh"]
case .zoomIn: ["bigger", "larger"]
case .zoomOut: ["smaller"]
case .actualSize: ["reset zoom", "100%"]
case .reader: ["reader", "reading mode"]
case .copyLink: ["copy address", "copy url"]
case .toggleSidebar: ["sidebar", "hide sidebar"]
case .toggleTabsInSidebar: ["tab bar", "vertical tabs"]
case .allTabs: ["tabs", "tab overview"]
default: []
}
}

/// The keys as the menu writes them: ⇧⌘R.
var shortcut: String {
var marks = ""
if modifiers.contains(.control) { marks += "⌃" }
if modifiers.contains(.alternate) { marks += "⌥" }
if modifiers.contains(.shift) { marks += "⇧" }
if modifiers.contains(.command) { marks += "⌘" }
let key = switch input { case "\t": "⇥"; case "=": "+"; default: input.uppercased() }
return marks + key
}
}

extension AppModel {
/// The menu actions the field offers now (Words.commandRows).
var commandCandidates: [CommandCandidate] {
BrowserKey.all.filter { $0.commandable && offers($0) }
.map { CommandCandidate(token: $0.token, title: $0.title, aliases: $0.aliases, shortcut: $0.shortcut) }
Comment on lines +306 to +308

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 New actions evade command search. commandCandidates only includes BrowserKey.all, which has no entries for the new Save as PDF, Duplicate Tab, or Split View actions. Typing those menu names therefore cannot find the actions. The repository requires new menu actions to be available by name in the command field.

Add command entries with the right availability checks, including actions that have no keyboard shortcut.

}
}
5 changes: 5 additions & 0 deletions Phone/Sources/App/BrowserWorkspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ final class BrowserWorkspace {
private(set) var secondFocused = false
private(set) var expanded = false
var paneFrame = CGRect.zero
/// The iPad's downloads button in sight, by its id, in the window:
/// where a file flies to (TabletDownloadFlights).
@ObservationIgnored var downloadsLandings: [String: CGRect] = [:]
var windowSize = CGSize.zero
var tabletControls = false
var regularWidth = false
Expand All @@ -83,6 +86,8 @@ final class BrowserWorkspace {
}
/// All Tabs lays three cards whole across an unfolded Duo on its side.
var galleryAcross: Bool { unfolded && windowSize.width > windowSize.height }
/// The iPad's page card, where All Tabs' cards leave from and land.
var galleryPageFrame: CGRect? { tabletControls && !paneFrame.isEmpty ? paneFrame : nil }
/// What the system reserves from a surface this wide at the window's left:
/// the column beside a page reaches only that edge.
func sides(ofSurface width: CGFloat) -> ChromeGeometry.Sides {
Expand Down
6 changes: 3 additions & 3 deletions Phone/Sources/App/BrowserWorkspaceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ struct BrowserWorkspaceView<Content: View>: View {
Menu {
Button { app.field.openSpaces() } label: { menuLabel("Show Tabs", .yabSidebar) }
if !app.pageIsPrivate, let current = app.browser.tab, !current.isMail {
Button { app.newTabBeside() } label: { menuLabel("Open Beside", .yabSplitPlus) }
Button { app.newTabBeside() } label: { menuLabel("Split View", .yabSplitPlus) }
if app.workspace.paired {
Button { app.workspace.fullSpread() } label: { menuLabel("Full Spread", .yabSplitSlash) }
Button { app.closeWorkspacePage() } label: { menuLabel("Close Page", .yabTabX) }
Button { app.workspace.fullSpread() } label: { menuLabel("Separate Split View", .yabSplitSlash) }
Button { app.closeWorkspacePage() } label: { menuLabel("Close Split", .yabTabX) }
}
}
} label: {
Expand Down
2 changes: 1 addition & 1 deletion Phone/Sources/App/PrivateLock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ final class PrivateLock {
phase = .failed("Private is still locked.")
case .unavailable:
retireAttempt()
phase = .failed("Set a device passcode in iPhone Settings to unlock Private.")
phase = .failed("Set a device passcode in \(DeviceWord.name) Settings to unlock Private.")
case .failed:
retireAttempt()
Haptics.play(.error, reason: Haptics.Reason.unlockFailed)
Expand Down
4 changes: 2 additions & 2 deletions Phone/Sources/App/PrivateLockView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ struct PrivateLockView: View {

private var message: String {
switch app.privateLock.phase {
case .authenticating: "Unlocking with your iPhone."
case .authenticating: "Unlocking with your \(DeviceWord.name)."
case let .failed(message): message
default: "Unlock with Face ID, Touch ID or your device passcode. Your private tabs stay on this iPhone."
default: "Unlock with Face ID, Touch ID or your device passcode. Your private tabs stay on this \(DeviceWord.name)."
}
}
}
2 changes: 1 addition & 1 deletion Phone/Sources/App/TabClearCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ final class TabClearCoordinator {
}
}
persist()
message = "Cleared \(ids.count) on this iPhone" + (unknown > 0 ? " · other tabs protected" : "")
message = "Cleared \(ids.count) on this \(DeviceWord.name)" + (unknown > 0 ? " · other tabs protected" : "")
// Offer Undo after the durable public write, rather than displaying an
// unusable Undo during that await; its six seconds start once its
// toast is on screen (seen).
Expand Down
Loading
Loading