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.

Tidy Downloads' strike ends inside the card, its blue reads on a dark space, and the bin isn't clipped by the Library button (#197)

Quinn Battersby9f5c14b100de
diff --git a/Sources/Cra/UI/Sidebar/DownloadRenameCard.swift b/Sources/Cra/UI/Sidebar/DownloadRenameCard.swift
index f45dbae..7bf8101 100644
--- a/Sources/Cra/UI/Sidebar/DownloadRenameCard.swift
+++ b/Sources/Cra/UI/Sidebar/DownloadRenameCard.swift
@@ -67,7 +67,7 @@ final class DownloadRenameCard: NSView {
/// Arc drew it navy on a dark space; a light space's card is white (Arc's Max picture), not measured.
private func style() {
- let blue = NSColor(srgbRed: 0x34 / 255, green: 0x3B / 255, blue: 0xD1 / 255, alpha: 1)
+ let blue = NSColor(hex: dark ? "#929BFF" : "#343BD1")
shape.fillColor = (dark ? NSColor(srgbRed: 0x03 / 255, green: 0x06 / 255, blue: 0x1F / 255, alpha: 1) : .white).cgColor
shape.shadowColor = NSColor.black.cgColor
shape.shadowOpacity = dark ? 0 : 0.12
@@ -106,13 +106,14 @@ final class DownloadRenameCard: NSView {
// ↶ and ✕ centred 47 and 21 pt in from the right, 17 pt down.
close.frame = NSRect(x: w - 21 - 13, y: 17 - 13, width: 26, height: 26)
revert.frame = NSRect(x: w - 47 - 13, y: 17 - 13, width: 26, height: 26)
- // The strike runs through the old name's lower-case middle.
+ // The text field truncates long names. Keep the animated strike inside its text area too.
let f = oldName.font ?? .systemFont(ofSize: 12)
let ink = (oldName.stringValue as NSString).size(withAttributes: [.font: f]).width
+ let textFrame = oldName.frame.insetBy(dx: SidebarText.inset, dy: 0)
let midY = 50 + f.capHeight - f.xHeight / 2
let line = CGMutablePath()
- line.move(to: CGPoint(x: 13, y: midY))
- line.addLine(to: CGPoint(x: 13 + ink, y: midY))
+ line.move(to: CGPoint(x: textFrame.minX, y: midY))
+ line.addLine(to: CGPoint(x: textFrame.minX + min(ink, textFrame.width), y: midY))
strike.path = line
strike.frame = bounds
sparkles.frame = bounds
diff --git a/Sources/Cra/UI/Sidebar/List/SidebarView.swift b/Sources/Cra/UI/Sidebar/List/SidebarView.swift
index 384d024..f9c9dae 100644
--- a/Sources/Cra/UI/Sidebar/List/SidebarView.swift
+++ b/Sources/Cra/UI/Sidebar/List/SidebarView.swift
@@ -1057,8 +1057,10 @@ final class LibraryButtonView: NSView {
binTip = ArcTooltipAnchorView(frame: .zero)
super.init(frame: .zero)
wantsLayer = true
- layer?.cornerRadius = 7
- layer?.cornerCurve = .continuous
+ // Round the glyph's hover fill. Rounding the button itself clips the overhanging thumbnail.
+ glyph.wantsLayer = true
+ glyph.layer?.cornerRadius = 7
+ glyph.layer?.cornerCurve = .continuous
glyph.imageScaling = .scaleNone
glyph.image = LibraryGlyph.image(dark: false)
addSubview(glyph)
@@ -1069,7 +1071,7 @@ final class LibraryButtonView: NSView {
binImage.cornerRadius = 8
binImage.cornerCurve = .continuous
binImage.masksToBounds = true
- binImage.contentsGravity = .resizeAspectFill
+ binImage.contentsGravity = .resizeAspect
bin.layer?.addSublayer(binImage)
bin.addSubview(binTip)
bin.isHidden = true
@@ -1115,7 +1117,7 @@ final class LibraryButtonView: NSView {
}
private func refresh() {
- layer?.backgroundColor = (hovering ? colors.hoverFill : .clear).cgColor
+ glyph.layer?.backgroundColor = (hovering ? colors.hoverFill : .clear).cgColor
}
override func layout() {
diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swift
index 850b07c..86695c3 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -708,10 +708,12 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
scale: window?.backingScaleFactor ?? 2, representationTypes: .thumbnail)
let id = download.identifier
QLThumbnailGenerator.shared.generateBestRepresentation(for: request) { [weak self] thumbnail, _ in
- guard let image = thumbnail?.nsImage else { return }
+ let image = thumbnail?.nsImage
DispatchQueue.main.async {
guard let self, var recent = self.sidebarUI.recentDownload, recent.id == id else { return }
- recent.image = image
+ // The first progress update can lack a filename. Use the finished file's Finder
+ // icon if Quick Look has no preview, including after Tidy Downloads renamed it.
+ recent.image = image ?? NSWorkspace.shared.icon(forFile: recent.path)
self.sidebarUI.recentDownload = recent
}
}
diff --git a/Tests/Fixtures/Pages/downloads.html b/Tests/Fixtures/Pages/downloads.html
new file mode 100644
index 0000000..b67a7d2
--- /dev/null
+++ b/Tests/Fixtures/Pages/downloads.html
@@ -0,0 +1,7 @@
+<!doctype html>
+<meta charset="utf-8">
+<title>Download fixtures</title>
+<style>a { display: block; line-height: 32px; }</style>
+<a download="mini_christmas_tree_012345678901234567890123456789012345678901234567890123456789.3mf" href="data:application/octet-stream,long">Long filename</a>
+<a download="tree_01.3mf" href="data:application/octet-stream,short">Short filename</a>
+<a download="Swatch.png" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAAAYCAIAAADF1mwTAAAAP0lEQVR4nO3PUQ0AEBQAwJfEBBFFGkmEEEIrMjybv9uuwMWZNaX1/VVZIyUEBAQEBAQEBAQEBAQEBAQEBF4CF0T+vPmTFIVvAAAAAElFTkSuQmCC">Wide thumbnail</a>
diff --git a/Tests/Scenarios/tidy-downloads.scenario b/Tests/Scenarios/tidy-downloads.scenario
new file mode 100644
index 0000000..030ef4d
--- /dev/null
+++ b/Tests/Scenarios/tidy-downloads.scenario
@@ -0,0 +1,20 @@
+# A long original name is truncated in a narrow sidebar. Its animated strike must end
+# inside the card's right padding; the short name below should only be struck through its text.
+cra://open?url=file://${FIXTURES}/Pages/downloads.html
+expect-log loaded file:
+cra://debug?cdp=Input.dispatchMouseEvent&params={"type":"mousePressed","x":36,"y":24,"button":"left","clickCount":1}
+cra://debug?cdp=Input.dispatchMouseEvent&params={"type":"mouseReleased","x":36,"y":24,"button":"left","clickCount":1}
+expect-log Tidy Downloads: renamed a download
+wait 1
+snapshot DownloadRenameCard download-rename-long
+cra://debug?cdp=Input.dispatchMouseEvent&params={"type":"mousePressed","x":36,"y":56,"button":"left","clickCount":1}
+cra://debug?cdp=Input.dispatchMouseEvent&params={"type":"mouseReleased","x":36,"y":56,"button":"left","clickCount":1}
+expect-log Tidy Downloads: renamed a download \(11
+wait 1
+snapshot DownloadRenameCard download-rename-short
+# After the rename card leaves, the download preview still sits over the Library button.
+# Both ends of the wide swatch must reach past the edges of the underlying glyph.
+cra://debug?cdp=Input.dispatchMouseEvent&params={"type":"mousePressed","x":36,"y":88,"button":"left","clickCount":1}
+cra://debug?cdp=Input.dispatchMouseEvent&params={"type":"mouseReleased","x":36,"y":88,"button":"left","clickCount":1}
+wait 9
+snapshot SpaceDockView download-preview-dock
diff --git a/Tests/Snapshots/download-preview-dock.png b/Tests/Snapshots/download-preview-dock.png
new file mode 100644
index 0000000..5581420
Binary files /dev/null and b/Tests/Snapshots/download-preview-dock.png differ
diff --git a/Tests/Snapshots/download-rename-long.png b/Tests/Snapshots/download-rename-long.png
new file mode 100644
index 0000000..5bd2440
Binary files /dev/null and b/Tests/Snapshots/download-rename-long.png differ
diff --git a/Tests/Snapshots/download-rename-short.png b/Tests/Snapshots/download-rename-short.png
new file mode 100644
index 0000000..b85dd93
Binary files /dev/null and b/Tests/Snapshots/download-rename-short.png differ
diff --git a/scripts/scenario.sh b/scripts/scenario.sh
index 4f5a200..1654402 100755
--- a/scripts/scenario.sh
+++ b/scripts/scenario.sh
@@ -69,7 +69,16 @@ LOG="$DATA/cra.log"
STARTED="$OUT/started"
touch "$STARTED"
# Past onboarding, and nothing taken from this Mac's Arc (its toolbar default) unless asked.
-grep -q '^fresh' "$FILE" || echo '{"hasSeenImportPrompt": true, "toolbarDefaultMigrated": true, "showToolbar": false}' > "$DATA/settings.json"
+app_env=(env)
+if [ "$NAME" = "tidy-downloads" ]; then
+ # Use a disposable Downloads folder as well as a disposable browser profile.
+ mkdir -p "$DATA/home/Downloads"
+ app_env+=(CFFIXED_USER_HOME="$DATA/home" CRA_TIDY_FAKE_MODEL=1)
+ echo '{"hasSeenImportPrompt": true, "toolbarDefaultMigrated": true, "tidyDownloads": true}' > "$DATA/settings.json"
+ echo '{"sidebarWidth": 266}' > "$DATA/windows.json"
+elif ! grep -q '^fresh' "$FILE"; then
+ echo '{"hasSeenImportPrompt": true, "toolbarDefaultMigrated": true, "showToolbar": false}' > "$DATA/settings.json"
+fi
PIDS=()
PID=""
@@ -90,7 +99,7 @@ WEBKIT="http://localhost:${PORT}"
CRA_DATA_DIR="$DATA" CRA_COMMAND_FILE="$CMD" CRA_HITCH_LOG="$HITCH" CRA_TEST_BACKGROUND=1 CRA_WEBKIT_HOSTS=localhost \
CRA_ARC_DIR="$FIXTURES/Arc" CRA_FLAGS="${CRA_FLAGS:-}" \
- "$APP/Contents/MacOS/Cra" >"$OUT/stdout.log" 2>&1 &
+ "${app_env[@]}" "$APP/Contents/MacOS/Cra" >"$OUT/stdout.log" 2>&1 &
PID=$!
PIDS+=("$PID")