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 parity: View ▸ Appearance for websites (Automatic, Light, Dark) and a setting for sound effects

Victor35bc84aa1cce
diff --git a/Packages/CraCore/Sources/CraCore/SidebarModel.swift b/Packages/CraCore/Sources/CraCore/SidebarModel.swift
index 837febe..1c246e1 100644
--- a/Packages/CraCore/Sources/CraCore/SidebarModel.swift
+++ b/Packages/CraCore/Sources/CraCore/SidebarModel.swift
@@ -509,6 +509,10 @@ public struct AppSettings: Codable, Equatable {
public var tabSleepOnMemoryPressure: Bool = false
/// Privacy ▸ "Always use secure connections": Chrome's HTTPS-Only Mode.
public var httpsOnly: Bool = false
+ /// Arc's View ▸ Appearance: what websites see as the colour scheme.
+ public var websiteAppearance: WebsiteAppearance = .automatic
+ /// Arc's Settings ▸ Advanced "Play Arc sound effects" (the capture shutter), on by default.
+ public var soundEffects: Bool = true
/// Arc's searchSuggestEnabled: the command bar asks the search engine for suggestions
/// as you type and fills its rows with them.
public var searchSuggestions: Bool = true
@@ -712,6 +716,8 @@ extension AppSettings {
tabSleepAfter = (try? c.decodeIfPresent(TabSleepThreshold.self, forKey: .tabSleepAfter)) ?? .fourHours
tabSleepOnMemoryPressure = try c.decodeIfPresent(Bool.self, forKey: .tabSleepOnMemoryPressure) ?? false
httpsOnly = try c.decodeIfPresent(Bool.self, forKey: .httpsOnly) ?? false
+ websiteAppearance = (try? c.decodeIfPresent(WebsiteAppearance.self, forKey: .websiteAppearance)) ?? .automatic
+ soundEffects = try c.decodeIfPresent(Bool.self, forKey: .soundEffects) ?? true
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
@@ -800,3 +806,25 @@ extension TabData {
homeTitle = try c.decodeIfPresent(String.self, forKey: .homeTitle)
}
}
+
+/// Arc's View ▸ Appearance ("Websites, Easels, and Notes will use:"): Automatic follows the Mac.
+public enum WebsiteAppearance: String, Codable, CaseIterable, Sendable {
+ case automatic, light, dark
+
+ public var title: String {
+ switch self {
+ case .automatic: "Automatic"
+ case .light: "Light"
+ case .dark: "Dark"
+ }
+ }
+ /// What Chromium's colour mode takes: 0 the system's, 1 light, 2 dark.
+ public var chromiumMode: Int {
+ switch self {
+ case .automatic: 0
+ case .light: 1
+ case .dark: 2
+ }
+ }
+}
+
diff --git a/Packages/CraCore/Tests/CraCoreTests/WebsiteAppearanceTests.swift b/Packages/CraCore/Tests/CraCoreTests/WebsiteAppearanceTests.swift
new file mode 100644
index 0000000..4c3c2c2
--- /dev/null
+++ b/Packages/CraCore/Tests/CraCoreTests/WebsiteAppearanceTests.swift
@@ -0,0 +1,31 @@
+import CraCore
+import Foundation
+import Testing
+
+/// Arc's View ▸ Appearance (Automatic / Light / Dark for websites) and Settings ▸ Advanced "Play Arc
+/// sound effects", added in the Arc parity sweep: settings from before them load as Arc's defaults,
+/// and a choice survives a save.
+struct WebsiteAppearanceTests {
+ @Test func olderSettingsLoadAsArcsDefaults() throws {
+ let s = try JSONDecoder().decode(AppSettings.self, from: Data(#"{"httpsOnly": true}"#.utf8))
+ #expect(s.websiteAppearance == .automatic)
+ #expect(s.soundEffects)
+ }
+
+ @Test func aChoiceSurvivesASave() throws {
+ var s = AppSettings()
+ s.websiteAppearance = .dark
+ s.soundEffects = false
+ let back = try JSONDecoder().decode(AppSettings.self, from: JSONEncoder().encode(s))
+ #expect(back.websiteAppearance == .dark && !back.soundEffects)
+ }
+
+ @Test func anUnknownValueFallsBackToAutomatic() throws {
+ let s = try JSONDecoder().decode(AppSettings.self, from: Data(#"{"websiteAppearance": "sepia"}"#.utf8))
+ #expect(s.websiteAppearance == .automatic)
+ }
+
+ @Test func chromiumModes() {
+ #expect(WebsiteAppearance.allCases.map(\.chromiumMode) == [0, 1, 2])
+ }
+}
diff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swift
index 7062c67..5113cc0 100644
--- a/Sources/Cra/App/AppDelegate.swift
+++ b/Sources/Cra/App/AppDelegate.swift
@@ -180,6 +180,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
}
observeContentBlocking()
observeHttpsOnly()
+ observeChanges(of: { [store] in store.settings.websiteAppearance }) { CraCEFRuntime.setWebsiteAppearance($0.chromiumMode) }
+ observeChanges(of: { [store] in store.settings.soundEffects }) { CaptureSound.enabled = $0 }
observeLinkMenu()
logSecureDNS()
}
@@ -1070,6 +1072,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
item.title = store.isPinnedCollapsed(main.focusedSpaceID) ? "Expand Pinned Tabs" : "Collapse Pinned Tabs"
return !main.isStandalone
case "stayOnTop": item.state = main.staysOnTop ? .on : .off
+ case "appearanceAutomatic", "appearanceLight", "appearanceDark":
+ item.state = "appearance" + store.settings.websiteAppearance.title == item.representedObject as? String ? .on : .off
case "copyURLQuote", "savePageAs", "captureFullPage", "revealTab": return store.selectedTabID != nil
case "clearArchive": return !store.archive.isEmpty
case "resetSpaceTabs": return !main.isStandalone
@@ -1272,6 +1276,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
case "showArchive": main.showLibrary(.archive)
case "clearArchive": store.clearArchive()
case "stayOnTop": main.toggleStayOnTop()
+ case "appearanceAutomatic": store.settings.websiteAppearance = .automatic
+ case "appearanceLight": store.settings.websiteAppearance = .light
+ case "appearanceDark": store.settings.websiteAppearance = .dark
case "revealData": NSWorkspace.shared.activateFileViewerSelecting([AppPaths.supportDir])
case "copyAppInfo": copy(appInfo())
case "print": main.currentBrowser?.print()
@@ -1492,6 +1499,16 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
menubar.addItem(submenu: edit, title: "Edit")
let view = NSMenu(title: "View")
+ // Arc: View ▸ Appearance ▸ "Websites, Easels, and Notes will use:" Automatic / Light / Dark.
+ let appearance = NSMenu(title: "Appearance")
+ appearance.addItem(withTitle: "Websites will use:", action: nil, keyEquivalent: "").isEnabled = false
+ for a in WebsiteAppearance.allCases {
+ let m = item("appearance" + a.title)
+ m.title = a.title
+ appearance.addItem(m)
+ }
+ view.addItem(submenu: appearance, title: "Appearance")
+ view.addItem(.separator())
view.addItem(item("toggleSidebar")); view.addItem(item("toggleToolbar")); view.addItem(item("collapsePinned"))
view.addItem(.separator())
view.addItem(item("stop")); view.addItem(item("reload")); view.addItem(item("hardReload"))
diff --git a/Sources/Cra/App/KeyBindings.swift b/Sources/Cra/App/KeyBindings.swift
index a2fa3ba..cefec44 100644
--- a/Sources/Cra/App/KeyBindings.swift
+++ b/Sources/Cra/App/KeyBindings.swift
@@ -157,6 +157,10 @@ final class KeyBindingRegistry {
// View
KeyAction(id: "toggleSidebar", name: "Hide Sidebar", section: .view, shortcuts: [Shortcut("s", cmd)], triggers: ["sidebar", "hide sidebar", "show sidebar"]),
KeyAction(id: "toggleToolbar", name: "Hide Toolbar", section: .view, shortcuts: [Shortcut("d", cmdShift)], triggers: ["toolbar"]),
+ // Arc: View ▸ Appearance, what websites see (Websites, Easels, and Notes will use:).
+ KeyAction(id: "appearanceAutomatic", name: "Website Appearance: Automatic", section: .none, shortcuts: [], triggers: ["website appearance", "system appearance"], symbol: "circle.lefthalf.filled"),
+ KeyAction(id: "appearanceLight", name: "Website Appearance: Light", section: .none, shortcuts: [], triggers: ["light mode", "light websites"], symbol: "sun.max"),
+ KeyAction(id: "appearanceDark", name: "Website Appearance: Dark", section: .none, shortcuts: [], triggers: ["dark mode", "dark websites"], symbol: "moon"),
// Arc: View ▸ Collapse Pinned Tabs / Expand Pinned Tabs.
KeyAction(id: "collapsePinned", name: "Collapse Pinned Tabs", section: .view, shortcuts: [], triggers: ["collapse pinned", "expand pinned"]),
KeyAction(id: "stop", name: "Stop Loading", section: .view, shortcuts: [Shortcut(".", cmd)], inCommandBar: false),
diff --git a/Sources/Cra/UI/Settings/AdvancedPane.swift b/Sources/Cra/UI/Settings/AdvancedPane.swift
index a6d4ccb..3f15ec3 100644
--- a/Sources/Cra/UI/Settings/AdvancedPane.swift
+++ b/Sources/Cra/UI/Settings/AdvancedPane.swift
@@ -28,6 +28,10 @@ struct AdvancedPane: View {
SearchEnginePicker(store: store, openURL: actions.openURL)
SettingsCheckbox(title: "Show search suggestions", isOn: $store.settings.searchSuggestions)
}
+ SettingsFormRow(label: "Sounds:") {
+ // Arc: Settings ▸ Advanced "Play Arc sound effects".
+ SettingsCheckbox(title: "Play Cra sound effects", isOn: $store.settings.soundEffects)
+ }
SettingsFormRow(label: "When quitting Cra:") {
SettingsCheckbox(title: "Warn before quitting", isOn: $store.settings.warnBeforeQuitting)
}
diff --git a/Sources/Cra/UI/Windows/CaptureOverlay.swift b/Sources/Cra/UI/Windows/CaptureOverlay.swift
index cb5a0b4..7365d6d 100644
--- a/Sources/Cra/UI/Windows/CaptureOverlay.swift
+++ b/Sources/Cra/UI/Windows/CaptureOverlay.swift
@@ -1008,7 +1008,10 @@ enum CaptureSound {
return AudioServicesCreateSystemSoundID(url as CFURL, &id) == noErr ? id : nil
}()
+ /// Settings ▸ Advanced "Play Cra sound effects" (Arc's "Play Arc sound effects").
+ static var enabled = true
+
static func play() {
- if let id { AudioServicesPlaySystemSound(id) }
+ if enabled, let id { AudioServicesPlaySystemSound(id) }
}
}
diff --git a/Sources/CraCEF/CraCEF.mm b/Sources/CraCEF/CraCEF.mm
index aa6d78e..ba5ae67 100644
--- a/Sources/CraCEF/CraCEF.mm
+++ b/Sources/CraCEF/CraCEF.mm
@@ -435,6 +435,8 @@ static void HideDownloadBubble(CefRefPtr<CefRequestContext> context) {
}
static bool g_httpsOnly = false;
+/// Arc's View ▸ Appearance for websites: 0 follows the Mac, 1 light, 2 dark.
+static NSInteger g_websiteAppearance = 0;
static bool g_incognitoReady = false;
/// Chrome's "Always use secure connections" (Settings ▸ Privacy in Cra).
@@ -448,7 +450,16 @@ static void ApplyHttpsOnly(CefRefPtr<CefRequestContext> context) {
}
}
+/// Chrome's colour mode for the profile, which is what its pages' prefers-color-scheme follows.
+static void ApplyWebsiteAppearance(CefRefPtr<CefRequestContext> context) {
+ if (!context) return;
+ cef_color_variant_t mode = g_websiteAppearance == 1 ? CEF_COLOR_VARIANT_LIGHT
+ : g_websiteAppearance == 2 ? CEF_COLOR_VARIANT_DARK : CEF_COLOR_VARIANT_SYSTEM;
+ if (context->GetChromeColorSchemeMode() != mode) context->SetChromeColorScheme(mode, 0);
+}
+
static void ApplyProfilePreferences(CefRefPtr<CefRequestContext> context) {
+ ApplyWebsiteAppearance(context);
ApplyWebRTCPolicy(context);
HideDownloadBubble(context);
ApplyHttpsOnly(context);
@@ -1049,6 +1060,7 @@ private:
/// are dark and white while they are light (measured on Arc 1.171, also for a tab it restores
/// unloaded). Pages follow the app's appearance; Cra sets no colour scheme of its own.
static BOOL PagesAreDark() {
+ if (g_websiteAppearance) return g_websiteAppearance == 2;
return [[NSApp.effectiveAppearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]]
isEqualToString:NSAppearanceNameDarkAqua];
}
@@ -2666,6 +2678,17 @@ static void MarkProfileExitedCleanly(NSString* profileDir) {
/// the rest get it from ApplyProfilePreferences when they load. Every settings write calls
/// this, so an unchanged value does nothing. Once quitting starts the global context goes
/// away (GetGlobalContext returns null, #36); the setting is applied again at the next start.
++ (void)setWebsiteAppearance:(NSInteger)mode {
+ if (mode == g_websiteAppearance) return;
+ g_websiteAppearance = mode;
+ if (!g_contextInitialized || g_quitting) return;
+ ApplyWebsiteAppearance(CefRequestContext::GetGlobalContext());
+ for (auto& [path, context] : g_profileContexts) {
+ if ([g_readyProfiles containsObject:@(path.c_str())]) ApplyWebsiteAppearance(context);
+ }
+ if (g_incognitoContext && g_incognitoReady) ApplyWebsiteAppearance(g_incognitoContext);
+}
++ (NSInteger)websiteAppearance { return g_websiteAppearance; }
+ (void)setHttpsOnlyModeEnabled:(BOOL)enabled {
if (enabled == g_httpsOnly) return;
g_httpsOnly = enabled;
diff --git a/Sources/CraCEF/include/CraCEF.h b/Sources/CraCEF/include/CraCEF.h
index 388dae4..2cd20d5 100644
--- a/Sources/CraCEF/include/CraCEF.h
+++ b/Sources/CraCEF/include/CraCEF.h
@@ -268,6 +268,11 @@ typedef NS_ENUM(NSInteger, CraLinkWindow) {
/// http:// navigations are upgraded, and a site without HTTPS shows Chrome's warning
/// page before it loads. Profiles that load later get it too. Off until enabled.
+ (void)setHttpsOnlyModeEnabled:(BOOL)enabled;
+/// Arc's View ▸ Appearance ("Websites, Easels, and Notes will use:"): 0 Automatic (the Mac's),
+/// 1 Light, 2 Dark. Chrome's colour mode in every profile, which pages' prefers-color-scheme and
+/// Chrome's own pages follow; profiles that load later get it too.
++ (void)setWebsiteAppearance:(NSInteger)mode;
+@property (class, nonatomic, readonly) NSInteger websiteAppearance;
/// Chromium's secure DNS setting (chrome://settings/security), app-wide in Local State:
/// `dns_over_https.mode` and `dns_over_https.templates` as Chromium holds them now. nil
/// before Chromium is ready and once quitting starts.
diff --git a/Tests/Scenarios/website-appearance.scenario b/Tests/Scenarios/website-appearance.scenario
new file mode 100644
index 0000000..7ded2fd
--- /dev/null
+++ b/Tests/Scenarios/website-appearance.scenario
@@ -0,0 +1,19 @@
+# Arc's View ▸ Appearance (Arc 1.172.1, docs/arc-parity.md): Light and Dark force what pages see
+# as prefers-color-scheme, live and without a reload; Automatic follows the Mac again.
+budget rss=700 stalls50=10
+cra://open?url=${PAGE}?n=look
+expect-log loaded 127\.0\.0\.1 \(HTTP 200\)
+cra://action/appearanceDark
+wait 1
+cra://debug?cdp=Runtime.evaluate&params={"expression":"'dark-'+matchMedia('(prefers-color-scheme: dark)').matches"}
+expect-log Cra cdp Runtime.evaluate .*"value":"dark-true"
+cra://action/appearanceLight
+wait 1
+cra://debug?cdp=Runtime.evaluate&params={"expression":"'light-'+matchMedia('(prefers-color-scheme: dark)').matches"}
+expect-log Cra cdp Runtime.evaluate .*"value":"light-false"
+cra://open?url=${PAGE}?n=new
+wait 2
+cra://debug?cdp=Runtime.evaluate&params={"expression":"'newtab-'+matchMedia('(prefers-color-scheme: dark)').matches"}
+expect-log Cra cdp Runtime.evaluate .*"value":"newtab-false"
+cra://action/appearanceAutomatic
+wait 1