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.

Loading pages sit on Arc's canvas, not a white flash (#46); keep incognito tabs off disk (#63)

Victor Kildahlba8fbc001f4a
diff --git a/Sources/Cra/Model/SidebarModel.swift b/Sources/Cra/Model/SidebarModel.swift
index 401a041..0ce0aa3 100644
--- a/Sources/Cra/Model/SidebarModel.swift
+++ b/Sources/Cra/Model/SidebarModel.swift
@@ -74,6 +74,9 @@ struct TabData: Codable, Equatable {
var liveSubtitle: String?
/// When its pull request left the live folder's results; the tab goes after a grace period.
var liveGoneAt: Date?
+ /// The page's toolbar colour as last reported (TabRuntime.themeColor). A slept or restored
+ /// tab's toolbar keeps it while the page loads again, as Arc's does.
+ var themeColor: String?
var iconKey: String? { customIconKey ?? faviconKey }
@@ -581,5 +584,6 @@ extension TabData {
liveItemURL = try c.decodeIfPresent(String.self, forKey: .liveItemURL)
liveSubtitle = try c.decodeIfPresent(String.self, forKey: .liveSubtitle)
liveGoneAt = try c.decodeIfPresent(Date.self, forKey: .liveGoneAt)
+ themeColor = try c.decodeIfPresent(String.self, forKey: .themeColor)
}
}
diff --git a/Sources/Cra/Services/BrowserManager.swift b/Sources/Cra/Services/BrowserManager.swift
index 1586611..938cdd8 100644
--- a/Sources/Cra/Services/BrowserManager.swift
+++ b/Sources/Cra/Services/BrowserManager.swift
@@ -142,7 +142,11 @@ final class BrowserManager: NSObject, @preconcurrency CraBrowserDelegate {
browser.userInfo = tabID.uuidString
let rt = TabRuntime(tabID: tabID, browser: browser)
rt.hiddenAt = clock.now
- if let t = store.item(tabID)?.tab, t.muted { browser.setAudioMuted(true) }
+ if let t = store.item(tabID)?.tab {
+ if t.muted { browser.setAudioMuted(true) }
+ // A slept or restored page's toolbar keeps its colour while it loads (Arc).
+ rt.themeColor = t.themeColor ?? ""
+ }
add(rt)
return rt
}
@@ -204,7 +208,12 @@ final class BrowserManager: NSObject, @preconcurrency CraBrowserDelegate {
var shown: [UUID] = []
for id in tabIDs {
guard let rt = ensureRuntime(for: id) else { shown.append(id); continue }
- if !wasVisible.contains(id) { returnToTab(rt) }
+ if !wasVisible.contains(id) {
+ returnToTab(rt)
+ // A page can change its colours while hidden. One still loading reports them as it
+ // paints; asked now, before its styles arrive, it would answer white.
+ if !rt.browser.isLoading { rt.browser.probeBackgroundColor() }
+ }
rt.hiddenAt = nil
rt.sleepProbeAfter = nil
let v = rt.browser.containerView
@@ -659,6 +668,7 @@ final class BrowserManager: NSObject, @preconcurrency CraBrowserDelegate {
func browser(_ browser: CraBrowser, didReportThemeColor hex: String) {
guard let id = tabID(of: browser) else { return }
runtimes[id]?.themeColor = hex
+ store.setThemeColor(id, hex)
delegate?.browserManagerDidUpdate(id)
}
diff --git a/Sources/Cra/Services/SidebarStore.swift b/Sources/Cra/Services/SidebarStore.swift
index a680dd9..fa06766 100644
--- a/Sources/Cra/Services/SidebarStore.swift
+++ b/Sources/Cra/Services/SidebarStore.swift
@@ -101,6 +101,18 @@ final class SidebarStore {
spaceOrder = doc.spaceOrder
for it in doc.items { items[it.id] = it }
}
+ // Containers of a space that is gone, with everything in them: an incognito window's,
+ // which updateTab used to write to disk. Its tabs never showed in a space again, but
+ // the command bar offered them in normal windows. They go before the orphan pass below
+ // would move them into a space.
+ func drop(_ id: UUID) {
+ for c in items[id]?.children ?? [] { drop(c) }
+ items[id] = nil
+ }
+ for (id, it) in items.all {
+ guard let sid = it.container?.spaceID, spaces[sid] == nil, sid != ContainerKind.sharedFavoritesSpaceID else { continue }
+ drop(id)
+ }
// Drop children references that do not resolve and orphans.
for (id, var it) in items.all {
it.children = it.children.filter { items[$0] != nil && items[$0]?.parentID == id }
@@ -441,8 +453,18 @@ final class SidebarStore {
// The window's layout (refresh) only depends on a tab becoming or ceasing to be an
// empty pane; the rows and the toolbar observe the tab themselves.
if it.isEmptyTab != wasEmpty { revision &+= 1 }
- sidebarFile.save(SidebarDocument(version: 1, spaceOrder: spaceOrder, spaces: orderedSpaces,
- items: Array(items.values), profiles: profiles), delay: 2)
+ // The document leaves incognito windows' tabs out.
+ sidebarFile.save(document, delay: 2)
+ }
+
+ /// Only saved: nothing on screen reads it back until the tab's page is made again. Incognito
+ /// tabs are never restored, so they keep none.
+ func setThemeColor(_ id: UUID, _ hex: String) {
+ guard !isIncognito(item: id), var it = items[id], var t = it.tab, t.themeColor != hex else { return }
+ t.themeColor = hex
+ it.data = .tab(t)
+ items[id] = it
+ sidebarFile.save(document, delay: 2)
}
func markUnread(_ id: UUID, _ unread: Bool = true) {
diff --git a/Sources/Cra/UI/SplitView/PaneCardView.swift b/Sources/Cra/UI/SplitView/PaneCardView.swift
index 1aed91d..2761d95 100644
--- a/Sources/Cra/UI/SplitView/PaneCardView.swift
+++ b/Sources/Cra/UI/SplitView/PaneCardView.swift
@@ -1,4 +1,5 @@
import AppKit
+import CraCEF
import SwiftUI
/// One content pane: Arc's rounded card with its toolbar strip on top and the
@@ -38,10 +39,13 @@ final class PaneCardView: NSView {
/// White page card, or Arc's tinted translucent empty pane.
var hasPage = true { didSet { refreshBackground() } }
var isDark = false { didSet { refreshBackground() } }
- /// The page's own background ("#RRGGBB"; white until it reports one). The page window trails
- /// the card by a frame or more while the window is resized quickly; in that gap the
- /// page area must look like the page, not like a white card.
+ /// The page's own background ("#RRGGBB"; Arc's canvas until it reports one). The page window
+ /// trails the card by a frame or more while the window is resized quickly, and a page that is
+ /// loading has not painted yet; in those gaps the page area must look like the page, not
+ /// like a white card.
var pageColor: String? { didSet { refreshBackground() } }
+ /// The canvas follows the appearance pages get (the app's), not the space theme's.
+ private var appearanceObservation: NSKeyValueObservation?
/// The toolbar's colour (the page's theme-color, white until it reports one). A white backing
/// under a dark bar shows through the bar's anti-aliased left edge as a 1px light line.
var toolbarColor: String? { didSet { refreshBackground() } }
@@ -98,6 +102,9 @@ final class PaneCardView: NSView {
addSubview(hairline)
addSubview(toolbarHost)
refreshBackground()
+ appearanceObservation = NSApp.observe(\.effectiveAppearance) { [weak self] _, _ in
+ MainActor.assumeIsolated { self?.refreshBackground() }
+ }
}
required init?(coder: NSCoder) { fatalError() }
@@ -108,7 +115,7 @@ final class PaneCardView: NSView {
layer?.backgroundColor = transparent || hasPage ? NSColor.clear.cgColor : NSColor(white: 1, alpha: isDark ? 0.08 : 0.2).cgColor
let bar = developerBar ?? toolbarColor.map { NSColor(Color(hex: $0)) } ?? .white
toolbarBackground.layer?.backgroundColor = (hasPage && !transparent ? bar : NSColor.clear).cgColor
- let page = pageColor.map { NSColor(Color(hex: $0)) } ?? .white
+ let page = pageColor.map { NSColor(Color(hex: $0)) } ?? CraBrowser.pageCanvasColor
pageBackground.layer?.backgroundColor = (hasPage && !transparent ? page : NSColor.clear).cgColor
hairline.isHidden = hasPage || transparent || !showToolbar
hairline.layer?.backgroundColor = NSColor(white: isDark ? 1 : 0, alpha: 0.08).cgColor
diff --git a/Sources/Cra/UI/Windows/LittleWindowController.swift b/Sources/Cra/UI/Windows/LittleWindowController.swift
index bdc2ba5..e57c24a 100644
--- a/Sources/Cra/UI/Windows/LittleWindowController.swift
+++ b/Sources/Cra/UI/Windows/LittleWindowController.swift
@@ -710,9 +710,10 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
}
func browser(_ browser: CraBrowser, didReportThemeColor hex: String) { state.themeColor = hex }
- /// The page window trails the shell during a fast resize; the gap shows the page's colour.
+ /// The page window trails the shell during a fast resize; the gap shows the page's colour
+ /// (Arc's canvas while a new page has none yet).
func browser(_ browser: CraBrowser, didReportBackgroundColor hex: String) {
- shell.page.layer?.backgroundColor = NSColor(Color(hex: hex)).cgColor
+ shell.page.layer?.backgroundColor = (hex.isEmpty ? CraBrowser.pageCanvasColor : NSColor(Color(hex: hex))).cgColor
}
func browser(_ browser: CraBrowser, didChangeStatusMessage message: String) {}
@@ -818,7 +819,7 @@ final class LittleShellView: NSView {
page.layer?.cornerCurve = .continuous
page.layer?.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
page.layer?.masksToBounds = true
- page.layer?.backgroundColor = NSColor(white: 34 / 255, alpha: 1).cgColor
+ page.layer?.backgroundColor = CraBrowser.pageCanvasColor.cgColor
page.autoresizesSubviews = true
addSubview(page)
}
diff --git a/Sources/CraCEF/CraCEF.mm b/Sources/CraCEF/CraCEF.mm
index 743906f..ac0b07c 100644
--- a/Sources/CraCEF/CraCEF.mm
+++ b/Sources/CraCEF/CraCEF.mm
@@ -191,8 +191,10 @@ static CraClient* AsCraClient(CefClient* c) {
- (void)hostWindowCreated:(NSWindow*)window;
- (void)hostPopupBrowserView:(CefRefPtr<CefBrowserView>)view;
@property (nonatomic, strong, nullable) NSWindow* hostWindow;
-/// The page's background as last reported by kBackgroundProbe (ARGB, white until then).
+/// The page's background as last reported by kBackgroundProbe (ARGB, 0 until then).
@property (nonatomic) cef_color_t pageBackgroundColor;
+/// What the view shows under the page: its reported background, else the canvas.
+@property (nonatomic, readonly) cef_color_t pageFill;
@end
// MARK: - CEF app
@@ -862,6 +864,17 @@ private:
IMPLEMENT_REFCOUNTING(DevToolsClient);
};
+/// The page area before a page reports its own background: Arc fills it black while websites
+/// 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() {
+ return [[NSApp.effectiveAppearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]]
+ isEqualToString:NSAppearanceNameDarkAqua];
+}
+static cef_color_t CraCanvasColor() {
+ return PagesAreDark() ? CefColorSetARGB(255, 0, 0, 0) : CefColorSetARGB(255, 255, 255, 255);
+}
+
// "rgb(r, g, b)" / "rgba(r, g, b, a)" from getComputedStyle as "#RRGGBB"; "" when
// unparsable or mostly transparent.
static NSString* HexFromCSSColor(const std::string& css) {
@@ -874,18 +887,34 @@ static NSString* HexFromCSSColor(const std::string& css) {
// What the page paints behind its content: the root's background, else the body's
// (CSS propagates it to the canvas), else the canvas colour of the page's color
-// scheme. Answers through OnConsoleMessage ("__cra_bg:"); installed once per
-// document, re-run on load, after late stylesheets and when the OS appearance flips.
+// scheme ('' before the document has a root).
+#define CRA_PAGE_BACKGROUND_FN \
+ "function(){var r=document.documentElement;if(!r)return '';" \
+ "var bg=function(e){var c=e?getComputedStyle(e).backgroundColor:'';return c&&c!=='transparent'&&c!=='rgba(0, 0, 0, 0)'?c:'';};" \
+ "var c=bg(r)||bg(document.body);" \
+ "if(!c){var d=document.createElement('div');d.style.color='Canvas';r.appendChild(d);c=getComputedStyle(d).color;d.remove();}" \
+ "return c;}"
+
+// Answers through OnConsoleMessage ("__cra_bg:"); installed once per document, re-run on
+// load, after late stylesheets and when the OS appearance flips.
static const char kBackgroundProbe[] =
- "(function(){if(!window.__craBg){window.__craBg=function(){try{"
- "var bg=function(e){var c=e?getComputedStyle(e).backgroundColor:'';return c&&c!=='transparent'&&c!=='rgba(0, 0, 0, 0)'?c:'';};"
- "var c=bg(document.documentElement)||bg(document.body);"
- "if(!c){var d=document.createElement('div');d.style.color='Canvas';document.documentElement.appendChild(d);c=getComputedStyle(d).color;d.remove();}"
- "console.log('__cra_bg:'+c);}catch(e){}};"
+ "(function(){if(!window.__craBg){var color=" CRA_PAGE_BACKGROUND_FN ";"
+ "window.__craBg=function(){try{var c=color();if(c)console.log('__cra_bg:'+c);}catch(e){}};"
"matchMedia('(prefers-color-scheme: dark)').addEventListener('change',function(){setTimeout(window.__craBg,50);});"
"setTimeout(window.__craBg,1500);}"
"window.__craBg();})();";
+// While a page is parsed, the same colour on every frame (only changes are sent). CEF draws a
+// new renderer's first page transparent (chromiumembedded/cef#3891), so the view's canvas showed
+// through a page with no background of its own until its load ended: black text on black while
+// a slow image loaded. Frames wait for render-blocking stylesheets, so the first answer already
+// has the page's styles; the probe above takes over once the document is parsed.
+static const char kLoadingBackgroundProbe[] =
+ "(function(){var color=" CRA_PAGE_BACKGROUND_FN ",last='',n=0;"
+ "function tick(){try{var c=color();if(c&&c!==last){last=c;console.log('__cra_bg:'+c);}}catch(e){}"
+ "if(document.readyState==='loading'&&++n<600)requestAnimationFrame(tick);}"
+ "requestAnimationFrame(tick);})();";
+
// MARK: - Content blocking and app links
// Cancels third-party requests to listed ad and tracker domains (CraContentBlocker.h).
@@ -1016,11 +1045,15 @@ public:
}
void OnLoadStart(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, TransitionType transition_type) override {
- // The last page's colour must not show under the next one while it loads.
+ // The last page's colour must not show under the next one while it loads: the canvas
+ // does until this one reports its own.
CraBrowser* o = owner_;
if (!o || !frame->IsMain()) return;
- o.pageBackgroundColor = CefColorSetARGB(255, 255, 255, 255);
- if (CefRefPtr<CefBrowserView> view = CefBrowserView::GetForBrowser(browser)) view->SetBackgroundColor(o.pageBackgroundColor);
+ o.pageBackgroundColor = 0;
+ if (CefRefPtr<CefBrowserView> view = CefBrowserView::GetForBrowser(browser)) view->SetBackgroundColor(o.pageFill);
+ if ([o.delegate respondsToSelector:@selector(browser:didReportBackgroundColor:)])
+ [o.delegate browser:o didReportBackgroundColor:@""];
+ frame->ExecuteJavaScript(kLoadingBackgroundProbe, frame->GetURL(), 0);
}
void OnLoadEnd(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, int httpStatusCode) override {
@@ -1520,7 +1553,7 @@ public:
// view takes the page's own colour instead; CEF resets it on every theme change.
void OnThemeChanged(CefRefPtr<CefView> view) override {
CraBrowser* o = owner_;
- if (!devtools_) view->SetBackgroundColor(o ? o.pageBackgroundColor : CefColorSetARGB(255, 255, 255, 255));
+ if (!devtools_) view->SetBackgroundColor(o ? o.pageFill : CraCanvasColor());
}
CefRefPtr<CefBrowserViewDelegate> GetDelegateForPopupBrowserView(CefRefPtr<CefBrowserView> browser_view,
const CefBrowserSettings& settings,
@@ -1627,7 +1660,6 @@ class CraDevToolsObserver : public CefDevToolsMessageObserver {
_delegate = delegate;
_isIncognito = incognito;
_profilePath = incognito ? nil : [profilePath copy];
- _pageBackgroundColor = CefColorSetARGB(255, 255, 255, 255);
_currentURL = url ?: @"";
_currentTitle = @"";
_pendingURL = url;
@@ -1982,6 +2014,8 @@ static NSView* FindRenderWidgetHostView(NSView* root) {
- (void)executeJavaScript:(NSString*)script {
if (_browser) _browser->GetMainFrame()->ExecuteJavaScript(CefStringFromNS(script), _browser->GetMainFrame()->GetURL(), 0);
}
+- (cef_color_t)pageFill { return _pageBackgroundColor ?: CraCanvasColor(); }
++ (NSColor*)pageCanvasColor { return PagesAreDark() ? NSColor.blackColor : NSColor.whiteColor; }
- (void)probeBackgroundColor {
if (_browser) _browser->GetMainFrame()->ExecuteJavaScript(kBackgroundProbe, _browser->GetMainFrame()->GetURL(), 0);
}
diff --git a/Sources/CraCEF/include/CraCEF.h b/Sources/CraCEF/include/CraCEF.h
index 8178385..7f55e15 100644
--- a/Sources/CraCEF/include/CraCEF.h
+++ b/Sources/CraCEF/include/CraCEF.h
@@ -73,8 +73,9 @@ typedef NS_ENUM(NSInteger, CraDownloadState) {
/// The video in the Picture in Picture window started or stopped playing.
- (void)browser:(CraBrowser *)browser didChangePictureInPicturePlayback:(BOOL)playing;
/// The colour the page paints behind its content (root/body background, else the
-/// canvas colour of its color scheme), as "#RRGGBB". The shell fills the area under
-/// the page window with it, so a page lagging behind a resize shows no white edge.
+/// canvas colour of its color scheme), as "#RRGGBB"; "" when a new page starts loading
+/// and has not reported one yet (show +[CraBrowser pageCanvasColor] then). The shell fills
+/// the area under the page window with it, so a page lagging behind a resize shows no white edge.
- (void)browser:(CraBrowser *)browser didReportBackgroundColor:(NSString *)hex;
/// Find in page progress: `count` matches, `activeMatch` is the highlighted one
/// (1-based). Either is -1 while Chromium has no new value for it.
@@ -166,6 +167,9 @@ typedef NS_ENUM(NSInteger, CraDownloadState) {
/// Asks the page for its background colour again (-browser:didReportBackgroundColor:);
/// pages can switch themes without a load.
- (void)probeBackgroundColor;
+/// What the page area shows before a page reports its background: Arc's black while
+/// websites are dark, white while they are light.
+@property (class, nonatomic, readonly) NSColor *pageCanvasColor;
/// Runs script in this browser's DevTools frontend, if open (debug aid behind cra://debug?devtoolsjs=).
- (void)executeJavaScript:(NSString *)script inDevTools:(BOOL)inDevTools;
/// Runtime.evaluate (`params` without a context) in the main frame's isolated world `world`,
diff --git a/Tests/BrowserManagerLifecycleTests.swift b/Tests/BrowserManagerLifecycleTests.swift
index db2c830..27fe624 100644
--- a/Tests/BrowserManagerLifecycleTests.swift
+++ b/Tests/BrowserManagerLifecycleTests.swift
@@ -81,6 +81,7 @@ enum BrowserManagerLifecycleTests {
devToolsCase()
await beforeUnloadCase()
nowPlayingCase()
+ pageColoursCase()
await sleepCase("malformed or missing replies cannot authorize sleeping", reply: nil) { _, _ in }
print("Browser manager lifecycle: \(checks) checks passed")
}
@@ -290,6 +291,31 @@ enum BrowserManagerLifecycleTests {
manager.closeAll()
}
+ /// A woken page's toolbar starts in the colour its page last reported (Arc, #46), and a tab
+ /// coming on screen asks its page for its background again unless the page is still loading.
+ @MainActor
+ private static func pageColoursCase() {
+ let store = SidebarStore()
+ let manager = BrowserManager(store: store, favicons: FaviconCache(), container: NSView())
+ let a = store.createTab(url: "https://example.test/dark").id, b = store.createTab(url: "https://example.test/other").id
+ let ra = manager.ensureRuntime(for: a)!
+ expect(ra.themeColor.isEmpty, "a page that never reported has no toolbar colour")
+ manager.browser(ra.browser, didReportThemeColor: "#203040")
+ expect(store.item(a)?.tab?.themeColor == "#203040", "the reported toolbar colour is kept on the tab")
+ manager.unload(a)
+ let woken = manager.ensureRuntime(for: a)!
+ expect(woken !== ra && woken.themeColor == "#203040", "the woken page's toolbar starts in its saved colour")
+ let rb = manager.ensureRuntime(for: b)!
+ rb.browser.setLoading(true)
+ manager.show(b, focus: false)
+ expect(rb.browser.backgroundProbes == 0, "a page still loading is not asked: it has no styles yet")
+ manager.show(a, focus: false)
+ expect(woken.browser.backgroundProbes == 1, "a loaded page coming on screen is asked for its background")
+ manager.show(a, focus: false)
+ expect(woken.browser.backgroundProbes == 1, "one already on screen is not asked again")
+ manager.closeAll()
+ }
+
@MainActor
private static func drainMainQueue() async {
await withCheckedContinuation { continuation in DispatchQueue.main.async { continuation.resume() } }
diff --git a/Tests/BrowserManagerSupport/AppServices.swift b/Tests/BrowserManagerSupport/AppServices.swift
index 9795b99..042bac7 100644
--- a/Tests/BrowserManagerSupport/AppServices.swift
+++ b/Tests/BrowserManagerSupport/AppServices.swift
@@ -3,7 +3,7 @@ import CraCEF
// Unrelated shell services required to typecheck the complete production manager.
// The tab store deliberately remains observable so stale callbacks can be asserted.
-struct TestTab { var url: String; var savedTitle = ""; var muted = false; var faviconKey: String? }
+struct TestTab { var url: String; var savedTitle = ""; var muted = false; var faviconKey: String?; var themeColor: String? }
struct TestItem {
let id: UUID
var tab: TestTab?
@@ -26,6 +26,7 @@ enum TestRoot { case today }
if let url { items[id]?.tab?.url = url }
if let title { items[id]?.tab?.savedTitle = title }
}
+ func setThemeColor(_ id: UUID, _ hex: String) { items[id]?.tab?.themeColor = hex }
func recordVisit(url: String, title: String) {}
func selectTab(_ id: UUID, window: UUID?) {}
func markUnread(_ id: UUID, _ unread: Bool) {}
diff --git a/Tests/BrowserManagerSupport/CraCEF.swift b/Tests/BrowserManagerSupport/CraCEF.swift
index 9331ae6..2f6a50e 100644
--- a/Tests/BrowserManagerSupport/CraCEF.swift
+++ b/Tests/BrowserManagerSupport/CraCEF.swift
@@ -49,6 +49,8 @@ public final class CraBrowser {
public func showDevTools() { hasDevTools = true; devToolsRequests.append("show") }
public func closeDevTools() { hasDevTools = false; devToolsRequests.append("close") }
public func setAudioMuted(_ muted: Bool) {}
+ public private(set) var backgroundProbes = 0
+ public func probeBackgroundColor() { backgroundProbes += 1 }
public func setFocused(_ focused: Bool) {}
public func requestPictureInPicture(automatic: Bool) {}
public func exitPictureInPicture() { isInPictureInPicture = false }
diff --git a/Tests/StoreTests.swift b/Tests/StoreTests.swift
index 8a695f5..15cab02 100644
--- a/Tests/StoreTests.swift
+++ b/Tests/StoreTests.swift
@@ -23,6 +23,7 @@ enum StoreTests {
liveFolderExpiry()
stampsUseTheClock()
persistenceFaults()
+ incognitoStaysOffDisk()
print("Store: \(checks) checks passed")
}
@@ -204,6 +205,41 @@ enum StoreTests {
expect(CraLog.faultCount == before + 3, "a write that fails is a fault")
}
+ /// Incognito tabs never reach sidebar.json (#46's review: updateTab saved every item), and
+ /// what older versions left there goes on load instead of turning into a normal tab.
+ @MainActor
+ private static func incognitoStaysOffDisk() {
+ let store = AppComposition(clock: ManualScheduler()).store
+ let normal = store.createTab(url: "https://example.com/normal")
+ let window = store.addIncognitoWindow(frame: nil)
+ let secret = store.createTab(url: "https://example.com/secret", in: window.focusedSpaceID, select: false)
+ store.updateTab(secret.id, url: "https://example.com/secret-later", title: "Secret")
+ store.setThemeColor(secret.id, "#101010")
+ expect(store.item(secret.id)?.tab?.themeColor == nil, "an incognito tab keeps no toolbar colour")
+ store.setThemeColor(normal.id, "#203040")
+ store.updateTab(normal.id, title: "Normal")
+ // Both save on a 2 s debounce on the persistence queue, not on the clock.
+ Thread.sleep(forTimeInterval: 2.5)
+ // JSONEncoder writes "/" as "\/".
+ let saved = ((try? String(contentsOf: AppPaths.file("sidebar.json"), encoding: .utf8)) ?? "").replacingOccurrences(of: "\\/", with: "/")
+ expect(saved.contains("https://example.com/normal") && saved.contains("#203040"), "a normal tab and its toolbar colour are saved")
+ expect(!saved.contains("example.com/secret") && !saved.contains("Secret"), "nothing of the incognito tab is")
+ let reloaded = AppComposition(clock: ManualScheduler()).store
+ expect(reloaded.item(normal.id)?.tab?.themeColor == "#203040", "the toolbar colour reads back after a relaunch")
+
+ // What 0.1.23 left behind when it crashed with an incognito window open.
+ var container = SidebarItem.container(.today(spaceID: UUID()))
+ let leftover = SidebarItem.tab("https://example.com/left-behind", title: "Left behind", parent: container.id)
+ container.children = [leftover.id]
+ store.items[container.id] = container
+ store.items[leftover.id] = leftover
+ store.repair()
+ expect(store.item(container.id) == nil && store.item(leftover.id) == nil, "a gone space's container goes with its tabs")
+ expect(!store.allTabs().contains { $0.tab?.url == "https://example.com/left-behind" }, "rather than landing in a space")
+ expect(store.item(secret.id) != nil, "an open incognito window keeps its tabs")
+ expect(store.integrityProblems().isEmpty, "and the sidebar stays sound")
+ }
+
private static func expect(_ condition: @autoclosure () -> Bool, _ message: String) {
guard condition() else {
FileHandle.standardError.write(Data("FAIL: \(message)\n".utf8))
diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.md
index ee94694..5d93c58 100644
--- a/docs/arc-reverse-engineering.md
+++ b/docs/arc-reverse-engineering.md
@@ -1920,3 +1920,26 @@ where Arc's is flat [U].
for a new-tab bar (not ⌘L, not an empty split pane) and cleared when the bar closes, before a commit selects
its tab. Settings ▸ Tabs "Show the New Tab button above tabs" defaults on; settings saved by 0.1.15–0.1.23
(always off) move to on once (`newTabButtonDefaultMigrated`).
+
+## The page area before a page paints (Arc 1.171, 1 Nov 2026, issue #46, 90–120 fps app-only recordings)
+
+Test page: `html{background:#203040}` behind a 1.5 s busy-wait in `<head>`, so nothing paints for 1.5 s.
+macOS in Dark, Victor's JYSK space, View ▸ Appearance ("Websites, Easels, and Notes will use") on Automatic.
+
+| Case | Page area until the first paint | Toolbar until the page reports a colour |
+|---|---|---|
+| Switching between loaded tabs | none: the next page's frame comes straight after | the page's colour |
+| New tab or Little Arc, a page Arc has never shown | #000000 | #FFFFFF |
+| A tab restored unloaded after relaunch (Cra's slept tab) | #000000 | the page's last colour, remembered across the relaunch |
+| Same, Appearance set to Light | #FFFFFF | (not measured) |
+
+So the fill follows the appearance websites get (black or white, not Chromium's #121212 canvas), and Arc
+remembers a tab's toolbar colour but not its page colour. Cra 0.1.23 showed #FFFFFF in the page area and the
+toolbar for both loading cases (169 frames at 120 fps on the test page). Cra now fills the CEF view and the
+pane card with the canvas (CraBrowser.pageCanvasColor), saves the toolbar colour on the tab (TabData.themeColor)
+and seeds it into a woken or restored tab's runtime.
+
+CEF still draws the first page of a new renderer transparent (chromiumembedded/cef#3891): with a black
+canvas, an unstyled page (no background, no color-scheme) showed black text on black until its load ended
+(4 s with a slow image). The page now reports its background on every frame while it is parsed
+(kLoadingBackgroundProbe; frames wait for render-blocking stylesheets), so it turns white with its first paint.