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.

The toolbar shows the host only, with Arc's Show Full URL, and its copy glyph hovers apart (#88)

Victor7aa74b39311f
diff --git a/Packages/CraCore/Sources/CraCore/SidebarModel.swift b/Packages/CraCore/Sources/CraCore/SidebarModel.swift
index 6ea93bb..c12eb20 100644
--- a/Packages/CraCore/Sources/CraCore/SidebarModel.swift
+++ b/Packages/CraCore/Sources/CraCore/SidebarModel.swift
@@ -419,6 +419,9 @@ public struct AppSettings: Codable, Equatable {
/// Cra 0.1.0 saved `showToolbar` as on for everyone; settings without this mark
/// take the toolbar from Arc's own preference once (off without Arc).
public var toolbarDefaultMigrated: Bool = true
+ /// Arc's "Show Full URL" on the toolbar address's menu (toolbarShowFullURLsEnabledPreference):
+ /// the normal bar shows the host and the dimmer path. Off like Arc, which shows the host only.
+ public var toolbarShowsFullURL: Bool = false
public var hasSeenImportPrompt: Bool = false
/// Arc's per-site Developer Mode (⌃D): the toolbar shows the full URL in
/// monospace with the developer icons, and the nav buttons move to the sidebar.
@@ -598,6 +601,7 @@ extension AppSettings {
if toolbarDefaultMigrated {
showToolbar = try c.decodeIfPresent(Bool.self, forKey: .showToolbar) ?? false
}
+ toolbarShowsFullURL = try c.decodeIfPresent(Bool.self, forKey: .toolbarShowsFullURL) ?? false
hasSeenImportPrompt = try c.decodeIfPresent(Bool.self, forKey: .hasSeenImportPrompt) ?? false
developerHosts = try c.decodeIfPresent(Set<String>.self, forKey: .developerHosts) ?? []
chromeEngine = try c.decodeIfPresent(Bool.self, forKey: .chromeEngine) ?? true
diff --git a/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/settings-bad-routes.json b/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/settings-bad-routes.json
index c5d062c..d9278e2 100644
--- a/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/settings-bad-routes.json
+++ b/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/settings-bad-routes.json
@@ -34,5 +34,6 @@
"tabSleep" : "oneHour",
"tabSleepEnabled" : false,
"toolbarDefaultMigrated" : true,
+ "toolbarShowsFullURL" : false,
"warnBeforeQuitting" : false
}
\ No newline at end of file
diff --git a/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/settings-empty.json b/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/settings-empty.json
index 637a6ec..f287642 100644
--- a/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/settings-empty.json
+++ b/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/settings-empty.json
@@ -43,5 +43,6 @@
"tabSleep" : "oneHour",
"tabSleepEnabled" : false,
"toolbarDefaultMigrated" : true,
+ "toolbarShowsFullURL" : false,
"warnBeforeQuitting" : false
}
\ No newline at end of file
diff --git a/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/settings-legacy.json b/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/settings-legacy.json
index d397d38..4b0bb6b 100644
--- a/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/settings-legacy.json
+++ b/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/settings-legacy.json
@@ -43,5 +43,6 @@
"tabSleep" : "oneHour",
"tabSleepEnabled" : false,
"toolbarDefaultMigrated" : true,
+ "toolbarShowsFullURL" : false,
"warnBeforeQuitting" : false
}
\ No newline at end of file
diff --git a/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/settings.json b/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/settings.json
index 0cda852..edb37f0 100644
--- a/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/settings.json
+++ b/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/settings.json
@@ -53,5 +53,6 @@
"tabSleep" : "fourHours",
"tabSleepEnabled" : true,
"toolbarDefaultMigrated" : true,
+ "toolbarShowsFullURL" : false,
"warnBeforeQuitting" : true
}
\ No newline at end of file
diff --git a/Packages/CraCore/Tests/CraCoreTests/SidebarModelTests.swift b/Packages/CraCore/Tests/CraCoreTests/SidebarModelTests.swift
index bb3c93b..e84a87a 100644
--- a/Packages/CraCore/Tests/CraCoreTests/SidebarModelTests.swift
+++ b/Packages/CraCore/Tests/CraCoreTests/SidebarModelTests.swift
@@ -120,6 +120,16 @@ struct SidebarModelTests {
#expect(settings.developerHosts.isEmpty, "no host, nothing to toggle")
}
+ @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)) }
+ #expect(try !decode("{}").toolbarShowsFullURL, "settings from before the option keep Arc's default")
+ #expect(try decode(#"{"toolbarShowsFullURL": true}"#).toolbarShowsFullURL)
+ var settings = AppSettings()
+ settings.toolbarShowsFullURL = true
+ #expect(try JSONDecoder().decode(AppSettings.self, from: JSONEncoder().encode(settings)).toolbarShowsFullURL)
+ }
+
@Test func littleWindowSwitchIsTheDefaultDestination() {
var settings = AppSettings()
#expect(settings.openExternalLinksInLittleWindow)
diff --git a/Sources/Cra/Services/Import/Importers.swift b/Sources/Cra/Services/Import/Importers.swift
index cc1d7ba..ddda8ec 100644
--- a/Sources/Cra/Services/Import/Importers.swift
+++ b/Sources/Cra/Services/Import/Importers.swift
@@ -52,11 +52,12 @@ struct ImportedSettings {
var autoArchive: AutoArchiveThreshold?
var sidebarWidth: Double?
var showToolbar: Bool?
+ var toolbarShowsFullURL: Bool?
var linkRoutes: [ImportedLinkRoute] = []
var defaultLinkDestination: ImportedLinkDestination?
var isEmpty: Bool {
- autoArchive == nil && sidebarWidth == nil && showToolbar == nil && linkRoutes.isEmpty && defaultLinkDestination == nil
+ autoArchive == nil && sidebarWidth == nil && showToolbar == nil && toolbarShowsFullURL == nil && linkRoutes.isEmpty && defaultLinkDestination == nil
}
}
@@ -120,6 +121,11 @@ enum ArcImporter {
UserDefaults(suiteName: "company.thebrowser.Browser")?.object(forKey: "topBarURLEnabled") as? Bool
}
+ /// Arc's "Show Full URL" on the toolbar address (off by default); nil when Arc never stored it.
+ static var showsFullURL: Bool? {
+ UserDefaults(suiteName: "company.thebrowser.Browser")?.object(forKey: "toolbarShowFullURLsEnabledPreference") as? Bool
+ }
+
static func plan() throws -> ImportPlan {
let url = supportDir.appendingPathComponent("StorableSidebar.json")
guard let data = try? Data(contentsOf: url) else { throw ImportError.notFound("Arc") }
@@ -219,6 +225,7 @@ enum ArcImporter {
plan.settings.autoArchive = AutoArchiveThreshold(rawValue: threshold)
}
plan.settings.showToolbar = showsToolbar
+ plan.settings.toolbarShowsFullURL = showsFullURL
if let ldata = try? Data(contentsOf: supportDir.appendingPathComponent("StorableLinkRouting.json")),
let lroot = try? JSONSerialization.jsonObject(with: ldata) as? [String: Any] {
plan.settings.defaultLinkDestination = linkDestination(lroot["defaultDestination"], spaceTitles: spaceTitleByID)
@@ -482,6 +489,7 @@ extension SidebarStore {
if let a = plan.settings.autoArchive { settings.autoArchive = a }
if let w = plan.settings.sidebarWidth { prefs.sidebarWidth = min(max(w, 220), 520) }
if let t = plan.settings.showToolbar { settings.showToolbar = t }
+ if let f = plan.settings.toolbarShowsFullURL { settings.toolbarShowsFullURL = f }
// Air Traffic Control, pointed at the spaces of the same name.
func destination(_ d: ImportedLinkDestination) -> LinkDestination {
switch d {
diff --git a/Sources/Cra/UI/PaneToolbarView.swift b/Sources/Cra/UI/PaneToolbarView.swift
index ded18d2..6112b40 100644
--- a/Sources/Cra/UI/PaneToolbarView.swift
+++ b/Sources/Cra/UI/PaneToolbarView.swift
@@ -80,6 +80,8 @@ final class PaneToolbarView: NSView {
addSubview(stripes)
placeholderLabel.stringValue = "Search or Enter URL…"
urlButton.action = { [weak self] in self?.editURL() }
+ urlButton.onCopy = { [weak self] in self?.copyURL() }
+ urlButton.menuProvider = { [weak self] in self?.addressMenu() }
urlButton.onCommit = { [weak self] in self?.actions.loadTyped($0) }
urlButton.onEditingChange = { [weak self] in self?.editVeil.isHidden = !$0 }
editVeil.wantsLayer = true
@@ -140,7 +142,8 @@ final class PaneToolbarView: NSView {
m.url = t.url
let human = SuggestionEngine.humanURL(t.url)
m.host = AppSettings.siteKey(for: t.url) ?? human
- m.path = human.hasPrefix(m.host) ? String(human.dropFirst(m.host.count)) : ""
+ // Arc shows the host only unless "Show Full URL" is on (#88).
+ m.path = store.settings.toolbarShowsFullURL && human.hasPrefix(m.host) ? String(human.dropFirst(m.host.count)) : ""
}
let extensions = ExtensionStore.shared
let entries = extensions.entries(inProfile: item.map { store.profileDirectoryName(item: $0.id) }
@@ -300,7 +303,7 @@ final class PaneToolbarView: NSView {
// Arc's developer URL has no hover fill (it edits in place on a click).
let urlHover = m.kind == .developer ? NSColor.clear : NSColor.white.withAlphaComponent(0.08)
urlButton.show(host: m.host, path: m.path, url: m.url, developer: m.kind == .developer, status: m.status,
- fg: m.fg, fgDim: m.fgDim, hover: urlHover, animated: old.status?.id != m.status?.id && window != nil)
+ fg: m.fg, fgDim: m.fgDim, hover: urlHover, copyHover: m.hover, animated: old.status?.id != m.status?.id && window != nil)
urlButton.selection = m.selection
case .noTab, .emptyPane:
urlButton.isHidden = true
@@ -406,6 +409,26 @@ final class PaneToolbarView: NSView {
if let id = paneTabID { actions.editPaneURL(id) } else { actions.openCommandBar(model.kind == .noTab ? .newTab : .editURL) }
}
+ private func copyURL() {
+ if let id = paneTabID { actions.focusPane(id) }
+ actions.performAction("copyURL")
+ }
+
+ /// Arc's menu on the toolbar address: Copy URL, and Show Full URL / Hide Full URL for the
+ /// normal bar (the developer bar always shows it).
+ private func addressMenu() -> NSMenu? {
+ guard model.kind == .normal || model.kind == .developer else { return nil }
+ let menu = NSMenu()
+ menu.addItem(ToolbarMenuAction.item("Copy URL", { [weak self] in self?.copyURL() }))
+ if model.kind == .normal {
+ let full = store.settings.toolbarShowsFullURL
+ menu.addItem(ToolbarMenuAction.item(full ? "Hide Full URL" : "Show Full URL", { [weak self] in
+ self?.store.settings.toolbarShowsFullURL.toggle()
+ }))
+ }
+ return menu
+ }
+
private func showSplitMenu(from view: NSView?) {
guard let id = paneTabID, let view else { return }
let menu = NSMenu()
@@ -562,10 +585,14 @@ final class ToolbarGlyphButton: NSView {
override func menu(for event: NSEvent) -> NSMenu? { menuProvider?() }
}
-/// The URL in the middle of the bar: link glyph, host bright and path dimmer (the full URL in
-/// monospace after a lock in developer mode), or the nav-bar status in its place.
+/// The URL in the middle of the bar: Arc's Copy Current URL glyph and the host (the dimmer path
+/// after it with Show Full URL; the full URL in monospace after a lock in developer mode), or the
+/// nav-bar status in its place.
final class ToolbarURLButton: NSView, NSTextFieldDelegate {
var action: () -> Void = {}
+ /// The link glyph's own click (Copy Current URL) and the address's right-click menu.
+ var onCopy: () -> Void = {}
+ var menuProvider: (() -> NSMenu?)?
/// Developer mode's in-place address field: the text Return submits, and editing starting/ending.
var onCommit: (String) -> Void = { _ in }
var onEditingChange: (Bool) -> Void = { _ in }
@@ -576,28 +603,46 @@ final class ToolbarURLButton: NSView, NSTextFieldDelegate {
private var url = ""
private var ink = NSColor.white
private var press = WindowDragGesture()
+ private var contextClick = false
private let content = NSView()
private let icon = NSImageView()
private let label = NSTextField.sidebarLabel(size: 13)
private let tip: ArcTooltipAnchorView
+ private let copyTip: ArcTooltipAnchorView
private var developer = false
private var hover = NSColor.white.withAlphaComponent(0.08)
- private var hovering = false { didSet { refreshFill() } }
+ private var copyHover = NSColor.white.withAlphaComponent(0.1)
+ /// Arc's normal bar (1.171, #88): the glyph is a 24 pt button of its own and the host has its
+ /// own pill, 24 pt tall, starting 20 pt in with the text 7 pt inside it. Each has its own hover;
+ /// the pointer picks one where they meet. A status or the developer bar is one piece.
+ private var split = false
+ private enum Region { case none, copy, address }
+ private var region = Region.none { didSet { if region != oldValue { refreshFill() } } }
+ private let copyFill = NSView()
+ private let addressFill = NSView()
+ private static let copyBox: CGFloat = 24, pillStart: CGFloat = 20, textStart: CGFloat = 27, pillPad: CGFloat = 7
override init(frame: NSRect) {
tip = ArcTooltipAnchorView(frame: .zero)
+ copyTip = ArcTooltipAnchorView(frame: .zero)
super.init(frame: frame)
wantsLayer = true
layer?.cornerCurve = .continuous
+ for f in [copyFill, addressFill] {
+ f.wantsLayer = true
+ f.layer?.cornerRadius = 7
+ f.layer?.cornerCurve = .continuous
+ addSubview(f)
+ }
icon.imageScaling = .scaleNone
content.wantsLayer = true
content.addSubview(icon)
content.addSubview(label)
addSubview(content)
tip.followsCursor = true
- tip.frame = bounds
- tip.autoresizingMask = [.width, .height]
addSubview(tip)
+ (copyTip.text, copyTip.keys) = ArcTooltipLabel.split("Copy URL (⇧⌘C)")
+ addSubview(copyTip)
}
required init?(coder: NSCoder) { fatalError() }
@@ -614,16 +659,20 @@ final class ToolbarURLButton: NSView, NSTextFieldDelegate {
/// The text's natural width plus padding; the bar centres and clips the button to it.
var idealWidth: CGFloat {
- ceil(10 + iconWidth + 7 + label.attributedStringValue.size().width + 10)
+ let text = label.attributedStringValue.size().width
+ return ceil(split ? Self.textStart + text + Self.pillPad : 10 + iconWidth + 7 + text + 10)
}
/// The glyph's own width, as SwiftUI lays an Image out; developer mode boxes it at 14 pt.
private var iconWidth: CGFloat { developer ? 14 : ceil(icon.image?.size.width ?? 12) }
func show(host: String, path: String, url: String, developer: Bool, status: ToolbarStatus?, fg: NSColor, fgDim: NSColor, hover: NSColor,
- animated: Bool) {
+ copyHover: NSColor, animated: Bool) {
self.developer = developer
self.hover = hover
+ self.copyHover = copyHover
+ split = !developer && status == nil
+ copyTip.isHidden = !split
self.url = url
ink = fg
field?.textColor = fg
@@ -660,6 +709,19 @@ final class ToolbarURLButton: NSView, NSTextFieldDelegate {
super.layout()
content.frame = bounds
let h = bounds.height
+ if split {
+ let box = Self.copyBox, y = (h - box) / 2
+ copyFill.frame = NSRect(x: 0, y: y, width: box, height: box)
+ addressFill.frame = NSRect(x: Self.pillStart, y: y, width: max(0, bounds.width - Self.pillStart), height: box)
+ icon.frame = NSRect(x: 0, y: 0, width: box, height: h)
+ let lh = label.intrinsicContentSize.height
+ label.frame = NSRect(x: Self.textStart - SidebarText.inset, y: (h - lh) / 2,
+ width: max(0, bounds.width - Self.textStart - Self.pillPad) + 2 * SidebarText.inset, height: lh)
+ copyTip.frame = NSRect(x: 0, y: 0, width: Self.pillStart, height: h)
+ tip.frame = NSRect(x: Self.pillStart, y: 0, width: max(0, bounds.width - Self.pillStart), height: h)
+ return
+ }
+ tip.frame = bounds
let pad: CGFloat = developer ? 6 : 10
let iconW = iconWidth
let gap: CGFloat = developer ? 12 : 7
@@ -735,23 +797,43 @@ final class ToolbarURLButton: NSView, NSTextFieldDelegate {
func controlTextDidEndEditing(_ obj: Notification) { endEditing(commit: false) }
private func refreshFill() {
- layer?.backgroundColor = (hovering ? hover : .clear).cgColor
+ layer?.backgroundColor = (!split && region != .none ? hover : .clear).cgColor
+ copyFill.layer?.backgroundColor = (split && region == .copy ? copyHover : .clear).cgColor
+ addressFill.layer?.backgroundColor = (split && region == .address ? hover : .clear).cgColor
+ }
+
+ private func region(at event: NSEvent) -> Region {
+ let p = convert(event.locationInWindow, from: nil)
+ guard bounds.contains(p) else { return .none }
+ return split && p.x < Self.pillStart ? .copy : .address
}
override func updateTrackingAreas() {
super.updateTrackingAreas()
for t in trackingAreas where t.owner === self { removeTrackingArea(t) }
- addTrackingArea(NSTrackingArea(rect: .zero, options: [.mouseEnteredAndExited, .activeAlways, .inVisibleRect], owner: self, userInfo: nil))
+ addTrackingArea(NSTrackingArea(rect: .zero, options: [.mouseEnteredAndExited, .mouseMoved, .activeAlways, .inVisibleRect], owner: self, userInfo: nil))
}
- override func mouseEntered(with event: NSEvent) { hovering = true }
- override func mouseExited(with event: NSEvent) { hovering = false }
- // Part of the bar: a click edits the URL, a drag moves the window like the rest of it.
- override func mouseDown(with event: NSEvent) { press.begin(event) }
- override func mouseDragged(with event: NSEvent) { press.drag(event) }
+ override func mouseEntered(with event: NSEvent) { region = region(at: event) }
+ override func mouseMoved(with event: NSEvent) { region = region(at: event) }
+ override func mouseExited(with event: NSEvent) { region = .none }
+ // Part of the bar: a click edits the URL (or copies it from the glyph), a drag moves the window
+ // like the rest of it.
+ override func mouseDown(with event: NSEvent) {
+ contextClick = event.modifierFlags.contains(.control)
+ if contextClick { if let menu = menu(for: event) { NSMenu.popUpContextMenu(menu, with: event, for: self) }; return }
+ press.begin(event)
+ }
+ override func mouseDragged(with event: NSEvent) { if !contextClick { press.drag(event) } }
override func mouseUp(with event: NSEvent) {
- if press.finish(), bounds.contains(convert(event.locationInWindow, from: nil)) { action() }
+ guard !contextClick, press.finish() else { return }
+ switch region(at: event) {
+ case .copy: onCopy()
+ case .address: action()
+ case .none: break
+ }
}
+ override func menu(for event: NSEvent) -> NSMenu? { field == nil ? menuProvider?() : nil }
}
/// Arc's developer-bar stripes (GitHub #42), measured on Arc 1.170 at 2x: white 2% bands at 45°
diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.md
index b4ea3fc..0f52dab 100644
--- a/docs/arc-reverse-engineering.md
+++ b/docs/arc-reverse-engineering.md
@@ -251,7 +251,7 @@ the frontend only offers when it can dock.
Arc's View ▸ Developer submenu (read via Accessibility): View Source ⌥⌘U, Developer Tools
⌥⌘I, Inspect Elements ⌥⌘C, JavaScript Console ⌥⌘J, "Turn off Developer Mode for this
site" ⌃D. ⇧⌘D is Hide Toolbar and ⌘D is Pin/Unpin Tab. Developer Mode is per site and
-swaps the toolbar: default = nav buttons left, centred friendly URL (host bright, path dim)
+swaps the toolbar: default = nav buttons left, centred host (path dim with Show Full URL)
behind a link glyph, sidebar toggle right; developer = lock + full monospace URL left,
copy/capture/DevTools/source icons right, nav buttons in the sidebar's title row. Cra
stores the hosts in `AppSettings.developerHosts`.
@@ -1931,9 +1931,17 @@ buttons accept first mouse while a child window is key. Clicks after the page ha
AX reads of Arc's windows, 1x window captures, and HID clicks while the Mac was idle:
-- [O] Normal bar address: `example.org/cra88/deep/path?q=1` shows host bright and path + query dim (AX
- static text carries all of it). Arc does not drop the path; Cra already matched. The link glyph before
- it is a separate button, "Copy Current URL".
+- [O] Normal bar address: `example.org/cra88/deep/path?q=1` showed host bright and path + query dim, but
+ only because Victor's Arc has **Show Full URL** on (`toolbarShowFullURLsEnabledPreference = 1`; the
+ reporter's screenshots, Arc's default, show `github.com` alone). The option is on the address's
+ right-click menu as "Show Full URL" / "Hide Full URL" (ArcCore strings, with "Copy URL" and "Hide
+ Toolbar"). Cra: `AppSettings.toolbarShowsFullURL`, off; the Arc import takes Arc's preference.
+- [O] The link glyph before the address is a button of its own, "Copy Current URL", 24 x 24 pt; the
+ address text starts 27 pt after the button's left edge (AX frames). Hovering the address lights a
+ 24 pt pill around the host only, 7 pt either side of the text, starting about 20 pt into the copy
+ button's box (reporter's 2x capture: glyph 14 pt at 34-48 pt, pill 49.75-132.5 pt, text 56.5-126 pt;
+ pill 86/86/86 on a 65/65/65 bar). Cra's ToolbarURLButton draws the two fills itself and gives the
+ 4 pt where they meet to the copy box.
- [O] Clicks: empty bar space left or right of the address opens nothing (window keyed by a page click
first, two runs, captures); the address opens the command bar; a click on the address while the bar
is open closes it and it stays closed; the next click opens it. Cra: PaneToolbarView only focuses its