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.
Cra 0.1.15: custom app icons, New Tab button above tabs, Helium import
Victord1a43cb54205
diff --git a/Package.swift b/Package.swiftindex 6ebb8f6..bef8d4f 100644--- a/Package.swift+++ b/Package.swift@@ -29,6 +29,9 @@ let package = Package(products: [.executable(name: "Cra", targets: ["Cra"]),.executable(name: "CraHelper", targets: ["CraHelper"]),+ // Loaded by the Dock, not by Cra; scripts/build.sh wraps it in+ // Cra.app/Contents/PlugIns/CraDockTile.docktileplugin.+ .library(name: "CraDockTile", type: .dynamic, targets: ["CraDockTile"]),],targets: [// Objective-C++ bridge between Swift and CEF.@@ -57,6 +60,12 @@ let package = Package(.linkedFramework("IOSurface"),]),+ // Dock tile plug-in: keeps the icon picked in Settings after Cra quits.+ .target(+ name: "CraDockTile",+ path: "Sources/CraDockTile",+ linkerSettings: [.linkedFramework("AppKit")]+ ),// The browser itself: AppKit window, SwiftUI sidebar and command bar..executableTarget(name: "Cra",diff --git a/README.md b/README.mdindex 2c061dd..cabe36a 100644--- a/README.md+++ b/README.md@@ -80,7 +80,7 @@ On first launch, or later from Cra ▸ Import from Arc or Dia…, Cra brings ove- **Arc:** spaces, pinned tabs, folders, favorites and the archive, plus passwords andsign-ins.-- **Dia, Chrome, Brave, Edge, Opera, Vivaldi, Chromium:** tabs, bookmarks, history,+- **Dia, Chrome, Brave, Edge, Opera, Vivaldi, Chromium, Helium:** tabs, bookmarks, history,passwords, sign-ins and extensions.- **Zen and Firefox:** open tabs, bookmarks and history, and Zen's spaces, Essentials andpinned tabs.diff --git a/Sources/Cra/App/main.swift b/Sources/Cra/App/main.swiftindex 530fce7..1b3ddd1 100644--- a/Sources/Cra/App/main.swift+++ b/Sources/Cra/App/main.swift@@ -13,6 +13,9 @@ MainActor.assumeIsolated {NewestCopy.openNewerInstalledCopy()NewestCopy.replaceOlderRunningCopy()+ // The icon picked in Settings, before the Dock first shows the running app.+ AppIconManager.shared.applyAtLaunch()+// Passwords and cookies staged by the import go into the profile while no// Chromium has it open: before initializing, and only when no other Cra runs.// The run loop has not started, so the list can still hold a Cra that just quit.diff --git a/Sources/Cra/Model/SidebarModel.swift b/Sources/Cra/Model/SidebarModel.swiftindex 15a0bd7..801e759 100644--- a/Sources/Cra/Model/SidebarModel.swift+++ b/Sources/Cra/Model/SidebarModel.swift@@ -324,6 +324,10 @@ struct ArchivedItem: Codable, Identifiable, Equatable {/// Closed from a Little Window (Arc: archive source `littleArc`); never/// had a place in the sidebar, so restoring puts it in the focused space.var fromLittleWindow: Bool? = nil+ /// The folder it was closed out of (live folders too) and its place there:+ /// restoring puts it back while that folder is still in the space.+ var sourceFolderID: UUID? = nil+ var sourceIndex: Int? = nil}enum AutoArchiveThreshold: String, Codable, CaseIterable, Identifiable {@@ -395,6 +399,9 @@ struct AppSettings: Codable, Equatable {var autoArchive: AutoArchiveThreshold = .twelveHoursvar searchEngine: SearchEngine = .googlevar newTabsAtTop: Bool = true+ /// Tabs ▸ "Show the New Tab button above tabs": the + New Tab row leads Today+ /// instead of following its last tab.+ var newTabButtonAtTop: Bool = falsevar showStatusBar: Bool = true/// Arc's toolbar above the page (URL, copy link, DevTools). ⇧⌘D toggles. Off by/// default like Arc, which keeps the URL at the top of the sidebar.@@ -509,6 +516,7 @@ extension AppSettings {autoArchive = try c.decodeIfPresent(AutoArchiveThreshold.self, forKey: .autoArchive) ?? .twelveHourssearchEngine = try c.decodeIfPresent(SearchEngine.self, forKey: .searchEngine) ?? .googlenewTabsAtTop = try c.decodeIfPresent(Bool.self, forKey: .newTabsAtTop) ?? true+ newTabButtonAtTop = try c.decodeIfPresent(Bool.self, forKey: .newTabButtonAtTop) ?? falseshowStatusBar = try c.decodeIfPresent(Bool.self, forKey: .showStatusBar) ?? trueif try c.decodeIfPresent(Bool.self, forKey: .toolbarDefaultMigrated) == true {showToolbar = try c.decodeIfPresent(Bool.self, forKey: .showToolbar) ?? falsediff --git a/Sources/Cra/Services/AppIconManager.swift b/Sources/Cra/Services/AppIconManager.swiftnew file mode 100644index 0000000..ad7010c--- /dev/null+++ b/Sources/Cra/Services/AppIconManager.swift@@ -0,0 +1,169 @@+import AppKit+import Observation+import UniformTypeIdentifiers++/// The app icon picked in Settings ▸ General: the bundled Segments icon, one of the+/// alternates in resources/app-icons, or an image of the user's own. Arc does the same+/// (AppIconClient + a Dock tile plug-in): the running app swaps+/// `NSApp.applicationIconImage`, and CraDockTile keeps the choice in the Dock after Cra+/// quits. The plug-in runs in the Dock's process, so the choice lives in Cra's defaults+/// (which it reads) rather than settings.json under the data folder (which it can't find).+@MainActor+@Observable+final class AppIconManager {+ static let shared = AppIconManager()++ struct Option: Identifiable, Equatable {+ let id: String+ let name: String+ }++ static let defaultID = "segments"+ static let customID = "custom"+ static let presets = [+ Option(id: defaultID, name: "Segments"),+ Option(id: "midnight", name: "Midnight"),+ Option(id: "mono", name: "Mono"),+ ]++ // Shared with Sources/CraDockTile.+ private enum Keys {+ static let selected = "appIcon"+ static let customPath = "appIconCustomPath"+ }+ private static var changedNotification: Notification.Name {+ Notification.Name((Bundle.main.bundleIdentifier ?? "dk.kildahl.cra") + ".appIconChanged")+ }++ private(set) var selectedID: String+ /// The user's own icon, kept even while a preset is selected.+ private(set) var customImage: NSImage?++ private static var customURL: URL { AppPaths.file("AppIcon.png") }++ private init() {+ let stored = UserDefaults.standard.string(forKey: Keys.selected) ?? Self.defaultID+ let custom = NSImage(contentsOf: Self.customURL)+ let known = Self.presets.contains { $0.id == stored } || (stored == Self.customID && custom != nil)+ selectedID = known ? stored : Self.defaultID+ customImage = custom+ }++ /// At start-up, before the Dock first draws the running app's tile.+ func applyAtLaunch() {+ if selectedID != Self.defaultID { NSApp.applicationIconImage = image(for: selectedID) }+ }++ func image(for id: String) -> NSImage? {+ // app-icons/segments.png is the bundled icon on the grid, for the picker; the Dock+ // gets AppIcon.icns itself (apply()).+ id == Self.customID ? customImage+ : Bundle.main.url(forResource: id, withExtension: "png", subdirectory: "app-icons").flatMap(NSImage.init(contentsOf:))+ }++ func select(_ id: String) {+ guard id != Self.customID || customImage != nil else { return }+ selectedID = id+ UserDefaults.standard.set(id, forKey: Keys.selected)+ apply()+ }++ /// Makes an icon of any image file and selects it. Throws when it isn't an image.+ func setCustom(from url: URL) throws {+ guard let source = NSImage(contentsOf: url), source.size.width > 0, source.size.height > 0,+ let png = Self.iconPNG(from: source) else {+ throw CocoaError(.fileReadCorruptFile, userInfo: [NSFilePathErrorKey: url.path])+ }+ try png.write(to: Self.customURL, options: .atomic)+ customImage = NSImage(data: png)+ UserDefaults.standard.set(Self.customURL.path, forKey: Keys.customPath)+ select(Self.customID)+ }++ func removeCustom() {+ try? FileManager.default.removeItem(at: Self.customURL)+ customImage = nil+ UserDefaults.standard.removeObject(forKey: Keys.customPath)+ if selectedID == Self.customID { select(Self.defaultID) } else { notifyDockTile() }+ }++ private func apply() {+ // nil puts the bundle's icon back.+ NSApp.applicationIconImage = selectedID == Self.defaultID ? nil : image(for: selectedID)+ notifyDockTile()+ }++ private func notifyDockTile() {+ DistributedNotificationCenter.default().postNotificationName(Self.changedNotification, object: nil, userInfo: nil, deliverImmediately: true)+ }++ /// Apple's macOS icon grid: the tile is 824 of 1024 px, centred. The Dock fits the bundled+ /// AppIcon.icns (drawn edge to edge) into it by itself, but draws applicationIconImage and+ /// the plug-in's image as they are, so every alternate and custom icon is made on the grid.+ static let gridBody: CGFloat = 824.0 / 1024++ /// 512 px on Apple's grid, like the alternates. An opaque image (a photo, a logo on a+ /// background) fills Cra's rounded tile. One with transparent corners (a finished app+ /// icon, a cut-out logo) is scaled so its visible part fits the tile's square, bigger or+ /// smaller than it came. Either way nothing reaches past where other Dock icons end.+ static func iconPNG(from source: NSImage) -> Data? {+ let px = 512+ guard let rep = bitmap(px), let ctx = NSGraphicsContext(bitmapImageRep: rep) else { return nil }+ let canvas = NSRect(x: 0, y: 0, width: px, height: px)+ let body = canvas.insetBy(dx: CGFloat(px) * (1 - gridBody) / 2, dy: CGFloat(px) * (1 - gridBody) / 2)+ let shape = analyse(source)+ NSGraphicsContext.saveGraphicsState()+ NSGraphicsContext.current = ctx+ ctx.imageInterpolation = .high+ if let visible = shape.visible, shape.cutOut {+ let size = source.size+ let content = NSSize(width: visible.width * size.width, height: visible.height * size.height)+ let target = fit(content, in: body, fill: false)+ let scale = target.width / content.width+ source.draw(in: NSRect(x: target.minX - visible.minX * size.width * scale, y: target.minY - visible.minY * size.height * scale,+ width: size.width * scale, height: size.height * scale))+ } else {+ // AppIcon.icns's tile: 14.3-unit corners on 64.+ let radius = body.width * 14.3 / 64+ NSBezierPath(roundedRect: body, xRadius: radius, yRadius: radius).addClip()+ source.draw(in: fit(source.size, in: body, fill: true))+ }+ NSGraphicsContext.restoreGraphicsState()+ return rep.representation(using: .png, properties: [:])+ }++ /// Whether the image's corners are transparent, and its more-than-half-opaque part as+ /// fractions of its size (origin bottom left), nil when nothing is.+ private static func analyse(_ image: NSImage) -> (cutOut: Bool, visible: NSRect?) {+ let px = 256+ guard let rep = bitmap(px), let ctx = NSGraphicsContext(bitmapImageRep: rep), let data = rep.bitmapData else { return (false, nil) }+ NSGraphicsContext.saveGraphicsState()+ NSGraphicsContext.current = ctx+ image.draw(in: NSRect(x: 0, y: 0, width: px, height: px)) // stretched: only fractions are read+ NSGraphicsContext.restoreGraphicsState()+ // RGBA rows from the top.+ func alpha(_ x: Int, _ y: Int) -> UInt8 { data[y * rep.bytesPerRow + x * 4 + 3] }+ let cutOut = [(1, 1), (px - 2, 1), (1, px - 2), (px - 2, px - 2)].allSatisfy { alpha($0.0, $0.1) < 26 }+ var minX = px, minY = px, maxX = -1, maxY = -1+ for y in 0..<px {+ for x in 0..<px where alpha(x, y) > 127 {+ minX = min(minX, x); maxX = max(maxX, x); minY = min(minY, y); maxY = max(maxY, y)+ }+ }+ guard maxX >= 0 else { return (cutOut, nil) }+ let n = CGFloat(px)+ return (cutOut, NSRect(x: CGFloat(minX) / n, y: CGFloat(px - 1 - maxY) / n,+ width: CGFloat(maxX - minX + 1) / n, height: CGFloat(maxY - minY + 1) / n))+ }++ private static func bitmap(_ px: Int) -> NSBitmapImageRep? {+ NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: px, pixelsHigh: px, bitsPerSample: 8, samplesPerPixel: 4,+ hasAlpha: true, isPlanar: false, colorSpaceName: .deviceRGB, bytesPerRow: 0, bitsPerPixel: 0)+ }++ private static func fit(_ size: NSSize, in rect: NSRect, fill: Bool) -> NSRect {+ let scale = fill ? max(rect.width / size.width, rect.height / size.height) : min(rect.width / size.width, rect.height / size.height)+ let w = size.width * scale, h = size.height * scale+ return NSRect(x: rect.midX - w / 2, y: rect.midY - h / 2, width: w, height: h)+ }+}diff --git a/Sources/Cra/Services/Import/BrowserSources.swift b/Sources/Cra/Services/Import/BrowserSources.swiftindex b6f1ad6..d8765dc 100644--- a/Sources/Cra/Services/Import/BrowserSources.swift+++ b/Sources/Cra/Services/Import/BrowserSources.swift@@ -1,7 +1,7 @@import AppKit/// A browser the import can read: Dia's list (Arc, Brave, Chrome, Edge,-/// Firefox, Opera, Opera GX, Safari) plus Dia itself, Vivaldi, Chromium and Zen.+/// Firefox, Opera, Opera GX, Safari) plus Dia itself, Vivaldi, Chromium, Helium and Zen.struct ImportSource: Identifiable, Hashable {enum Kind: Hashable {/// Arc and Dia: their own sidebar stores, and a Chromium profile for passwords and cookies.@@ -29,9 +29,10 @@ struct ImportSource: Identifiable, Hashable {FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("Library/Application Support", isDirectory: true)}- private static func chromium(_ id: String, _ name: String, _ bundleID: String, _ path: String, account: String) -> ImportSource {+ private static func chromium(_ id: String, _ name: String, _ bundleID: String, _ path: String, account: String,+ service: String? = nil) -> ImportSource {ImportSource(id: id, name: name, bundleID: bundleID, kind: .chromium, dataDir: support.appendingPathComponent(path, isDirectory: true),- keychainService: "\(account) Safe Storage", keychainAccount: account)+ keychainService: service ?? "\(account) Safe Storage", keychainAccount: account)}static let arc = ImportSource(id: "arc", name: "Arc", bundleID: "company.thebrowser.Browser", kind: .arc,@@ -50,6 +51,8 @@ struct ImportSource: Identifiable, Hashable {chromium("operagx", "Opera GX", "com.operasoftware.OperaGX", "com.operasoftware.OperaGX", account: "Opera GX"),chromium("vivaldi", "Vivaldi", "com.vivaldi.Vivaldi", "Vivaldi", account: "Vivaldi"),chromium("chromium", "Chromium", "org.chromium.Chromium", "Chromium", account: "Chromium"),+ // Helium renames its Keychain item instead of using "<Name> Safe Storage".+ chromium("helium", "Helium", "net.imput.helium", "net.imput.helium", account: "Helium", service: "Helium Storage Key"),ImportSource(id: "firefox", name: "Firefox", bundleID: "org.mozilla.firefox", kind: .firefox,dataDir: support.appendingPathComponent("Firefox", isDirectory: true)),ImportSource(id: "zen", name: "Zen", bundleID: "app.zen-browser.zen", kind: .zen,diff --git a/Sources/Cra/Services/Import/ChromiumImporter.swift b/Sources/Cra/Services/Import/ChromiumImporter.swiftindex d184935..cf73ae9 100644--- a/Sources/Cra/Services/Import/ChromiumImporter.swift+++ b/Sources/Cra/Services/Import/ChromiumImporter.swift@@ -1,6 +1,6 @@import AppKit-// Chrome, Brave, Edge, Vivaldi, Opera and Chromium (and Arc's and Dia's own+// Chrome, Brave, Edge, Vivaldi, Opera, Chromium and Helium (and Arc's and Dia's own// Chromium profiles for passwords and cookies). Dia's import lists the same// browsers; each profile becomes a space with its bookmarks bar pinned and its// last session's tabs in Today.diff --git a/Sources/Cra/Services/LiveFolderManager.swift b/Sources/Cra/Services/LiveFolderManager.swiftindex d0574f4..3bac200 100644--- a/Sources/Cra/Services/LiveFolderManager.swift+++ b/Sources/Cra/Services/LiveFolderManager.swift@@ -133,13 +133,16 @@ final class LiveFolderManager {/// One list from the folder's searches: who made it and who's asked come from the search/// it was found by, and from the author when the page names the signed-in user.static func merge(_ pages: [(GitHubLiveFilter.Attributes, GitHubLiveClient.Page)]) -> [LivePullRequest] {- let viewer = pages.lazy.compactMap { $0.1.viewer }.first { !$0.isEmpty }?.lowercased()+ let viewerLogin = pages.lazy.compactMap { $0.1.viewer }.first { !$0.isEmpty }+ let viewer = viewerLogin?.lowercased()var byURL: [String: LivePullRequest] = [:]var order: [String] = []for (attribute, page) in pages {for var pr in page.pullRequests {if attribute == .authored { pr.createdByMe = true } else { pr.isAwaitingMyReview = true }if let viewer, pr.author?.lowercased() == viewer { pr.createdByMe = true }+ // Your own pull requests are named after you even when the page leaves the author out.+ if pr.author == nil, attribute == .authored { pr.author = viewerLogin }if var seen = byURL[pr.url] {seen.createdByMe = seen.createdByMe || pr.createdByMeseen.isAwaitingMyReview = seen.isAwaitingMyReview || pr.isAwaitingMyReviewdiff --git a/Sources/Cra/Services/SidebarStore.swift b/Sources/Cra/Services/SidebarStore.swiftindex 11b4860..1b5d0ad 100644--- a/Sources/Cra/Services/SidebarStore.swift+++ b/Sources/Cra/Services/SidebarStore.swift@@ -982,7 +982,8 @@ final class SidebarStore {let firstFill = live.lastFetch == nil || (live.lastError != nil && existing.isEmpty)var order: [UUID] = []for pr in wanted {- let subtitle = pr.createdByMe ? nil : pr.author+ // Arc leaves the author off your own pull requests; Cra names everyone's.+ let subtitle = pr.authorif let id = existing.removeValue(forKey: pr.url) ?? adoptableTab(for: pr, folderID: folderID),var it = items[id], var t = it.tab {if it.parentID != folderID {@@ -1075,21 +1076,24 @@ final class SidebarStore {// MARK: Archivefunc archiveTab(_ id: UUID, reason: ArchiveReason) {- guard var it = items[id], it.isTab else { return }+ guard let it = items[id], it.isTab else { return }let sid = spaceID(ofItem: id)let selectedIn = sid.map { s in prefs.windows.filter { $0.selectedTabPerSpace[s] == id }.map(\.id) } ?? []let pinned = isPinned(id)let split = splitContaining(id)- // Closed out of a live folder: the item stays out (Arc: hiddenItems).- if let p = it.parentID, items[p]?.isLiveFolder == true {- hideLiveItem(id, in: p)- it = items[id] ?? it+ let folder = it.parentID.flatMap { items[$0]?.isFolder == true ? $0 : nil }+ let index = folder.flatMap { items[$0]?.children.firstIndex(of: id) }+ // Closed out of a live folder: the item stays out (Arc: hiddenItems). The archive keeps+ // the live copy so ⇧⌘T can put it back.+ if let folder, items[folder]?.isLiveFolder == true {+ hideLiveItem(id, in: folder)}detach(id)items[id] = nil// Empty panes never had a page and incognito pages leave no trace: nothing for the Library.if !it.isEmptyTab, !isIncognito(space: sid) {- archive.insert(ArchivedItem(archivedAt: Date(), reason: reason, sourceSpaceID: sid, wasPinned: pinned, item: it), at: 0)+ archive.insert(ArchivedItem(archivedAt: Date(), reason: reason, sourceSpaceID: sid, wasPinned: pinned, item: it,+ sourceFolderID: folder, sourceIndex: index), at: 0)if archive.count > 2000 { archive.removeLast(archive.count - 2000) }}if !selectedIn.isEmpty, let sid {@@ -1127,13 +1131,24 @@ final class SidebarStore {var it = entry.itemlet sid = entry.sourceSpaceID.flatMap { spaces[$0] != nil ? $0 : nil } ?? focusedSpaceIDlet space = spaces[sid]!- let parent = entry.wasPinned ? space.pinnedContainerID : space.todayContainerID+ // Back into the folder it was closed from, if that's still in the space.+ let folder = entry.sourceFolderID.flatMap { items[$0]?.isFolder == true && spaceID(ofItem: $0) == sid ? $0 : nil }+ let parent = folder ?? (entry.wasPinned ? space.pinnedContainerID : space.todayContainerID)+ if let folder, let url = it.tab?.liveItemURL, items[folder]?.isLiveFolder == true {+ updateLiveFolder(folder) { $0.hiddenItems.removeAll { $0 == url } }+ } else if var t = it.tab, t.liveItemURL != nil {+ t.liveItemURL = nil+ t.liveSubtitle = nil+ t.liveGoneAt = nil+ it.data = .tab(t)+ }it.parentID = parentit.children = []it.isUnread = falseitems[it.id] = itvar p = items[parent]!- p.children.insert(it.id, at: entry.wasPinned ? p.children.count : 0)+ let index = folder != nil ? min(entry.sourceIndex ?? 0, p.children.count) : entry.wasPinned ? p.children.count : 0+ p.children.insert(it.id, at: index)items[parent] = pif select { selectTab(it.id) } else { touch() }return itdiff --git a/Sources/Cra/UI/Settings/AppIconPicker.swift b/Sources/Cra/UI/Settings/AppIconPicker.swiftnew file mode 100644index 0000000..76558c6--- /dev/null+++ b/Sources/Cra/UI/Settings/AppIconPicker.swift@@ -0,0 +1,117 @@+import AppKit+import SwiftUI+import UniformTypeIdentifiers++/// General ▸ App Icon: the bundled icon, the alternates and the user's own image, a row of+/// tiles like Arc's App Icon pane (AppIconPreferencesContentView) in Cra's card idiom.+struct AppIconSection: View {+ private let icons = AppIconManager.shared+ @State private var error: String?++ var body: some View {+ VStack(alignment: .leading, spacing: 0) { content }+ }++ @ViewBuilder private var content: some View {+ SettingsHeader("App Icon")+ SettingsCard {+ HStack(alignment: .top, spacing: 0) {+ ForEach(AppIconManager.presets) { option in+ AppIconTile(name: option.name, image: icons.image(for: option.id),+ selected: icons.selectedID == option.id) { icons.select(option.id) }+ }+ AppIconTile(name: "Custom", image: icons.customImage, selected: icons.selectedID == AppIconManager.customID) {+ if icons.customImage == nil { chooseImage() } else { icons.select(AppIconManager.customID) }+ }+ .dropDestination(for: URL.self) { urls, _ in+ guard let url = urls.first else { return false }+ use(url)+ return true+ }+ }+ .padding(.horizontal, SettingsMetrics.cardRowInset)+ .padding(.vertical, 8)+ SettingsCardDivider()+ SettingsCardRow {+ Text("Your own icon").font(.system(size: 13))+ } trailing: {+ if icons.customImage != nil {+ Button("Remove") { icons.removeCustom(); error = nil }+ }+ Button("Choose Image…") { chooseImage() }+ }+ }+ SettingsFootnote("Pick any image or drop one on Custom. It’s sized to match the other icons in the Dock, and a photo or a logo on a background fills the rounded tile. The Dock keeps the icon after Cra quits.")+ if let error { SettingsFootnote(error).foregroundStyle(.red) }+ }++ private func chooseImage() {+ let panel = NSOpenPanel()+ panel.allowedContentTypes = [.image]+ panel.message = "Choose an image for Cra’s icon"+ panel.prompt = "Use as Icon"+ let done: (NSApplication.ModalResponse) -> Void = { response in+ if response == .OK, let url = panel.url { use(url) }+ }+ if let window = NSApp.keyWindow { panel.beginSheetModal(for: window, completionHandler: done) } else { panel.begin(completionHandler: done) }+ }++ private func use(_ url: URL) {+ do {+ try icons.setCustom(from: url)+ error = nil+ } catch {+ self.error = "“\(url.lastPathComponent)” isn’t an image Cra can read."+ }+ }+}++/// One icon with its name; the selected one gets an accent ring.+private struct AppIconTile: View {+ let name: String+ let image: NSImage?+ let selected: Bool+ let action: () -> Void+ @State private var hovering = false++ /// The tile; the images carry Apple's grid margin around it, as in the Dock.+ private static let size: CGFloat = 56+ private static let canvas = size / AppIconManager.gridBody+ /// The icons' own corners: 14.3 of 64 units.+ private static let corner = size * 14.3 / 64++ var body: some View {+ Button(action: action) {+ VStack(spacing: 0) {+ icon+ .frame(width: Self.canvas, height: Self.canvas)+ .overlay(RoundedRectangle(cornerRadius: Self.corner + 4, style: .continuous)+ .strokeBorder(Color.accentColor, lineWidth: 2.5)+ .frame(width: Self.size + 8, height: Self.size + 8)+ .opacity(selected ? 1 : 0))+ .scaleEffect(hovering && !selected ? 1.04 : 1)+ .animation(.easeOut(duration: 0.15), value: hovering)+ Text(name)+ .font(.system(size: 11))+ .foregroundStyle(selected ? Color.primary : Color.secondary)+ }+ .frame(maxWidth: .infinity)+ .contentShape(Rectangle())+ }+ .buttonStyle(.plain)+ .onHover { hovering = $0 }+ .accessibilityLabel("\(name) app icon")+ .accessibilityAddTraits(selected ? .isSelected : [])+ }++ @ViewBuilder private var icon: some View {+ if let image {+ Image(nsImage: image).resizable().interpolation(.high).aspectRatio(contentMode: .fit)+ } else {+ RoundedRectangle(cornerRadius: Self.corner, style: .continuous)+ .strokeBorder(Color.secondary.opacity(0.5), style: StrokeStyle(lineWidth: 1.5, dash: [4, 3]))+ .overlay(Image(systemName: "plus").font(.system(size: 18, weight: .medium)).foregroundStyle(.secondary))+ .frame(width: Self.size, height: Self.size)+ }+ }+}diff --git a/Sources/Cra/UI/Settings/GeneralPane.swift b/Sources/Cra/UI/Settings/GeneralPane.swiftindex 4126033..58aacb2 100644--- a/Sources/Cra/UI/Settings/GeneralPane.swift+++ b/Sources/Cra/UI/Settings/GeneralPane.swift@@ -45,6 +45,7 @@ struct GeneralPane: View {SettingsFootnote("Cra works best as your default browser.")}if let error { SettingsFootnote(error).foregroundStyle(.red) }+ AppIconSection().padding(.top, 20)}.onAppear { system.refresh() }}diff --git a/Sources/Cra/UI/Settings/TabsPane.swift b/Sources/Cra/UI/Settings/TabsPane.swiftindex 2450116..3db29dc 100644--- a/Sources/Cra/UI/Settings/TabsPane.swift+++ b/Sources/Cra/UI/Settings/TabsPane.swift@@ -11,6 +11,7 @@ struct TabsPane: View {SettingsFormPane {SettingsFormRow(label: "General:") {SettingsCheckbox(title: "Add new tabs to the top", isOn: $store.settings.newTabsAtTop)+ SettingsCheckbox(title: "Show the New Tab button above tabs", isOn: $store.settings.newTabButtonAtTop)SettingsCheckbox(title: "Haptic feedback when reordering tabs", isOn: $store.settings.hapticFeedbackOnReorder)SettingsCheckbox(title: "Show toolbar above the page", isOn: $store.settings.showToolbar)SettingsCheckbox(title: "Enable Picture in Picture when you leave a video tab", isOn: $store.settings.autoPictureInPicture)diff --git a/Sources/Cra/UI/Sidebar/SidebarItemView.swift b/Sources/Cra/UI/Sidebar/SidebarItemView.swiftindex 24b94dd..b7db375 100644--- a/Sources/Cra/UI/Sidebar/SidebarItemView.swift+++ b/Sources/Cra/UI/Sidebar/SidebarItemView.swift@@ -84,7 +84,7 @@ struct TabRow: View {/// Arc shows the host under a pinned tab only when it has left the pinned/// site (navigating within the same host shows nothing).private var subtitle: String? {- // A live folder's pull request by someone else shows its author (Arc's sidebarItemSubtitleTextField).+ // A live folder's pull request shows its author (Arc's sidebarItemSubtitleTextField, mine too).if let author = tab.liveSubtitle, URL(string: tab.url)?.host == "github.com" { return author }guard navigatedAway, let host = URL(string: tab.url)?.host, let saved = URL(string: tab.savedURL)?.host,host.replacingOccurrences(of: "www.", with: "") != saved.replacingOccurrences(of: "www.", with: "") else { return nil }diff --git a/Sources/Cra/UI/Sidebar/SidebarListDrop.swift b/Sources/Cra/UI/Sidebar/SidebarListDrop.swiftindex 4c40013..179c1f5 100644--- a/Sources/Cra/UI/Sidebar/SidebarListDrop.swift+++ b/Sources/Cra/UI/Sidebar/SidebarListDrop.swift@@ -278,7 +278,9 @@ struct SidebarListDropDelegate: DropDelegate {if p.y < (pinned.maxY + today.minY) / 2 {target = .insert(parent: space.pinnedContainerID, index: p.y < pinned.minY ? 0 : store.children(of: space.pinnedContainerID).count)} else {- target = .insert(parent: space.todayContainerID, index: p.y < today.minY ? 0 : store.children(of: space.todayContainerID).count)+ // The New Tab row may lead Today, so its first tab, not the section, marks the top.+ let firstToday = rows.first { $0.parent == space.todayContainerID }?.frame.minY ?? today.minY+ target = .insert(parent: space.todayContainerID, index: p.y < firstToday ? 0 : store.children(of: space.todayContainerID).count)}}diff --git a/Sources/Cra/UI/Sidebar/SidebarRootView.swift b/Sources/Cra/UI/Sidebar/SidebarRootView.swiftindex ed6e3d9..0a59d0a 100644--- a/Sources/Cra/UI/Sidebar/SidebarRootView.swift+++ b/Sources/Cra/UI/Sidebar/SidebarRootView.swift@@ -451,11 +451,12 @@ struct SpaceSectionView: View {.animation(.easeOut(duration: 0.15), value: hoverDivider)VStack(spacing: CraMetrics.rowSpacing) {+ if store.settings.newTabButtonAtTop { NewTabRow(palette: palette) }ForEach(todayItems) { item inSidebarItemView(item: item, depth: 0, palette: palette, section: .today).id(item.id)}- NewTabRow(palette: palette)+ if !store.settings.newTabButtonAtTop { NewTabRow(palette: palette) }}.onGeometryChange(for: CGRect.self) { $0.frame(in: .named(SidebarListDropDelegate.coordinateSpace)) } action: { ui.rowFrames[space.todayContainerID] = $0 }.padding(.horizontal, 10)diff --git a/Sources/Cra/UI/Windows/LittleWindowController.swift b/Sources/Cra/UI/Windows/LittleWindowController.swiftindex 1375851..a23bb85 100644--- a/Sources/Cra/UI/Windows/LittleWindowController.swift+++ b/Sources/Cra/UI/Windows/LittleWindowController.swift@@ -11,7 +11,7 @@ import SwiftUI/// Geometry and colours were measured from Arc 1.168's Little Arc on 24 Oct/// 2026 (docs/arc-reverse-engineering.md, "Little Arc"): a 46pt navy strip with/// muted traffic lights, one full-width search pill, and a split-/// "Open in <Space> ⌘O | ⌄" button; the page fills the rest edge to edge.+/// "Open in <Space> ⌘O | ⌄" button; the page fills the rest, inside the window's rim.@MainActor@Observablefinal class LittleWindowState {@@ -54,7 +54,11 @@ enum LittleMetrics {static let pillGap: CGFloat = 10 // pill → buttonstatic let rightMargin: CGFloat = 7static let chevronWidth: CGFloat = 29+ /// Arc's window corners; used when the system radius can't be read (see LittleWindow).static let cornerRadius: CGFloat = 10+ /// The light rim macOS draws along the window's edge. The page is a child window+ /// above the Little Window, so laid edge to edge it covered the rim on three sides.+ static let edgeInset: CGFloat = 1static let popupWidth: CGFloat = 240static let popupRowHeight: CGFloat = 54static let popupHeaderHeight: CGFloat = 46@@ -197,7 +201,12 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco/// as a child window over the page area and round its bottom corners.private func attachHostWindow(_ w: NSWindow) {guard let window, w.parent !== window else { return }+ // Borderless like MainWindowController's pages: a titled window gets macOS's+ // rounded corners on all four sides and a resize zone past the page's edges.+ w.styleMask.remove([.titled, .resizable])w.styleMask.insert(.fullSizeContentView)+ ChromiumWindowCorners.setSquare(true, for: w)+ ChromiumChildHover.setDocked(true, for: w)w.titlebarAppearsTransparent = truew.titleVisibility = .hiddenw.isMovable = false@@ -208,9 +217,9 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @precoif let cv = w.contentView {cv.isHidden = false // a background tab's page (MainWindowController hides it)cv.wantsLayer = true- cv.layer?.cornerRadius = LittleMetrics.cornerRadiuscv.layer?.cornerCurve = .continuous- cv.layer?.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]+ // Chromium's content view is flipped, so its layer's MaxY edge is the bottom.+ cv.layer?.maskedCorners = cv.isFlipped ? [.layerMinXMaxYCorner, .layerMaxXMaxYCorner] : [.layerMinXMinYCorner, .layerMaxXMinYCorner]cv.layer?.masksToBounds = true}window.addChildWindow(w, ordered: .above)@@ -228,7 +237,12 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco// showed as a strip above the page and cut off its bottom.let full = NSRect(origin: .zero, size: onScreen.size)if let cv = w.contentView, cv.frame != full { cv.frame = full }- if let cv = w.contentView { cv.layer?.cornerRadius = window.styleMask.contains(.fullScreen) ? 0 : LittleMetrics.cornerRadius }+ // Chromium can restore its own style mask (fullscreen, display changes).+ if w.styleMask.contains(.titled) || w.styleMask.contains(.resizable) {+ w.styleMask.remove([.titled, .resizable])+ ChromiumWindowCorners.setSquare(true, for: w)+ }+ if let layer = w.contentView?.layer, layer.cornerRadius != shell.pageCornerRadius { layer.cornerRadius = shell.pageCornerRadius }}private func focusPage() {@@ -738,7 +752,6 @@ final class LittleShellView: NSView {}addSubview(toolbarHost)page.wantsLayer = true- page.layer?.cornerRadius = LittleMetrics.cornerRadiuspage.layer?.cornerCurve = .continuouspage.layer?.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]page.layer?.masksToBounds = true@@ -794,11 +807,18 @@ final class LittleShellView: NSView {let fullscreen = window?.styleMask.contains(.fullScreen) ?? falselet barH = LittleMetrics.barHeighttoolbarHost.frame = NSRect(x: 0, y: b.maxY - barH, width: b.width, height: barH)- page.frame = NSRect(x: 0, y: b.minY, width: b.width, height: max(0, b.height - barH))- page.layer?.cornerRadius = fullscreen ? 0 : LittleMetrics.cornerRadius+ let inset = fullscreen ? 0 : LittleMetrics.edgeInset+ page.frame = NSRect(x: inset, y: b.minY + inset, width: max(0, b.width - 2 * inset), height: max(0, b.height - barH - inset))+ page.layer?.cornerRadius = pageCornerRadiusfor sub in page.subviews where sub.frame != page.bounds { sub.frame = page.bounds }onPageFrame?(convert(page.frame, to: nil))}++ /// The page's bottom corners follow the window's, just inside its rim.+ var pageCornerRadius: CGFloat {+ guard let window = window as? LittleWindow, !window.styleMask.contains(.fullScreen) else { return 0 }+ return max(0, window.systemCornerRadius - LittleMetrics.edgeInset)+ }}/// Traffic lights at Arc's spots (x 17/39/61, centred on the strip), always in@@ -810,6 +830,16 @@ final class LittleWindow: NSWindow {/// Arc's open animation: ~120 ms from a small rectangle to the full frame.override func animationResizeTime(_ newFrame: NSRect) -> TimeInterval { LittleMetrics.openDuration }+ /// macOS's corner radius for this window (16 pt on macOS 26, larger than Arc's+ /// 10), read from the frame view's private `_cornerRadius`.+ var systemCornerRadius: CGFloat {+ typealias RadiusIMP = @convention(c) (AnyObject, Selector) -> CGFloat+ let sel = NSSelectorFromString("_cornerRadius")+ guard let frameView = contentView?.superview, let method = class_getInstanceMethod(type(of: frameView), sel) else { return LittleMetrics.cornerRadius }+ let radius = unsafeBitCast(method_getImplementation(method), to: RadiusIMP.self)(frameView, sel)+ return radius > 0 ? radius : LittleMetrics.cornerRadius+ }+override func layoutIfNeeded() {super.layoutIfNeeded()positionTrafficLights()diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swiftindex 8c600df..21332a6 100644--- a/Sources/Cra/UI/Windows/MainWindowController.swift+++ b/Sources/Cra/UI/Windows/MainWindowController.swift@@ -1204,6 +1204,11 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserMprivate func installSwipeMonitor() {scrollMonitor = NSEvent.addLocalMonitorForEvents(matching: .scrollWheel) { [weak self] event inguard let self else { return event }+ // Any new gesture ends the last space swipe. Pages are child windows (and every+ // main window has this monitor), so a scroll that starts there never reaches the+ // phase switch below; a stale .horizontal would eat the page's momentum and+ // scrolling would stop dead the moment the fingers lift.+ if event.phase == .began || event.phase == .mayBegin { self.swipeAxis = .vertical }// The momentum tail of a space swipe belongs to the swipe, not the tab list.if !event.momentumPhase.isEmpty { return self.swipeAxis == .horizontal ? nil : event }guard event.window === self.window, event.hasPreciseScrollingDeltas else { return event }diff --git a/Sources/CraDockTile/CraDockTilePlugIn.swift b/Sources/CraDockTile/CraDockTilePlugIn.swiftnew file mode 100644index 0000000..3c8c699--- /dev/null+++ b/Sources/CraDockTile/CraDockTilePlugIn.swift@@ -0,0 +1,50 @@+import AppKit++/// Cra's Dock tile plug-in (NSDockTilePlugIn in Info.plist): the Dock loads it while Cra+/// is in the Dock but not running, so the icon picked in Settings stays after Cra quits.+/// Arc and Dia ship the same kind of plug-in. It runs in the Dock's plug-in host, reads+/// the choice from Cra's defaults and the images from Cra's bundle or data folder, and+/// redraws when Cra posts "<bundle id>.appIconChanged" (AppIconManager).+@objc(CraDockTilePlugIn)+final class CraDockTilePlugIn: NSObject, NSDockTilePlugIn {+ private var tile: NSDockTile?+ private var observer: NSObjectProtocol?+ /// Cra.app, three levels up from Contents/PlugIns/CraDockTile.docktileplugin.+ private let app: Bundle? = Bundle(url: Bundle(for: CraDockTilePlugIn.self).bundleURL+ .deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent())++ func setDockTile(_ dockTile: NSDockTile?) {+ tile = dockTile+ if let observer { DistributedNotificationCenter.default().removeObserver(observer) }+ observer = nil+ guard dockTile != nil, let id = app?.bundleIdentifier else { return }+ observer = DistributedNotificationCenter.default().addObserver(+ forName: Notification.Name(id + ".appIconChanged"), object: nil, queue: .main) { [weak self] _ in self?.update() }+ update()+ }++ private func update() {+ guard let tile else { return }+ if let image = selectedImage() {+ let view = NSImageView(frame: NSRect(origin: .zero, size: tile.size))+ view.image = image+ view.imageScaling = .scaleProportionallyUpOrDown+ tile.contentView = view+ } else {+ // No content view: the Dock draws the bundle's own icon.+ tile.contentView = nil+ }+ tile.display()+ }++ /// The keys AppIconManager writes; nil for the bundled icon.+ private func selectedImage() -> NSImage? {+ guard let app, let id = app.bundleIdentifier as CFString? else { return nil }+ CFPreferencesAppSynchronize(id)+ guard let selected = CFPreferencesCopyAppValue("appIcon" as CFString, id) as? String, selected != "segments" else { return nil }+ if selected == "custom" {+ return (CFPreferencesCopyAppValue("appIconCustomPath" as CFString, id) as? String).flatMap(NSImage.init(contentsOfFile:))+ }+ return app.url(forResource: selected, withExtension: "png", subdirectory: "app-icons").flatMap(NSImage.init(contentsOf:))+ }+}diff --git a/brand/README.md b/brand/README.mdindex 63e29ad..3ff5374 100644--- a/brand/README.md+++ b/brand/README.md@@ -1,6 +1,6 @@# Cra brand marks-Chosen 2026-10-24 from the layered explorations. Both marks are built from translucent+Chosen 2026-10-24 from the layered explorations. The mark is built from translucentribbons that multiply where they overlap, wrapped in a white sticker edge.| File | Use |@@ -8,9 +8,6 @@ ribbons that multiply where they overlap, wrapped in a white sticker edge.| `cra-segments.svg` | **Primary mark.** A C cut into four coloured segments. Transparent background: nav, documents, hero. || `cra-segments-mono.svg` | Single colour, inherits `currentColor`: footer, sidebar, favicons on busy backgrounds. || `cra-segments-icon.svg` | App icon: the mark on the sand tile with a soft shadow. Source for `website/src/app/icon.svg` and the macOS `.icns`. |-| `cra-sticker-c.svg` | **Secondary mark.** A heavy c with a caret dot. Kept for stickers, loading states, small merch. |-| `cra-sticker-c-mono.svg` | Single colour version of the above. |-| `cra-sticker-c-icon.svg` | App icon version of the above. |## Colours@@ -19,7 +16,7 @@ ribbons that multiply where they overlap, wrapped in a white sticker edge.| 1 | `#3f6df5` blue | top right, the opening of the C || 2 | `#4fbe7e` green | bottom left || 3 | `#f0574f` coral | top left |-| 4 | `#f6c34a` yellow | bottom right, and the caret in Sticker c· |+| 4 | `#f6c34a` yellow | bottom right || Tile | `#f2e3c4` to `#e8d3aa` | the sand gradient behind the icon |Ribbons are drawn at 92% opacity with `mix-blend-mode: multiply`, so overlaps go darker.diff --git a/brand/cra-sticker-c-icon.svg b/brand/cra-sticker-c-icon.svgdeleted file mode 100644index 166e346..0000000--- a/brand/cra-sticker-c-icon.svg+++ /dev/null@@ -1 +0,0 @@-<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64"><defs><linearGradient id="t" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#f2e3c4"/><stop offset="1" stop-color="#e8d3aa"/></linearGradient></defs><rect width="64" height="64" rx="14.3" fill="url(#t)"/><g transform="translate(3.84 3.84) scale(0.88)"><g opacity=".18" transform="translate(0 2.5)" style="filter:blur(1.5px)"><path d="M36.64 22.51A15 15 0 1 0 36.64 45.49" fill="none" stroke="#000" stroke-width="19" stroke-linecap="round" stroke-linejoin="round"/><circle cx="51" cy="34" r="10.1" fill="#000"/></g><path d="M36.64 22.51A15 15 0 1 0 36.64 45.49" fill="none" stroke="#fff" stroke-width="19" stroke-linecap="round" stroke-linejoin="round"/><circle cx="51" cy="34" r="10.1" fill="#fff"/><path d="M36.64 22.51A15 15 0 1 0 36.64 45.49" fill="none" stroke="#3f6df5" stroke-width="12" stroke-linecap="round" stroke-linejoin="round" style="mix-blend-mode:multiply" opacity=".92"/><circle cx="51" cy="34" r="6.6" fill="#f6c34a" style="mix-blend-mode:multiply" opacity=".92"/></g></svg>diff --git a/brand/cra-sticker-c-mono.svg b/brand/cra-sticker-c-mono.svgdeleted file mode 100644index 19fa1b6..0000000--- a/brand/cra-sticker-c-mono.svg+++ /dev/null@@ -1 +0,0 @@-<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" fill="currentColor"><path d="M36.64 22.51A15 15 0 1 0 36.64 45.49" fill="none" stroke="currentColor" stroke-width="12" stroke-linecap="round" stroke-linejoin="round"/><circle cx="51" cy="34" r="6.6" fill="currentColor"/></svg>diff --git a/brand/cra-sticker-c.svg b/brand/cra-sticker-c.svgdeleted file mode 100644index 5e22026..0000000--- a/brand/cra-sticker-c.svg+++ /dev/null@@ -1 +0,0 @@-<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64"><path d="M36.64 22.51A15 15 0 1 0 36.64 45.49" fill="none" stroke="#fff" stroke-width="19" stroke-linecap="round" stroke-linejoin="round"/><circle cx="51" cy="34" r="10.1" fill="#fff"/><path d="M36.64 22.51A15 15 0 1 0 36.64 45.49" fill="none" stroke="#3f6df5" stroke-width="12" stroke-linecap="round" stroke-linejoin="round" style="mix-blend-mode:multiply" opacity=".92"/><circle cx="51" cy="34" r="6.6" fill="#f6c34a" style="mix-blend-mode:multiply" opacity=".92"/></svg>diff --git a/docs/live-folders.md b/docs/live-folders.mdindex 84e470f..0fe4ffd 100644--- a/docs/live-folders.md+++ b/docs/live-folders.md@@ -71,7 +71,8 @@ Legend: [O] observed, [I] inference, [U] unknown.title bold like other folders. A 26×26 trailing button showed a ⚠ that stayed on hover (the folder was inan error state; the healthy state's button was not seen).- [O] Pull request rows: GitHub mark as the icon, author login under the title for other people's pull- requests (`sidebarItemSubtitleTextField`), none under your own; unread dot; ✕ on hover like any pinned tab.+ requests (`sidebarItemSubtitleTextField`), none under your own (Cra names your own too, Victor's call+ 28 Oct); unread dot; ✕ on hover like any pinned tab.- [O] Context menu strings: "Copy All Links as Markdown", "Delete Live Folder", repository list explained by"This list is generated based on your currently active pull requests.", "Failed to update". Deleting asks"Delete your %@ Live Folder?". Not in Arc's menu bar (only a debug menu "Automatic Live Folders").diff --git a/resources/DockTile-Info.plist b/resources/DockTile-Info.plistnew file mode 100644index 0000000..3800ab0--- /dev/null+++ b/resources/DockTile-Info.plist@@ -0,0 +1,26 @@+<?xml version="1.0" encoding="UTF-8"?>+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">+<plist version="1.0">+<dict>+ <key>CFBundleDevelopmentRegion</key>+ <string>en</string>+ <key>CFBundleExecutable</key>+ <string>CraDockTile</string>+ <key>CFBundleIdentifier</key>+ <string>dk.kildahl.cra.docktile</string>+ <key>CFBundleInfoDictionaryVersion</key>+ <string>6.0</string>+ <key>CFBundleName</key>+ <string>CraDockTile</string>+ <key>CFBundlePackageType</key>+ <string>BNDL</string>+ <key>CFBundleShortVersionString</key>+ <string>__VERSION__</string>+ <key>CFBundleVersion</key>+ <string>__BUILD__</string>+ <key>LSMinimumSystemVersion</key>+ <string>14.0</string>+ <key>NSPrincipalClass</key>+ <string>CraDockTilePlugIn</string>+</dict>+</plist>diff --git a/resources/Info.plist b/resources/Info.plistindex d91cdfc..058dacc 100644--- a/resources/Info.plist+++ b/resources/Info.plist@@ -22,6 +22,9 @@<string>__BUILD__</string><key>CFBundleIconFile</key><string>AppIcon</string>+ <!-- Keeps the icon picked in Settings in the Dock while Cra is not running. -->+ <key>NSDockTilePlugIn</key>+ <string>CraDockTile.docktileplugin</string><key>LSMinimumSystemVersion</key><string>14.0</string><key>LSApplicationCategoryType</key>diff --git a/resources/app-icons/midnight.png b/resources/app-icons/midnight.pngnew file mode 100644index 0000000..fab861dBinary files /dev/null and b/resources/app-icons/midnight.png differdiff --git a/resources/app-icons/mono.png b/resources/app-icons/mono.pngnew file mode 100644index 0000000..c9efa52Binary files /dev/null and b/resources/app-icons/mono.png differdiff --git a/resources/app-icons/segments.png b/resources/app-icons/segments.pngnew file mode 100644index 0000000..d6380aaBinary files /dev/null and b/resources/app-icons/segments.png differdiff --git a/scripts/build.sh b/scripts/build.shindex 5193839..ce02a07 100755--- a/scripts/build.sh+++ b/scripts/build.sh@@ -41,6 +41,7 @@ echo -n "APPL????" > "$APP/Contents/PkgInfo"[ -d resources/brand ] && cp -R resources/brand "$APP/Contents/Resources/brand"[ -d resources/blocklist ] && cp -R resources/blocklist "$APP/Contents/Resources/blocklist"[ -d resources/browsers ] && cp -R resources/browsers "$APP/Contents/Resources/browsers"+[ -d resources/app-icons ] && cp -R resources/app-icons "$APP/Contents/Resources/app-icons"FRAMEWORK_SRC="$ROOT/vendor/cef/Release/Chromium Embedded Framework.framework"cp -R "$FRAMEWORK_SRC" "$APP/Contents/Frameworks/"@@ -62,6 +63,12 @@ for entry in "|" " (Alerts)|.alerts" " (GPU)|.gpu" " (Plugin)|.plugin" " (Renderecho -n "APPL????" > "$HELPER/Contents/PkgInfo"done+# The Dock tile plug-in (Info.plist NSDockTilePlugIn), a SwiftPM dynamic library in a bundle.+DOCK_TILE="$APP/Contents/PlugIns/CraDockTile.docktileplugin"+mkdir -p "$DOCK_TILE/Contents/MacOS"+cp "$BIN/libCraDockTile.dylib" "$DOCK_TILE/Contents/MacOS/CraDockTile"+sed -e "s/__VERSION__/$VERSION/" -e "s/__BUILD__/$BUILD_NUMBER/" resources/DockTile-Info.plist > "$DOCK_TILE/Contents/Info.plist"+# Code signing, innermost first. Ad-hoc by default; set CRA_SIGN_IDENTITY to a# "Developer ID Application: …" identity for a distributable build with the# hardened runtime, timestamps and the CEF entitlements. scripts/release.sh@@ -85,6 +92,7 @@ sign "$SPARKLE/Versions/B/Autoupdate"sign "$SPARKLE/Versions/B/Updater.app"sign "$SPARKLE"for h in "$APP"/Contents/Frameworks/*.app; do sign "$h" "$ROOT/resources/CraHelper.entitlements"; done+sign "$DOCK_TILE"# Passkeys need entitlements only a provisioning profile can grant: the Touch ID# keychain group ("<app id>.webauthn", scripts/cef-patches) and, once Apple approves# it, iCloud Keychain (web-browser.public-key-credential). Withdiff --git a/scripts/clips/clip.sh b/scripts/clips/clip.shindex 98b1120..ae4620d 100644--- a/scripts/clips/clip.sh+++ b/scripts/clips/clip.sh@@ -59,10 +59,19 @@ reset() {(CRA_DATA_DIR="$CLIPS/data" CRA_COMMAND_FILE="$CLIPS/commands.txt" "$APP/Contents/MacOS/CraClip" > "$CLIPS/craclip.log" 2>&1 &)nap 5PID=$(clip_pid)+ # The largest window is the main one; Chromium's page windows are AX windows too.read -r WX WY WW WH < <(osascript -e "tell application \"System Events\" to tell (first process whose unix id is $PID)- set {x, y} to position of window 1- set {w, h} to size of window 1- return (x as text) & \" \" & (y as text) & \" \" & (w as text) & \" \" & (h as text)+ set best to \"\"+ set area to 0+ repeat with win in windows+ set {x, y} to position of win+ set {w, h} to size of win+ if w * h > area then+ set area to w * h+ set best to (x as text) & \" \" & (y as text) & \" \" & (w as text) & \" \" & (h as text)+ end if+ end repeat+ return bestend tell")nap "${1:-3}"}diff --git a/scripts/dev.sh b/scripts/dev.shindex a82e578..065a3fe 100755--- a/scripts/dev.sh+++ b/scripts/dev.sh@@ -65,7 +65,7 @@ build() {fidonecp "$bin/Cra" "$APP/Contents/MacOS/$NAME"- for d in web brand blocklist browsers; do+ for d in web brand blocklist browsers app-icons; do[ -d "resources/$d" ] && rsync -a --delete "resources/$d/" "$APP/Contents/Resources/$d/"donecodesign --force --sign - --entitlements resources/Cra.entitlements "$APP"diff --git a/scripts/make-app-icons.swift b/scripts/make-app-icons.swiftnew file mode 100644index 0000000..658c12a--- /dev/null+++ b/scripts/make-app-icons.swift@@ -0,0 +1,72 @@+// Renders the alternate app icons in Settings ▸ General ▸ App Icon from the brand marks+// (brand/*.svg) into resources/app-icons/<id>.png, 512 px (Dock tiles top out at 128 pt), on Apple's icon grid:+// the tile is 824 of 1024 px, centred, the size the Dock gives the edge-to-edge AppIcon.icns.+// segments.png is only the picker's preview of the bundled icon.+// WebKit draws them so the ribbons' multiply blending survives (see brand/README.md).+// swift scripts/make-app-icons.swift+import AppKit+import WebKit++let root = URL(fileURLWithPath: #filePath).deletingLastPathComponent().deletingLastPathComponent()+func brand(_ name: String) -> String { try! String(contentsOf: root.appendingPathComponent("brand/\(name).svg"), encoding: .utf8) }++let sand = ##"<stop offset="0" stop-color="#f2e3c4"/><stop offset="1" stop-color="#e8d3aa"/>"##+let segments = brand("cra-segments-icon")+// The mono mark's ribbons, white, with the icon's drop shadow under them.+let monoRibbons = brand("cra-segments-mono")+ .replacingOccurrences(of: #"^<svg[^>]*>"#, with: "", options: .regularExpression)+ .replacingOccurrences(of: "</svg>", with: "")+ .replacingOccurrences(of: "currentColor", with: "#fff")+let shadow = segments.range(of: #"<g opacity=".18".*?</g>"#, options: .regularExpression).map { String(segments[$0]) }!++let icons: [String: String] = [+ // Dark tile; on dark, the ribbons blend normally (brand/README.md).+ "segments": segments,+ "midnight": segments+ .replacingOccurrences(of: sand, with: ##"<stop offset="0" stop-color="#2c2e36"/><stop offset="1" stop-color="#16171b"/>"##)+ .replacingOccurrences(of: "mix-blend-mode:multiply", with: "mix-blend-mode:normal"),+ // The shadow follows the 12-wide ribbons here, not the 19-wide white edge.+ "mono": ##"<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64"><defs><linearGradient id="t" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#5a84f8"/><stop offset="1" stop-color="#2f58d8"/></linearGradient></defs><rect width="64" height="64" rx="14.3" fill="url(#t)"/><g transform="translate(3.84 3.84) scale(0.88)">"##+ + shadow.replacingOccurrences(of: #"stroke-width="19""#, with: #"stroke-width="12""#) + monoRibbons + "</g></svg>",+]++final class Renderer: NSObject, WKNavigationDelegate {+ let view = WKWebView(frame: NSRect(x: 0, y: 0, width: 256, height: 256))+ var queue: [(String, String)]+ init(_ icons: [String: String]) { queue = icons.sorted { $0.key < $1.key } }++ func next() {+ guard let (_, svg) = queue.first else { exit(0) }+ view.navigationDelegate = self+ view.setValue(false, forKey: "drawsBackground")+ // Only the <svg> tag's size: the tile <rect> has the same attributes.+ let tag = svg.range(of: #"width="64" height="64""#)!+ let sized = svg.replacingCharacters(in: tag, with: #"style="display:block;width:80.46875vw;height:80.46875vw;margin:9.765625vw""#)+ view.loadHTMLString("<!doctype html><html><body style='margin:0;background:transparent;overflow:hidden'>\(sized)</body></html>", baseURL: nil)+ }++ func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {+ let (id, _) = queue.removeFirst()+ // 256 pt on the 2x backing: 512 px.+ webView.takeSnapshot(with: nil) { image, error in+ guard let image, let cg = image.cgImage(forProposedRect: nil, context: nil, hints: nil) else {+ fatalError("\(id): \(error?.localizedDescription ?? "no image")")+ }+ let rep = NSBitmapImageRep(cgImage: cg)+ let out = root.appendingPathComponent("resources/app-icons/\(id).png")+ try! FileManager.default.createDirectory(at: out.deletingLastPathComponent(), withIntermediateDirectories: true)+ try! rep.representation(using: .png, properties: [:])!.write(to: out)+ print("wrote \(out.path) (\(rep.pixelsWide) px)")+ self.next()+ }+ }+}++let app = NSApplication.shared+let window = NSWindow(contentRect: NSRect(x: -10000, y: -10000, width: 256, height: 256), styleMask: .borderless, backing: .buffered, defer: false)+window.backingType = .buffered+let renderer = Renderer(icons)+window.contentView = renderer.view+window.orderBack(nil)+renderer.next()+app.run()