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.

Arc's GitHub live folder imports as a live folder that refreshes, not a frozen plain folder (#215)

Victor4aa54e6ac5ea
diff --git a/Sources/Cra/Services/Import/Importers.swift b/Sources/Cra/Services/Import/Importers.swift
index 00672c0..a70eee5 100644
--- a/Sources/Cra/Services/Import/Importers.swift
+++ b/Sources/Cra/Services/Import/Importers.swift
@@ -14,6 +14,10 @@ struct ImportedItem {
var createdAt = Date()
/// Cached favicon file in the source browser, if any.
var faviconPath: String?
+ /// A live folder's source and filter (Arc's GitHub live folder, #215): it keeps refreshing.
+ var liveFolder: LiveFolderData?
+ /// The live item a tab in a live folder stands for (Arc: `liveItemID.url`).
+ var liveItemURL: String?
}
struct ImportedSpace {
@@ -115,6 +119,11 @@ private func pairs(_ list: Any?) -> [(String, [String: Any])] {
return out
}
+/// Arc wraps an enum case's value as `{case: {_0: value}}`.
+private func tagged<T>(_ value: Any?, _ key: String) -> T? {
+ ((value as? [String: Any])?[key] as? [String: Any])?["_0"] as? T
+}
+
// MARK: - Arc
enum ArcImporter {
@@ -163,11 +172,12 @@ enum ArcImporter {
if let tab = dataDict["tab"] as? [String: Any] {
guard let u = tab["savedURL"] as? String, !u.isEmpty else { return nil }
return ImportedItem(customTitle: custom, pageTitle: tab["savedTitle"] as? String ?? "", url: u, createdAt: created,
- faviconPath: faviconFile(forItemID: id))
+ faviconPath: faviconFile(forItemID: id), liveItemURL: tagged(tab["liveItemID"], "url"))
}
- if dataDict["list"] != nil {
+ if let list = dataDict["list"] as? [String: Any] {
return ImportedItem(customTitle: custom, pageTitle: custom ?? "Folder", url: nil, isFolder: true,
- children: childIDs.compactMap(convert), createdAt: created)
+ children: childIDs.compactMap(convert), createdAt: created,
+ liveFolder: liveFolder(list["automaticLiveFolderData"]))
}
if dataDict["splitView"] != nil || dataDict["tabGroup"] != nil {
// Flatten split views into their tabs.
@@ -256,6 +266,23 @@ enum ArcImporter {
return plan
}
+ /// Arc's `automaticLiveFolderData` for a GitHub folder: `dataSource {github: {}}`, `filter
+ /// {github: {_0: {attributes, hiddenRepositories [{owner, name}]}}}`, `hiddenItems [{url: {_0}}]`.
+ /// Its `lastFetch` stays behind, so the folder refreshes as soon as Cra runs (#215).
+ static func liveFolder(_ value: Any?) -> LiveFolderData? {
+ guard let data = value as? [String: Any], (data["dataSource"] as? [String: Any])?["github"] != nil else { return nil }
+ var live = LiveFolderData()
+ if let filter: [String: Any] = tagged(data["filter"], "github") {
+ if let bits = filter["attributes"] as? Int { live.filter.attributes = GitHubLiveFilter.Attributes(rawValue: bits).intersection(.all) }
+ live.filter.hiddenRepositories = (filter["hiddenRepositories"] as? [[String: Any]] ?? []).compactMap { r in
+ guard let owner = r["owner"] as? String, let name = r["name"] as? String else { return nil }
+ return "\(owner)/\(name)"
+ }
+ }
+ live.hiddenItems = (data["hiddenItems"] as? [Any] ?? []).compactMap { tagged($0, "url") }
+ return live
+ }
+
/// One Air Traffic Control rule: `sourceComponents[0].componentType.urlMatch` is
/// `{_0: {contains: {}} | {matches: {}}, _1: text}`.
private static func linkRoute(_ rule: [String: Any], spaceTitles: [String: String]) -> ImportedLinkRoute? {
@@ -447,7 +474,9 @@ extension SidebarStore {
func insert(_ items: [ImportedItem], into parent: UUID, skip: Set<String>, pinned: Bool) {
var skip = skip
for it in items {
- if it.isFolder {
+ if let live = it.liveFolder {
+ insertLiveFolder(it, live, into: parent, pinned: pinned)
+ } else if it.isFolder {
let name = it.customTitle ?? it.pageTitle
// Re-importing must not duplicate folders: reuse one with the same name.
let folder: SidebarItem
@@ -466,13 +495,32 @@ extension SidebarStore {
tab.createdAt = it.createdAt
// An open tab was alive in the other browser: auto-archive counts from the import,
// not from when the tab was made (Dia keeps tabs for weeks with auto-clean off).
- if var t = tab.tab { t.timeLastActiveAt = pinned ? it.createdAt : clock.now; tab.data = .tab(t) }
+ if var t = tab.tab {
+ t.timeLastActiveAt = pinned ? it.createdAt : clock.now
+ if self.items[parent]?.isLiveFolder == true { t.liveItemURL = it.liveItemURL }
+ tab.data = .tab(t)
+ }
insertItem(tab, into: parent, at: nil)
result.tabs += 1
}
}
}
+ // A space has one GitHub live folder: importing again fills the one it has.
+ func insertLiveFolder(_ it: ImportedItem, _ live: LiveFolderData, into parent: UUID, pinned: Bool) {
+ guard let sid = self.spaceID(ofItem: parent), !isIncognito(space: sid) else { return }
+ let folder: SidebarItem
+ if let existing = self.liveFolder(live.source, inSpace: sid) {
+ folder = existing
+ } else {
+ folder = createFolder(named: it.customTitle ?? it.pageTitle, in: parent)
+ self.items[folder.id]?.liveFolder = live
+ setExpanded(folder.id, false)
+ result.folders += 1
+ }
+ insert(it.children.filter { $0.liveItemURL != nil }, into: folder.id, skip: existingURLs(under: folder.id), pinned: pinned)
+ }
+
let current = focusedSpace.favoritesContainerID
insert(plan.favorites, into: current, skip: existingURLs(under: current), pinned: true)
diff --git a/Tests/StoreTests.swift b/Tests/StoreTests.swift
index 354f622..27a69aa 100644
--- a/Tests/StoreTests.swift
+++ b/Tests/StoreTests.swift
@@ -40,6 +40,7 @@ enum StoreTests {
themePreview()
try arcSpacesWithoutAThemeShareOneDefault()
try arcItemListedTwice()
+ try arcLiveFolderImportsLive()
littleWindowProfile()
tidyTabs()
pinHook()
@@ -436,6 +437,73 @@ enum StoreTests {
"an item listed twice imports once, as its later entry")
}
+ // promise: #215
+ /// Arc's GitHub live folder (a `list` with `automaticLiveFolderData`, Arc 1.170's shape) imports
+ /// as a Cra live folder with its filter, hidden repositories and closed pull requests, so it
+ /// refreshes and has the live folder's menu. It used to arrive as a plain folder holding the
+ /// pull requests of import day, which never changed again (#215).
+ @MainActor
+ private static func arcLiveFolderImportsLive() throws {
+ let fixture = URL(fileURLWithPath: #filePath).deletingLastPathComponent().appendingPathComponent("Fixtures/Arc/StorableSidebar.json")
+ var root = try JSONSerialization.jsonObject(with: Data(contentsOf: fixture)) as! [String: Any]
+ var sidebar = root["sidebar"] as! [String: Any]
+ var containers = sidebar["containers"] as! [[String: Any]]
+ let main = containers.firstIndex { $0["spaces"] != nil }!
+ var items = containers[main]["items"] as! [Any]
+ func item(_ id: String, parent: String, children: [String] = [], data: [String: Any], title: String? = nil) -> [Any] {
+ [id, ["id": id, "title": title as Any, "parentID": parent, "childrenIds": children, "isUnread": false,
+ "originatingDevice": "FIXTURE", "createdAt": 800000000.0, "data": data] as [String: Any]]
+ }
+ func pr(_ n: Int) -> String { "https://github.com/example/app/pull/\(n)" }
+ let live: [String: Any] = ["list": [
+ "customInfo": ["iconType": ["icon": "github"]],
+ "automaticLiveFolderData": [
+ "dataSource": ["github": [String: Any]()],
+ "filter": ["github": ["_0": ["attributes": 3, "hiddenRepositories": [["owner": "example", "name": "old", "provider": "github"]]]]],
+ "hiddenItems": [["url": ["_0": pr(9)]]],
+ "lastFetch": ["timestamp": 800000000.0, "status": ["success": [String: Any]()]],
+ ] as [String: Any],
+ ]]
+ func prTab(_ n: Int) -> [String: Any] {
+ ["tab": ["savedURL": pr(n), "savedTitle": "Pull \(n)", "liveItemID": ["url": ["_0": pr(n)]]]]
+ }
+ items += item("work-prs", parent: "work-pinned", children: ["work-pr1", "work-pr2"], data: live, title: "Pull Requests")
+ items += item("work-pr1", parent: "work-prs", data: prTab(1))
+ items += item("work-pr2", parent: "work-prs", data: prTab(2))
+ let pinned = items.firstIndex { ($0 as? String) == "work-pinned" }! + 1
+ var container = items[pinned] as! [String: Any]
+ container["childrenIds"] = ["work-prs"]
+ items[pinned] = container
+ containers[main]["items"] = items
+ sidebar["containers"] = containers
+ root["sidebar"] = sidebar
+ let plan = try ArcImporter.plan(sidebar: JSONSerialization.data(withJSONObject: root))
+
+ let folder = plan.spaces[1].pinned.first
+ expect(folder?.liveFolder?.filter == GitHubLiveFilter(attributes: [.authored, .reviewRequests], hiddenRepositories: ["example/old"])
+ && folder?.liveFolder?.hiddenItems == [pr(9)], "Arc's live folder keeps its filter and hidden pull requests")
+ expect(folder?.children.map(\.liveItemURL) == [pr(1), pr(2)], "its tabs keep the pull requests they stand for")
+
+ let clock = ManualScheduler()
+ let store = AppComposition(clock: clock).store
+ let result = store.apply(plan, includeArchive: false, includeSettings: false)
+ guard let work = result.spaceIDs.last, let imported = store.liveFolder(.github, inSpace: work) else {
+ return expect(false, "the Work space has a GitHub live folder after the import")
+ }
+ expect(imported.title == "Pull Requests" && imported.liveFolder?.lastFetch == nil,
+ "it keeps its title and is due for a refresh at once")
+ expect(store.children(of: imported.id).map(\.tab?.liveItemURL) == [pr(1), pr(2)], "its tabs are the folder's live items")
+ store.applyLiveResults([LivePullRequest(owner: "example", repo: "app", number: 2, title: "Pull 2, renamed"),
+ LivePullRequest(owner: "example", repo: "app", number: 3, title: "Pull 3")], to: imported.id, ssoOrganizations: [])
+ let kids = store.children(of: imported.id)
+ expect(kids.count == 3 && kids.filter { $0.tab?.liveItemURL == pr(2) }.count == 1,
+ "the first refresh updates the imported tabs instead of adding them again")
+ expect(kids.first { $0.tab?.liveItemURL == pr(1) }?.tab?.liveGoneAt == clock.now,
+ "an imported pull request that left the results goes like any other")
+ expect(kids.allSatisfy { !$0.isUnread }, "nothing the first refresh brings is marked unread")
+ expect(store.integrityProblems().isEmpty, "the imported live folder keeps the sidebar sound")
+ }
+
// promise: #30
/// Arc spaces without a `windowTheme` (both in the made-up profile) import with one fixed
/// default, not the next preset each, which shifted every later space's colour (#30).
diff --git a/Tests/promises.lock b/Tests/promises.lock
index 6774cea..bcccc3f 100644
--- a/Tests/promises.lock
+++ b/Tests/promises.lock
@@ -328,3 +328,4 @@
#209 Packages/CraCore/Tests/CraCoreTests/BrowserLanguagesTests.swift::readsThePrefAsChromiumListsIt d7fa1a3f36a4
#209 Tests/Scenarios/accept-languages.scenario 6ca3402ebe15
#211 Packages/CraCore/Tests/CraCoreTests/FaviconKeyTests.swift::tabsOnOneHostKeepTheirOwnIcons 21d360f30e94
+#215 Tests/StoreTests.swift::arcLiveFolderImportsLive a5c462b3a9c7
diff --git a/docs/live-folders.md b/docs/live-folders.md
index 0fe4ffd..c891d6b 100644
--- a/docs/live-folders.md
+++ b/docs/live-folders.md
@@ -92,6 +92,10 @@ Legend: [O] observed, [I] inference, [U] unknown.
45 s after a tab goes from a repository's compare page to a pull request (one was just created) or to a
`#pullrequestreview-` anchor (a review was submitted). One GitHub folder per space ("New GitHub Live
Folder" in the sidebar menus and command bar). Not copied: Dia's realtime updates (see below).
+- Import: Arc's live folder (`automaticLiveFolderData` with `dataSource.github`) comes over as a Cra live
+ folder with its `attributes`, `hiddenRepositories` and `hiddenItems`; its tabs keep `liveItemID.url` as
+ `liveItemURL`. Arc's `lastFetch` stays behind, so the first refresh runs at once and marks nothing unread.
+ Before #215 it arrived as a plain folder of import day's pull requests that never refreshed.
## Verified (27 Oct 2026)
- GitHub's answers when signed out: `/pulls` with the JSON headers returns 404 `{"error":"Couldn’t authenticate you"}`;