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.
Settings ▸ Profiles ▸ Rebuild from Arc: spaces an older import left on Default go back on their Arc profiles (#131) (#146)
Victor Kildahla182f5d880f5
diff --git a/Packages/CraCore/Sources/CraCore/ArcProfileRebuild.swift b/Packages/CraCore/Sources/CraCore/ArcProfileRebuild.swiftnew file mode 100644index 0000000..f17420d--- /dev/null+++ b/Packages/CraCore/Sources/CraCore/ArcProfileRebuild.swift@@ -0,0 +1,55 @@+import Foundation++/// Settings ▸ Profiles ▸ Rebuild from Arc (GitHub #131): an import from before Cra kept Arc's+/// profiles left every space on Default. This finds the spaces to move back onto the profile+/// their Arc space is on, matched by name, since ids differ between the browsers.+public enum ArcProfileRebuild {+ public struct CraSpace: Equatable, Sendable {+ public var id: UUID+ public var title: String+ /// On Default and not incognito: the only spaces a rebuild moves. One already on a+ /// profile was put there by hand.+ public var movable: Bool++ public init(id: UUID, title: String, movable: Bool) {+ self.id = id+ self.title = title+ self.movable = movable+ }+ }++ public struct ArcSpace: Equatable, Sendable {+ public var title: String+ /// Arc's profile folder ("Profile 2"); nil for Default.+ public var folder: String?+ /// The profile's name in Arc.+ public var name: String++ public init(title: String, folder: String?, name: String) {+ self.title = title+ self.folder = folder+ self.name = name+ }+ }++ public struct Move: Equatable, Sendable {+ public var spaceID: UUID+ public var spaceTitle: String+ public var folder: String+ public var profileName: String+ }++ /// The Cra spaces to put on an Arc profile: a movable space whose name (any case) is one Arc+ /// space's, when that space is on a profile other than Default. A name Arc uses on more than+ /// one profile, or Cra on more than one space, says nothing about which is which: skipped.+ public static func moves(cra: [CraSpace], arc: [ArcSpace]) -> [Move] {+ let arcByTitle = Dictionary(grouping: arc) { $0.title.lowercased() }+ let craCount = Dictionary(grouping: cra) { $0.title.lowercased() }.mapValues(\.count)+ return cra.compactMap { space in+ let key = space.title.lowercased()+ guard space.movable, craCount[key] == 1, let matches = arcByTitle[key],+ Set(matches.map(\.folder)).count == 1, let match = matches.first, let folder = match.folder else { return nil }+ return Move(spaceID: space.id, spaceTitle: space.title, folder: folder, profileName: match.name)+ }+ }+}diff --git a/Packages/CraCore/Sources/CraCore/ExtensionProfiles.swift b/Packages/CraCore/Sources/CraCore/ExtensionProfiles.swiftindex 2564c60..c498a32 100644--- a/Packages/CraCore/Sources/CraCore/ExtensionProfiles.swift+++ b/Packages/CraCore/Sources/CraCore/ExtensionProfiles.swift@@ -65,10 +65,14 @@ public struct ImportProfileMap: Equatable, Sendable {/// The Cra profiles an extension the source had in `sources` loads in: nil (every profile)/// when the import bound no profiles, or when that is every profile Cra has (`allFolders`).- public func extensionProfiles(sources: Set<String>, allFolders: Set<String>) -> Set<String>? {+ /// `keepUnmapped`: an extension already loading everywhere (a rebuild from Arc) also stays in+ /// the Cra profiles no source profile maps to, made in Cra and unknown to the source.+ public func extensionProfiles(sources: Set<String>, allFolders: Set<String>, keepUnmapped: Bool = false) -> Set<String>? {guard bindsProfiles else { return nil }- let targets = Set(sources.map { craFolder(forSource: $0) })- return targets.isEmpty || allFolders.isSubset(of: targets) ? nil : targets+ var targets = Set(sources.map { craFolder(forSource: $0) })+ if targets.isEmpty { return nil }+ if keepUnmapped { targets.formUnion(allFolders.subtracting(folders.values).subtracting(["Default"])) }+ return allFolders.isSubset(of: targets) ? nil : targets}/// Arc's `profile` of a space: `{"custom": {"_0": {"directoryBasename": "Profile 2", …}}}`, ordiff --git a/Packages/CraCore/Tests/CraCoreTests/ExtensionProfilesTests.swift b/Packages/CraCore/Tests/CraCoreTests/ExtensionProfilesTests.swiftindex 2ffb86b..fa6fd9d 100644--- a/Packages/CraCore/Tests/CraCoreTests/ExtensionProfilesTests.swift+++ b/Packages/CraCore/Tests/CraCoreTests/ExtensionProfilesTests.swift@@ -70,4 +70,36 @@ struct ExtensionProfilesTests {#expect(pins.ids(inProfile: "Profile A") == ["b", "c"])#expect(pins.profiles["Profile B"] == nil, "the same list as everyone's stays shared")}++ /// Rebuild from Arc (#131): spaces an older import left on Default go back to their Arc profiles.+ @Test func rebuildMatchesSpacesByName() {+ let home = UUID(), work = UUID(), client = UUID(), mine = UUID(), twin1 = UUID(), twin2 = UUID(), shared = UUID()+ let cra = [+ ArcProfileRebuild.CraSpace(id: home, title: "Home", movable: true),+ .init(id: work, title: "work", movable: true),+ .init(id: client, title: "Client", movable: false),+ .init(id: mine, title: "Mine", movable: true),+ .init(id: twin1, title: "Twin", movable: true), .init(id: twin2, title: "Twin", movable: true),+ .init(id: shared, title: "Shared", movable: true),+ ]+ let arc = [+ ArcProfileRebuild.ArcSpace(title: "Home", folder: nil, name: "Personal"),+ .init(title: "Work", folder: "Profile 2", name: "Work"),+ .init(title: "Client", folder: "Profile 3", name: "Client"),+ .init(title: "Twin", folder: "Profile 2", name: "Work"),+ .init(title: "Shared", folder: "Profile 2", name: "Work"), .init(title: "Shared", folder: "Profile 3", name: "Client"),+ ]+ let moves = ArcProfileRebuild.moves(cra: cra, arc: arc)+ #expect(moves.map(\.spaceID) == [work], "only a movable space whose name is one Arc space's on a profile")+ #expect(moves.first?.folder == "Profile 2" && moves.first?.profileName == "Work" && moves.first?.spaceTitle == "work")+ }++ @Test func rebuildKeepsExtensionsInProfilesMadeInCra() {+ let map = ImportProfileMap(folders: ["Default": "Default", "Profile 2": "Profile W"])+ let all: Set<String> = ["Default", "Profile W", "Profile Mine"]+ #expect(map.extensionProfiles(sources: ["Profile 2"], allFolders: all, keepUnmapped: true) == ["Profile W", "Profile Mine"])+ #expect(map.extensionProfiles(sources: ["Default"], allFolders: all, keepUnmapped: true) == ["Default", "Profile Mine"])+ #expect(map.extensionProfiles(sources: ["Default", "Profile 2"], allFolders: all, keepUnmapped: true) == nil)+ #expect(map.extensionProfiles(sources: [], allFolders: all, keepUnmapped: true) == nil, "not in Arc: left alone")+ }}diff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swiftindex 93ddd7c..ac8b6df 100644--- a/Sources/Cra/App/AppDelegate.swift+++ b/Sources/Cra/App/AppDelegate.swift@@ -914,6 +914,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {case "previousSplitPane": main.cycleSplitPane(-1)case "settings": showSettingsWindow()case "importData": main.showImport()+ case "rebuildArcProfiles": ArcProfileRebuilder.run(store: store) { [weak self] in self?.relaunch() }case "setDefaultBrowser": Task { await SystemIntegration.shared.makeDefaultBrowser() }default:if id.hasPrefix("item"), let n = Int(id.dropFirst(4)) {@@ -955,6 +956,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {if settingsController == nil {let actions = SettingsActions(importData: { [weak self] in self?.main.showImport() },+ rebuildArcProfiles: { [weak self] in+ guard let self else { return }+ ArcProfileRebuilder.run(store: self.store) { [weak self] in self?.relaunch() }+ },openURL: { [weak self] url inguard let self else { return }self.useNormalWindow()diff --git a/Sources/Cra/App/KeyBindings.swift b/Sources/Cra/App/KeyBindings.swiftindex f07a8bb..26ad3d6 100644--- a/Sources/Cra/App/KeyBindings.swift+++ b/Sources/Cra/App/KeyBindings.swift@@ -215,6 +215,7 @@ final class KeyBindingRegistry {// Arc's app menu shows ⌘♡ beside it, a glyph no key types (see buildMenus).KeyAction(id: "setDefaultBrowser", name: "Set as Default Browser", section: .app, shortcuts: [], triggers: ["default browser"]),KeyAction(id: "importData", name: "Import from Arc or Dia…", section: .app, shortcuts: [], triggers: ["import", "arc", "dia"]),+ KeyAction(id: "rebuildArcProfiles", name: "Rebuild Profiles from Arc…", section: .app, shortcuts: [], triggers: ["profiles", "arc profiles"]),]for n in 1...9 {list.append(KeyAction(id: "item\(n)", name: "Go to Tab \(n)", section: .tabs,diff --git a/Sources/Cra/Services/ArcProfileRebuilder.swift b/Sources/Cra/Services/ArcProfileRebuilder.swiftnew file mode 100644index 0000000..01bb1c3--- /dev/null+++ b/Sources/Cra/Services/ArcProfileRebuilder.swift@@ -0,0 +1,90 @@+import AppKit++/// Settings ▸ Profiles ▸ Rebuild from Arc (GitHub #131). An Arc import from before 0.1.28 left+/// every space on Default. This puts the spaces back on the profiles their Arc spaces are on and+/// brings what those Arc profiles held: sign-ins and passwords, the extensions they had (an+/// imported extension then loads only there) and their pinned extensions. Cra restarts to load+/// them, as after an import.+@MainActor+enum ArcProfileRebuilder {+ /// Shown in Settings only while Arc's sidebar is on this Mac.+ static var isAvailable: Bool { ArcImporter.isAvailable }++ /// Asks, moves the spaces and restarts; says so when there is nothing to do or Arc can't be read.+ static func run(store: SidebarStore, relaunch: @escaping () -> Void) {+ guard let plan = try? ArcImporter.plan() else {+ alert("Cra couldn't read Arc's spaces.", "Arc's sidebar file is missing or in a format this version doesn't know.")+ return+ }+ let moves = store.arcProfileMoves(plan)+ guard !moves.isEmpty else {+ alert("No spaces to move", "Every space named like one of your Arc spaces is already on the right profile, or Arc has it on its Default profile.")+ return+ }+ let a = NSAlert()+ a.messageText = "Move \(moves.count == 1 ? "this space" : "these spaces") to \(moves.count == 1 ? "its" : "their") Arc profile\(moves.count == 1 ? "" : "s")?"+ a.informativeText = moves.map { "\($0.spaceTitle) → \($0.profileName)" }.joined(separator: "\n") + "\n\n"+ + "Cra brings over the sign-ins, passwords and extensions these Arc profiles have, so the spaces work as they did in Arc. "+ + "Sign-ins and passwords you added in Cra since the import stay with Default. macOS asks for your password to unlock Arc's data, then Cra restarts."+ a.addButton(withTitle: "Move and Restart")+ a.addButton(withTitle: "Cancel")+ guard a.runModal() == .alertFirstButtonReturn else { return }++ let folders = Set(moves.map(\.folder))+ let profiles = ChromiumImporter.profiles(userData: ArcImporter.userData).filter { folders.contains($0.id) }+ Task { @MainActor in+ var credentials = ImportedCredentials()+ if !profiles.isEmpty {+ let result = await Task.detached(priority: .userInitiated) {+ Result { try ChromiumImporter.credentials(browser: "Arc", profiles: profiles, keychainService: "Arc Safe Storage",+ keychainAccount: "Arc", cookies: true, passwords: true) }+ }.value+ switch result {+ case .success(let c): credentials = c+ case .failure(let error):+ CraLog.note("rebuild from Arc: sign-ins not read: \(error.localizedDescription)")+ let b = NSAlert()+ b.messageText = "Move the spaces without their sign-ins?"+ b.informativeText = "\(error.localizedDescription) The spaces would start signed out of every site. Cancel changes nothing."+ b.addButton(withTitle: "Move Without Sign-ins")+ b.addButton(withTitle: "Cancel")+ guard b.runModal() == .alertFirstButtonReturn else { return }+ }+ }+ let map = store.applyArcProfileMoves(moves)+ CraLog.note("rebuild from Arc: moved \(moves.count) space(s), \(credentials.cookies.count) cookies, \(credentials.logins.count) passwords")+ if !credentials.isEmpty, !(await Task.detached(priority: .userInitiated) { CredentialImport.stage(credentials, profiles: map) }.value) {+ alert("Cra couldn't save Arc's sign-ins.", "The spaces moved, but they start signed out.")+ }+ scopeExtensions(map, store: store)+ seedPins(map)+ relaunch()+ }+ }++ /// Extensions an older import copied in, loading everywhere: from now on only in the profiles+ /// that had them in Arc, and in profiles made in Cra, which keep what they had.+ private static func scopeExtensions(_ map: ImportProfileMap, store: SidebarStore) {+ let all = Set(["Default"] + store.profiles.map(\.directoryName))+ for ext in ExtensionImporter.extensions(inUserData: ArcImporter.userData) where ExtensionStore.isInstalled(id: ext.id) {+ let profiles = map.extensionProfiles(sources: ext.sourceProfiles, allFolders: all, keepUnmapped: true)+ if let profiles { CraLog.note("rebuild from Arc: extension \(ext.id) for \(profiles.sorted().joined(separator: ", "))") }+ ExtensionStore.scopeImported(folder: ext.id, profiles: profiles)+ }+ }++ /// Each moved profile starts with the toolbar pins it has in Arc.+ private static func seedPins(_ map: ImportProfileMap) {+ for (folder, target) in map.folders where target != "Default" {+ guard let ids = ExtensionImporter.pinnedIDs(inProfile: ArcImporter.userData.appendingPathComponent(folder, isDirectory: true)) else { continue }+ ExtensionStore.shared.seedPinned(ids, inProfile: target)+ }+ }++ private static func alert(_ title: String, _ text: String) {+ let a = NSAlert()+ a.messageText = title+ a.informativeText = text+ a.runModal()+ }+}diff --git a/Sources/Cra/Services/ExtensionStore.swift b/Sources/Cra/Services/ExtensionStore.swiftindex 02a3c2d..ef0ba36 100644--- a/Sources/Cra/Services/ExtensionStore.swift+++ b/Sources/Cra/Services/ExtensionStore.swift@@ -75,6 +75,15 @@ final class ExtensionStore {try saveProfiles(scopes)}+ /// Rebuild from Arc (#131): an extension an older import left loading everywhere gets the+ /// profiles that had it. One that already has its own list keeps it.+ nonisolated static func scopeImported(folder: String, profiles: Set<String>?) {+ var scopes = loadProfiles()+ guard scopes.profiles(ofFolder: folder) == nil, let profiles else { return }+ scopes.add(folder: folder, profiles: profiles, folderExisted: false)+ try? saveProfiles(scopes)+ }+private nonisolated static func importExtension(_ ext: ImportableExtension) throws {let fm = FileManager.defaulttry fm.createDirectory(at: directory, withIntermediateDirectories: true)diff --git a/Sources/Cra/Services/Import/Importers.swift b/Sources/Cra/Services/Import/Importers.swiftindex 2136f30..5a7d63d 100644--- a/Sources/Cra/Services/Import/Importers.swift+++ b/Sources/Cra/Services/Import/Importers.swift@@ -482,16 +482,11 @@ extension SidebarStore {return "\(title) \(n)"}- // A source profile becomes a Cra profile of the same name (one already there is reused, so- // importing again doesn't add "Work" twice); its spaces go on it, the rest stay on Default.- func craProfile(for source: ImportedProfile) -> BrowserProfile {- profiles.first { $0.name == source.name } ?? createProfile(name: source.name)- }-+ // A source profile's spaces go on the Cra profile of its name; the rest stay on Default.for sp in plan.spaces {let space = createSpace(title: freeTitle(sp.title), emoji: sp.emoji, theme: sp.theme, focus: false)if let source = sp.profile {- let folder = result.profiles.folders[source.folder] ?? craProfile(for: source).directoryName+ let folder = result.profiles.folders[source.folder] ?? importedProfile(named: source.name).directoryNameresult.profiles.folders[source.folder] = folderif let p = profiles.first(where: { $0.directoryName == folder }) { setProfile(p.id, forSpace: space.id) }} else {@@ -539,4 +534,32 @@ extension SidebarStore {touchAfterImport()return result}++ /// The Cra profile a source profile becomes: one already there of the same name is reused, so+ /// importing again (or rebuilding from Arc) doesn't add "Work" twice.+ private func importedProfile(named name: String) -> BrowserProfile {+ profiles.first { $0.name == name } ?? createProfile(name: name)+ }++ // MARK: Rebuild from Arc (GitHub #131)++ /// Spaces an import from before Cra kept Arc's profiles left on Default, that Arc has on a+ /// profile of their own (matched by name).+ func arcProfileMoves(_ plan: ImportPlan) -> [ArcProfileRebuild.Move] {+ let cra = orderedSpaces.map { ArcProfileRebuild.CraSpace(id: $0.id, title: $0.title, movable: $0.profileID == nil && !isIncognito(space: $0.id)) }+ let arc = plan.spaces.map { ArcProfileRebuild.ArcSpace(title: $0.title, folder: $0.profile?.folder, name: $0.profile?.name ?? "Default") }+ return ArcProfileRebuild.moves(cra: cra, arc: arc)+ }++ /// Puts each space on the Cra profile its Arc profile becomes; what Arc's profiles map to.+ @discardableResult+ func applyArcProfileMoves(_ moves: [ArcProfileRebuild.Move]) -> ImportProfileMap {+ var map = ImportProfileMap(folders: ["Default": "Default"])+ for m in moves where spaces[m.spaceID] != nil {+ let profile = map.folders[m.folder].flatMap { f in profiles.first { $0.directoryName == f } } ?? importedProfile(named: m.profileName)+ map.folders[m.folder] = profile.directoryName+ setProfile(profile.id, forSpace: m.spaceID)+ }+ return map+ }}diff --git a/Sources/Cra/UI/Settings/ProfilesPane.swift b/Sources/Cra/UI/Settings/ProfilesPane.swiftindex 681853e..b6f9534 100644--- a/Sources/Cra/UI/Settings/ProfilesPane.swift+++ b/Sources/Cra/UI/Settings/ProfilesPane.swift@@ -4,6 +4,7 @@ import SwiftUI/// use each, "Create Profile…" under the card. A space picks its profile in Edit Space./// Arc only deletes profiles no space uses, and never Default.struct ProfilesPane: View {+ let actions: SettingsActions@Environment(SidebarStore.self) private var store@State private var naming: BrowserProfile?@State private var creating = false@@ -27,6 +28,11 @@ struct ProfilesPane: View {HStack {Button("Create Profile…") { name = ""; creating = true }Spacer()+ // Spaces an Arc import left on Default, back on their Arc profiles (#131).+ if ArcProfileRebuilder.isAvailable {+ Button("Rebuild from Arc…") { actions.rebuildArcProfiles() }+ .help("Put spaces imported from Arc back on the profiles they use in Arc, with their sign-ins and extensions.")+ }}.padding(.top, 7.5)SettingsFootnote("Profiles help keep your data separate across Spaces, like logins, cookies and site data. You can use any Profile across one or more Spaces: right-click a Space and choose Edit Space to pick one. Only Profiles not assigned to any Spaces can be deleted.")diff --git a/Sources/Cra/UI/Settings/SettingsWindowController.swift b/Sources/Cra/UI/Settings/SettingsWindowController.swiftindex 8dd0160..33e17ac 100644--- a/Sources/Cra/UI/Settings/SettingsWindowController.swift+++ b/Sources/Cra/UI/Settings/SettingsWindowController.swift@@ -4,6 +4,7 @@ import SwiftUI/// Callbacks the panes hand back to the app.struct SettingsActions {var importData: () -> Void = {}+ var rebuildArcProfiles: () -> Void = {}var openURL: (String) -> Void = { _ in }var exportDiagnostics: () -> Void = {}}@@ -237,7 +238,7 @@ struct SettingsContent: View {case .general: GeneralPane()case .tabs: TabsPane()case .privacy: PrivacyPane(actions: actions)- case .profiles: ProfilesPane()+ case .profiles: ProfilesPane(actions: actions)case .extensions: ExtensionsPane(actions: actions)case .shortcuts: ShortcutsPane()case .performance: PerformancePane(nav: nav, actions: actions)diff --git a/Sources/Cra/UI/Settings/ShortcutsPane.swift b/Sources/Cra/UI/Settings/ShortcutsPane.swiftindex 682d1a7..80bc39a 100644--- a/Sources/Cra/UI/Settings/ShortcutsPane.swift+++ b/Sources/Cra/UI/Settings/ShortcutsPane.swift@@ -311,5 +311,6 @@ enum ShortcutDescriptions {"settings": "Open Settings.","setDefaultBrowser": "Make Cra the default browser.","importData": "Bring tabs, spaces and extensions over from Arc or Dia.",+ "rebuildArcProfiles": "Put spaces imported from Arc back on their Arc profiles, with their sign-ins and extensions.",]}diff --git a/Tests/StoreTests.swift b/Tests/StoreTests.swiftindex 1b0c57d..08198f3 100644--- a/Tests/StoreTests.swift+++ b/Tests/StoreTests.swift@@ -94,6 +94,25 @@ enum StoreTests {expect(ExtensionImporter.pinnedIDs(inProfile: ArcImporter.userData.appendingPathComponent("Profile 2")) == [String(repeating: "c", count: 32), String(repeating: "a", count: 32)],"Arc's pins of a profile come from its Preferences")newProfileDatabases()+ rebuildFromArc(plan: plan)+ }++ /// Rebuild from Arc (#131): a sidebar imported before profiles came over gets them afterwards.+ @MainActor+ private static func rebuildFromArc(plan: ImportPlan) {+ let store = AppComposition(clock: ManualScheduler()).store+ var flat = plan+ for i in flat.spaces.indices { flat.spaces[i].profile = nil }+ store.apply(flat, includeArchive: false, includeSettings: false)+ expect(store.profiles.isEmpty, "an import that drops the profiles, as before #131")+ let moves = store.arcProfileMoves(plan)+ expect(moves.map(\.spaceTitle) == ["Work"] && moves.first?.folder == "Profile 2", "only Work is on an Arc profile")+ let map = store.applyArcProfileMoves(moves)+ let work = store.orderedSpaces.first { $0.title == "Work" }!+ let client = store.profiles.first { $0.name == "Client" }+ expect(store.profiles.count == 1 && work.profileID == client?.id && map.folders == ["Default": "Default", "Profile 2": client!.directoryName],+ "Work goes on a Client profile, Home stays on Default")+ expect(store.arcProfileMoves(plan).isEmpty, "a second rebuild finds nothing to move")}/// A profile Chromium hasn't opened gets its sign-in databases with Default's schema (#131).diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.mdindex d94046b..ed39411 100644--- a/docs/arc-reverse-engineering.md+++ b/docs/arc-reverse-engineering.md@@ -2405,6 +2405,11 @@ tap with a real Shift key held around them; the space read from each window's `s- Checked on a test copy with a three-profile fake Arc: each space's page read its own profile's cookie, Chromium'sper-profile prefs held exactly the probes that profile was given, and the toolbar and Extensions menu differed perspace as in Arc.+- Installs imported before this: Settings ▸ Profiles ▸ Rebuild from Arc… (also the command bar's "Rebuild Profiles+ from Arc…"). It moves spaces still on Default onto their Arc space's profile, matched by name (a name Arc or Cra+ uses twice is skipped), stages those Arc profiles' sign-ins (or, if the Keychain refuses, moves them signed out+ after asking), scopes the extensions the old import left loading everywhere (profiles made in Cra keep them),+ seeds the pins and restarts. Sign-ins made in Cra since the import stay with Default.## The tab shown after ⌘W (Arc 1.171, 2 Nov 2026, issue #105, offline Arc driven through its menus)Offline Arc as in "One space": one space with pinned S and P2 and Today C, B, A, D (A, B, C saved with