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.

Edit Space… keeps a space's icon: symbols round-trip, the sheet opens Arc's icon picker (#205)

Victor8f511ac14ddc
diff --git a/Packages/CraCore/Sources/CraCore/SidebarModel.swift b/Packages/CraCore/Sources/CraCore/SidebarModel.swift
index 4188e54..a4536c6 100644
--- a/Packages/CraCore/Sources/CraCore/SidebarModel.swift
+++ b/Packages/CraCore/Sources/CraCore/SidebarModel.swift
@@ -770,6 +770,9 @@ extension Space {
createdAt = try c.decode(Date.self, forKey: .createdAt)
profileID = try c.decodeIfPresent(UUID.self, forKey: .profileID)
symbol = try c.decodeIfPresent(String.self, forKey: .symbol)
+ // Edit Space… → Save in 0.1.31 and older wrote 🌱 beside a space's symbol, and the sidebar
+ // drew both stacked (#205). The symbol was the space's icon, so the emoji beside it goes.
+ if symbol?.isEmpty == false { emoji = "" }
}
}
diff --git a/Packages/CraCore/Sources/CraCore/SpaceIcon.swift b/Packages/CraCore/Sources/CraCore/SpaceIcon.swift
new file mode 100644
index 0000000..3451876
--- /dev/null
+++ b/Packages/CraCore/Sources/CraCore/SpaceIcon.swift
@@ -0,0 +1,40 @@
+import Foundation
+
+/// A space's icon: an emoji, an SF Symbol from the Icon tab of Arc's picker, or none (Remove
+/// Icon). sidebar.json keeps it as `emoji` and `symbol`, never both: a symbol leaves `emoji` empty.
+public enum SpaceIcon: Hashable, Sendable {
+ case emoji(String)
+ case symbol(String)
+ case none
+
+ /// What New Space starts with.
+ public static let newSpace = SpaceIcon.emoji("🌱")
+
+ /// The stored pair: a symbol wins over an emoji beside it.
+ public init(emoji: String, symbol: String?) {
+ if let symbol, !symbol.isEmpty { self = .symbol(symbol) } else if emoji.isEmpty { self = .none } else { self = .emoji(emoji) }
+ }
+
+ /// `Space.emoji`: empty for a symbol or no icon.
+ public var emoji: String {
+ if case .emoji(let e) = self { return e }
+ return ""
+ }
+
+ /// `Space.symbol`.
+ public var symbol: String? {
+ if case .symbol(let s) = self { return s }
+ return nil
+ }
+}
+
+extension Space {
+ /// Reading and writing both fields at once, so an emoji and a symbol never stack (#205).
+ public var icon: SpaceIcon {
+ get { SpaceIcon(emoji: emoji, symbol: symbol) }
+ set {
+ emoji = newValue.emoji
+ symbol = newValue.symbol
+ }
+ }
+}
diff --git a/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/input/sidebar-stacked-icon.json b/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/input/sidebar-stacked-icon.json
new file mode 100644
index 0000000..c3afb6e
--- /dev/null
+++ b/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/input/sidebar-stacked-icon.json
@@ -0,0 +1,22 @@
+{
+ "version": 1,
+ "spaceOrder": ["A0000000-0000-0000-0000-000000000001"],
+ "spaces": [
+ {
+ "id": "A0000000-0000-0000-0000-000000000001", "title": "Imported", "emoji": "🌱", "symbol": "square.on.square.fill",
+ "theme": {"colors": ["#2861B3", "#2861B3"], "intensity": 1, "noise": 0, "appearance": "dark", "vibrant": true, "accent": "#2861B3", "solid": true},
+ "favoritesContainerID": "C0000000-0000-0000-0000-000000000001",
+ "pinnedContainerID": "C0000000-0000-0000-0000-000000000002",
+ "todayContainerID": "C0000000-0000-0000-0000-000000000003",
+ "createdAt": "2026-11-05T08:00:00Z"
+ }
+ ],
+ "items": [
+ {"id": "C0000000-0000-0000-0000-000000000001", "children": [], "isUnread": false, "createdAt": "2026-11-05T08:00:00Z",
+ "data": {"container": {"_0": {"favorites": {"spaceID": "A0000000-0000-0000-0000-000000000001"}}}}},
+ {"id": "C0000000-0000-0000-0000-000000000002", "children": [], "isUnread": false, "createdAt": "2026-11-05T08:00:00Z",
+ "data": {"container": {"_0": {"pinned": {"spaceID": "A0000000-0000-0000-0000-000000000001"}}}}},
+ {"id": "C0000000-0000-0000-0000-000000000003", "children": [], "isUnread": false, "createdAt": "2026-11-05T08:00:00Z",
+ "data": {"container": {"_0": {"today": {"spaceID": "A0000000-0000-0000-0000-000000000001"}}}}}
+ ]
+}
diff --git a/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/sidebar-stacked-icon.json b/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/sidebar-stacked-icon.json
new file mode 100644
index 0000000..67dff9c
--- /dev/null
+++ b/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/sidebar-stacked-icon.json
@@ -0,0 +1,83 @@
+{
+ "items" : [
+ {
+ "children" : [
+
+ ],
+ "createdAt" : "2026-11-05T08:00:00Z",
+ "data" : {
+ "container" : {
+ "_0" : {
+ "favorites" : {
+ "spaceID" : "A0000000-0000-0000-0000-000000000001"
+ }
+ }
+ }
+ },
+ "id" : "C0000000-0000-0000-0000-000000000001",
+ "isUnread" : false
+ },
+ {
+ "children" : [
+
+ ],
+ "createdAt" : "2026-11-05T08:00:00Z",
+ "data" : {
+ "container" : {
+ "_0" : {
+ "pinned" : {
+ "spaceID" : "A0000000-0000-0000-0000-000000000001"
+ }
+ }
+ }
+ },
+ "id" : "C0000000-0000-0000-0000-000000000002",
+ "isUnread" : false
+ },
+ {
+ "children" : [
+
+ ],
+ "createdAt" : "2026-11-05T08:00:00Z",
+ "data" : {
+ "container" : {
+ "_0" : {
+ "today" : {
+ "spaceID" : "A0000000-0000-0000-0000-000000000001"
+ }
+ }
+ }
+ },
+ "id" : "C0000000-0000-0000-0000-000000000003",
+ "isUnread" : false
+ }
+ ],
+ "spaceOrder" : [
+ "A0000000-0000-0000-0000-000000000001"
+ ],
+ "spaces" : [
+ {
+ "createdAt" : "2026-11-05T08:00:00Z",
+ "emoji" : "",
+ "favoritesContainerID" : "C0000000-0000-0000-0000-000000000001",
+ "id" : "A0000000-0000-0000-0000-000000000001",
+ "pinnedContainerID" : "C0000000-0000-0000-0000-000000000002",
+ "symbol" : "square.on.square.fill",
+ "theme" : {
+ "accent" : "#2861B3",
+ "appearance" : "dark",
+ "colors" : [
+ "#2861B3",
+ "#2861B3"
+ ],
+ "intensity" : 1,
+ "noise" : 0,
+ "solid" : true,
+ "vibrant" : true
+ },
+ "title" : "Imported",
+ "todayContainerID" : "C0000000-0000-0000-0000-000000000003"
+ }
+ ],
+ "version" : 1
+}
\ No newline at end of file
diff --git a/Packages/CraCore/Tests/CraCoreTests/ModelFixtureTests.swift b/Packages/CraCore/Tests/CraCoreTests/ModelFixtureTests.swift
index eb1e71e..0294c46 100644
--- a/Packages/CraCore/Tests/CraCoreTests/ModelFixtureTests.swift
+++ b/Packages/CraCore/Tests/CraCoreTests/ModelFixtureTests.swift
@@ -48,13 +48,21 @@ struct ModelFixtureTests {
try decoder.decode(T.self, from: encoder.encode(value)) == value
}
- @Test(arguments: ["sidebar.json", "sidebar-legacy.json"])
+ @Test(arguments: ["sidebar.json", "sidebar-legacy.json", "sidebar-stacked-icon.json"])
func sidebarLoadsAsRecorded(name: String) throws {
let (loaded, recorded) = try Self.load(name, as: SidebarDocument.self)
#expect(loaded == recorded)
#expect(try Self.roundTrips(loaded))
}
+ /// 0.1.31's Edit Space… → Save wrote 🌱 beside an imported space's symbol (#205): the symbol
+ /// stays and the emoji goes, so the sidebar draws one icon again.
+ @Test func stackedSpaceIconLoadsAsItsSymbol() throws {
+ let (loaded, _) = try Self.load("sidebar-stacked-icon.json", as: SidebarDocument.self)
+ #expect(loaded.spaces.map(\.emoji) == [""])
+ #expect(loaded.spaces.map(\.icon) == [.symbol("square.on.square.fill")])
+ }
+
@Test(arguments: ["settings.json", "settings-legacy.json", "settings-empty.json", "settings-bad-routes.json"])
func settingsLoadAsRecorded(name: String) throws {
let (loaded, recorded) = try Self.loadSettings(name)
diff --git a/Packages/CraCore/Tests/CraCoreTests/SpaceIconTests.swift b/Packages/CraCore/Tests/CraCoreTests/SpaceIconTests.swift
new file mode 100644
index 0000000..81d8f76
--- /dev/null
+++ b/Packages/CraCore/Tests/CraCoreTests/SpaceIconTests.swift
@@ -0,0 +1,38 @@
+import CraCore
+import Foundation
+import Testing
+
+/// Edit Space… → Save turned an imported space's symbol into 🌱 stacked on the symbol (#205).
+struct SpaceIconTests {
+ static func space(emoji: String, symbol: String?) -> Space {
+ Space(id: UUID(), title: "S", emoji: emoji, theme: SpaceColorPresets.newSpaceTheme(), favoritesContainerID: UUID(),
+ pinnedContainerID: UUID(), todayContainerID: UUID(), createdAt: Date(timeIntervalSince1970: 0), symbol: symbol)
+ }
+
+ @Test(arguments: [("", "square.on.square.fill"), ("🏠", nil), ("", nil)] as [(String, String?)])
+ func savingTheIconItReadsChangesNothing(emoji: String, symbol: String?) {
+ let space = Self.space(emoji: emoji, symbol: symbol)
+ var saved = space
+ saved.icon = space.icon
+ #expect(saved == space)
+ }
+
+ @Test func iconsNeverStack() {
+ var s = Self.space(emoji: "", symbol: "star.fill")
+ #expect(s.icon == .symbol("star.fill"))
+ s.icon = .emoji("🌱")
+ #expect(s.emoji == "🌱" && s.symbol == nil)
+ s.icon = .symbol("leaf.fill")
+ #expect(s.emoji == "" && s.symbol == "leaf.fill")
+ s.icon = .none
+ #expect(s.emoji == "" && s.symbol == nil)
+ }
+
+ /// A symbol wins over an emoji stored beside it; an empty symbol counts as none.
+ @Test func readingTheStoredPair() {
+ #expect(SpaceIcon(emoji: "🌱", symbol: "square.on.square.fill") == .symbol("square.on.square.fill"))
+ #expect(SpaceIcon(emoji: "🌱", symbol: "") == .emoji("🌱"))
+ #expect(SpaceIcon(emoji: "", symbol: nil) == .none)
+ #expect(SpaceIcon.newSpace.emoji == "🌱" && SpaceIcon.newSpace.symbol == nil)
+ }
+}
diff --git a/Sources/Cra/Services/SidebarStore.swift b/Sources/Cra/Services/SidebarStore.swift
index bcf379d..94b15f6 100644
--- a/Sources/Cra/Services/SidebarStore.swift
+++ b/Sources/Cra/Services/SidebarStore.swift
@@ -1785,7 +1785,7 @@ final class SidebarStore {
// MARK: Spaces
@discardableResult
- func createSpace(title: String, emoji: String, theme: SpaceTheme? = nil, focus: Bool = true) -> Space {
+ func createSpace(title: String, emoji: String, symbol: String? = nil, theme: SpaceTheme? = nil, focus: Bool = true) -> Space {
let id = UUID()
let favorites = SidebarItem.container(.favorites(spaceID: id))
let pinned = SidebarItem.container(.pinned(spaceID: id))
@@ -1795,7 +1795,7 @@ final class SidebarStore {
items[today.id] = today
let t = theme ?? SpaceTheme.presets[spaceOrder.count % SpaceTheme.presets.count]
let space = Space(id: id, title: title, emoji: emoji, theme: t, favoritesContainerID: favorites.id,
- pinnedContainerID: pinned.id, todayContainerID: today.id, createdAt: clock.now)
+ pinnedContainerID: pinned.id, todayContainerID: today.id, createdAt: clock.now, symbol: symbol)
spaces[id] = space
spaceOrder.append(id)
if settings.sharedFavorites { shareFavorites() }
diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swift
index f45ab42..0ec6688 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -2893,14 +2893,14 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
// Arc's New Space starts on the profile of the space it was opened from.
let initialProfile = space == nil && !isIncognito ? SpaceProfiles.forNewSpace(from: store.focusedSpace, profiles: store.profiles) : nil
let store = self.store
- let view = SpaceEditorView(existing: space, profiles: store.profiles, initialProfile: initialProfile, onSave: { [weak panel] title, emoji, theme, profile, newName in
+ let view = SpaceEditorView(existing: space, profiles: store.profiles, initialProfile: initialProfile, onSave: { [weak panel] title, icon, theme, profile, newName in
let id: UUID
if let sid = space?.id, var s = store.space(sid) {
- s.title = title; s.emoji = emoji; s.theme = theme
+ s.title = title; s.icon = icon; s.theme = theme
store.updateSpace(s)
id = s.id
} else {
- id = store.createSpace(title: title, emoji: emoji, theme: theme).id
+ id = store.createSpace(title: title, emoji: icon.emoji, symbol: icon.symbol, theme: theme).id
}
switch profile {
case .existing(let p): store.setProfile(p, forSpace: id)
diff --git a/Sources/Cra/UI/Windows/SpaceEditorView.swift b/Sources/Cra/UI/Windows/SpaceEditorView.swift
index 136b602..047dd99 100644
--- a/Sources/Cra/UI/Windows/SpaceEditorView.swift
+++ b/Sources/Cra/UI/Windows/SpaceEditorView.swift
@@ -6,19 +6,21 @@ enum SpaceProfileChoice: Hashable {
case new
}
-/// Create or edit a space: name, emoji, profile and, beside them, Arc's theme editor (the same
+/// Create or edit a space: name, icon, profile and, beside them, Arc's theme editor (the same
/// card Edit Theme Color… opens: pad, presets, intensity, grain, Auto / Light / Dark). An existing
/// space shows each change at once (`onPreview`); Cancel puts its theme back, Save writes it.
struct SpaceEditorView: View {
let existing: Space?
let profiles: [BrowserProfile]
- /// Title, emoji, theme, profile; a new profile comes with its name.
- let onSave: (String, String, SpaceTheme, SpaceProfileChoice, String) -> Void
+ /// Title, icon, theme, profile; a new profile comes with its name.
+ let onSave: (String, SpaceIcon, SpaceTheme, SpaceProfileChoice, String) -> Void
let onCancel: () -> Void
let onPreview: (SpaceTheme) -> Void
@State private var title: String
- @State private var emoji: String
+ /// Saved as it is: an untouched symbol or empty icon stays what it was (#205).
+ @State private var icon: SpaceIcon
+ @State private var pickingIcon = false
@State private var theme: SpaceTheme
@State private var profile: SpaceProfileChoice
@State private var newProfileName = ""
@@ -28,7 +30,7 @@ struct SpaceEditorView: View {
/// `initialProfile` is a new space's starting profile (Arc: the focused space's).
init(existing: Space?, profiles: [BrowserProfile], initialProfile: UUID? = nil,
- onSave: @escaping (String, String, SpaceTheme, SpaceProfileChoice, String) -> Void, onCancel: @escaping () -> Void,
+ onSave: @escaping (String, SpaceIcon, SpaceTheme, SpaceProfileChoice, String) -> Void, onCancel: @escaping () -> Void,
onPreview: @escaping (SpaceTheme) -> Void = { _ in }) {
self.existing = existing
self.profiles = profiles
@@ -37,7 +39,7 @@ struct SpaceEditorView: View {
self.onCancel = onCancel
self.onPreview = onPreview
_title = State(initialValue: existing?.title ?? "")
- _emoji = State(initialValue: existing?.emoji ?? "🌱")
+ _icon = State(initialValue: existing?.icon ?? .newSpace)
_theme = State(initialValue: existing?.theme ?? SpaceColorPresets.newSpaceTheme())
}
@@ -47,19 +49,17 @@ struct SpaceEditorView: View {
HStack(alignment: .top, spacing: 16) {
VStack(alignment: .leading, spacing: 12) {
preview
- TextField("Name", text: $title).textFieldStyle(.roundedBorder)
+ HStack(spacing: 6) {
+ iconButton
+ TextField("Name", text: $title).textFieldStyle(.roundedBorder)
+ }
LazyVGrid(columns: Array(repeating: GridItem(.fixed(28), spacing: 4), count: 8), spacing: 4) {
ForEach(Self.emojis, id: \.self) { e in
Text(e).font(.system(size: 16)).frame(width: 28, height: 28)
- .background(RoundedRectangle(cornerRadius: 6).fill(e == emoji ? Color.accentColor.opacity(0.25) : .clear))
- .onTapGesture { emoji = e }
+ .background(RoundedRectangle(cornerRadius: 6).fill(icon == .emoji(e) ? Color.accentColor.opacity(0.25) : .clear))
+ .onTapGesture { icon = .emoji(e) }
}
}
- HStack {
- Text("Custom emoji").font(.system(size: 11)).foregroundStyle(.secondary)
- TextField("", text: $emoji).textFieldStyle(.roundedBorder).frame(width: 50)
- .onChange(of: emoji) { _, v in if v.count > 2 { emoji = String(v.suffix(2)) } }
- }
Divider()
profileSection
Spacer(minLength: 0)
@@ -74,7 +74,7 @@ struct SpaceEditorView: View {
Button("Cancel") { onCancel() }.keyboardShortcut(.cancelAction)
Spacer()
Button(existing == nil ? "Create Space" : "Save") {
- onSave(title.isEmpty ? "Space" : title, emoji.isEmpty ? "🌱" : emoji, theme, profile, trimmedProfileName)
+ onSave(title.isEmpty ? "Space" : title, icon, theme, profile, trimmedProfileName)
}
.keyboardShortcut(.defaultAction)
.disabled((title.trimmingCharacters(in: .whitespaces).isEmpty && existing == nil) || (profile == .new && trimmedProfileName.isEmpty))
@@ -90,7 +90,7 @@ struct SpaceEditorView: View {
SpaceBackground(palette: theme.palette)
VStack(spacing: 6) {
HStack(spacing: 6) {
- Text(emoji).font(.system(size: 15))
+ glyph(size: 15, color: theme.palette.textPrimary)
Text(title.isEmpty ? "Space" : title).font(.system(size: 13, weight: .semibold)).foregroundStyle(theme.palette.textPrimary)
Spacer(minLength: 0)
}
@@ -103,6 +103,42 @@ struct SpaceEditorView: View {
.clipShape(RoundedRectangle(cornerRadius: 12, style: .continuous))
}
+ /// Arc's icon picker (Emoji / Icon / Remove Icon) in a popover, as Change Space Icon… opens
+ /// it; the grid below keeps a few emoji one click away.
+ private var iconButton: some View {
+ Button { pickingIcon = true } label: {
+ Group {
+ if icon == .none {
+ Image(systemName: "face.dashed").font(.system(size: 14)).foregroundStyle(.secondary)
+ } else {
+ glyph(size: 16, color: .primary)
+ }
+ }
+ .frame(width: 28, height: 22)
+ .background(RoundedRectangle(cornerRadius: 6).fill(Color.primary.opacity(pickingIcon ? 0.14 : 0.07)))
+ .contentShape(Rectangle())
+ }
+ .buttonStyle(.plain)
+ .help("Change Icon")
+ .accessibilityLabel("Change Icon")
+ .popover(isPresented: $pickingIcon, arrowEdge: .bottom) {
+ SpaceIconPicker(current: icon.emoji, currentSymbol: icon.symbol,
+ onPick: { icon = .emoji($0); pickingIcon = false },
+ onPickSymbol: { icon = .symbol($0); pickingIcon = false },
+ onRemove: { icon = .none; pickingIcon = false })
+ }
+ }
+
+ /// The icon as the sidebar draws it: an emoji, or a symbol in the space's text colour.
+ @ViewBuilder
+ private func glyph(size: CGFloat, color: Color) -> some View {
+ switch icon {
+ case .emoji(let e): Text(e).font(.system(size: size))
+ case .symbol(let name): Image(systemName: name).font(.system(size: size - 2, weight: .medium)).foregroundStyle(color)
+ case .none: EmptyView()
+ }
+ }
+
private var trimmedProfileName: String { newProfileName.trimmingCharacters(in: .whitespaces) }
/// Arc's copy: "Profiles make your Spaces truly separate…" and, when an existing space