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 Send To… an easel

Victorb09185a4e350
diff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swift
index 84faf9d..205b7ac 100644
--- a/Sources/Cra/App/AppDelegate.swift
+++ b/Sources/Cra/App/AppDelegate.swift
@@ -764,7 +764,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
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 }
+ if let how = dict["captureToEasel"] { main.debugCaptureToEasel(send: how == "send"); 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 e7e80f1..3a09809 100644
--- a/Sources/Cra/UI/Easel/EaselBrowser.swift
+++ b/Sources/Cra/UI/Easel/EaselBrowser.swift
@@ -129,6 +129,20 @@ enum EaselFiles {
}
static func load(_ id: UUID) -> Easel { store(id).load(or: { Easel(id: id) }) }
+ /// Arc's capture menu ▸ Send To…: the capture added below what the easel holds.
+ static func add(picture png: Data, to id: UUID) -> Bool {
+ guard let image = NSImage(data: png) else { return false }
+ var easel = load(id)
+ let name = UUID().uuidString + ".png"
+ guard (try? png.write(to: pictures(id).appendingPathComponent(name))) != nil else { return false }
+ let scale = min(1, 640 / max(image.size.width, image.size.height, 1))
+ let bottom = easel.items.map { $0.frame.y + $0.frame.height }.max() ?? 160
+ easel.items.append(Easel.Item(kind: .image(file: name), frame: .init(x: 120, y: bottom + 40, width: image.size.width * scale,
+ height: image.size.height * scale)))
+ store(id).saveNow(easel)
+ return true
+ }
+
/// 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 }
diff --git a/Sources/Cra/UI/Windows/CaptureOverlay.swift b/Sources/Cra/UI/Windows/CaptureOverlay.swift
index 636b4d0..31e4988 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, newEasel, retake }
+ enum Action { case copy, save, message, newEasel, sendToEasel, 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 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.
+/// Arc's Send To… puts the capture on an easel you pick, New Easel starts one with it; its other
+/// rows (Save to Library, Edit) Cra doesn't have yet.
final class CaptureMenu: NSView {
struct Row {
let title: String
@@ -797,7 +797,8 @@ 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: "Send To…", symbol: "paperplane.fill", action: .sendToEasel),
+ 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 52e85ff..b3805d9 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -1853,13 +1853,30 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
return CGImageSourceCreateImageAtIndex(source, 0, nil)
}
+ /// Send To… an easel: the capture goes on it, under what is there, and its tab comes forward
+ /// (a new one when it has none open).
+ private func sendCapture(_ png: Data, toEasel id: UUID) {
+ guard EaselFiles.add(picture: png, to: id) else { return }
+ CraLog.note("capture sent to an easel, which now holds \(EaselFiles.load(id).items.count) items")
+ let url = Easel(id: id).url
+ if let tab = store.allTabs().first(where: { $0.tab?.url == url }) {
+ browsers.unload(tab.id) // opened again from the file, picture included
+ store.selectTab(tab.id, window: windowID)
+ refresh()
+ } else {
+ _ = store.createTab(url: url, title: EaselFiles.load(id).title, select: true, window: windowID)
+ }
+ }
+
/// Testing without the pointer (cra://debug?captureToEasel=1): the visible page captured and
/// the capture menu's New Easel chosen.
- func debugCaptureToEasel() {
+ func debugCaptureToEasel(send: Bool = false) {
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) }
+ // send: Send To… the easel edited last, as if picked from its menu.
+ if send, let png, let last = EaselFiles.all().first { self?.sendCapture(png, toEasel: last.id); return }
self?.captureFinished(.newEasel, png)
}
}
@@ -1884,6 +1901,18 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
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 .sendToEasel?:
+ guard let png else { return }
+ let easels = EaselFiles.all()
+ guard !easels.isEmpty else {
+ if let easel = EaselFiles.create(withPicture: png) { _ = store.createTab(url: easel.url, title: easel.title, select: true, window: windowID) }
+ return
+ }
+ let menu = NSMenu()
+ for e in easels {
+ MenuItems.add(menu, e.title) { [weak self] in self?.sendCapture(png, toEasel: e.id) }
+ }
+ menu.popUp(positioning: nil, at: NSEvent.mouseLocation, in: nil)
case .retake?:
capturePage()
case nil:
diff --git a/Tests/Scenarios/easel.scenario b/Tests/Scenarios/easel.scenario
index cf6167f..f8af2ca 100644
--- a/Tests/Scenarios/easel.scenario
+++ b/Tests/Scenarios/easel.scenario
@@ -19,3 +19,8 @@ cra://debug?captureToEasel=1
wait 2
cra://debug?browserWindows=captured
expect-log browser windows captured: kind=normal listed=1 tabs=3 open=1
+# Send To… an easel: the capture lands on the easel edited last, next to the first one.
+cra://open?url=${PAGE}?n=sent
+wait 2
+cra://debug?captureToEasel=send
+expect-log capture sent to an easel, which now holds 2 items
diff --git a/docs/arc-parity.md b/docs/arc-parity.md
index 85988e0..b16b099 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. 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). |
+| 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. The capture menu's Send To… done too. Missing: 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 ↗". |