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.

Menus, sheets and popovers follow macOS, not the space colour; a one-colour theme keeps its look (#171)

Victor4e9d32f0dd65
diff --git a/Packages/CraCore/Sources/CraCore/ArcThemeImport.swift b/Packages/CraCore/Sources/CraCore/ArcThemeImport.swift
index c95f774..78c96d3 100644
--- a/Packages/CraCore/Sources/CraCore/ArcThemeImport.swift
+++ b/Packages/CraCore/Sources/CraCore/ArcThemeImport.swift
@@ -13,8 +13,12 @@ public enum ArcThemeImport {
if let light, let dark { return SpaceTheme(light: light, dark: dark) }
return dark ?? light
}
- guard let single = (bg["single"] as? [String: Any])?["_0"] as? [String: Any] else { return nil }
- return theme(variant: single, appearance: "auto", windowTheme: wt)
+ guard let single = (bg["single"] as? [String: Any])?["_0"] as? [String: Any],
+ var t = theme(variant: single, appearance: "auto", windowTheme: wt) else { return nil }
+ // A `single` theme never follows macOS in Arc. Without `contentOverBackgroundAppearance` it
+ // takes the side its colours suit (#171).
+ if t.followsSystem { t.appearance = t.isDark ? "dark" : "light" }
+ return t
}
/// One half of `background`: its own `contentOverBackgroundAppearance` wins over `appearance`.
diff --git a/Packages/CraCore/Sources/CraCore/SpaceTheme.swift b/Packages/CraCore/Sources/CraCore/SpaceTheme.swift
index 3611902..cf91541 100644
--- a/Packages/CraCore/Sources/CraCore/SpaceTheme.swift
+++ b/Packages/CraCore/Sources/CraCore/SpaceTheme.swift
@@ -19,8 +19,8 @@ public struct SpaceTheme: Codable, Equatable {
public var solid: Bool = false
/// Arc's Auto theme (background.appearanceBased): with `appearance` "auto" the space follows
/// macOS, the fields above are its light half and this is the half shown while macOS is dark.
- /// nil on an "auto" theme from before 0.1.29: its colours are the half their brightness
- /// suits, and the other half is derived (`resolved(systemDark:)`).
+ /// nil on an "auto" theme with one set of colours (saved before 0.1.29, the Edit Space sheet's
+ /// Auto, a Zen import): it stays on the side its colours suit whatever macOS shows.
public var dark: Variant? = nil
/// The theme editor's pad colours the theme was built from (Arc: the editor's key colour and
/// the ones its wheel adds); nil for a preset or an import, whose own colours go on the pad.
@@ -94,11 +94,12 @@ public struct SpaceTheme: Codable, Equatable {
return SpaceTheme(colors: d.colors, intensity: d.intensity, noise: d.noise, appearance: "dark", vibrant: d.vibrant,
accent: d.accent, solid: d.solid)
}
- // An Auto theme saved before both halves were kept shows as it always did on the side its
- // colours suit, and as the derived other half on the other.
+ // One set of colours keeps its look on both sides, as an Arc `single` theme does: swapping
+ // it for a derived half made an imported space look nothing like Arc's while macOS ran the
+ // other way (#171).
var t = self
t.appearance = isDark ? "dark" : "light"
- return t.isDark == systemDark ? t : SpaceThemeVariants.flipped(t)
+ return t
}
/// Dark first: colors borrowed from Victor's other projects (GhostWriter
diff --git a/Packages/CraCore/Sources/CraCore/SpaceThemeVariants.swift b/Packages/CraCore/Sources/CraCore/SpaceThemeVariants.swift
index 5b4f1cf..6283fab 100644
--- a/Packages/CraCore/Sources/CraCore/SpaceThemeVariants.swift
+++ b/Packages/CraCore/Sources/CraCore/SpaceThemeVariants.swift
@@ -20,12 +20,6 @@ public enum SpaceThemeVariants {
return t
}
- /// The other half of a theme that has one: a dark theme's light half or a light theme's dark half.
- public static func flipped(_ t: SpaceTheme) -> SpaceTheme {
- t.isDark ? light(key: t.colors, intensity: t.intensity, noise: t.noise)
- : dark(key: t.colors, intensity: t.intensity, noise: t.noise)
- }
-
/// The half shown while macOS is light, from the pad's colours: the colours themselves (Arc
/// saves a colour picked in Light as that colour), lifted to Arc's default light half (HSL
/// lightness 0.9, #8389FF → #C8CAFF) when they would read as a dark theme. One colour is Arc's
diff --git a/Packages/CraCore/Tests/CraCoreTests/ArcThemeImportTests.swift b/Packages/CraCore/Tests/CraCoreTests/ArcThemeImportTests.swift
index 6cc6eae..735dab7 100644
--- a/Packages/CraCore/Tests/CraCoreTests/ArcThemeImportTests.swift
+++ b/Packages/CraCore/Tests/CraCoreTests/ArcThemeImportTests.swift
@@ -54,6 +54,25 @@ struct ArcThemeImportTests {
appearance: "light", accent: "#C8CAFF"))
}
+ /// Arc's `single` theme never follows macOS: one without `contentOverBackgroundAppearance` takes
+ /// the side its colours suit instead of Auto, so it is never swapped for a derived half (#171).
+ @Test(arguments: [("solidRedDark", "dark"), ("solidWhiteLight", "light"), ("gradientVibrantLight", "light")])
+ func singleWithoutAppearanceKeepsItsSide(name: String, appearance: String) throws {
+ let theme = try #require(ArcThemeImport.theme(from: Self.withoutAppearanceKey(Self.spaces[name]!)))
+ #expect(theme.appearance == appearance && !theme.followsSystem)
+ #expect(theme.resolved(systemDark: true) == theme && theme.resolved(systemDark: false) == theme)
+ }
+
+ static func withoutAppearanceKey(_ space: [String: Any]) -> [String: Any] {
+ var space = space
+ var info = space["customInfo"] as! [String: Any], wt = info["windowTheme"] as! [String: Any]
+ var bg = wt["background"] as! [String: Any], single = bg["single"] as! [String: Any]
+ var v = single["_0"] as! [String: Any]
+ v["contentOverBackgroundAppearance"] = nil
+ single["_0"] = v; bg["single"] = single; wt["background"] = bg; info["windowTheme"] = wt; space["customInfo"] = info
+ return space
+ }
+
/// An appearance-based theme with one half shows that half whatever macOS shows.
@Test func appearanceBasedWithOneHalfKeepsIt() throws {
var space = Self.spaces["gradientAppearanceBasedDark"]!
@@ -178,15 +197,15 @@ struct SpaceThemeAppearanceTests {
#expect(Self.dark.resolved(systemDark: systemDark) == Self.dark)
}
- /// An Auto theme saved before 0.1.29 (one set of colours) looks as it did on the side its colours
- /// suit and gets a derived half on the other.
- @Test(arguments: ["#F8D558", "#2861B3"])
- func olderAutoThemeKeepsItsSideAndDerivesTheOther(hex: String) {
+ /// An Auto theme with one set of colours (saved before 0.1.29, or an import that had no second
+ /// half) stays on the side its colours suit while macOS changes: no derived half (#171).
+ @Test(arguments: ["#F8D558", "#2861B3", "#F25E6B"])
+ func autoThemeWithOneHalfKeepsItsLook(hex: String) {
let theme = SpaceTheme(colors: [hex, hex], intensity: 0.8, noise: 0.1, appearance: "auto")
- let own = theme.resolved(systemDark: theme.isDark)
- #expect(own.colors == theme.colors && own.isDark == theme.isDark)
- let other = theme.resolved(systemDark: !theme.isDark)
- #expect(other.isDark != theme.isDark && other.colors != theme.colors)
+ var own = theme
+ own.appearance = theme.isDark ? "dark" : "light"
+ #expect(theme.resolved(systemDark: false) == own)
+ #expect(theme.resolved(systemDark: true) == own)
}
/// Both halves and the editor's colours are saved; a theme without them saves as before.
diff --git a/Sources/Cra/UI/SiteControlCenter.swift b/Sources/Cra/UI/SiteControlCenter.swift
index 222d20b..3a17a04 100644
--- a/Sources/Cra/UI/SiteControlCenter.swift
+++ b/Sources/Cra/UI/SiteControlCenter.swift
@@ -189,6 +189,7 @@ final class SiteControlCenterView: NSView {
}
/// Arc's site control center palette (dark values sampled from Arc 1.170; light ones mirror them).
+/// `dark` is macOS's appearance, not the space's: like Arc's menus, the popover follows the Mac (#171).
struct SiteControlCenterColors {
let dark: Bool
var background: NSColor { dark ? NSColor(hex: "#272728") : NSColor(hex: "#F4F4F5") }
diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swift
index 99e1c63..b3de90a 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -363,8 +363,12 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
shell.placeholderHost.wantsLayer = true
shell.placeholderHost.layer?.backgroundColor = (palette.isDark ? NSColor.white.withAlphaComponent(0.04) : NSColor.black.withAlphaComponent(0.03)).cgColor
shell.isDarkTheme = palette.isDark
- window?.appearance = NSAppearance(named: palette.isDark ? .darkAqua : .aqua)
- commandPanel?.appearance = window?.appearance
+ // The space's light or dark goes to the window's content (sidebar, toolbar, pages'
+ // frame), not to the window: AppKit hands a window's appearance to every menu, sheet,
+ // alert and popover it presents, and those follow macOS as Arc's do, whatever the
+ // space colour (#171).
+ shell.appearance = NSAppearance(named: palette.isDark ? .darkAqua : .aqua)
+ commandPanel?.appearance = shell.appearance
// Vibrant themes see through to the desktop like Arc; others are opaque.
shell.vibrancy.isHidden = !palette.vibrant
shell.vibrancyLift.isHidden = !palette.vibrant
@@ -2205,7 +2209,7 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
self?.openTab("chrome://settings/content/siteDetails?site=" + (origin.addingPercentEncoding(withAllowedCharacters: .alphanumerics) ?? origin))
}
siteControlCenterSpaceID = focusedSpaceID
- siteControlCenter.show(relativeTo: rect, of: content, url: url, secure: secure, dark: focusedSpace.theme.palette.isDark,
+ siteControlCenter.show(relativeTo: rect, of: content, url: url, secure: secure, dark: SystemAppearance.shared.isDark,
profile: profileDirectoryName, tab: selectedTabID, store: store, actions: actions)
}
@@ -2351,9 +2355,9 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
// Always centred in the window, also when opened from the toolbar.
commandBar.attached = false
commandBar.panelWidth = min(CraMetrics.commandBarWidth, window.frame.width - 80)
- // Light or dark with the space's theme, as the window is: a child panel would otherwise
+ // Light or dark with the space's theme, as the sidebar is: a child panel would otherwise
// follow macOS, a dark bar over a light space while the Mac runs dark (reported on X).
- commandPanel.appearance = window.appearance
+ commandPanel.appearance = shell.appearance
positionCommandPanel()
if commandPanel.parent == nil { window.addChildWindow(commandPanel, ordered: .above) }
commandBarOpenedAt = Date()
diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.md
index f56706b..6fd4e54 100644
--- a/docs/arc-reverse-engineering.md
+++ b/docs/arc-reverse-engineering.md
@@ -2776,7 +2776,8 @@ that waits 3 s before answering and then serves a page whose image takes 5 s.
switch redraws at once. Arc imports keep both halves. The editor builds halves from its pad (`SpaceTheme.key`) with
`SpaceThemeVariants`: the light half is the pad's colours (lifted to HSL lightness 0.9 only when they read dark),
the dark half keeps their hue at HSL lightness 0.064, drawn like an imported dark half (27 % over #2B2632). An
- Auto theme saved before keeps its colours on the side they suit and derives the other.
+ Auto theme with one set of colours (saved before, or from the Edit Space sheet or Zen) stays on the side they suit
+ whatever macOS shows, and an Arc `single` without `contentOverBackgroundAppearance` imports as that side (#171).
- [?] Not worked out: how Arc's editor maps a picked colour to its halves (the pad's `lightnessRange` and the bias
value). Cra's halves are fitted to Arc's default theme only.