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.

Share Favorites across Spaces with the same profile, exactly as Arc (#154) (#158)

Victor Kildahle5353766e6c1
diff --git a/Packages/CraCore/Sources/CraCore/FavoritesSharing.swift b/Packages/CraCore/Sources/CraCore/FavoritesSharing.swift
new file mode 100644
index 0000000..6806ab7
--- /dev/null
+++ b/Packages/CraCore/Sources/CraCore/FavoritesSharing.swift
@@ -0,0 +1,155 @@
+import Foundation
+
+/// Settings ▸ Tabs ▸ "Share Favorites across Spaces with the same profile" (GitHub #154), Arc's
+/// favorites: one list per profile (StorableSidebar topApps{profile}) that every space on the
+/// profile shows. The list belongs to the profile, not to a space: a space that changes profile
+/// shows the other profile's list and takes nothing along, and a list nobody shows stays until a
+/// space uses the profile again. Off, Cra's favorites are per space; SidebarStore turns one
+/// shape into the other.
+public enum FavoritesSharing {
+ /// A space's favorites as the store holds them.
+ public struct SpaceFavorites: Equatable {
+ public var spaceID: UUID
+ public var profileID: UUID?
+ public var containerID: UUID
+ /// The container's items in order, with `key(of:children:)` for each.
+ public var items: [Entry]
+
+ public init(spaceID: UUID, profileID: UUID?, containerID: UUID, items: [Entry]) {
+ self.spaceID = spaceID
+ self.profileID = profileID
+ self.containerID = containerID
+ self.items = items
+ }
+ }
+
+ /// A profile's list and what is in it.
+ public struct ProfileList: Equatable {
+ public var list: ProfileFavorites
+ public var items: [Entry]
+
+ public init(_ list: ProfileFavorites, items: [Entry]) {
+ self.list = list
+ self.items = items
+ }
+ }
+
+ public struct Entry: Equatable {
+ public var id: UUID
+ public var key: String?
+
+ public init(id: UUID, key: String?) {
+ self.id = id
+ self.key = key
+ }
+ }
+
+ public struct Move: Equatable {
+ public var item: UUID
+ public var container: UUID
+
+ public init(item: UUID, container: UUID) {
+ self.item = item
+ self.container = container
+ }
+ }
+
+ public struct Plan: Equatable {
+ /// Every profile's list afterwards: the ones there were, then new ones.
+ public var lists: [ProfileFavorites] = []
+ /// Lists to make, empty.
+ public var created: [UUID] = []
+ /// The list each space shows.
+ public var containers: [UUID: UUID] = [:]
+ /// Favorites that join the end of a list, in this order.
+ public var moves: [Move] = []
+ /// Favorites of the same page as one the list already has: they go, and a window
+ /// that had one open shows the kept one.
+ public var duplicates: [UUID: UUID] = [:]
+ /// Space containers emptied into a list.
+ public var dropped: [UUID] = []
+
+ public init() {}
+ }
+
+ /// Sharing on: each space shows its profile's list, made when the profile has none, and its
+ /// own favorites join it in sidebar order. Already shared, nothing changes.
+ public static func share(_ spaces: [SpaceFavorites], lists: [ProfileList], newID: () -> UUID = UUID.init) -> Plan {
+ var plan = Plan()
+ plan.lists = lists.map(\.list)
+ var target: [UUID?: UUID] = [:]
+ var keys: [UUID: [String: UUID]] = [:]
+ var taken: Set<UUID> = []
+ for l in lists where target[l.list.profileID] == nil {
+ target[l.list.profileID] = l.list.containerID
+ keys[l.list.containerID] = index(l.items, into: [:])
+ }
+ for l in lists { taken.insert(l.list.containerID) }
+ for s in spaces {
+ let t: UUID
+ if let known = target[s.profileID] {
+ t = known
+ } else {
+ t = newID()
+ target[s.profileID] = t
+ plan.created.append(t)
+ plan.lists.append(ProfileFavorites(profileID: s.profileID, containerID: t))
+ taken.insert(t)
+ }
+ plan.containers[s.spaceID] = t
+ guard taken.insert(s.containerID).inserted else { continue }
+ // A page the list already had goes; two of a page from one space both stay.
+ let before = keys[t] ?? [:]
+ for e in s.items {
+ if let k = e.key, let kept = before[k] {
+ plan.duplicates[e.id] = kept
+ } else {
+ plan.moves.append(Move(item: e.id, container: t))
+ }
+ }
+ keys[t] = index(s.items.filter { plan.duplicates[$0.id] == nil }, into: before)
+ plan.dropped.append(s.containerID)
+ }
+ return plan
+ }
+
+ /// Sharing off: the spaces showing a list each get a list of their own. The first in sidebar
+ /// order takes the favorites themselves, open pages too; the others get copies. Lists no
+ /// space shows stay with their profiles.
+ public struct Split: Equatable {
+ public var spaceID: UUID
+ public var from: UUID
+ /// True for the space that takes the favorites, false for a copy.
+ public var takes: Bool
+
+ public init(spaceID: UUID, from: UUID, takes: Bool) {
+ self.spaceID = spaceID
+ self.from = from
+ self.takes = takes
+ }
+ }
+
+ public static func unshare(_ spaces: [SpaceFavorites], lists: [ProfileFavorites]) -> [Split] {
+ let listIDs = Set(lists.map(\.containerID))
+ var seen: Set<UUID> = []
+ return spaces.filter { listIDs.contains($0.containerID) }.map {
+ Split(spaceID: $0.spaceID, from: $0.containerID, takes: seen.insert($0.containerID).inserted)
+ }
+ }
+
+ /// What makes two favorites the same when lists merge: a tab's pinned home, a split's panes'
+ /// homes in order. Nil never matches (an empty pane, anything else).
+ public static func key(of item: SidebarItem, children: [SidebarItem]) -> String? {
+ if let t = item.tab { return t.savedURL.isEmpty ? nil : "tab " + t.savedURL }
+ guard item.isSplit else { return nil }
+ let homes = children.compactMap { $0.tab?.savedURL }
+ guard !homes.isEmpty, !homes.contains(where: \.isEmpty) else { return nil }
+ return "split " + homes.joined(separator: " ")
+ }
+
+ private static func index(_ items: [Entry], into start: [String: UUID]) -> [String: UUID] {
+ var out = start
+ for e in items { if let k = e.key, out[k] == nil { out[k] = e.id } }
+ return out
+ }
+}
diff --git a/Packages/CraCore/Sources/CraCore/SidebarModel.swift b/Packages/CraCore/Sources/CraCore/SidebarModel.swift
index 8e92c02..aca15de 100644
--- a/Packages/CraCore/Sources/CraCore/SidebarModel.swift
+++ b/Packages/CraCore/Sources/CraCore/SidebarModel.swift
@@ -3,7 +3,8 @@ import Foundation
// Cra's sidebar model. Shape follows what Arc persists in StorableSidebar.json
// (see docs/arc-reverse-engineering.md): spaces own a favorites, a pinned and a
// "today" container, tabs/folders are items in a tree keyed by id with explicit
-// child ordering. Unlike Arc, favorites are not shared between spaces.
+// child ordering. Unlike Arc, favorites are not shared between spaces unless
+// AppSettings.sharedFavorites is on (FavoritesSharing).
public typealias ItemID = UUID
@@ -18,8 +19,9 @@ public enum ContainerKind: Codable, Equatable, Hashable {
}
}
- /// Stands in for the space of the favorites container every space shared
- /// before favorites became per space; SidebarStore splits it up on load.
+ /// Stands in for the space of a favorites container no one space owns: a profile's
+ /// shared list (#154, `SidebarDocument.profileFavorites`), or the one every space shared
+ /// in files from before favorites became per space, which SidebarStore splits up on load.
public static let sharedFavoritesSpaceID = UUID(uuid: (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
private enum CodingKeys: String, CodingKey { case favorites, pinned, today }
@@ -286,6 +288,18 @@ public struct BrowserProfile: Identifiable, Codable, Equatable {
public var directoryName: String { "Profile \(id.uuidString)" }
}
+/// A profile's favorites list (Arc: StorableSidebar.topAppsContainerIDs, profile → container).
+public struct ProfileFavorites: Codable, Equatable {
+ /// nil is the Default profile.
+ public var profileID: UUID?
+ public var containerID: UUID
+
+ public init(profileID: UUID?, containerID: UUID) {
+ self.profileID = profileID
+ self.containerID = containerID
+ }
+}
+
public struct SidebarDocument: Codable, Equatable {
public var version: Int = 1
public var spaceOrder: [UUID]
@@ -296,15 +310,19 @@ public struct SidebarDocument: Codable, Equatable {
public var items: [SidebarItem]
/// Profiles besides Default (missing in files from before profiles).
public var profiles: [BrowserProfile]?
+ /// Arc's favorites per profile (topApps{profile}), with AppSettings.sharedFavorites on: the
+ /// list each profile's spaces show. A list outlives its spaces, as in Arc (#154).
+ public var profileFavorites: [ProfileFavorites]?
public init(version: Int = 1, spaceOrder: [UUID], spaces: [Space], favoritesContainerID: UUID? = nil, items: [SidebarItem],
- profiles: [BrowserProfile]? = nil) {
+ profiles: [BrowserProfile]? = nil, profileFavorites: [ProfileFavorites]? = nil) {
self.version = version
self.spaceOrder = spaceOrder
self.spaces = spaces
self.favoritesContainerID = favoritesContainerID
self.items = items
self.profiles = profiles
+ self.profileFavorites = profileFavorites
}
public static func fresh() -> SidebarDocument {
@@ -477,6 +495,9 @@ public struct AppSettings: Codable, Equatable {
/// Arc's showSpaceHeaderOnSingleUnnamedSpaces: with only one space, its header (and the
/// dock's lone space icon) can be hidden, for people who don't use spaces.
public var showSpaceHeaderOnSingleSpace: Bool = true
+ /// GitHub #154: the spaces of one profile show one set of favorites, as Arc's do (a topApps
+ /// container per profile). Off by default: Cra keeps favorites per space (FavoritesSharing).
+ public var sharedFavorites: Bool = false
/// GitHub #24, not in Arc: the page fills the window with no margin and no rounded
/// card, like a traditional browser. Off by default.
public var edgeToEdgeContent: Bool = false
@@ -645,6 +666,7 @@ extension AppSettings {
httpsOnly = try c.decodeIfPresent(Bool.self, forKey: .httpsOnly) ?? false
searchSuggestions = try c.decodeIfPresent(Bool.self, forKey: .searchSuggestions) ?? true
showSpaceHeaderOnSingleSpace = try c.decodeIfPresent(Bool.self, forKey: .showSpaceHeaderOnSingleSpace) ?? true
+ sharedFavorites = try c.decodeIfPresent(Bool.self, forKey: .sharedFavorites) ?? false
edgeToEdgeContent = try c.decodeIfPresent(Bool.self, forKey: .edgeToEdgeContent) ?? false
perfRecording = try c.decodeIfPresent(Bool.self, forKey: .perfRecording) ?? Self.perfRecordingDefault
perfHidesSiteNames = try c.decodeIfPresent(Bool.self, forKey: .perfHidesSiteNames) ?? false
diff --git a/Packages/CraCore/Tests/CraCoreTests/FavoritesSharingTests.swift b/Packages/CraCore/Tests/CraCoreTests/FavoritesSharingTests.swift
new file mode 100644
index 0000000..9b2713d
--- /dev/null
+++ b/Packages/CraCore/Tests/CraCoreTests/FavoritesSharingTests.swift
@@ -0,0 +1,103 @@
+import CraCore
+import Foundation
+import Testing
+
+/// GitHub #154: Arc's one favorites list per profile, as a setting.
+struct FavoritesSharingTests {
+ typealias S = FavoritesSharing.SpaceFavorites
+ typealias E = FavoritesSharing.Entry
+ typealias L = FavoritesSharing.ProfileList
+
+ static func ids(_ n: Int) -> [UUID] { (0..<n).map { _ in UUID() } }
+
+ @Test func eachProfileGetsOneListOfItsSpacesFavorites() {
+ let sp = Self.ids(4), c = Self.ids(4), f = Self.ids(5), made = Self.ids(2), work = UUID()
+ var next = made.makeIterator()
+ let plan = FavoritesSharing.share([
+ S(spaceID: sp[0], profileID: nil, containerID: c[0], items: [E(id: f[0], key: "tab https://mail.example")]),
+ S(spaceID: sp[1], profileID: work, containerID: c[1], items: [E(id: f[1], key: "tab https://jira.example")]),
+ S(spaceID: sp[2], profileID: nil, containerID: c[2], items: [E(id: f[2], key: "tab https://music.example"),
+ E(id: f[3], key: "tab https://mail.example")]),
+ S(spaceID: sp[3], profileID: work, containerID: c[3], items: [E(id: f[4], key: nil)]),
+ ], lists: [], newID: { next.next()! })
+ #expect(plan.created == made)
+ #expect(plan.lists == [ProfileFavorites(profileID: nil, containerID: made[0]), ProfileFavorites(profileID: work, containerID: made[1])])
+ #expect(plan.containers == [sp[0]: made[0], sp[1]: made[1], sp[2]: made[0], sp[3]: made[1]])
+ #expect(plan.moves == [.init(item: f[0], container: made[0]), .init(item: f[1], container: made[1]),
+ .init(item: f[2], container: made[0]), .init(item: f[4], container: made[1])])
+ #expect(plan.duplicates == [f[3]: f[0]], "the same page once: the first space's tile stays")
+ #expect(plan.dropped == c)
+ }
+
+ /// Arc keeps a profile's list while no space uses it; turning sharing on again starts from it.
+ @Test func aProfilesListIsReused() {
+ let sp = UUID(), c = UUID(), list = UUID(), f = Self.ids(3)
+ let plan = FavoritesSharing.share(
+ [S(spaceID: sp, profileID: nil, containerID: c, items: [E(id: f[1], key: "tab https://a.example"), E(id: f[2], key: "tab https://b.example")])],
+ lists: [L(ProfileFavorites(profileID: nil, containerID: list), items: [E(id: f[0], key: "tab https://a.example")])],
+ newID: { Issue.record("no new list"); return UUID() })
+ #expect(plan.created.isEmpty && plan.containers == [sp: list])
+ #expect(plan.moves == [.init(item: f[2], container: list)] && plan.duplicates == [f[1]: f[0]])
+ }
+
+ @Test func twoOfAPageInOneSpaceBothStay() {
+ let sp = UUID(), c = UUID(), f = Self.ids(2)
+ let plan = FavoritesSharing.share([S(spaceID: sp, profileID: nil, containerID: c,
+ items: [E(id: f[0], key: "tab https://a.example"), E(id: f[1], key: "tab https://a.example")])], lists: [])
+ #expect(plan.moves.map(\.item) == f && plan.duplicates.isEmpty)
+ }
+
+ /// Off gives each space its own list again; on folds the copies back, so the list comes back
+ /// as it was, not doubled.
+ @Test func offAndOnAgainChangesNothing() {
+ let sp = Self.ids(3), list = UUID(), c = Self.ids(2), f = Self.ids(4)
+ let shared = [E(id: f[0], key: "tab https://a.example"), E(id: f[1], key: "split https://b.example https://c.example")]
+ let lists = [ProfileFavorites(profileID: nil, containerID: list)]
+ let off = FavoritesSharing.unshare(sp.map { S(spaceID: $0, profileID: nil, containerID: list, items: shared) }, lists: lists)
+ #expect(off == [.init(spaceID: sp[0], from: list, takes: true), .init(spaceID: sp[1], from: list, takes: false),
+ .init(spaceID: sp[2], from: list, takes: false)])
+ let copy = [E(id: f[2], key: shared[0].key), E(id: f[3], key: shared[1].key)]
+ let on = FavoritesSharing.share([S(spaceID: sp[0], profileID: nil, containerID: c[0], items: shared),
+ S(spaceID: sp[1], profileID: nil, containerID: c[1], items: copy)],
+ lists: [L(lists[0], items: [])], newID: { Issue.record("no new list"); return UUID() })
+ #expect(on.moves.map(\.item) == [f[0], f[1]])
+ #expect(on.duplicates == [f[2]: f[0], f[3]: f[1]])
+ }
+
+ @Test func sharedListsStayPut() {
+ let sp = Self.ids(2), list = UUID(), work = UUID(), f = UUID()
+ let lists = [L(ProfileFavorites(profileID: work, containerID: list), items: [E(id: f, key: "tab https://a.example")])]
+ let plan = FavoritesSharing.share(sp.map { S(spaceID: $0, profileID: work, containerID: list, items: lists[0].items) }, lists: lists)
+ #expect(plan.containers == [sp[0]: list, sp[1]: list] && plan.lists == [lists[0].list])
+ #expect(plan.moves.isEmpty && plan.duplicates.isEmpty && plan.dropped.isEmpty && plan.created.isEmpty)
+ #expect(FavoritesSharing.unshare([S(spaceID: sp[0], profileID: nil, containerID: UUID(), items: [])], lists: [lists[0].list]).isEmpty,
+ "a space with its own list keeps it")
+ }
+
+ @Test func keys() {
+ let tab = SidebarItem.tab("https://mail.example/inbox", parent: nil)
+ #expect(FavoritesSharing.key(of: tab, children: []) == "tab https://mail.example/inbox")
+ #expect(FavoritesSharing.key(of: SidebarItem.tab("", parent: nil), children: []) == nil, "an empty pane matches nothing")
+ let split = SidebarItem.split(parent: nil)
+ let panes = [SidebarItem.tab("https://a.example", parent: split.id), SidebarItem.tab("https://b.example", parent: split.id)]
+ #expect(FavoritesSharing.key(of: split, children: panes) == "split https://a.example https://b.example")
+ #expect(FavoritesSharing.key(of: split, children: panes.reversed()) != FavoritesSharing.key(of: split, children: panes))
+ #expect(FavoritesSharing.key(of: split, children: [panes[0], SidebarItem.tab("", parent: split.id)]) == nil)
+ #expect(FavoritesSharing.key(of: SidebarItem.folder("F", parent: nil), children: []) == nil)
+ }
+
+ @Test func settingIsOffUntilTurnedOn() throws {
+ let empty = try JSONDecoder().decode(AppSettings.self, from: Data("{}".utf8))
+ #expect(!empty.sharedFavorites)
+ let on = try JSONDecoder().decode(AppSettings.self, from: Data(#"{"sharedFavorites": true}"#.utf8))
+ #expect(on.sharedFavorites)
+ }
+
+ @Test func listsRoundTrip() throws {
+ var doc = SidebarDocument.fresh()
+ doc.profileFavorites = [ProfileFavorites(profileID: nil, containerID: UUID()), ProfileFavorites(profileID: UUID(), containerID: UUID())]
+ let data = try JSONEncoder().encode(doc)
+ #expect(try JSONDecoder().decode(SidebarDocument.self, from: data).profileFavorites == doc.profileFavorites)
+ #expect(SidebarDocument.fresh().profileFavorites == nil, "files without shared favorites don't change")
+ }
+}
diff --git a/Sources/Cra/Services/Import/Importers.swift b/Sources/Cra/Services/Import/Importers.swift
index 5a7d63d..0694ab4 100644
--- a/Sources/Cra/Services/Import/Importers.swift
+++ b/Sources/Cra/Services/Import/Importers.swift
@@ -495,7 +495,9 @@ extension SidebarStore {
result.spaces += 1
result.spaceIDs.append(space.id)
if imported[sp.title.lowercased()] == nil { imported[sp.title.lowercased()] = space.id }
- insert(sp.favorites, into: space.favoritesContainerID, skip: existingURLs(under: space.favoritesContainerID), pinned: true)
+ // With shared favorites (#154) the profile picks which list the space shows.
+ let favorites = self.space(space.id)?.favoritesContainerID ?? space.favoritesContainerID
+ insert(sp.favorites, into: favorites, skip: existingURLs(under: favorites), pinned: true)
insert(sp.pinned, into: space.pinnedContainerID, skip: existingURLs(under: space.pinnedContainerID), pinned: true)
insert(sp.today, into: space.todayContainerID, skip: existingURLs(under: space.todayContainerID), pinned: false)
}
diff --git a/Sources/Cra/Services/SidebarIntegrity.swift b/Sources/Cra/Services/SidebarIntegrity.swift
index 9ad7cb6..05e6e4b 100644
--- a/Sources/Cra/Services/SidebarIntegrity.swift
+++ b/Sources/Cra/Services/SidebarIntegrity.swift
@@ -40,8 +40,15 @@ extension SidebarStore {
problems.append("space \(name(space.id)) has no container \(name(c))")
}
}
+ // A shared favorite stays open in a space that changed profile (#154, Arc).
+ let lists = Set(profileFavorites.map(\.containerID))
+ func inList(_ id: UUID) -> Bool {
+ var up = all[id]?.parentID
+ while let p = up { if lists.contains(p) { return true }; up = all[p]?.parentID }
+ return false
+ }
for w in prefs.windows {
- for (sid, tid) in w.selectedTabPerSpace where all[tid] != nil && spaceID(ofItem: tid) != sid {
+ for (sid, tid) in w.selectedTabPerSpace where all[tid] != nil && !isInSpace(tid, sid) && !inList(tid) {
problems.append("window \(name(w.id)) selects \(name(tid)) for space \(name(sid)), but it lives elsewhere")
}
}
diff --git a/Sources/Cra/Services/SidebarStore.swift b/Sources/Cra/Services/SidebarStore.swift
index b74663e..807873d 100644
--- a/Sources/Cra/Services/SidebarStore.swift
+++ b/Sources/Cra/Services/SidebarStore.swift
@@ -13,6 +13,9 @@ final class SidebarStore {
private(set) var spaceOrder: [UUID] = []
/// Profiles besides Default, in the order they were made.
private(set) var profiles: [BrowserProfile] = []
+ /// Arc's favorites per profile, with Share Favorites on (#154): the list each profile's
+ /// spaces show. One stays while no space uses its profile.
+ private(set) var profileFavorites: [ProfileFavorites] = []
/// Observed item by item (ItemTable): a view re-renders when an item it read changes.
let items = ItemTable()
private(set) var archive: [ArchivedItem] = [] { didSet { archiveChanged = true } }
@@ -61,6 +64,7 @@ final class SidebarStore {
let doc = sidebarFile.load(or: SidebarDocument.fresh)
for s in doc.spaces { spaces[s.id] = s }
profiles = doc.profiles ?? []
+ profileFavorites = doc.profileFavorites ?? []
spaceOrder = doc.spaceOrder.filter { spaces[$0] != nil }
for s in doc.spaces where !spaceOrder.contains(s.id) { spaceOrder.append(s.id) }
for it in doc.items { items[it.id] = it }
@@ -80,6 +84,8 @@ final class SidebarStore {
activeWindowID = prefs.windows[0].id
lastNormalWindowID = activeWindowID
splitSharedFavorites(doc.favoritesContainerID)
+ // Lists as the setting has them, also in a file an older Cra or a hand edit wrote.
+ settings.sharedFavorites ? shareFavorites() : unshareFavorites()
}
/// Make sure every space has its containers and no item points at a
@@ -275,7 +281,8 @@ final class SidebarStore {
if isIncognito(space: sid), let s = spaces[sid] {
return tabs(under: s.favoritesContainerID) + tabs(under: s.pinnedContainerID) + tabs(under: s.todayContainerID)
}
- return allTabs().filter { !isIncognito(item: $0.id) }
+ // Not the favorites of a profile no space uses (#154): nothing shows them.
+ return allTabs().filter { !isIncognito(item: $0.id) && spaceID(ofItem: $0.id) != nil }
}
private func collectSubtree(of space: Space, into ids: inout Set<UUID>) {
@@ -352,11 +359,13 @@ final class SidebarStore {
}
/// Which container an item ultimately lives in.
- func rootContainer(of id: UUID) -> ContainerKind? {
+ func rootContainer(of id: UUID) -> ContainerKind? { rootContainerItem(of: id)?.container }
+
+ private func rootContainerItem(of id: UUID) -> SidebarItem? {
var cur = items[id]
var hops = 0
while let c = cur, hops < 64 {
- if let kind = c.container { return kind }
+ if c.container != nil { return c }
guard let p = c.parentID else { return nil }
cur = items[p]
hops += 1
@@ -364,7 +373,28 @@ final class SidebarStore {
return nil
}
- func spaceID(ofItem id: UUID) -> UUID? { rootContainer(of: id)?.spaceID }
+ /// The space an item is in. Shared favorites (#154) are in every space of their profile:
+ /// then it's the window's space when that is one of them, else the first.
+ func spaceID(ofItem id: UUID, window: UUID? = nil) -> UUID? {
+ guard let root = rootContainerItem(of: id), let kind = root.container else { return nil }
+ guard case .favorites(let owner) = kind, owner == ContainerKind.sharedFavoritesSpaceID else { return kind.spaceID }
+ if let focused = untrackedWindow(window).focusedSpaceID, spaces[focused]?.favoritesContainerID == root.id { return focused }
+ return spaceOrder.first { spaces[$0]?.favoritesContainerID == root.id }
+ }
+
+ /// Whether a space lists the item: its own, or favorites it shares.
+ func isInSpace(_ id: UUID, _ sid: UUID) -> Bool {
+ guard let root = rootContainerItem(of: id)?.id, let s = spaces[sid] else { return false }
+ return [s.favoritesContainerID, s.pinnedContainerID, s.todayContainerID].contains(root)
+ }
+
+ /// The spaces that show an item: one, every space on its profile for a shared favorite, or
+ /// none for one on a profile no space uses.
+ func spaceIDs(ofItem id: UUID) -> [UUID] {
+ guard let root = rootContainerItem(of: id), let kind = root.container else { return [] }
+ guard case .favorites(let owner) = kind, owner == ContainerKind.sharedFavoritesSpaceID else { return [kind.spaceID] }
+ return spaceOrder.filter { spaces[$0]?.favoritesContainerID == root.id }
+ }
func isPinned(_ id: UUID) -> Bool {
switch rootContainer(of: id) {
@@ -418,7 +448,7 @@ final class SidebarStore {
touch()
return
}
- let sid = spaceID(ofItem: id) ?? focused
+ let sid = spaceID(ofItem: id, window: w) ?? focused
// Incognito pages stay in their own window; normal tabs never open in one.
guard self.window(w).isIncognito ? sid == focused : !isIncognito(space: sid) else { return }
updateWindow(w) {
@@ -593,7 +623,7 @@ final class SidebarStore {
for sid in incognitoSpaceIDs { if let s = spaces[sid] { collectSubtree(of: s, into: &hidden) } }
return SidebarDocument(version: 1, spaceOrder: spaceOrder, spaces: orderedSpaces,
items: hidden.isEmpty ? Array(items.values) : items.values.filter { !hidden.contains($0.id) },
- profiles: profiles)
+ profiles: profiles, profileFavorites: profileFavorites.isEmpty ? nil : profileFavorites)
}
/// The tab switcher's list (⌃Tab): a space's most recently used tabs, newest first
@@ -959,10 +989,149 @@ final class SidebarStore {
func removeFromFavorites(_ id: UUID) {
let id = splitContaining(id)?.id ?? id
+ // Arc's Remove Favorite (1.171, shared favorites): the favorite is gone, not pinned or archived.
+ if profileList(ofItem: id) != nil {
+ let tabs = items[id]?.isSplit == true ? children(of: id).filter(\.isTab).map(\.id) : [id]
+ for t in tabs { archiveTab(t, reason: .manual) }
+ archive.removeAll { tabs.contains($0.id) }
+ return
+ }
guard let space = spaceID(ofItem: id).flatMap({ spaces[$0] }) else { return }
moveItem(id, to: space.pinnedContainerID, index: nil)
}
+ // MARK: Shared favorites (#154)
+
+ /// Settings ▸ Tabs ▸ Share Favorites: Arc's favorites, one list per profile. On, each
+ /// profile's spaces show its list, which takes in their own favorites (a page in two of them
+ /// once); off, each space gets its own list again.
+ func setFavoritesShared(_ on: Bool) {
+ guard settings.sharedFavorites != on else { return }
+ settings.sharedFavorites = on
+ on ? shareFavorites() : unshareFavorites()
+ }
+
+ private func entries(_ container: UUID) -> [FavoritesSharing.Entry] {
+ children(of: container).map { FavoritesSharing.Entry(id: $0.id, key: FavoritesSharing.key(of: $0, children: children(of: $0.id))) }
+ }
+
+ private func favoritesBySpace() -> [FavoritesSharing.SpaceFavorites] {
+ orderedSpaces.map {
+ FavoritesSharing.SpaceFavorites(spaceID: $0.id, profileID: $0.profileID, containerID: $0.favoritesContainerID,
+ items: entries($0.favoritesContainerID))
+ }
+ }
+
+ /// A profile's list, made empty when it has none (a space moving to a new profile).
+ private func profileList(_ profileID: UUID?) -> UUID {
+ if let l = profileFavorites.first(where: { $0.profileID == profileID }), items[l.containerID] != nil { return l.containerID }
+ let c = SidebarItem.container(.favorites(spaceID: ContainerKind.sharedFavoritesSpaceID))
+ items[c.id] = c
+ profileFavorites.removeAll { $0.profileID == profileID }
+ profileFavorites.append(ProfileFavorites(profileID: profileID, containerID: c.id))
+ return c.id
+ }
+
+ private func isProfileList(_ container: UUID) -> Bool { profileFavorites.contains { $0.containerID == container } }
+
+ /// Arc's Move to ▸ Profile on a favorite: it joins the end of that profile's list.
+ func moveFavorite(_ id: UUID, toProfile profileID: UUID?) {
+ let id = splitContaining(id)?.id ?? id
+ guard let from = profileList(ofItem: id), from.profileID != profileID, profileID == nil || profile(profileID) != nil else { return }
+ reparent(id, to: profileList(profileID))
+ touch()
+ }
+
+ /// Makes the sidebar match FavoritesSharing.share; nothing changes when it already does.
+ private func shareFavorites() {
+ profileFavorites.removeAll { items[$0.containerID] == nil }
+ let lists = profileFavorites.map { FavoritesSharing.ProfileList($0, items: entries($0.containerID)) }
+ let plan = FavoritesSharing.share(favoritesBySpace(), lists: lists)
+ for c in plan.created { items[c] = SidebarItem.container(.favorites(spaceID: ContainerKind.sharedFavoritesSpaceID), id: c) }
+ // Raw moves: a favorite keeps its home (moveItem would make the current page it).
+ for m in plan.moves { reparent(m.item, to: m.container) }
+ // A window that had a dropped duplicate open shows the kept one (a split's panes in order).
+ var replaced: [UUID: UUID] = [:]
+ for (dup, kept) in plan.duplicates {
+ replaced[dup] = kept
+ let keptPanes = items[kept]?.children ?? []
+ for (i, pane) in (items[dup]?.children ?? []).enumerated() { replaced[pane] = keptPanes.indices.contains(i) ? keptPanes[i] : kept }
+ detach(dup)
+ func drop(_ id: UUID) {
+ for c in items[id]?.children ?? [] { drop(c) }
+ items[id] = nil
+ }
+ drop(dup)
+ }
+ for c in plan.dropped { items[c] = nil }
+ var changed = !plan.created.isEmpty || !plan.moves.isEmpty || !plan.duplicates.isEmpty || !plan.dropped.isEmpty
+ profileFavorites = plan.lists
+ for (sid, c) in plan.containers where spaces[sid]?.favoritesContainerID != c {
+ spaces[sid]?.favoritesContainerID = c
+ changed = true
+ }
+ if !replaced.isEmpty {
+ var windows = prefs.windows
+ for i in windows.indices {
+ for (sid, tid) in windows[i].selectedTabPerSpace { if let r = replaced[tid] { windows[i].selectedTabPerSpace[sid] = r } }
+ }
+ prefs.windows = windows
+ for (w, tid) in previousTab { if let r = replaced[tid] { previousTab[w] = r } }
+ }
+ if changed { touch() }
+ }
+
+ /// Each space showing a list gets one of its own: the first takes the favorites and their
+ /// pages, the others copies. A list no space shows stays with its profile for next time.
+ private func unshareFavorites() {
+ let splits = FavoritesSharing.unshare(favoritesBySpace(), lists: profileFavorites)
+ guard !splits.isEmpty else { return }
+ var windows = prefs.windows
+ var expanded = prefs.expandedFolders
+ var own: [UUID: UUID] = [:]
+ for s in splits {
+ let c = SidebarItem.container(.favorites(spaceID: s.spaceID))
+ items[c.id] = c
+ own[s.spaceID] = c.id
+ }
+ // Copies first: the space that takes the favorites empties the list.
+ for s in splits where !s.takes {
+ var map: [UUID: UUID] = [:]
+ for child in items[s.from]?.children ?? [] { copySubtree(child, into: own[s.spaceID]!, copies: &map) }
+ // A favorite open in this space stays open: it is now this space's copy.
+ for i in windows.indices {
+ if let sel = windows[i].selectedTabPerSpace[s.spaceID], let copy = map[sel] { windows[i].selectedTabPerSpace[s.spaceID] = copy }
+ }
+ for (old, new) in map where expanded.contains(old) { expanded.insert(new) }
+ }
+ for s in splits where s.takes {
+ for child in items[s.from]?.children ?? [] { reparent(child, to: own[s.spaceID]!) }
+ }
+ for s in splits { spaces[s.spaceID]?.favoritesContainerID = own[s.spaceID]! }
+ let emptied = Set(splits.map(\.from))
+ for c in emptied { items[c] = nil }
+ profileFavorites.removeAll { emptied.contains($0.containerID) }
+ // A favorite left open in a space that changed profile now belongs to one space.
+ for i in windows.indices {
+ for (sid, tid) in windows[i].selectedTabPerSpace where items[tid] != nil && !isInSpace(tid, sid) && profileList(ofItem: tid) == nil {
+ windows[i].selectedTabPerSpace[sid] = nil
+ }
+ }
+ var p = prefs
+ p.windows = windows
+ p.expandedFolders = expanded
+ prefs = p
+ touch()
+ }
+
+ private func reparent(_ id: UUID, to parent: UUID) {
+ guard var it = items[id] else { return }
+ detach(id)
+ it.parentID = parent
+ items[id] = it
+ items[parent]?.children.append(id)
+ }
+
/// `following`: the window that goes along to `sid`.
func moveTab(_ id: UUID, toSpace sid: UUID, following: UUID? = nil) {
moveTabs([id], toSpace: sid, following: following)
@@ -977,11 +1146,12 @@ final class SidebarStore {
let from = spaceID(ofItem: first)
let moved = Set(ids + ids.flatMap { items[$0]?.children ?? [] })
let today = from.flatMap { spaces[$0] }.map { shownTabs(under: $0.todayContainerID) } ?? []
- let favorites = ids.filter { isFavorite($0) }
+ // Favorites the space already shows (#154) stay where they are.
+ let favorites = ids.filter { isFavorite($0) && !isInSpace($0, sid) }
let pinned = ids.filter { !isFavorite($0) && isPinned($0) }
moveItems(favorites, to: space.favoritesContainerID, index: nil)
moveItems(pinned, to: space.pinnedContainerID, index: nil)
- moveItems(ids.filter { !favorites.contains($0) && !pinned.contains($0) }, to: space.todayContainerID, index: 0)
+ moveItems(ids.filter { !isFavorite($0) && !pinned.contains($0) }, to: space.todayContainerID, index: 0)
// The window that goes along leaves nothing selected in the old space (Arc 1.171, Move to
// Today in <space>); another window that had it open there picks the next tab, as on close.
guard let from, from != sid, spaceID(ofItem: first) == sid else { return }
@@ -1343,7 +1513,9 @@ final class SidebarStore {
func archiveTab(_ id: UUID, reason: ArchiveReason) {
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) } ?? []
+ // Each window and space that has it open, every space sharing it for a favorite.
+ let shownIn = spaceIDs(ofItem: id)
+ let selectedIn = prefs.windows.flatMap { w in shownIn.filter { w.selectedTabPerSpace[$0] == id }.map { (w.id, $0) } }
let pinned = isPinned(id)
let split = splitContaining(id)
let folder = it.parentID.flatMap { items[$0]?.isFolder == true ? $0 : nil }
@@ -1362,8 +1534,8 @@ final class SidebarStore {
sourceFolderID: folder, sourceIndex: index), at: 0)
if archive.count > 2000 { archive.removeLast(archive.count - 2000) }
}
- if !selectedIn.isEmpty, let sid {
- for w in selectedIn {
+ if !selectedIn.isEmpty {
+ for (w, sid) in selectedIn {
// Closing a pane keeps the split on screen: focus a neighbour pane. The split
// still goes back to the tab shown before it (Arc).
let kept = previousTab[w]
@@ -1382,15 +1554,15 @@ final class SidebarStore {
/// The tab shown once the selected `id` closes in window `w`: `list` is the space's Today
/// tabs while `id` is still among them, empty for a pinned tab.
private func closeSuccessor(of id: UUID, in sid: UUID, window w: UUID, list: [UUID]) -> UUID? {
- let back = previousTab[w].flatMap { spaceID(ofItem: $0) == sid ? $0 : nil }
+ let back = previousTab[w].flatMap { isInSpace($0, sid) ? $0 : nil }
return CloseSuccessor.next(closing: id, previous: back, hasPage: hasPage, list: list)
}
/// A pinned tab, favorite or pinned split closed (unloaded) while selected: the tab to show
/// instead, if any.
func closeSuccessor(ofPinned id: UUID, window w: UUID) -> UUID? {
- guard let sid = spaceID(ofItem: id) else { return nil }
- let back = previousTab[w].flatMap { spaceID(ofItem: $0) == sid ? $0 : nil }
+ guard let sid = spaceID(ofItem: id, window: w) else { return nil }
+ let back = previousTab[w].flatMap { isInSpace($0, sid) ? $0 : nil }
return CloseSuccessor.afterPinned(closing: id, isSplit: splitContaining(id) != nil, previous: back, hasPage: hasPage)
}
@@ -1475,9 +1647,10 @@ final class SidebarStore {
pinnedContainerID: pinned.id, todayContainerID: today.id, createdAt: clock.now)
spaces[id] = space
spaceOrder.append(id)
+ if settings.sharedFavorites { shareFavorites() }
if focus, !window().isIncognito { updateWindow(nil) { $0.focusedSpaceID = id } }
touch()
- return space
+ return spaces[id] ?? space
}
func updateSpace(_ space: Space) {
@@ -1488,11 +1661,14 @@ final class SidebarStore {
func deleteSpace(_ id: UUID) {
guard spaceOrder.count > 1, spaceOrder.contains(id), let space = spaces[id] else { return }
- for t in tabs(under: space.favoritesContainerID) + tabs(under: space.pinnedContainerID) + tabs(under: space.todayContainerID) {
+ // A profile's favorites stay with the profile (Arc).
+ let shared = isProfileList(space.favoritesContainerID)
+ let favorites = shared ? [] : [space.favoritesContainerID]
+ for t in (favorites + [space.pinnedContainerID, space.todayContainerID]).flatMap({ tabs(under: $0) }) {
archiveTab(t.id, reason: .spaceDeleted)
}
- for c in children(of: space.favoritesContainerID) + children(of: space.pinnedContainerID) where c.isFolder { deleteFolder(c.id) }
- items[space.favoritesContainerID] = nil
+ for c in (favorites + [space.pinnedContainerID]).flatMap({ children(of: $0) }) where c.isFolder { deleteFolder(c.id) }
+ for c in favorites { items[c] = nil }
items[space.pinnedContainerID] = nil
items[space.todayContainerID] = nil
spaces[id] = nil
@@ -1513,7 +1689,7 @@ final class SidebarStore {
func exportSpace(_ id: UUID, intoFolderIn target: UUID) -> SidebarItem? {
guard id != target, let space = spaces[id], let dest = spaces[target], spaceOrder.count > 1 else { return nil }
let folder = createFolder(named: space.title, in: dest.pinnedContainerID, index: 0)
- let moving = [space.favoritesContainerID, space.pinnedContainerID, space.todayContainerID]
+ let moving = ((isProfileList(space.favoritesContainerID) ? [] : [space.favoritesContainerID]) + [space.pinnedContainerID, space.todayContainerID])
.flatMap { children(of: $0) }
.filter { !$0.isLiveFolder }
.map(\.id)
@@ -1533,7 +1709,17 @@ final class SidebarStore {
/// The Chromium folder a tab's pages load in: its space's profile, or nil for the
/// Default profile (and for incognito, which has its own off-the-record one).
func profilePath(item id: UUID) -> String? {
- spaceID(ofItem: id).flatMap { profilePath(space: $0) }
+ if let l = profileList(ofItem: id) {
+ return profile(l.profileID).map { AppPaths.chromiumCache.appendingPathComponent($0.directoryName, isDirectory: true).path }
+ }
+ return spaceID(ofItem: id).flatMap { profilePath(space: $0) }
+ }
+
+ /// A shared favorite loads in its list's profile (#154): a space that changed profile with
+ /// one open keeps showing it, in the profile it was opened in (Arc).
+ func profileList(ofItem id: UUID) -> ProfileFavorites? {
+ guard let root = rootContainerItem(of: id)?.id else { return nil }
+ return profileFavorites.first { $0.containerID == root }
}
func profilePath(space sid: UUID) -> String? {
@@ -1548,7 +1734,10 @@ final class SidebarStore {
return p.directoryName
}
- func profileDirectoryName(item id: UUID) -> String { spaceID(ofItem: id).map { profileDirectoryName(space: $0) } ?? "Default" }
+ func profileDirectoryName(item id: UUID) -> String {
+ if let l = profileList(ofItem: id) { return profile(l.profileID)?.directoryName ?? "Default" }
+ return spaceID(ofItem: id).map { profileDirectoryName(space: $0) } ?? "Default"
+ }
@discardableResult
func createProfile(name: String) -> BrowserProfile {
@@ -1567,6 +1756,10 @@ final class SidebarStore {
/// Pages already open in the space load again in the new profile (BrowserManager).
func setProfile(_ profileID: UUID?, forSpace id: UUID) {
guard var s = spaces[id], s.profileID != profileID, profileID == nil || profile(profileID) != nil else { return }
+ // Arc: favorites belong to the profile. The space shows its new profile's list and takes
+ // nothing along; the old list stays with the old profile, shown or not. A favorite open in
+ // the space stays open, in its own profile, though its tile is gone (Arc 1.171).
+ if isProfileList(s.favoritesContainerID) { s.favoritesContainerID = profileList(profileID) }
s.profileID = profileID
spaces[id] = s
touch()
@@ -1577,6 +1770,15 @@ final class SidebarStore {
func deleteProfile(_ id: UUID) {
guard let p = profile(id), spaces.values.allSatisfy({ $0.profileID != id }) else { return }
profiles.removeAll { $0.id == id }
+ // Its favorites go with it.
+ for l in profileFavorites where l.profileID == id {
+ func drop(_ id: UUID) {
+ for c in items[id]?.children ?? [] { drop(c) }
+ items[id] = nil
+ }
+ drop(l.containerID)
+ }
+ profileFavorites.removeAll { $0.profileID == id }
ProfileCleanup.schedule(p.directoryName)
touch()
}
diff --git a/Sources/Cra/UI/Settings/TabsPane.swift b/Sources/Cra/UI/Settings/TabsPane.swift
index a12d2f2..a16d25b 100644
--- a/Sources/Cra/UI/Settings/TabsPane.swift
+++ b/Sources/Cra/UI/Settings/TabsPane.swift
@@ -24,6 +24,12 @@ struct TabsPane: View {
SettingsCheckbox(title: "Show the space header with only one space", isOn: $store.settings.showSpaceHeaderOnSingleSpace)
Text("Off hides the space’s name and its icon at the bottom of the sidebar while you have one space.")
.font(.system(size: 11)).foregroundStyle(.secondary)
+ // #154: Arc's favorites, one set per profile.
+ SettingsCheckbox(title: "Share Favorites across Spaces with the same profile",
+ isOn: Binding(get: { store.settings.sharedFavorites }, set: { store.setFavoritesShared($0) }))
+ Text("Spaces on one profile show the same Favorites, as in Arc. Turning it on combines their Favorites; turning it off gives each Space its own copy.")
+ .font(.system(size: 11)).foregroundStyle(.secondary)
+ .fixedSize(horizontal: false, vertical: true)
}
// Arc's Links pane: the Little Arc switch and "Choose where links open inside
// Arc." with an "Air Traffic Control…" button.
diff --git a/Sources/Cra/UI/Sidebar/List/SidebarMenus.swift b/Sources/Cra/UI/Sidebar/List/SidebarMenus.swift
index e71eff9..2915bb9 100644
--- a/Sources/Cra/UI/Sidebar/List/SidebarMenus.swift
+++ b/Sources/Cra/UI/Sidebar/List/SidebarMenus.swift
@@ -81,9 +81,8 @@ enum SidebarMenus {
}
menu.addItem(.separator())
let spaces = submenu(menu, "Move to Space")
- let current = store.spaceID(ofItem: id)
for s in store.orderedSpaces {
- add(spaces, "\(s.emoji) \(s.title)", enabled: s.id != current) { store.moveTab(id, toSpace: s.id, window: ui.windowID) }
+ add(spaces, "\(s.emoji) \(s.title)", enabled: !store.isInSpace(id, s.id)) { store.moveTab(id, toSpace: s.id, window: ui.windowID) }
}
folderItems(menu, [id], list: list)
menu.addItem(.separator())
@@ -259,9 +258,9 @@ enum SidebarMenus {
add(menu, "Rename…") { ui.renamingID = id }
menu.addItem(.separator())
let spaces = submenu(menu, "Move to")
- let current = store.spaceID(ofItem: id)
for s in store.orderedSpaces {
- add(spaces, "\(s.emoji) \(s.title)", on: s.id == current) { if s.id != current { store.moveTab(id, toSpace: s.id, window: ui.windowID) } }
+ let current = store.isInSpace(id, s.id)
+ add(spaces, "\(s.emoji) \(s.title)", on: current) { if !current { store.moveTab(id, toSpace: s.id, window: ui.windowID) } }
}
menu.addItem(.separator())
add(menu, "Archive Item") { for c in children { store.archiveTab(c, reason: .manual) } }
diff --git a/Sources/Cra/UI/Sidebar/List/SpaceColumnView.swift b/Sources/Cra/UI/Sidebar/List/SpaceColumnView.swift
index 3480025..faa6c84 100644
--- a/Sources/Cra/UI/Sidebar/List/SpaceColumnView.swift
+++ b/Sources/Cra/UI/Sidebar/List/SpaceColumnView.swift
@@ -14,6 +14,8 @@ final class SpaceColumnView: NSView {
private let favorites: FavoritesGridView
private let header: SpaceHeaderView
private let list: SpaceListView
+ /// How far SpacePagerView holds the favorites left of their place (see holdFavorites).
+ private var favoritesShift: CGFloat = 0
init(spaceID: UUID, store: SidebarStore, ui: SidebarUIState, actions: SidebarActions, favicons: FaviconCache) {
self.spaceID = spaceID
@@ -51,6 +53,20 @@ final class SpaceColumnView: NSView {
place(animated: false)
}
+ /// Arc's favorites sit beside its space pager, not on a page (AX tree, 25 Oct), so a swipe
+ /// between spaces that share them (#154) leaves the tiles still. SpacePagerView shifts each
+ /// of the two pages' copies back by the page's offset and shows the nearer page's one.
+ func holdFavorites(shift: CGFloat, shown: Bool) {
+ let alpha: CGFloat = shown ? 1 : 0
+ guard shift != favoritesShift || favorites.alphaValue != alpha else { return }
+ favoritesShift = shift
+ CATransaction.begin()
+ CATransaction.setDisableActions(true)
+ favorites.setFrameOrigin(NSPoint(x: 8 + shift, y: favorites.frame.minY))
+ favorites.alphaValue = alpha
+ CATransaction.commit()
+ }
+
/// Arc 1.171 (one space, live, 31 Oct) places everything under the favorites from the tiles'
/// bottom, or with no favorites from the URL field's (the column starts 8 pt under it, where
/// the first tile's top goes): the header's hover fill 8–44 pt below, 8 pt in from both
@@ -60,7 +76,7 @@ final class SpaceColumnView: NSView {
let w = bounds.width
let fh = favorites.height(forWidth: w - 16)
let set = { (v: NSView, f: NSRect) in if v.frame != f { animated ? (v.animator().frame = f) : (v.frame = f) } }
- set(favorites, NSRect(x: 8, y: 0, width: w - 16, height: fh))
+ set(favorites, NSRect(x: 8 + favoritesShift, y: 0, width: w - 16, height: fh))
let tiles = favorites.tilesBottom(forWidth: w - 16)
let base = tiles ?? -8
set(header, NSRect(x: 8, y: base + 8, width: w - 16, height: header.isHidden ? 0 : 36))
@@ -1053,14 +1069,15 @@ final class FavoriteTileView: NSView, ArcTooltipTarget, NSDraggingSource {
let id = itemID
if item.isSplit, let m = model {
return SidebarMenus.split(id, panes: m.cells.map { ($0.id, $0.title) }, open: m.selected, store: store, ui: ui, actions: actions) {
- MenuItems.add($0, action: "favoriteTab", title: "Remove from Favorites") { store.removeFromFavorites(id) }
+ MenuItems.add($0, action: "favoriteTab", title: Self.removeTitle(id, store)) { store.removeFromFavorites(id) }
+ Self.moveToProfile($0, id, store)
$0.addItem(.separator())
}
}
let tileColor = item.tab?.tileColor
let m = NSMenu()
m.autoenablesItems = false
- MenuItems.add(m, action: "favoriteTab", title: "Remove from Favorites") { store.removeFromFavorites(id) }
+ MenuItems.add(m, action: "favoriteTab", title: Self.removeTitle(id, store)) { store.removeFromFavorites(id) }
MenuItems.add(m, action: "renameTab", title: "Rename…") { ui.renamingID = id }
if let t = item.tab, t.liveItemURL == nil {
SidebarMenus.pinnedURLItems(m, id, navigatedAway: t.url != t.savedURL, store: store, actions: actions)
@@ -1096,12 +1113,28 @@ final class FavoriteTileView: NSView, ArcTooltipTarget, NSDraggingSource {
guard let grid else { return }
store.setTileColor(tileColor, for: grid.spaceFavoriteIDs())
}
+ Self.moveToProfile(m, id, store)
m.addItem(.separator())
MenuItems.add(m, action: "closeTab", title: "Close") { actions.closeTab(id) }
MenuItems.add(m, "Archive") { store.archiveTab(id, reason: .manual) }
return m
}
+ /// Shared favorites (#154) take Arc's words: Remove Favorite deletes the favorite.
+ private static func removeTitle(_ id: UUID, _ store: SidebarStore) -> String {
+ store.profileList(ofItem: id) == nil ? "Remove from Favorites" : "Remove Favorite"
+ }
+
+ /// Arc 1.171's Move to ▸ Profile ▸ ✓Default / <profile>… on a shared favorite.
+ private static func moveToProfile(_ menu: NSMenu, _ id: UUID, _ store: SidebarStore) {
+ guard let list = store.profileList(ofItem: id) else { return }
+ let profiles = MenuItems.submenu(MenuItems.submenu(menu, "Move to"), "Profile")
+ MenuItems.add(profiles, "Default", on: list.profileID == nil) { store.moveFavorite(id, toProfile: nil) }
+ for p in store.profiles {
+ MenuItems.add(profiles, p.name, on: list.profileID == p.id) { store.moveFavorite(id, toProfile: p.id) }
+ }
+ }
+
private func pickIcon() {
guard let grid, let item = grid.store.item(itemID) else { return }
let panel = NSOpenPanel()
diff --git a/Sources/Cra/UI/Sidebar/List/SpacePagerView.swift b/Sources/Cra/UI/Sidebar/List/SpacePagerView.swift
index 055eb73..5ee31ee 100644
--- a/Sources/Cra/UI/Sidebar/List/SpacePagerView.swift
+++ b/Sources/Cra/UI/Sidebar/List/SpacePagerView.swift
@@ -97,6 +97,25 @@ final class SpacePagerView: NSView {
CATransaction.setDisableActions(true)
strip.setFrameOrigin(NSPoint(x: x, y: 0))
CATransaction.commit()
+ holdSharedFavorites()
+ }
+
+ /// Between two pages that show one favorites list (#154) the tiles stay where they are,
+ /// as Arc's do: each page's copy is held back by the page's offset, the nearer one shown.
+ private func holdSharedFavorites() {
+ guard placedWidth > 0 else { return }
+ let ids = store.pagedSpaces(window: ui.windowID).map(\.id)
+ let shown = -strip.frame.minX / placedWidth
+ let left = Int(shown.rounded(.down))
+ let moving = abs(shown - shown.rounded()) > 0.001
+ func list(_ i: Int) -> UUID? { ids.indices.contains(i) ? store.space(ids[i])?.favoritesContainerID : nil }
+ let shared = moving && list(left) != nil && list(left) == list(left + 1)
+ for (i, id) in ids.enumerated() {
+ guard let column = columns[id] as? SpaceColumnView else { continue }
+ guard shared, i == left || i == left + 1 else { column.holdFavorites(shift: 0, shown: true); continue }
+ let dx = column.frame.minX + strip.frame.minX
+ column.holdFavorites(shift: -dx, shown: i == Int(shown.rounded()))
+ }
}
private func column(for id: UUID) -> NSView {
diff --git a/Tests/StoreTests.swift b/Tests/StoreTests.swift
index f171914..2902a90 100644
--- a/Tests/StoreTests.swift
+++ b/Tests/StoreTests.swift
@@ -33,6 +33,7 @@ enum StoreTests {
folderPeek()
closeSuccessor()
favoritesEmptyState()
+ sharedFavorites()
print("Store: \(checks) checks passed")
}
@@ -438,6 +439,102 @@ enum StoreTests {
"and it stays closed after a relaunch")
}
+ /// Settings ▸ Tabs ▸ Share Favorites (#154): Arc's one favorites list per profile.
+ @MainActor
+ private static func sharedFavorites() {
+ let store = AppComposition(clock: ManualScheduler()).store
+ let home = store.focusedSpaceID
+ // Spaces earlier tests saved would share Default's list too.
+ for s in store.orderedSpaces where s.id != home { store.deleteSpace(s.id) }
+ let work = store.createSpace(title: "Shared Work", emoji: "💼", focus: false).id
+ let client = store.createProfile(name: "Shared Client")
+ let other = store.createSpace(title: "Shared Client", emoji: "🧾", focus: false).id
+ store.setProfile(client.id, forSpace: other)
+ func list(_ sid: UUID) -> UUID { store.space(sid)!.favoritesContainerID }
+ func favorites(_ sid: UUID) -> [UUID] { store.children(of: list(sid)).map(\.id) }
+ func favorite(_ url: String, in sid: UUID) -> UUID {
+ let t = store.createTab(url: url, in: sid, select: false)
+ store.addToFavorites(t.id, in: sid)
+ return t.id
+ }
+ let before = favorites(home)
+ let mail = favorite("https://example.com/shared-mail", in: home)
+ let music = favorite("https://example.com/shared-music", in: work)
+ let mailAgain = favorite("https://example.com/shared-mail", in: work)
+ let jira = favorite("https://example.com/shared-jira", in: other)
+ store.selectTab(mailAgain)
+
+ store.setFavoritesShared(true)
+ expect(list(home) == list(work) && list(other) != list(home), "spaces on one profile show one list, another profile its own")
+ expect(store.profileFavorites.map(\.profileID) == [nil, client.id], "one list per profile")
+ expect(favorites(home) == before + [mail, music] && favorites(other) == [jira],
+ "the spaces' favorites in sidebar order, a page they both had once")
+ expect(store.item(mailAgain) == nil && store.focusedSpaceID == work && store.selectedTabID == mail,
+ "the window that had the dropped copy open shows the kept one, in the space it was in")
+ expect(store.spaceID(ofItem: mail) == work && store.isInSpace(mail, home) && store.isInSpace(mail, work) && !store.isInSpace(mail, other),
+ "a shared favorite is in the window's space, and in every space of its profile")
+ expect(store.integrityProblems().isEmpty, "sharing leaves the sidebar sound")
+
+ let third = store.createSpace(title: "Shared Third", emoji: "3️⃣", focus: false).id
+ expect(list(third) == list(home), "a new space shows its profile's list")
+ store.moveTab(music, toSpace: home)
+ expect(favorites(home) == before + [mail, music], "moving a favorite to a space that shows it changes nothing")
+
+ store.focusSpace(third)
+ store.selectTab(music)
+ store.focusSpace(work)
+ store.selectTab(music)
+ store.archiveTab(music, reason: .manual)
+ expect(store.selectedTabID(in: work) != music && store.selectedTabID(in: third) != music,
+ "closing a shared favorite closes it in every space that had it open")
+
+ let defaults = list(home)
+ store.selectTab(mail)
+ store.setProfile(client.id, forSpace: work)
+ expect(list(work) == list(other) && favorites(work) == [jira] && favorites(home) == before + [mail],
+ "a space changing profile shows its new profile's list and takes nothing along (Arc)")
+ expect(store.selectedTabID(in: work) == mail && store.profileDirectoryName(item: mail) == "Default"
+ && store.profileDirectoryName(item: jira) == client.directoryName && store.integrityProblems().isEmpty,
+ "a favorite it had open stays open in the profile it was opened in (Arc)")
+
+ store.deleteSpace(home)
+ store.setProfile(client.id, forSpace: third)
+ expect(store.item(defaults) != nil && store.children(of: defaults).map(\.id) == before + [mail],
+ "Default's list stays while no space uses Default (Arc)")
+ expect(store.spaceIDs(ofItem: mail).isEmpty && store.spaceID(ofItem: mail) == nil, "no space shows it")
+ expect(!store.profileTabs(window: nil).contains { $0.id == mail }, "and the command bar doesn't offer it")
+ store.setProfile(nil, forSpace: third)
+ expect(list(third) == defaults, "a space back on Default shows that list again")
+
+ store.setFavoritesShared(false)
+ expect(list(work) != list(other) && favorites(work) == [jira] && favorites(other).count == 1 && favorites(other) != [jira]
+ && store.item(favorites(other)[0])?.tab?.savedURL == "https://example.com/shared-jira",
+ "turning it off gives each space its own copy, the first in the sidebar keeping the favorites themselves")
+ expect(favorites(third) == before + [mail] && store.profileFavorites.isEmpty, "every list was shown, so none is left")
+ expect(store.integrityProblems().isEmpty, "unsharing leaves the sidebar sound")
+ store.setFavoritesShared(true)
+ expect(list(work) == list(other) && favorites(work) == [jira], "on again, the copies fold back into one list")
+ store.setProfile(nil, forSpace: other)
+ let unused = store.createProfile(name: "Shared Unused")
+ store.setProfile(unused.id, forSpace: other)
+ store.setProfile(client.id, forSpace: other)
+ let unusedList = store.profileFavorites.first { $0.profileID == unused.id }?.containerID
+ store.deleteProfile(unused.id)
+ expect(unusedList.map { store.item($0) == nil } == true && !store.profileFavorites.contains { $0.profileID == unused.id },
+ "deleting a profile deletes its favorites")
+ let moving = favorite("https://example.com/shared-move", in: work)
+ store.moveFavorite(moving, toProfile: nil)
+ expect(store.profileList(ofItem: moving)?.profileID == nil && !store.isInSpace(moving, work) && store.isInSpace(moving, third),
+ "Move to ▸ Profile puts a favorite on the other profile's list (Arc)")
+ store.removeFromFavorites(moving)
+ expect(store.item(moving) == nil && !store.archive.contains { $0.id == moving }, "Remove Favorite deletes it, unarchived (Arc)")
+ store.setFavoritesShared(false)
+ store.saveAll()
+ let reloaded = AppComposition(clock: ManualScheduler()).store
+ expect(!reloaded.settings.sharedFavorites && reloaded.space(work)!.favoritesContainerID != reloaded.space(other)!.favoritesContainerID
+ && reloaded.integrityProblems().isEmpty, "the lists load as they were saved")
+ }
+
/// Move Tab to Space N (#86) and the command bar's Move Tab to <space>, like Arc's "Move to
/// Today in <space>": the tab goes to the top of the other space's Today, the window follows
/// it there with the tab selected, and the space it left opens another tab.
diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.md
index 06442c2..178ea7a 100644
--- a/docs/arc-reverse-engineering.md
+++ b/docs/arc-reverse-engineering.md
@@ -27,6 +27,8 @@ Legend: [O] observed in shipped artifact or data file, [I] inference, [U] unknow
- itemContainer { containerType: topApps{profile} | spaceItems{spaceID} }
- [O strings only] easel, splitView, arcDocument, tabGroup also exist.
- [O] Favorites = the "topApps" container, one per profile, shared by all spaces (StorableSidebar.topAppsContainerIDs).
+ Cra keeps favorites per space by default; Settings ▸ Tabs ▸ "Share Favorites across Spaces with the same profile"
+ (#154) does it Arc's way (see "Favorites per profile").
- [O] Every space owns one pinned container and one unpinned ("Today") container; ordering = childrenIds; folders nest via parentID.
- [O] A pinned tab keeps savedURL/savedTitle as its home; strings: resetTab, resetCurrentTab, replacePinnedTab,
PinnedTabNavigationProfile, renamePinnedTabsEnabled=1.
@@ -1973,6 +1975,28 @@ GitHub issue #4: opening in window B a tab that window A shows left A with no ta
registrable domain (`SiteKey`). Verified on a test bundle with a CDP click in a favorite: Peek opened, the tab
stayed, promote and ⌘W worked.
+### Favorites per profile (Arc 1.171, 3 Nov 2026, offline Arc, issue #154)
+Offline Arc (fake home with Arc's own second profile "Work" = Profile 1, see "One space") with spaces Personal and
+Side on Default (topApps: Mail, Music, News) and Work on Profile 1 (topApps: Jira). Space switches through
+Spaces ▸ <space> (AX), profile changes through Spaces ▸ Change Profile (the sheet's picker is a SwiftUI menu: one HID
+click, then AX), 120 fps region recordings.
+- [O] AX: `sidebarFavoritesCollectionView` (347×63) is its own list above the 3 × 347 pt pager of space pages.
+- [O live] Personal → Side (same profile): header and list slide, the tiles stay still in every frame. Side → Work
+ (other profile): the tiles slide out with the page and Work's slide in.
+- [O live] The open tab is per space: Mail opened in Personal, Side still showed its own (nothing), Music opened in
+ Side; each space came back to its own.
+- [O live] Change Profile: the space shows the new profile's list, nothing moves. With Personal and Side both on Work,
+ StorableSidebar kept Default's topApps container with all three; Personal back on Default showed them again, Mail
+ still highlighted. A favorite open in the space stays on screen (same page, title) after the change, its tile gone.
+- [O live] A favorite's menu: Copy Link, Share ›, Change Icon…, Rename…, Mute, Edit Pinned Page ›, Open in Split View
+ (Add Split View while open), Duplicate, Move to › Profile › ✓Default / Work, (Close Tab ⌘W while open), Remove
+ Favorite. Remove Favorite deletes it: not in any space's pinned or Today list, not in StorableArchive.
+- Cra (`FavoritesSharing`, `SidebarDocument.profileFavorites`): with the setting on, each profile has a list
+ (container kind `.favorites(spaceID: sharedFavoritesSpaceID)`) that its spaces point at and that outlives them;
+ a favorite loads in its list's profile; turning it on merges the spaces' own favorites into their profile's list
+ (a page twice once), off gives each space its own copy. Tile menu: Remove Favorite, Move to › Profile.
+ SpacePagerView holds the tiles still between two pages that show one list.
+
### Splits in Favorites (Arc 1.171, 31 Oct 2026, Swift metadata + offline Arc)
Request from a Cra user (DM, 31 Oct): "the split tabs being pinned, I also need them pinned at the top".
- [O static] A top-apps item can be a split: `AppTray…ViewState.AppItem { childItems: OrderedDictionary<id,