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: the capture menu's New Easel

Victorc85c87881b54
diff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swift
index 65dc0a0..84faf9d 100644
--- a/Sources/Cra/App/AppDelegate.swift
+++ b/Sources/Cra/App/AppDelegate.swift
@@ -763,6 +763,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
// tidy: the divider's Tidy on the window's space, without hovering it; undoTidy: ⌘Z's.
if dict["tidy"] != nil { TidyTabsService.shared.tidy(store.focusedSpace(window: main.windowID).id, store: store); return }
if dict["undoTidy"] != nil { _ = store.undoTidy(); return }
+ // captureToEasel=1: the page's screenshot, then the capture menu's New Easel.
+ if dict["captureToEasel"] != nil { main.debugCaptureToEasel(); return }
// settingsPane=max: Settings opened on that pane.
if let p = dict["settingsPane"].flatMap(SettingsPane.init(rawValue:)) {
showSettingsWindow()
diff --git a/Sources/Cra/UI/Easel/EaselBrowser.swift b/Sources/Cra/UI/Easel/EaselBrowser.swift
index feec5f4..e7e80f1 100644
--- a/Sources/Cra/UI/Easel/EaselBrowser.swift
+++ b/Sources/Cra/UI/Easel/EaselBrowser.swift
@@ -129,6 +129,19 @@ enum EaselFiles {
}
static func load(_ id: UUID) -> Easel { store(id).load(or: { Easel(id: id) }) }
+ /// Arc's capture menu ▸ New Easel: an easel with the capture on it, under the title.
+ static func create(withPicture png: Data) -> Easel? {
+ guard let image = NSImage(data: png) else { return nil }
+ var easel = Easel()
+ let name = UUID().uuidString + ".png"
+ guard (try? png.write(to: pictures(easel.id).appendingPathComponent(name))) != nil else { return nil }
+ let scale = min(1, 640 / max(image.size.width, image.size.height, 1))
+ easel.items = [Easel.Item(kind: .image(file: name), frame: .init(x: 120, y: 160, width: image.size.width * scale,
+ height: image.size.height * scale))]
+ store(easel.id).saveNow(easel)
+ return easel
+ }
+
/// Every easel on disk, newest edit first, for Library ▸ Easels.
static func all() -> [(id: UUID, title: String, edited: Date)] {
let files = (try? FileManager.default.contentsOfDirectory(at: folder, includingPropertiesForKeys: [.contentModificationDateKey])) ?? []
diff --git a/Sources/Cra/UI/Windows/CaptureOverlay.swift b/Sources/Cra/UI/Windows/CaptureOverlay.swift
index 7365d6d..636b4d0 100644
--- a/Sources/Cra/UI/Windows/CaptureOverlay.swift
+++ b/Sources/Cra/UI/Windows/CaptureOverlay.swift
@@ -17,7 +17,7 @@ import UniformTypeIdentifiers
/// capture is exactly what was on screen. Decisions (picker, geometry) are in CraCore's ContentCapture.
@MainActor
final class CaptureOverlay {
- enum Action { case copy, save, message, retake }
+ enum Action { case copy, save, message, newEasel, retake }
private let panel: CapturePanel
private let view: CaptureView
@@ -779,8 +779,8 @@ final class CaptureBubble: NSView {
/// Arc's CapturedImageActionsView, dark whatever the theme: 273 pt wide, 10 pt corners, fill
/// (18,15,46); 40 pt rows with a 13 pt symbol centred 25 pt in at white 30 % and 14 pt medium text
/// from 41 pt at white 90 %; sections apart by 9 pt with a hairline 10 pt in from both sides.
-/// Arc's other rows (Send To… for Easels, Save to Library, Edit, New Easel) belong to features
-/// Cra doesn't have.
+/// Arc's New Easel row starts an easel with the capture on it; its other rows (Send To… an easel,
+/// Save to Library, Edit) Cra doesn't have yet.
final class CaptureMenu: NSView {
struct Row {
let title: String
@@ -797,6 +797,7 @@ final class CaptureMenu: NSView {
[Row(title: "Copy", symbol: "doc.on.doc.fill", action: .copy),
Row(title: "Save...", symbol: "square.and.arrow.down.fill", action: .save),
Row(title: "Send via iMessage...", symbol: "message.fill", action: .message)],
+ [Row(title: "New Easel", symbol: "pencil.and.scribble", action: .newEasel)],
[Row(title: "Retake", symbol: "arrow.counterclockwise", action: .retake)],
]
diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swift
index de96579..52e85ff 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -1853,6 +1853,18 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
return CGImageSourceCreateImageAtIndex(source, 0, nil)
}
+ /// Testing without the pointer (cra://debug?captureToEasel=1): the visible page captured and
+ /// the capture menu's New Easel chosen.
+ func debugCaptureToEasel() {
+ currentBrowser?.sendDevToolsMethod("Page.captureScreenshot", params: #"{"format":"png"}"#) { [weak self] shot, _ in
+ MainActor.assumeIsolated {
+ let o = shot.flatMap { try? JSONSerialization.jsonObject(with: Data($0.utf8)) as? [String: Any] }
+ let png = (o?["data"] as? String).flatMap { Data(base64Encoded: $0) }
+ self?.captureFinished(.newEasel, png)
+ }
+ }
+ }
+
/// The capture menu's choice, once the overlay is down.
private func captureFinished(_ action: CaptureOverlay.Action?, _ png: Data?) {
captureOverlay = nil
@@ -1869,6 +1881,9 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
if let png { saveCapture(png) }
case .message?:
if let png { sendCaptureViaMessages(png) }
+ case .newEasel?:
+ guard let png, let easel = EaselFiles.create(withPicture: png) else { return }
+ _ = store.createTab(url: easel.url, title: easel.title, select: true, window: windowID)
case .retake?:
capturePage()
case nil:
diff --git a/Tests/Scenarios/easel.scenario b/Tests/Scenarios/easel.scenario
index 64e6784..cf6167f 100644
--- a/Tests/Scenarios/easel.scenario
+++ b/Tests/Scenarios/easel.scenario
@@ -11,3 +11,11 @@ cra://debug?browserWindows=relaunched
expect-log browser windows relaunched: kind=normal listed=1 tabs=1 open=1
cra://action/viewEasels
wait 1
+# The capture menu's New Easel: an easel with the capture on it opens in a new tab (after the
+# relaunch only cra.log is read, which counts tabs rather than naming them).
+cra://open?url=${PAGE}?n=captured
+expect-log loaded 127\.0\.0\.1 \(HTTP 200\)
+cra://debug?captureToEasel=1
+wait 2
+cra://debug?browserWindows=captured
+expect-log browser windows captured: kind=normal listed=1 tabs=3 open=1
diff --git a/docs/arc-parity.md b/docs/arc-parity.md
index bef5c1b..4236b9a 100644
--- a/docs/arc-parity.md
+++ b/docs/arc-parity.md
@@ -15,7 +15,7 @@ or Arc-only service), per CONTRIBUTING.md.
| Arc feature | Where in Arc | Cra | Notes |
|---|---|---|---|
| Boosts (per-site CSS/JS, colours, fonts, Zap) | URL bar ✎, Library ▸ Boosts, Settings ▸ Advanced "Enable Boosts" | missing | Biggest local feature still absent. |
-| Easels | File ▸ New Easel ⌃⇧E, Library ▸ Easels | partial | File ▸ New Easel (⌃⇧E): canvas, title, Pointer/Image/Text/Ellipse/Rectangle/Arrow/Freehand, pictures by file, paste or drop, saved per easel. Library ▸ Easels and Window ▸ View Easels… done. The canvas shows the window's backdrop under a 50 % veil as in Arc. The toolbar strip above it takes the same veil. Missing: captures into an easel, Aa's choice of font (the pill's + and − work); sharing is *skip* (cloud). |
+| Easels | File ▸ New Easel ⌃⇧E, Library ▸ Easels | partial | File ▸ New Easel (⌃⇧E): canvas, title, Pointer/Image/Text/Ellipse/Rectangle/Arrow/Freehand, pictures by file, paste or drop, saved per easel. Library ▸ Easels and Window ▸ View Easels… done. The canvas shows the window's backdrop under a 50 % veil as in Arc. The toolbar strip above it takes the same veil. The capture menu's New Easel done. Missing: the capture menu's Send To… an existing easel, Aa's choice of font (the pill's + and − work); sharing is *skip* (cloud). |
| Notes | File ▸ New Note ⌃⇧N, ⌃⌥N in split, Help ▸ Export Arc Notes | *skip* | Arc 1.172.1 no longer creates Notes: New Note is gone from the File menu and ⌃⇧N does nothing; only Help ▸ Export Arc Notes is left. |
| Library ▸ Media | Window ▸ View Media…, Library rail | done | Off until Show Media; ⋯ picks the folders (Cra has no captures folder). |
| Essential Keyboard Shortcuts window | Help ▸ Essential Keyboard Shortcuts, Settings ▸ Shortcuts | done | 475×462 floating dark panel, five rows of key caps, "View All ↗". |