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.

Developer Mode shows its bar with the toolbar hidden, as in Arc (#185)

Victor9059477e9af7
diff --git a/Packages/CraCore/Sources/CraCore/SidebarModel.swift b/Packages/CraCore/Sources/CraCore/SidebarModel.swift
index 8cb044e..988a2db 100644
--- a/Packages/CraCore/Sources/CraCore/SidebarModel.swift
+++ b/Packages/CraCore/Sources/CraCore/SidebarModel.swift
@@ -543,6 +543,12 @@ public struct AppSettings: Codable, Equatable {
set { defaultLinkDestination = newValue ? .littleWindow : .mostRecentSpace }
}
public func isDeveloperMode(url: String) -> Bool { AppSettings.siteKey(for: url).map(developerHosts.contains) ?? false }
+ /// Whether a page shown alone carries a bar above it: the toolbar while it is shown, and
+ /// Arc's developer bar on a Developer Mode site even with the toolbar hidden (#185). A
+ /// split's panes always carry bars (#178); the shell adds that rule.
+ public func showsBar(above url: String?) -> Bool {
+ showToolbar || url.map(isDeveloperMode) == true
+ }
public mutating func toggleDeveloperMode(url: String) {
guard let k = AppSettings.siteKey(for: url) else { return }
if developerHosts.contains(k) { developerHosts.remove(k) } else { developerHosts.insert(k) }
diff --git a/Packages/CraCore/Tests/CraCoreTests/SidebarModelTests.swift b/Packages/CraCore/Tests/CraCoreTests/SidebarModelTests.swift
index 5f607ff..86450db 100644
--- a/Packages/CraCore/Tests/CraCoreTests/SidebarModelTests.swift
+++ b/Packages/CraCore/Tests/CraCoreTests/SidebarModelTests.swift
@@ -151,6 +151,21 @@ struct SidebarModelTests {
#expect(settings.developerHosts.isEmpty, "no host, nothing to toggle")
}
+ /// #185: Developer Mode from the Site Control Center showed nothing with the toolbar hidden
+ /// (Cra's default). Arc shows its developer bar above that site's pages anyway.
+ @Test func developerBarShowsWithTheToolbarHidden() {
+ var settings = AppSettings()
+ #expect(!settings.showToolbar)
+ #expect(!settings.showsBar(above: "https://example.com/a"))
+ #expect(!settings.showsBar(above: nil), "no tab, no bar")
+ settings.toggleDeveloperMode(url: "https://example.com/")
+ #expect(settings.showsBar(above: "https://example.com/a"))
+ #expect(!settings.showsBar(above: "https://other.org/"), "only the site in Developer Mode")
+ #expect(!settings.showsBar(above: ""), "an empty tab has no site")
+ settings.showToolbar = true
+ #expect(settings.showsBar(above: "https://other.org/") && settings.showsBar(above: nil))
+ }
+
@Test func toolbarShowsTheHostOnlyUnlessAsked() throws {
#expect(!AppSettings().toolbarShowsFullURL, "Arc's default: the host only")
let decode = { (json: String) in try JSONDecoder().decode(AppSettings.self, from: Data(json.utf8)) }
diff --git a/Sources/Cra/UI/ShellView.swift b/Sources/Cra/UI/ShellView.swift
index 715472e..48678fc 100644
--- a/Sources/Cra/UI/ShellView.swift
+++ b/Sources/Cra/UI/ShellView.swift
@@ -121,6 +121,8 @@ final class ShellView: NSView {
var contentFullscreen = false { didSet { needsLayout = true } }
/// Settings ▸ "Pages fill the window edge to edge" (GitHub #24): no margin, square cards.
var edgeToEdge = false { didSet { needsLayout = true } }
+ /// Whether a lone page has a bar: the toolbar, or the developer bar on a Developer Mode site
+ /// (AppSettings.showsBar(above:), #185).
var showToolbar = true { didSet { needsLayout = true } }
/// Whether the cards carry their bars. Arc keeps every pane's bar in a split even with the
/// toolbar hidden (View ▸ Show Toolbar is disabled while a split is open, GitHub #178).
diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swift
index 4231149..c002a9e 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -107,7 +107,7 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
onClose: { [weak self] in self?.hideFindBar() }))
shell.sidebarWidth = CGFloat(store.prefs.sidebarWidth)
shell.sidebarVisible = sidebarVisible
- shell.showToolbar = store.settings.showToolbar
+ shell.showToolbar = store.settings.showsBar(above: selectedTabID.flatMap { store.item($0)?.tab?.url })
shell.edgeToEdge = store.settings.edgeToEdgeContent
lastSidebarVisible = sidebarVisible
window.trafficLightsHidden = !sidebarVisible
@@ -311,10 +311,14 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
// Toolbar buttons are ~34 pt wide and the click lands near the middle: the popup's
// right edge lines up with the button's (Chrome anchors popups that way).
sidebarActions.runExtension = { [weak self] id in
+ guard let self else { return }
let button = Self.extensionButtonUnderPointer()
- // A pin in the sidebar's grid (toolbar hidden) hangs its popup under its own button.
- self?.runExtensionAction(id, buttonRightX: button?.maxX ?? NSEvent.mouseLocation.x + 17,
- buttonBottomY: self?.store.settings.showToolbar == false ? button?.minY : nil)
+ // A pin in the sidebar's grid (toolbar hidden) hangs its popup under its own button; one in
+ // a bar above the page (the toolbar, a split pane's, the developer bar) under that bar.
+ let inBar = button.map { self.isInPaneBar($0) } ?? false
+ self.runExtensionAction(id, buttonRightX: button?.maxX ?? NSEvent.mouseLocation.x + 17,
+ buttonBottomY: inBar ? self.toolbarBottomOnScreen()?.y
+ : self.store.settings.showToolbar == false ? button?.minY : nil)
}
sidebarActions.showExtensionsMenu = { [weak self] in self?.showToolbarExtensionsMenu() }
sidebarActions.paneRunExtension = { [weak self] pane, id in
@@ -430,7 +434,9 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
let split = selected.flatMap { store.splitContaining($0) }
let factors = SplitPaneLayout.normalizedFactors(ids: panes, stored: split?.split?.widthFactors ?? [:])
let empty = Set(panes.filter { store.item($0)?.isEmptyTab == true })
- if shell.showToolbar != store.settings.showToolbar { shell.showToolbar = store.settings.showToolbar }
+ // A lone page's bar: the toolbar, or the developer bar on a Developer Mode site (#185).
+ let loneBar = store.settings.showsBar(above: panes.count == 1 ? store.item(panes[0])?.tab?.url : nil)
+ if shell.showToolbar != loneBar { shell.showToolbar = loneBar }
if shell.edgeToEdge != store.settings.edgeToEdgeContent { shell.edgeToEdge = store.settings.edgeToEdgeContent }
// Before setPanes: a pane whose page is not live yet gets its bar colour now, not white.
let bars = toolbarColors(panes: panes)
@@ -2170,6 +2176,15 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
return rect.maxY - CraMetrics.titleAreaHeight - 2 - 36
}
+ /// Whether a button (screen rect) sits in a bar above a page rather than in the sidebar.
+ private func isInPaneBar(_ button: NSRect) -> Bool {
+ guard shell.panesShowBars, let window else { return false }
+ let mid = NSPoint(x: button.midX, y: button.midY)
+ return shell.paneCards.contains { card in
+ window.convertToScreen(card.toolbarHost.convert(card.toolbarHost.bounds, to: nil)).contains(mid)
+ }
+ }
+
/// Under the extension's pinned toolbar button when the toolbar shows one, else under the
/// toolbar at the card's right end.
fileprivate func extensionPopupAnchor(_ id: String) -> NSPoint? {
@@ -2189,7 +2204,7 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
let browser = currentBrowser
let anchor = bar.map { bar in
// Under the URL bar, or under a grid pin lower down.
- buttonRightX.map { x in NSPoint(x: x, y: min(buttonBottomY ?? .infinity, urlBarBottomOnScreen() ?? bar.y)) } ?? extensionPopupAnchor(id) ?? NSPoint(x: bar.cardMaxX - 8, y: bar.y)
+ buttonRightX.map { x in NSPoint(x: x, y: buttonBottomY ?? urlBarBottomOnScreen() ?? bar.y) } ?? extensionPopupAnchor(id) ?? NSPoint(x: bar.cardMaxX - 8, y: bar.y)
}
let available = profileExtensions
switch ExtensionLaunch.decide(id, available: available, hasPage: bar != nil && browser != nil) {
diff --git a/Tests/Scenarios/component-snapshots.scenario b/Tests/Scenarios/component-snapshots.scenario
index 54e32d4..a26b942 100644
--- a/Tests/Scenarios/component-snapshots.scenario
+++ b/Tests/Scenarios/component-snapshots.scenario
@@ -26,6 +26,12 @@ expect-log Cra suggest check for up .*command\("checkForUpdates"\) Check for Upd
cra://open?url=${PAGE}?n=snap
wait 3
snapshot SidebarURLPill url-pill
+# Developer Mode brings its bar with the toolbar hidden too, as Arc does (#185).
+cra://action/toggleDeveloperMode
+wait 2
+snapshot PaneToolbarView toolbar-developer
+cra://action/toggleDeveloperMode
+wait 1
cra://action/toggleToolbar
wait 1
snapshot PaneToolbarView toolbar