Skip to content

armgit / cra

Public Imported from GitHub
0

The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.

One toast design (downloads into the list), peeked folders close on click, toast restart and dark variant (Arc, #85 follow-up) (#108)

Victor Kildahl7464d28e1f5a
diff --git a/Packages/CraCore/Sources/CraCore/DownloadRow.swift b/Packages/CraCore/Sources/CraCore/DownloadRow.swift
new file mode 100644
index 0000000..a8222b6
--- /dev/null
+++ b/Packages/CraCore/Sources/CraCore/DownloadRow.swift
@@ -0,0 +1,56 @@
+import Foundation
+
+/// A row in the downloads list. Arc 1.171 shows downloads that are still running, failed or were
+/// cancelled there, with the finished ones, and has no download toast (its strings: "Failed to
+/// Download", a download speed "e.g. 3 MB/s", subtitles for paused and cancelled downloads).
+/// Cra's bottom-right download cards were the only other toast design and are gone (#85 follow-up).
+public enum DownloadRow {
+ public enum State: Equatable {
+ case downloading(received: Int64, total: Int64, bytesPerSecond: Double?)
+ case failed
+ case cancelled
+ case finished(at: Date)
+ }
+
+ /// The line under the file name: progress and speed while it runs, Arc's failure text, or
+ /// how long ago it finished ("54 seconds ago").
+ public static func subtitle(_ state: State, now: Date) -> String {
+ switch state {
+ case let .downloading(received, total, speed):
+ var s = bytes(received)
+ if total > 0 { s += " of " + bytes(total) }
+ if let speed, speed > 0 { s += " — " + bytes(Int64(speed)) + "/s" }
+ return s
+ case .failed: return "Failed to Download"
+ case .cancelled: return "Cancelled"
+ // At least a second: a row read just as it finished said "in 0 seconds".
+ case let .finished(at): return age.localizedString(fromTimeInterval: -max(1, now.timeIntervalSince(at)))
+ }
+ }
+
+ /// Bytes per second from two progress reports; nil until there is a span to measure.
+ public static func speed(fromBytes a: Int64, at t0: Date, toBytes b: Int64, at t1: Date) -> Double? {
+ let dt = t1.timeIntervalSince(t0)
+ guard dt >= 0.25, b >= a else { return nil }
+ return Double(b - a) / dt
+ }
+
+ /// Finder's sizes (1000-based: "980 bytes", "12 KB", "3 MB", "1.5 GB"), always in English like the
+ /// rest of Cra; ByteCountFormatter follows the system's locale.
+ public static func bytes(_ n: Int64) -> String {
+ if n < 1000 { return "\(n) bytes" }
+ let units = ["KB", "MB", "GB", "TB"]
+ var v = Double(n) / 1000, i = 0
+ while v >= 999.95, i < units.count - 1 { v /= 1000; i += 1 }
+ if i == 0 { return "\(Int(v.rounded())) KB" }
+ let r = (v * 10).rounded() / 10
+ return (r == r.rounded() ? "\(Int(r))" : String(format: "%.1f", locale: Locale(identifier: "en_US_POSIX"), r)) + " " + units[i]
+ }
+
+ private static let age: RelativeDateTimeFormatter = {
+ let f = RelativeDateTimeFormatter()
+ f.locale = Locale(identifier: "en_US")
+ f.unitsStyle = .full
+ return f
+ }()
+}
diff --git a/Packages/CraCore/Sources/CraCore/FolderPeek.swift b/Packages/CraCore/Sources/CraCore/FolderPeek.swift
index 8adc767..934cb91 100644
--- a/Packages/CraCore/Sources/CraCore/FolderPeek.swift
+++ b/Packages/CraCore/Sources/CraCore/FolderPeek.swift
@@ -28,6 +28,13 @@ public enum FolderPeek {
return out
}
+ /// Whether a click on a folder's row opens it. A folder keeping tabs in sight closes instead,
+ /// keeping only the open tab listed (`expanding(_:false:)`), so a folder showing the open tab
+ /// doesn't open from a click at all (Arc 1.171, real clicks, 2 Nov 2026).
+ public static func clickOpens(expanded: Bool, peeked: Bool) -> Bool {
+ !expanded && !peeked
+ }
+
/// The peeks once `tab` closes (⌘W) or leaves the sidebar.
public static func removing<ID: Hashable>(_ tab: ID, peeks: [ID: [ID]]) -> [ID: [ID]] {
var out: [ID: [ID]] = [:]
diff --git a/Packages/CraCore/Tests/CraCoreTests/DownloadRowTests.swift b/Packages/CraCore/Tests/CraCoreTests/DownloadRowTests.swift
new file mode 100644
index 0000000..9338922
--- /dev/null
+++ b/Packages/CraCore/Tests/CraCoreTests/DownloadRowTests.swift
@@ -0,0 +1,37 @@
+import CraCore
+import Foundation
+import Testing
+
+/// Downloads show their progress and failures in the downloads list, as in Arc (#85 follow-up).
+struct DownloadRowTests {
+ let now = Date(timeIntervalSince1970: 1_800_000_000)
+
+ @Test func runningShowsProgressAndSpeed() {
+ let s = DownloadRow.subtitle(.downloading(received: 3_000_000, total: 10_000_000, bytesPerSecond: 1_500_000), now: now)
+ #expect(s == "3 MB of 10 MB — 1.5 MB/s")
+ #expect(DownloadRow.subtitle(.downloading(received: 3_000_000, total: -1, bytesPerSecond: nil), now: now) == "3 MB")
+ }
+
+ @Test func failedAndCancelled() {
+ #expect(DownloadRow.subtitle(.failed, now: now) == "Failed to Download")
+ #expect(DownloadRow.subtitle(.cancelled, now: now) == "Cancelled")
+ }
+
+ @Test func finishedShowsItsAge() {
+ #expect(DownloadRow.subtitle(.finished(at: now.addingTimeInterval(-54)), now: now) == "54 seconds ago")
+ // Just finished, or a clock that ran backwards: never "in 0 seconds".
+ #expect(DownloadRow.subtitle(.finished(at: now), now: now) == "1 second ago")
+ #expect(DownloadRow.subtitle(.finished(at: now.addingTimeInterval(2)), now: now) == "1 second ago")
+ }
+
+ @Test(arguments: [(Int64(980), "980 bytes"), (12_400, "12 KB"), (3_000_000, "3 MB"), (1_540_000_000, "1.5 GB"), (999_960, "1 MB")])
+ func sizesInEnglish(n: Int64, text: String) {
+ #expect(DownloadRow.bytes(n) == text)
+ }
+
+ @Test func speedNeedsASpanAndGrowth() {
+ #expect(DownloadRow.speed(fromBytes: 0, at: now, toBytes: 1_000, at: now.addingTimeInterval(0.1)) == nil)
+ #expect(DownloadRow.speed(fromBytes: 1_000, at: now, toBytes: 500, at: now.addingTimeInterval(1)) == nil)
+ #expect(DownloadRow.speed(fromBytes: 0, at: now, toBytes: 2_000, at: now.addingTimeInterval(2)) == 1_000)
+ }
+}
diff --git a/Packages/CraCore/Tests/CraCoreTests/FolderPeekTests.swift b/Packages/CraCore/Tests/CraCoreTests/FolderPeekTests.swift
index 31e992a..3ee39b3 100644
--- a/Packages/CraCore/Tests/CraCoreTests/FolderPeekTests.swift
+++ b/Packages/CraCore/Tests/CraCoreTests/FolderPeekTests.swift
@@ -35,6 +35,15 @@ struct FolderPeekTests {
#expect(FolderPeek.expanding(inner, true, openTabInside: nil, peeks: peeks) == peeks)
}
+ @Test func aClickOnAPeekedFolderClosesIt() {
+ #expect(FolderPeek.clickOpens(expanded: false, peeked: false))
+ #expect(!FolderPeek.clickOpens(expanded: true, peeked: false))
+ #expect(!FolderPeek.clickOpens(expanded: false, peeked: true))
+ // Closing it keeps only the open tab: a peek of another tab goes, the open tab's stays.
+ #expect(FolderPeek.expanding(outer, false, openTabInside: nil, peeks: [outer: [other]]).isEmpty)
+ #expect(FolderPeek.expanding(outer, false, openTabInside: tab, peeks: [outer: [tab, other]]) == [outer: [tab]])
+ }
+
@Test func closingATabDropsItFromEveryPeek() {
let peeks = [outer: [tab, other], inner: [tab]]
#expect(FolderPeek.removing(tab, peeks: peeks) == [outer: [other]])
diff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swift
index 90c8c0d..a0d4326 100644
--- a/Sources/Cra/App/AppDelegate.swift
+++ b/Sources/Cra/App/AppDelegate.swift
@@ -225,7 +225,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
/// window_dialog_sheet_visible, active tabs). Little Windows go to the Library on quit,
/// so an open one waits too.
func autoUpdateBlocker() -> String? {
- if mainWindows.contains(where: { $0.overlay.toasts.contains { $0.state == CraDownloadState.inProgress.rawValue } }) { return "a download is in progress" }
+ if DownloadHistory.shared.hasRunningDownloads { return "a download is in progress" }
if NSApp.modalWindow != nil || NSApp.windows.contains(where: { $0.isVisible && $0.attachedSheet != nil }) { return "a dialog is open" }
if !littleWindows.isEmpty { return "a Little Window is open" }
if PictureInPictureChrome.shared.isPlaying { return "Picture in Picture is playing" }
@@ -782,12 +782,12 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
case "copyURL":
if let url = current.flatMap({ store.item($0)?.tab?.url }) {
copy(url)
- main.sidebarUI.flashStatus("Copied Current URL", symbol: "link")
+ main.showToast("Copied Current URL")
}
case "copyURLMarkdown":
if let c = current, let it = store.item(c), let url = it.tab?.url {
copy("[\(it.displayTitle)](\(url))")
- main.sidebarUI.flashStatus("Copied URL as Markdown", symbol: "link")
+ main.showToast("Copied URL as Markdown")
}
case "print": main.currentBrowser?.print()
case "capturePage": main.capturePage()
diff --git a/Sources/Cra/Services/DownloadHistory.swift b/Sources/Cra/Services/DownloadHistory.swift
index e3aa47b..f712c7c 100644
--- a/Sources/Cra/Services/DownloadHistory.swift
+++ b/Sources/Cra/Services/DownloadHistory.swift
@@ -4,6 +4,8 @@ import QuickLookThumbnailing
/// Finished downloads, newest last, for the list Arc shows when you hover the Library
/// button (its downloads tray). Kept in downloads.json; files deleted since drop out.
+/// Downloads still running, and ones that failed or were cancelled, are listed too (`live`,
+/// not saved): Arc shows progress and failures there, not in a toast.
@MainActor
@Observable
final class DownloadHistory {
@@ -29,9 +31,85 @@ final class DownloadHistory {
entries = file.load(or: { [] })
}
- /// The hover list: newest downloads still on disk, oldest first.
- var recent: [Entry] {
- Array(entries.filter { FileManager.default.fileExists(atPath: $0.path) }.suffix(Self.listLimit))
+ /// A download Chromium is still reporting on, or one that ended without a file.
+ struct Live: Identifiable, Equatable {
+ let id: UInt32
+ var name: String
+ var path: String
+ var started: Date
+ var received: Int64
+ var total: Int64
+ var percent: Int
+ var bytesPerSecond: Double?
+ /// The last point the speed was measured from.
+ var sampleBytes: Int64 = 0
+ var sampleAt = Date.distantPast
+ var failed = false
+ var cancelled = false
+ /// When Chromium last reported on it (see MainWindowController.checkStalledDownloads).
+ var updated: Date
+
+ var running: Bool { !failed && !cancelled }
+ var row: DownloadRow.State {
+ failed ? .failed : cancelled ? .cancelled : .downloading(received: received, total: total, bytesPerSecond: bytesPerSecond)
+ }
+ }
+
+ private(set) var live: [Live] = []
+
+ /// A row in the hover list.
+ enum Listed: Identifiable, Equatable {
+ case finished(Entry)
+ case live(Live)
+
+ var id: String {
+ switch self {
+ case .finished(let e): return e.id.uuidString
+ case .live(let l): return "live-\(l.id)"
+ }
+ }
+ var date: Date {
+ switch self {
+ case .finished(let e): return e.date
+ case .live(let l): return l.started
+ }
+ }
+ }
+
+ /// The hover list: newest downloads, oldest first: files still on disk, and running, failed
+ /// or cancelled ones.
+ var recent: [Listed] {
+ let finished = entries.filter { FileManager.default.fileExists(atPath: $0.path) }.map(Listed.finished)
+ return Array((finished + live.map(Listed.live)).sorted { $0.date < $1.date }.suffix(Self.listLimit))
+ }
+
+ var hasRunningDownloads: Bool { live.contains(where: \.running) }
+
+ /// Chromium's report on a download: running ones update their row, a finished one leaves for
+ /// `add(path:)`, a failed or cancelled one stays listed for this session.
+ func report(id: UInt32, name: String, path: String, received: Int64, total: Int64, percent: Int,
+ complete: Bool, cancelled: Bool, failed: Bool, now: Date = Date()) {
+ if complete {
+ live.removeAll { $0.id == id }
+ return
+ }
+ var l = live.first { $0.id == id } ?? Live(id: id, name: name, path: path, started: now, received: received, total: total,
+ percent: percent, updated: now)
+ if l.sampleAt == .distantPast {
+ (l.sampleBytes, l.sampleAt) = (received, now)
+ } else if let speed = DownloadRow.speed(fromBytes: l.sampleBytes, at: l.sampleAt, toBytes: received, at: now) {
+ l.bytesPerSecond = speed
+ (l.sampleBytes, l.sampleAt) = (received, now)
+ }
+ l.updated = now
+ l.name = name
+ if !path.isEmpty { l.path = path }
+ l.received = received
+ l.total = total
+ l.percent = percent
+ l.failed = failed
+ l.cancelled = cancelled
+ if let i = live.firstIndex(where: { $0.id == id }) { live[i] = l } else { live.append(l) }
}
@discardableResult
diff --git a/Sources/Cra/UI/Overlays.swift b/Sources/Cra/UI/Overlays.swift
index 518a2d0..8ce8b9f 100644
--- a/Sources/Cra/UI/Overlays.swift
+++ b/Sources/Cra/UI/Overlays.swift
@@ -1,19 +1,7 @@
import AppKit
import Observation
-struct DownloadToast: Identifiable, Equatable {
- let id: UInt32
- var name: String
- var percent: Int
- var state: Int
- var path: String
- var totalBytes: Int64 = -1
- /// When Chromium last reported on it (see MainWindowController.checkStalledDownloads).
- var updated = Date()
-}
-
-/// Overlay state shown on top of the web content: link status, find bar,
-/// download toasts.
+/// Overlay state shown on top of the web content: link status, find bar.
@MainActor
@Observable
final class OverlayState {
@@ -24,7 +12,6 @@ final class OverlayState {
/// Find in page results ("2/7" in the bar); nil until the page answers.
var findMatchCount: Int?
var findActiveMatch = 0
- var toasts: [DownloadToast] = []
}
/// The link under the pointer, bottom left over the page. AppKit: it changes on every link the
@@ -214,122 +201,3 @@ final class FindBarPanel: NSPanel {
hidesOnDeactivate = false
}
}
-
-/// Download toasts, bottom trailing over the page, newest at the bottom.
-final class ToastStackView: NSView {
- private let overlay: OverlayState
- private let onDismiss: (UInt32) -> Void
- private var rows: [UInt32: ToastRowView] = [:]
- private var order: [UInt32] = []
-
- static let rowSize = NSSize(width: 300, height: 52)
-
- init(overlay: OverlayState, onDismiss: @escaping (UInt32) -> Void) {
- self.overlay = overlay
- self.onDismiss = onDismiss
- super.init(frame: .zero)
- observe()
- }
-
- required init?(coder: NSCoder) { fatalError() }
-
- private func observe() {
- let toasts = withObservationTracking { overlay.toasts } onChange: { [weak self] in
- Task { @MainActor in self?.observe() }
- }
- let ids = Set(toasts.map(\.id))
- for (id, r) in rows where !ids.contains(id) { r.removeFromSuperview(); rows[id] = nil }
- for t in toasts {
- let r = rows[t.id] ?? {
- let r = ToastRowView { [weak self] in self?.onDismiss(t.id) }
- rows[t.id] = r
- addSubview(r)
- return r
- }()
- r.show(t)
- }
- order = toasts.map(\.id)
- needsLayout = true
- }
-
- override func layout() {
- super.layout()
- // VStack(spacing: 6) inside padding 10, pinned bottom trailing.
- var y: CGFloat = 10
- for id in order.reversed() {
- guard let r = rows[id] else { continue }
- r.frame = NSRect(x: bounds.width - 10 - Self.rowSize.width, y: y, width: Self.rowSize.width, height: Self.rowSize.height)
- y += Self.rowSize.height + 6
- }
- }
-}
-
-private final class ToastRowView: NSView {
- private let card = MaterialCardView(radius: 10)
- private let icon = NSImageView()
- private let name = NSTextField.sidebarLabel(size: 12, weight: .medium)
- private let detail = NSTextField.sidebarLabel(size: 11)
- private let progress = NSProgressIndicator()
- private let show = ClosureButton(title: "Show", controlSize: .small) {}
- private let close: ClosureButton
- private var path = ""
-
- init(onDismiss: @escaping () -> Void) {
- // Hides the toast only; the download carries on (the Library still has it).
- close = ClosureButton(symbol: "xmark", size: 9, weight: .semibold, tint: .secondaryLabelColor, onPress: onDismiss)
- super.init(frame: .zero)
- addSubview(card)
- icon.imageScaling = .scaleNone
- addSubview(icon)
- addSubview(name)
- detail.textColor = .secondaryLabelColor
- addSubview(detail)
- progress.style = .bar
- progress.controlSize = .small
- progress.isIndeterminate = false
- progress.minValue = 0
- progress.maxValue = 100
- addSubview(progress)
- show.onPress = { [weak self] in
- guard let self else { return }
- NSWorkspace.shared.activateFileViewerSelecting([URL(fileURLWithPath: self.path)])
- }
- addSubview(show)
- addSubview(close)
- }
-
- required init?(coder: NSCoder) { fatalError() }
-
- func show(_ t: DownloadToast) {
- path = t.path
- icon.image = SidebarSymbols.image(t.state == 1 ? "checkmark.circle.fill" : (t.state == 0 ? "arrow.down.circle" : "exclamationmark.circle"), size: 13)
- icon.contentTintColor = t.state == 1 ? .systemGreen : .secondaryLabelColor
- name.stringValue = t.name
- progress.isHidden = t.state != 0
- progress.doubleValue = Double(max(0, t.percent))
- detail.isHidden = t.state == 0
- detail.stringValue = t.state == 1 ? "Downloaded" : (t.state == 2 ? "Cancelled" : "Failed")
- show.isHidden = t.state != 1
- needsLayout = true
- }
-
- override func layout() {
- super.layout()
- card.frame = bounds
- let h = bounds.height
- // padding 10: icon, 10, name over status (flexible), 10, Show, 10, ✕ 16×16, padding 10.
- var x = bounds.width - 10 - 16
- close.frame = NSRect(x: x, y: (h - 16) / 2, width: 16, height: 16)
- if !show.isHidden {
- let s = show.fittingSize
- x -= 10 + s.width
- show.frame = NSRect(x: x, y: (h - s.height) / 2, width: s.width, height: s.height)
- }
- let iw = icon.image?.size.width ?? 15
- icon.frame = NSRect(x: 10, y: 0, width: iw, height: h)
- let tx = 10 + iw + 10, tw = max(0, x - 10 - tx)
- name.frame = NSRect(x: tx - SidebarText.inset, y: h / 2 + 1, width: tw + 2 * SidebarText.inset, height: 15)
- detail.frame = NSRect(x: tx - SidebarText.inset, y: h / 2 - 15, width: tw + 2 * SidebarText.inset, height: 14)
- progress.frame = NSRect(x: tx, y: h / 2 - 11, width: tw, height: 6)
- }
-}
diff --git a/Sources/Cra/UI/PaneToolbarView.swift b/Sources/Cra/UI/PaneToolbarView.swift
index 6112b40..7970389 100644
--- a/Sources/Cra/UI/PaneToolbarView.swift
+++ b/Sources/Cra/UI/PaneToolbarView.swift
@@ -28,7 +28,6 @@ final class PaneToolbarView: NSView {
var url = ""
var host = ""
var path = ""
- var status: ToolbarStatus?
var sidebarVisible = true
var pinned: [Ext] = []
var hasExtensions = false
@@ -132,7 +131,6 @@ final class PaneToolbarView: NSView {
m.canGoBack = nav.canGoBack
m.canGoForward = nav.canGoForward
m.isLoading = nav.isLoading
- m.status = m.focusedPane ? ui.toolbarStatus : nil
m.sidebarVisible = store.window(ui.windowID).sidebarVisible
if let item, item.isEmptyTab {
m.kind = .emptyPane
@@ -302,8 +300,8 @@ final class PaneToolbarView: NSView {
placeholderLabel.isHidden = true
// Arc's developer URL has no hover fill (it edits in place on a click).
let urlHover = m.kind == .developer ? NSColor.clear : NSColor.white.withAlphaComponent(0.08)
- urlButton.show(host: m.host, path: m.path, url: m.url, developer: m.kind == .developer, status: m.status,
- fg: m.fg, fgDim: m.fgDim, hover: urlHover, copyHover: m.hover, animated: old.status?.id != m.status?.id && window != nil)
+ urlButton.show(host: m.host, path: m.path, url: m.url, developer: m.kind == .developer,
+ fg: m.fg, fgDim: m.fgDim, hover: urlHover, copyHover: m.hover)
urlButton.selection = m.selection
case .noTab, .emptyPane:
urlButton.isHidden = true
@@ -586,8 +584,7 @@ final class ToolbarGlyphButton: NSView {
}
/// The URL in the middle of the bar: Arc's Copy Current URL glyph and the host (the dimmer path
-/// after it with Show Full URL; the full URL in monospace after a lock in developer mode), or the
-/// nav-bar status in its place.
+/// after it with Show Full URL; the full URL in monospace after a lock in developer mode).
final class ToolbarURLButton: NSView, NSTextFieldDelegate {
var action: () -> Void = {}
/// The link glyph's own click (Copy Current URL) and the address's right-click menu.
@@ -614,7 +611,7 @@ final class ToolbarURLButton: NSView, NSTextFieldDelegate {
private var copyHover = NSColor.white.withAlphaComponent(0.1)
/// Arc's normal bar (1.171, #88): the glyph is a 24 pt button of its own and the host has its
/// own pill, 24 pt tall, starting 20 pt in with the text 7 pt inside it. Each has its own hover;
- /// the pointer picks one where they meet. A status or the developer bar is one piece.
+ /// the pointer picks one where they meet. The developer bar is one piece.
private var split = false
private enum Region { case none, copy, address }
private var region = Region.none { didSet { if region != oldValue { refreshFill() } } }
@@ -666,30 +663,19 @@ final class ToolbarURLButton: NSView, NSTextFieldDelegate {
/// The glyph's own width, as SwiftUI lays an Image out; developer mode boxes it at 14 pt.
private var iconWidth: CGFloat { developer ? 14 : ceil(icon.image?.size.width ?? 12) }
- func show(host: String, path: String, url: String, developer: Bool, status: ToolbarStatus?, fg: NSColor, fgDim: NSColor, hover: NSColor,
- copyHover: NSColor, animated: Bool) {
+ func show(host: String, path: String, url: String, developer: Bool, fg: NSColor, fgDim: NSColor, hover: NSColor,
+ copyHover: NSColor) {
self.developer = developer
self.hover = hover
self.copyHover = copyHover
- split = !developer && status == nil
+ split = !developer
copyTip.isHidden = !split
self.url = url
ink = fg
field?.textColor = fg
refreshFill()
tip.text = url
- if animated {
- // SwiftUI's .transition(.opacity) on the status swap.
- let fade = CATransition()
- fade.type = .fade
- fade.duration = 0.18
- content.layer?.add(fade, forKey: "fade")
- }
- if let status {
- icon.image = SidebarSymbols.image(status.symbol, size: 12, weight: .medium)
- icon.contentTintColor = fgDim
- label.attributedStringValue = NSAttributedString(string: status.text, attributes: [.font: NSFont.systemFont(ofSize: 13), .foregroundColor: fgDim])
- } else if developer {
+ if developer {
icon.image = SidebarSymbols.image(url.hasPrefix("https://") ? "lock.fill" : "globe", size: 11, weight: .semibold)
icon.contentTintColor = fgDim
label.attributedStringValue = NSAttributedString(string: url, attributes: [.font: NSFont.monospacedSystemFont(ofSize: 12, weight: .regular), .foregroundColor: fg])
diff --git a/Sources/Cra/UI/ShellView.swift b/Sources/Cra/UI/ShellView.swift
index 1da82dd..9791ce8 100644
--- a/Sources/Cra/UI/ShellView.swift
+++ b/Sources/Cra/UI/ShellView.swift
@@ -62,7 +62,7 @@ final class ShellView: NSView {
var onPaneResizeBegan: (() -> Void)?
/// Builds a pane's toolbar (the window controller owns the environment).
var makeToolbar: ((UUID?) -> NSView)?
- /// Where the status bubble, toasts and find bar live (the content container, or an
+ /// Where the status bubble and find bar live (the content container, or an
/// overlay panel's content view when pages are separate windows).
private(set) var overlayParent: NSView
/// Set while the sidebar/card frames are being animated; layout() then leaves them alone.
@@ -72,7 +72,6 @@ final class ShellView: NSView {
/// Arc's faint card over the gradient while no tab is selected.
let placeholderHost = NSView()
let statusHost: NSView
- let toastHost: NSView
let findHost: NSView
/// Stand-in pane id for the no-tab state (toolbar on the gradient, no card).
@@ -169,14 +168,12 @@ final class ShellView: NSView {
}
var statusVisible = false
var findVisible = false
- var toastCount = 0
private var trackingArea: NSTrackingArea?
- init(frame: NSRect, background: NSView, sidebar: NSView, toolbar: NSView, status: NSView, toasts: NSView, find: NSView) {
+ init(frame: NSRect, background: NSView, sidebar: NSView, toolbar: NSView, status: NSView, find: NSView) {
backgroundHost = background
sidebarHost = sidebar
statusHost = status
- toastHost = toasts
findHost = find
overlayParent = contentContainer
super.init(frame: frame)
@@ -247,7 +244,7 @@ final class ShellView: NSView {
self.layoutSubtreeIfNeeded()
}
contentContainer.addSubview(placeholderHost)
- for h in [statusHost, toastHost, findHost] as [NSView] {
+ for h in [statusHost, findHost] as [NSView] {
h.isHidden = true
contentContainer.addSubview(h)
}
@@ -621,17 +618,12 @@ final class ShellView: NSView {
if showDev, selfDock, let pr = frontendPageRect { webInContainer = contentContainer.convert(pr, from: nil) }
let wb = overlayParent === contentContainer ? webInContainer : NSRect(origin: .zero, size: webInContainer.size)
if overlayParent === contentContainer {
- for h in [statusHost, toastHost, findHost] where contentContainer.subviews.last !== h {
+ for h in [statusHost, findHost] where contentContainer.subviews.last !== h {
contentContainer.addSubview(h, positioned: .above, relativeTo: nil)
}
}
statusHost.isHidden = !statusVisible
statusHost.frame = NSRect(x: wb.minX, y: wb.minY, width: min(540, wb.width), height: 34)
- if toastHost.superview === overlayParent {
- let size = Self.toastStackSize(count: toastCount)
- toastHost.isHidden = toastCount == 0
- toastHost.frame = NSRect(x: wb.maxX - size.width, y: wb.minY, width: size.width, height: size.height)
- }
if findHost.superview === overlayParent {
let size = CraMetrics.findBarSize, inset = CraMetrics.findBarInset
findHost.isHidden = !findVisible
@@ -640,25 +632,18 @@ final class ShellView: NSView {
if !animatingPanes, paneCards.allSatisfy({ $0.frozenWebBounds == nil }) { onPaneFrames?(paneWebFrames(layout)) }
}
- /// The download toast stack, bottom trailing over the focused page.
- static func toastStackSize(count: Int) -> NSSize {
- NSSize(width: 330, height: CGFloat(count) * 76 + 20)
- }
-
/// Chrome-style hosting: the status bubble moves into a click-through panel above the
- /// page windows; the find bar and the toasts, which take clicks, each into their own
- /// panel just their size, which the window controller places.
- func moveOverlays(to view: NSView, findBar: NSPanel, toasts: NSPanel) {
+ /// page windows; the find bar, which takes clicks, into its own panel just its size, which
+ /// the window controller places.
+ func moveOverlays(to view: NSView, findBar: NSPanel) {
overlayParent = view
statusHost.removeFromSuperview()
view.addSubview(statusHost)
- for (host, panel) in [(findHost, findBar), (toastHost, toasts)] {
- host.removeFromSuperview()
- host.isHidden = false
- host.autoresizingMask = [.width, .height]
- host.frame = panel.contentView!.bounds
- panel.contentView!.addSubview(host)
- }
+ findHost.removeFromSuperview()
+ findHost.isHidden = false
+ findHost.autoresizingMask = [.width, .height]
+ findHost.frame = findBar.contentView!.bounds
+ findBar.contentView!.addSubview(findHost)
needsLayout = true
}
diff --git a/Sources/Cra/UI/Sidebar/DownloadsTray.swift b/Sources/Cra/UI/Sidebar/DownloadsTray.swift
index 4abf137..383ca27 100644
--- a/Sources/Cra/UI/Sidebar/DownloadsTray.swift
+++ b/Sources/Cra/UI/Sidebar/DownloadsTray.swift
@@ -1,4 +1,5 @@
import AppKit
+import UniformTypeIdentifiers
/// Arc's downloads list: hovering the Library button lists the recent downloads over the
/// bottom of the sidebar, newest at the bottom, and the tab list behind them fades out.
@@ -142,7 +143,12 @@ final class DownloadsTrayView: NSView {
private final class DownloadsTrayRowView: NSView, NSDraggingSource {
var colors = SidebarColors() { didSet { refresh() } }
- private var entry: DownloadHistory.Entry?
+ private var listed: DownloadHistory.Listed?
+ /// The finished file this row stands for (live rows have nothing to open or drag yet).
+ private var entry: DownloadHistory.Entry? {
+ if case .finished(let e)? = listed { return e }
+ return nil
+ }
var now = Date() { didSet { refreshAge() } }
private let thumb = NSView()
private let name = NSTextField.sidebarLabel(size: 14)
@@ -167,9 +173,9 @@ private final class DownloadsTrayRowView: NSView, NSDraggingSource {
override var isFlipped: Bool { true }
- /// Also when only a thumbnail arrived.
- func show(_ e: DownloadHistory.Entry) {
- entry = e
+ /// Also when only a thumbnail arrived, and on every progress report.
+ func show(_ l: DownloadHistory.Listed) {
+ listed = l
refresh()
}
@@ -177,9 +183,18 @@ private final class DownloadsTrayRowView: NSView, NSDraggingSource {
let ink: NSColor = colors.isDark ? .white : .black
name.textColor = ink.withAlphaComponent(0.82)
age.textColor = ink.withAlphaComponent(0.5)
- guard let entry else { return }
- name.stringValue = (entry.path as NSString).lastPathComponent
- if let image = DownloadHistory.shared.thumbnail(for: entry.path) {
+ guard let listed else { return }
+ var image: NSImage?
+ switch listed {
+ case .finished(let e):
+ name.stringValue = (e.path as NSString).lastPathComponent
+ image = DownloadHistory.shared.thumbnail(for: e.path)
+ case .live(let l):
+ // Still running, failed or cancelled: the file type's icon, as in the bin before it lands.
+ name.stringValue = l.name
+ image = NSWorkspace.shared.icon(for: UTType(filenameExtension: (l.name as NSString).pathExtension) ?? .data)
+ }
+ if let image {
// .aspectRatio(contentMode: .fill): the layer fills and crops.
let scale = window?.backingScaleFactor ?? 2
var rect = NSRect(x: 0, y: 0, width: DownloadsTrayMetrics.thumbnail, height: DownloadsTrayMetrics.thumbnail)
@@ -193,19 +208,18 @@ private final class DownloadsTrayRowView: NSView, NSDraggingSource {
refreshAge()
}
+ /// "54 seconds ago", "6 minutes ago"; progress, "Failed to Download" or "Cancelled" (DownloadRow).
private func refreshAge() {
- guard let entry else { return }
- let s = Self.age.localizedString(for: min(entry.date, now), relativeTo: now)
+ guard let listed else { return }
+ let state: DownloadRow.State
+ switch listed {
+ case .finished(let e): state = .finished(at: e.date)
+ case .live(let l): state = l.row
+ }
+ let s = DownloadRow.subtitle(state, now: now)
if age.stringValue != s { age.stringValue = s }
}
- /// "54 seconds ago", "6 minutes ago".
- private static let age: RelativeDateTimeFormatter = {
- let f = RelativeDateTimeFormatter()
- f.unitsStyle = .full
- return f
- }()
-
override func layout() {
super.layout()
let t = DownloadsTrayMetrics.thumbnail
diff --git a/Sources/Cra/UI/Sidebar/List/SidebarRowViews.swift b/Sources/Cra/UI/Sidebar/List/SidebarRowViews.swift
index a63b1fd..f10452c 100644
--- a/Sources/Cra/UI/Sidebar/List/SidebarRowViews.swift
+++ b/Sources/Cra/UI/Sidebar/List/SidebarRowViews.swift
@@ -1184,7 +1184,7 @@ final class FolderRowView: SidebarRowView, NSTextFieldDelegate {
override func click(_ event: NSEvent, at point: NSPoint) {
guard let m = model, let list else { return }
if m.editing { commitRename() }
- list.store.setExpanded(m.id, !m.expanded)
+ list.store.setExpanded(m.id, FolderPeek.clickOpens(expanded: m.expanded, peeked: m.peeked))
}
override func contextMenu(at point: NSPoint) -> NSMenu? {
diff --git a/Sources/Cra/UI/Sidebar/List/SidebarView.swift b/Sources/Cra/UI/Sidebar/List/SidebarView.swift
index f23b8cf..215cd08 100644
--- a/Sources/Cra/UI/Sidebar/List/SidebarView.swift
+++ b/Sources/Cra/UI/Sidebar/List/SidebarView.swift
@@ -341,7 +341,7 @@ final class SidebarTopBarView: NSView {
let entries = ext.entries(inProfile: tab.map { store.profileDirectoryName(item: $0.id) }
?? store.profileDirectoryName(space: store.focusedSpaceID(window: ui.windowID)))
let pinned = ext.pinnedIDs.compactMap { id in entries.first { $0.extensionID == id }.map { (id, $0.name, ext.toolbarIcon(for: $0)) } }
- pill.show(text: text, url: url, hasTab: tab != nil, status: ui.toolbarStatus, colors: colors, active: active,
+ pill.show(text: text, url: url, hasTab: tab != nil, colors: colors, active: active,
pinned: pinned, hasExtensions: !entries.isEmpty)
}
needsLayout = true
@@ -444,7 +444,6 @@ final class SidebarURLPill: NSView {
var actions: SidebarActions?
var showAccessories = false { didSet { if showAccessories != oldValue { refreshAccessories(animated: true) } } }
private let label = NSTextField.sidebarLabel(size: 13)
- private let statusIcon = NSImageView()
private let tip: ArcTooltipAnchorView
private var accessories: [NSView] = []
private var hovering = false { didSet { if hovering != oldValue { refreshFill() } } }
@@ -459,8 +458,6 @@ final class SidebarURLPill: NSView {
layer?.cornerRadius = 10
layer?.cornerCurve = .continuous
label.lineBreakMode = .byTruncatingMiddle
- statusIcon.imageScaling = .scaleNone
- addSubview(statusIcon)
addSubview(label)
tip.followsCursor = true
tip.autoresizingMask = [.width, .height]
@@ -472,22 +469,13 @@ final class SidebarURLPill: NSView {
override var isFlipped: Bool { true }
override var mouseDownCanMoveWindow: Bool { false }
- func show(text: String, url: String, hasTab: Bool, status: ToolbarStatus?, colors: SidebarColors, active: Bool,
+ func show(text: String, url: String, hasTab: Bool, colors: SidebarColors, active: Bool,
pinned: [(String, String, NSImage?)], hasExtensions: Bool) {
self.colors = colors
self.hasTab = hasTab
tip.text = url
- if let status {
- statusIcon.isHidden = false
- statusIcon.image = SidebarSymbols.image(status.symbol, size: 10, weight: .semibold)
- statusIcon.contentTintColor = colors.textSecondary
- label.stringValue = status.text
- label.textColor = colors.textSecondary
- } else {
- statusIcon.isHidden = true
- label.stringValue = text
- label.textColor = hasTab ? colors.textPrimary : colors.textTertiary
- }
+ label.stringValue = text
+ label.textColor = hasTab ? colors.textPrimary : colors.textTertiary
model = (pinned, hasExtensions, active)
refreshAccessories(animated: false)
refreshFill()
@@ -541,11 +529,7 @@ final class SidebarURLPill: NSView {
v.frame = NSRect(x: right, y: (h - 28) / 2, width: 28, height: 28)
right -= 1
}
- var x: CGFloat = 12
- if !statusIcon.isHidden {
- statusIcon.frame = NSRect(x: x, y: 0, width: 12, height: h)
- x += 12 + 6
- }
+ let x: CGFloat = 12
let lh = label.intrinsicContentSize.height
label.frame = NSRect(x: x - SidebarText.inset, y: (h - lh) / 2, width: max(0, right - x) + 2 * SidebarText.inset, height: lh)
tip.frame = NSRect(x: 0, y: 0, width: right, height: h)
diff --git a/Sources/Cra/UI/SidebarUIState.swift b/Sources/Cra/UI/SidebarUIState.swift
index 1e2fd5c..b9f4664 100644
--- a/Sources/Cra/UI/SidebarUIState.swift
+++ b/Sources/Cra/UI/SidebarUIState.swift
@@ -122,22 +122,6 @@ final class SidebarUIState {
var selectionAnchor: UUID?
/// A sidebar drag over the space's list and what releasing it would do.
var listDrop: SidebarListDrop?
- /// Dia's nav-bar status: a short confirmation shown in place of the URL
- /// ("Copied Current URL"), then the URL comes back.
- var toolbarStatus: ToolbarStatus?
- @ObservationIgnored private var statusClear: Task<Void, Never>?
-
- func flashStatus(_ text: String, symbol: String, for seconds: Double = 2) {
- let status = ToolbarStatus(symbol: symbol, text: text)
- withAnimation(.easeOut(duration: 0.15)) { toolbarStatus = status }
- statusClear?.cancel()
- statusClear = Task { @MainActor [weak self] in
- try? await Task.sleep(for: .seconds(seconds))
- guard !Task.isCancelled, let self, self.toolbarStatus?.id == status.id else { return }
- withAnimation(.easeOut(duration: 0.2)) { self.toolbarStatus = nil }
- }
- }
-
func navState(for id: UUID) -> TabNavState { navStates[id] ?? TabNavState() }
/// ⌘-click toggles a tab, ⇧-click adds the run of rows from the anchor.
@@ -167,12 +151,6 @@ final class SidebarUIState {
}
}
-struct ToolbarStatus: Equatable, Identifiable {
- let id = UUID()
- let symbol: String
- let text: String
-}
-
struct RecentDownload: Equatable {
let id: UInt32
var path: String
diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swift
index d26ed70..815b025 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -47,7 +47,7 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
private var lastSidebarWidth: CGFloat = 0
private var commandBarOpenedAt = Date.distantPast
private var commandBarClosingClick = DismissingClick()
- private let backgroundTabToast = BackgroundTabToast()
+ private let toast = ShinyToast()
private var commandObserving = false
/// Closed for good (another window stayed open): it no longer follows the store.
private var isTornDown = false
@@ -95,7 +95,6 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
sidebar: SidebarView(store: store, ui: sidebarUI, actions: sidebarActions, favicons: app.favicons),
toolbar: PaneToolbarView(paneTabID: nil, store: store, ui: sidebarUI, actions: sidebarActions),
status: StatusBubbleView(overlay: overlay),
- toasts: ToastStackView(overlay: overlay, onDismiss: { [weak self] id in self?.removeToast(id) }),
find: FindBarView(overlay: overlay, onFind: { [weak self] q, fwd in self?.find(q, forward: fwd) },
onClose: { [weak self] in self?.hideFindBar() }))
shell.sidebarWidth = CGFloat(store.prefs.sidebarWidth)
@@ -438,7 +437,7 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
func addSplitPane() {
guard let current = selectedTabID else { openCommandBar(.newTab); return }
if store.paneTabIDs(for: current).count >= 4 {
- sidebarUI.flashStatus("Cannot Add New Pane", symbol: "rectangle.portrait.split.2x1.slash")
+ showToast("Cannot Add New Pane")
return
}
guard store.addEmptyPane(nextTo: current) != nil else { return }
@@ -508,48 +507,33 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
func browserManager(download: CraDownloadInfo) {
let name = (download.fullPath as NSString).lastPathComponent.isEmpty ? download.suggestedName : (download.fullPath as NSString).lastPathComponent
- let toast = DownloadToast(id: download.identifier, name: name, percent: download.percent, state: download.state.rawValue,
- path: download.fullPath, totalBytes: download.totalBytes)
- if let i = overlay.toasts.firstIndex(where: { $0.id == toast.id }) { overlay.toasts[i] = toast } else {
- overlay.toasts.append(toast)
+ if windowDownloads.insert(download.identifier).inserted {
ChromeDownloadAnimation.suppress()
showDownloadInSidebar(download, name: name)
}
+ // Progress and failures show in the downloads list, as in Arc (it has no download toast).
+ DownloadHistory.shared.report(id: download.identifier, name: name, path: download.fullPath, received: download.receivedBytes,
+ total: download.totalBytes, percent: download.percent, complete: download.state == .complete,
+ cancelled: download.state == .cancelled, failed: download.state == .interrupted)
updateRecentDownload(download)
if download.state == .complete, !download.fullPath.isEmpty, finishedDownloads.insert(download.identifier).inserted {
DownloadHistory.shared.add(path: download.fullPath)
}
- layoutToasts()
- if download.state != .inProgress {
- let id = toast.id
- DispatchQueue.main.asyncAfter(deadline: .now() + 8) { [weak self] in self?.removeToast(id) }
- } else if downloadWatchdog == nil {
+ if download.state == .inProgress, downloadWatchdog == nil {
downloadWatchdog = Timer.scheduledTimer(withTimeInterval: 2, repeats: true) { [weak self] _ in
MainActor.assumeIsolated { self?.checkStalledDownloads() }
}
}
}
- private func removeToast(_ id: UInt32) {
- guard overlay.toasts.contains(where: { $0.id == id }) else { return }
- overlay.toasts.removeAll { $0.id == id }
- layoutToasts()
- }
-
- private func layoutToasts() {
- shell.toastCount = overlay.toasts.count
- shell.layoutContentChildren()
- layoutToastPanel()
- }
-
private var downloadWatchdog: Timer?
/// Chromium stops reporting a download once the tab that started it is gone (the
- /// download carries on, or ends, silently), which left its toast "in progress" for
- /// good. A toast that hasn't heard from Chromium for a while reads the file instead:
+ /// download carries on, or ends, silently), which left its row "in progress" for
+ /// good. A row that hasn't heard from Chromium for a while reads the file instead:
/// gone means it ended, the full size with no .crdownload beside it means it's done.
private func checkStalledDownloads() {
- let inProgress = overlay.toasts.filter { $0.state == CraDownloadState.inProgress.rawValue }
+ let inProgress = DownloadHistory.shared.live.filter { $0.running && windowDownloads.contains($0.id) }
guard !inProgress.isEmpty else {
downloadWatchdog?.invalidate()
downloadWatchdog = nil
@@ -561,13 +545,13 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
let size = (try? fm.attributesOfItem(atPath: t.path))?[.size] as? Int64
let state: CraDownloadState
if size == nil { state = .cancelled }
- else if let size, t.totalBytes > 0, size >= t.totalBytes { state = .complete }
+ else if let size, t.total > 0, size >= t.total { state = .complete }
else { continue }
let info = CraDownloadInfo()
info.identifier = t.id
info.fullPath = t.path
info.suggestedName = t.name
- info.totalBytes = t.totalBytes
+ info.totalBytes = t.total
info.receivedBytes = size ?? 0
info.percent = state == .complete ? 100 : t.percent
info.state = state
@@ -598,6 +582,8 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
}
private var finishedDownloads: Set<UInt32> = []
+ /// Downloads this window's pages started (its flight and stall checks).
+ private var windowDownloads: Set<UInt32> = []
/// Keeps the Library button's file current: its path once known, its Quick Look
/// thumbnail once the download is complete (Arc showed a text file's page).
@@ -649,10 +635,9 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
/// Page-sized and always click-through: it covers the whole page, so if it ever took
/// mouse events every click on the page would land in it. Anything clickable over the
- /// page gets its own panel just its size (the find bar, the toasts).
+ /// page gets its own panel just its size (the find bar).
private var overlayPanel: NSPanel?
private var findPanel: FindBarPanel?
- private var toastPanel: NSPanel?
/// Page area per visible tab, window coordinates (one entry per pane).
private var lastPaneFrames: [UUID: NSRect] = [:]
/// While a divider is dragged the page windows follow every mouse move.
@@ -674,40 +659,17 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
let panel = clearPanel()
panel.ignoresMouseEvents = true
let find = FindBarPanel()
- let toasts = clearPanel()
- shell.moveOverlays(to: panel.contentView!, findBar: find, toasts: toasts)
+ shell.moveOverlays(to: panel.contentView!, findBar: find)
window.addChildWindow(panel, ordered: .above)
overlayPanel = panel
findPanel = find
- toastPanel = toasts
if overlay.findVisible { window.addChildWindow(find, ordered: .above) }
- layoutToastPanel()
- }
-
- /// The toast panel is on screen only while there are toasts, sized to the stack in the
- /// bottom trailing corner of the focused page (the overlay panel's frame).
- private func layoutToastPanel() {
- guard let window, let panel = toastPanel, let page = overlayPanel?.frame else { return }
- guard !overlay.toasts.isEmpty else {
- if panel.parent != nil { window.removeChildWindow(panel) }
- if panel.isVisible { panel.orderOut(nil) }
- return
- }
- let frame = toastPanelFrame(page: page)
- if panel.frame != frame { panel.setFrame(frame, display: true) }
- if panel.parent !== window { window.addChildWindow(panel, ordered: .above) }
- }
-
- private func toastPanelFrame(page: NSRect) -> NSRect {
- let size = ShellView.toastStackSize(count: overlay.toasts.count)
- return NSRect(x: page.maxX - size.width, y: page.minY, width: size.width, height: size.height)
}
/// Overlay panel above the page windows (and the floating sidebar), the find bar above it.
private func raiseOverlayPanels() {
guard let window else { return }
var panels: [NSPanel?] = [overlayPanel]
- if !overlay.toasts.isEmpty { panels.append(toastPanel) }
if overlay.findVisible { panels.append(findPanel) }
// A Peek (and its dimming) stays above everything else in the window.
let wanted = panels.compactMap { $0 } + peeks.flatMap(\.peekWindows)
@@ -903,7 +865,6 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
let focusOnScreen = window.convertToScreen(focusPage)
if let panel = overlayPanel, panel.frame != focusOnScreen { panel.setFrame(focusOnScreen, display: true) }
if let find = findPanel, find.frame != findPanelFrame(page: focusOnScreen) { find.setFrame(findPanelFrame(page: focusOnScreen), display: true) }
- layoutToastPanel()
}
/// Pages follow their cards without Chromium laying them out on every frame (an animated
@@ -941,7 +902,6 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
}
overlayPanel?.animator().setFrame(window.convertToScreen(focusPage), display: true)
findPanel?.animator().setFrame(findPanelFrame(page: window.convertToScreen(focusPage)), display: true)
- if !overlay.toasts.isEmpty { toastPanel?.animator().setFrame(toastPanelFrame(page: window.convertToScreen(focusPage)), display: true) }
}
}
@@ -1507,7 +1467,7 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
f.sidebarHidden = { [weak self] in self.map { !$0.sidebarVisible } ?? false }
f.staysShown = { FolderPreviewController.shared.isOpen }
f.didAttachPanel = { [weak self] in
- // Keep toasts and the find bar above the floating sidebar.
+ // Keep the find bar above the floating sidebar.
self?.raiseOverlayPanels()
}
f.install()
@@ -2219,13 +2179,17 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
commandBarOpenedAt = Date()
browsers.ensureRuntime(for: tab.id) // load it so the title and favicon fill in
// With the sidebar out the new row shows there; hidden, Arc says so in a toast.
- if !sidebarVisible, let window {
- let page = shell.webContainer.convert(shell.webContainer.bounds, to: nil)
- backgroundTabToast.show("New Tab Created", page: page, in: window, theme: focusedSpace.theme)
- }
+ if !sidebarVisible { showToast("New Tab Created") }
return true
}
+ /// Arc's toast at the top right of the page (ShinyToast): Cra's confirmations.
+ func showToast(_ text: String) {
+ guard let window else { return }
+ let page = shell.webContainer.convert(shell.webContainer.bounds, to: nil)
+ toast.show(text, page: page, in: window, theme: focusedSpace.theme)
+ }
+
/// Navigate the focused tab (an empty split pane gets its first page here).
func loadInSelectedTab(_ url: String) {
guard let id = selectedTabID else { return }
diff --git a/Sources/Cra/UI/Windows/BackgroundTabToast.swift b/Sources/Cra/UI/Windows/ShinyToast.swift
similarity index 66%
rename from Sources/Cra/UI/Windows/BackgroundTabToast.swift
rename to Sources/Cra/UI/Windows/ShinyToast.swift
index 5c8b091..9428316 100644
--- a/Sources/Cra/UI/Windows/BackgroundTabToast.swift
+++ b/Sources/Cra/UI/Windows/ShinyToast.swift
@@ -1,14 +1,16 @@
import AppKit
import QuartzCore
-/// Arc's "New Tab Created" toast (Toasts.ShinyToastView, the `backgroundTabCreated` toast), shown
-/// when ⌘Return in the command bar opens a tab the sidebar can't show because it is hidden
-/// (GitHub #85). Arc 1.171, measured 2 Nov 2026 at 1x: a 42 pt pill 8 pt below the top of the
+/// Arc's toast (Toasts.ShinyToastView): every short confirmation in Arc is one, "New Tab Created"
+/// (⌘Return in the command bar with the sidebar hidden, GitHub #85), "Copied Current URL",
+/// "Cannot Add New Pane" and the rest (`backgroundTabCreated`, `copyTabURL`, `maxNumberPanes`…), so
+/// Cra shows all of its confirmations with this. Arc 1.171, measured 2 Nov 2026 at 1x: a 42 pt pill 8 pt below the top of the
/// page and 9 pt in from its right edge, 14 pt medium black text with 12 pt either side, a fill
/// from the space's colours with a 1 pt darker outline. It springs in from its top centre
-/// (≈0.3 s response, 4 % overshoot), stays 4.85 s and shrinks back into its top in 80 ms.
+/// (≈0.3 s response, 4 % overshoot), stays 4.85 s after the last tab it announced (another one
+/// bumps it by 4 %) and shrinks back into its top in 80 ms.
@MainActor
-final class BackgroundTabToast {
+final class ShinyToast {
static let height: CGFloat = 42
static let topInset: CGFloat = 8
static let trailingInset: CGFloat = 9
@@ -17,11 +19,11 @@ final class BackgroundTabToast {
/// Room around the pill in its panel, so the spring's overshoot isn't clipped.
static let margin: CGFloat = 8
static let font = NSFont.systemFont(ofSize: 14, weight: .medium)
- /// How long the toast stays up after the last tab it announced.
+ /// How long the toast stays up after the last message.
static let visibleFor: TimeInterval = 4.85
private let panel: NSPanel
- private let pill = CALayer()
+ private let pill = CAGradientLayer()
private let label = CATextLayer()
private var hide: DispatchWorkItem?
@@ -63,8 +65,10 @@ final class BackgroundTabToast {
pill.anchorPoint = CGPoint(x: 0.5, y: 1)
pill.bounds = CGRect(x: 0, y: 0, width: width, height: Self.height)
pill.position = CGPoint(x: Self.margin + width / 2, y: Self.margin + Self.height)
- pill.backgroundColor = colors.fill.cgColor
+ // Top to bottom (a layer's y runs up).
+ pill.colors = [colors.bottom.cgColor, colors.top.cgColor]
pill.borderColor = colors.outline.cgColor
+ label.foregroundColor = colors.text.cgColor
label.contentsScale = scale
label.string = text
let lineHeight = ceil(Self.font.ascender - Self.font.descender)
@@ -79,6 +83,8 @@ final class BackgroundTabToast {
} else {
if panel.parent !== window { window.addChildWindow(panel, ordered: .above) }
setOpacity(1)
+ // Another message while it is up: Arc bumps it (1 → 1.044 → 1 in ~0.2 s) and restarts its time.
+ DispatchQueue.main.async { [weak self] in self?.pulse() }
}
hide?.cancel()
let work = DispatchWorkItem { [weak self] in self?.dismiss() }
@@ -104,6 +110,15 @@ final class BackgroundTabToast {
setOpacity(1)
}
+ private func pulse() {
+ let bump = CAKeyframeAnimation(keyPath: "transform.scale")
+ bump.values = [1, 1.044, 1]
+ bump.keyTimes = [0, 0.2, 1]
+ bump.duration = 0.21
+ bump.timingFunctions = [CAMediaTimingFunction(name: .easeOut), CAMediaTimingFunction(name: .easeInEaseOut)]
+ pill.add(bump, forKey: "appear")
+ }
+
/// The model value only; the explicit animations above are the ones that show.
private func setOpacity(_ value: Float) {
CATransaction.begin()
@@ -138,15 +153,27 @@ final class BackgroundTabToast {
CATransaction.commit()
}
- /// Arc builds it from the window's background (ShinyToastBackgroundBasedPalette). Fitted to one
- /// theme (a yellow/green one, fill ≈ 214/222/174 sRGB mid-height): the theme colours' mean 70 %
- /// of the way to white, 8 % darker, and the outline at 69 % of that.
- static func colors(_ theme: SpaceTheme) -> (fill: NSColor, outline: NSColor) {
+ /// Arc builds it from the space's background (ShinyToastBackgroundBasedPalette): the theme's hue,
+ /// pale with black text on a light theme, deep with white text on a dark one, a little darker
+ /// at the bottom, outlined darker still. Fitted to one Arc theme of each kind (2 Nov 2026, sRGB):
+ /// light (Victor's yellow/green) 220/226/184 → 208/218/163, outline 151/157/124; dark (the
+ /// default theme in dark mode) 43/24/102 → 33/19/79, outline 26/15/62, white text.
+ static func colors(_ theme: SpaceTheme) -> (top: NSColor, bottom: NSColor, outline: NSColor, text: NSColor) {
let comps = theme.colors.compactMap(HexColor.components)
- guard !comps.isEmpty else { return (NSColor(white: 0.9, alpha: 1), NSColor(white: 0.62, alpha: 1)) }
- let n = Double(comps.count)
- func channel(_ v: Double) -> Double { (v / n + (1 - v / n) * 0.7) * 0.92 }
- let r = channel(comps.reduce(0) { $0 + $1.r }), g = channel(comps.reduce(0) { $0 + $1.g }), b = channel(comps.reduce(0) { $0 + $1.b })
- return (NSColor(srgbRed: r, green: g, blue: b, alpha: 1), NSColor(srgbRed: r * 0.69, green: g * 0.69, blue: b * 0.69, alpha: 1))
+ let n = Double(max(comps.count, 1))
+ let mean = NSColor(srgbRed: comps.reduce(0) { $0 + $1.r } / n, green: comps.reduce(0) { $0 + $1.g } / n,
+ blue: comps.reduce(0) { $0 + $1.b } / n, alpha: 1)
+ let hue = mean.hueComponent, sat = comps.isEmpty ? 0 : mean.saturationComponent
+ func color(_ s: CGFloat, _ b: CGFloat) -> NSColor {
+ NSColor(hue: hue, saturation: s, brightness: b, alpha: 1).usingColorSpace(.sRGB) ?? .gray
+ }
+ if theme.isDark {
+ let s = min(0.76, sat * 1.9)
+ let top = color(s, 0.40)
+ return (top, color(s, 0.31), color(s, 0.24), .white)
+ }
+ let s = min(0.19, sat * 0.3)
+ let top = color(s, 0.89)
+ return (top, color(min(0.25, s * 1.3), 0.85), color(s, 0.61), .black)
}
}
diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.md
index 50c8c05..ebd05f1 100644
--- a/docs/arc-reverse-engineering.md
+++ b/docs/arc-reverse-engineering.md
@@ -1185,7 +1185,9 @@ Static only (strings of `Dia.app/Contents/MacOS/Dia`, no decompiler; not observe
(split limit; `rectangle.portrait.split.2x1.slash` sits next to the view), extension installed,
password saved, import progress/result, '<shortcut> again to <action>', trace status.
- Unknown: display duration and transition (no runtime capture). Cra shows the status for 2 s
- with a 0.15 s fade in / 0.2 s fade out (`SidebarUIState.flashStatus`).
+ with a 0.15 s fade in / 0.2 s fade out (`SidebarUIState.flashStatus`). Replaced 2 Nov 2026: Arc shows these
+ ("Copied Current URL", "Cannot Add New Pane") as its toast, one component for every confirmation, and Cra now
+ does too (`ShinyToast`, see the #85 section).
## Dia Extensions menu (Dia 1.54.2, 25 Oct 2026)
@@ -1582,7 +1584,12 @@ Arc's popup this time, so geometry is not measured.
with no toolbar to anchor to, which swallowed the next click on the page. Cra turns it off the way Chrome's
"Show downloads when they're done" setting does: `download_bubble.partial_view_enabled` = false on the global and
incognito request contexts (CraCEF.mm HideDownloadBubble). Verified in a test instance: no bubble window, the first
- click after a download reaches the page, Cra's toast still shows.
+ click after a download reaches the page.
+- Arc has no download toast. A running download, a failed one ("Failed to Download") and paused or cancelled ones are
+ rows in its downloads list, with a speed ("e.g. 3 MB/s"); finished ones read "54 seconds ago". Cra's bottom-right
+ download cards (its only other toast design) are gone (2 Nov 2026, #85 follow-up): the hover list shows running,
+ failed and cancelled downloads too (DownloadHistory.live, DownloadRow). [U] Arc's exact wording and icon for a
+ running or failed row (Cra: "81.3 MB of 104.9 MB — 30.1 MB/s", the file type's icon) — to capture live.
- Chrome's download-started animation (DownloadBubbleStartedAnimationViews, Chromium 156.0.8078.48): a views popup
parented to the page, `accept_events = false`, 2 × kIconBackgroundRadius 32 = 64×64 pt, 500 ms, flying to the hidden
toolbar's download button. Only reduced motion turns it off (CEF_CTBT_DOWNLOAD is deprecated: downloads became a
@@ -2195,12 +2202,26 @@ was frontmost, 1x region captures and 100 fps recordings; test tabs archived aft
1 pt outline at ~69 % of the fill; fill 220/226/184 at the top to 208/218/163 at the bottom over a dark page on a
yellow/green theme (`ShinyToastBackgroundBasedPalette`). It springs in from its top centre (width 0.41 → 1.04 at
~0.2 s → 1.0 by ~0.4 s, i.e. ≈0.3 s response, damping 0.67), stays ~4.85 s and shrinks into its top while fading in
- ~80 ms. [U] Whether a second ⌘Return restarts its timer; the fill on other themes. Cra: BackgroundTabToast.
+ ~80 ms. Another ⌘Return while it is up restarts its time (gone 4.77 s after the last one) and bumps it,
+ width 1 → 1.044 (~40 ms) → 1 by ~0.2 s, rather than springing in again. On the default theme in dark mode
+ (JYSK space) it is dark with white text: 43/24/102 → 33/19/79, outline 26/15/62, i.e. the same hue at
+ saturation 0.76, brightness 0.40 → 0.31 (outline 0.24); the light one is saturation 0.19 → 0.25, brightness
+ 0.89 → 0.85 (outline 0.61) in the theme's hue. Cra: ShinyToast.
+- [O static] It is Arc's one toast (Toasts.ShinyToastView, `ToastContent`): the same component carries
+ "Copied Current URL" (`copyTabURL`), "Cannot Add New Pane" (`maxNumberPanes`), "Screenshot Copied to Clipboard",
+ "Pinned Tab to …", zoom changes, undo and more; some kinds add an SF Symbol (`quote.bubble.fill`,
+ `checkmark.shield.fill`, `xmark.octagon.fill` sit next to their strings). Cra shows its confirmations with
+ ShinyToast (MainWindowController.showToast), not Dia's nav-bar status. [U] Whether the copy and pane-limit
+ toasts carry a symbol, and where they sit with the sidebar out: the live check was cut short (Victor in a call).
- [O] Return on a "Switch to Tab" row for a pinned tab two closed folders down (Netfinder ▸ Endpoints ▸ tab): no folder
opens. The tab is listed one level under the outermost closed folder (its row slides in, ~0.15 s), Endpoints stays
hidden, and the folder's glyph gets three dots (2 pt, 4 pt pitch). StorableWindows.json keeps it per window as
`expandedItems: [folder, {"peeked": {"_0": [tab ids]}}]`; the tab stays listed after another tab is picked. The bar
lists only the window's space's tabs; a typed URL puts the typed row first and the "Switch to Tab" row second.
Arc also has Tabs ▸ Reveal Tab in Sidebar (`revealTabInSidebar`). Cra: FolderPeek (CraCore),
- WindowPrefs.peekedFolders, SidebarStore.peekedTabs/setExpanded, FolderGlyphView's dots. [U] What a click on a
- peeked folder does in Arc (Cra opens it and drops the peek; closing it again keeps the open tab listed).
+ WindowPrefs.peekedFolders, SidebarStore.peekedTabs/setExpanded, FolderGlyphView's dots.
+- [O] Real clicks (cliclick, Victor idle) on a peeked folder never open it: with the peeked tab open it stays
+ closed with the tab listed (two clicks), with another tab open it closes for good and drops the peek and the
+ dots. A folder without a peek opens as usual. Arc's window state then has no entry for it. So a click on a
+ closed folder that keeps tabs in sight means "close", keeping only the open tab (as the 29 Oct folder-peek
+ notes found). Cra: FolderPeek.clickOpens.