rvlib-shipkit 2.22.1 → 2.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/package.json +1 -1
- package/src/annex/annex.ts +3 -0
- package/src/annex/born.ts +464 -0
- package/src/annex/flush.ts +46 -0
- package/src/annex/offload.ts +171 -38
- package/src/annex/snapshots.ts +53 -0
- package/src/annex/tidy.ts +368 -0
- package/src/checks/SK041-annex-links.check.ts +4 -2
- package/src/checks/SK043-scratch-on-the-mac.check.ts +45 -0
- package/src/cli/cmd_Annex.ts +60 -9
- package/src/cli/cmd_Home.ts +28 -0
- package/src/cli/cmd_Rec.ts +17 -7
- package/src/cli/cmd_Review.ts +27 -3
- package/src/core/machine-db.ts +8 -0
- package/src/home/claude-temp.ts +139 -0
- package/src/home/daemon-jobs.ts +10 -3
- package/src/home/global-units.ts +3 -0
- package/src/home/machine-stores.ts +27 -3
- package/src/home/pm.ts +4 -1
- package/src/home/run-pm.ts +1 -0
- package/src/identities/identities.ts +92 -24
- package/src/media-store/daemon.ts +2 -2
- package/src/media-store/purge.ts +4 -0
- package/src/recordings/load.ts +3 -3
- package/src/recordings/model.ts +7 -0
- package/src/recordings/open.ts +12 -0
- package/src/recordings/presets.ts +12 -5
- package/src/recordings/recorder-app/Capture.swift +34 -5
- package/src/recordings/recorder-app/Clip.swift +126 -17
- package/src/recordings/recorder-app/Editor.swift +177 -7
- package/src/recordings/recorder-app/Hud.swift +189 -0
- package/src/recordings/recorder-app/Tray.swift +179 -36
- package/src/recordings/recorder-app/icon.svg +16 -0
- package/src/recordings/recorder-app/main.swift +349 -18
- package/src/recordings/recorder-app.ts +8 -4
- package/src/recordings/recorder.shipkit.ts +2 -1
- package/src/recordings/routes.ts +52 -6
- package/src/recordings/run-recorder.ts +2 -1
- package/src/recordings/share.ts +27 -0
- package/src/recordings/take.ts +36 -4
- package/src/recordings/view.ts +11 -0
- package/src/repo-config.ts +9 -1
- package/src/review/model.ts +33 -4
- package/src/serve/hub-app/hub.css +4 -0
- package/src/serve/hub-app/recordings-st.ts +135 -24
- package/src/serve/hub-app/recordings-view.tsx +293 -54
- package/src/serve/hub-app/recordings.css +77 -24
- package/src/shipkit-files.ts +5 -0
- package/src/social/drafts.ts +4 -3
- package/src/social/load.ts +7 -2
- package/src/social/publish/discord.ts +10 -3
package/src/media-store/purge.ts
CHANGED
|
@@ -15,6 +15,10 @@ export const KEEP_DAYS = 14
|
|
|
15
15
|
/** under this much free disk the daemon purges, when the owner turned it on */
|
|
16
16
|
export const FREE_MIN_BYTES = 40e9
|
|
17
17
|
|
|
18
|
+
/** the daemon's window for a disk with `free` bytes: 14 days, 3 under FREE_MIN_BYTES, 1 under half of it. A young,
|
|
19
|
+
* heavy repo fills the disk in days, and a row its kind pins stays whatever the window */
|
|
20
|
+
export const windowDays = (free: number): number => (free >= FREE_MIN_BYTES ? KEEP_DAYS : free >= FREE_MIN_BYTES / 2 ? 3 : 1)
|
|
21
|
+
|
|
18
22
|
export interface Candidate {
|
|
19
23
|
item: string
|
|
20
24
|
name: string
|
package/src/recordings/load.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { basename } from 'node:path'
|
|
|
6
6
|
import { UNASSIGNED } from './place.ts'
|
|
7
7
|
import { mergePresets, type NamedPreset } from './presets.ts'
|
|
8
8
|
|
|
9
|
-
export type RecorderState = { presets: NamedPreset[]; problems: string[]; repos: string[]; repo: string; home: string | null }
|
|
9
|
+
export type RecorderState = { presets: NamedPreset[]; trayKeys: string[]; problems: string[]; repos: string[]; repo: string; home: string | null }
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
/** the house repos and every preset, read from their configs side by side */
|
|
@@ -30,8 +30,8 @@ export async function recorderState(cwd = process.cwd()): Promise<RecorderState>
|
|
|
30
30
|
const others = repos.filter((r) => r !== house)
|
|
31
31
|
const each = await Promise.all(others.map(read))
|
|
32
32
|
const merged = mergePresets(own, others.map((root, i) => ({ root, recorder: each[i] })))
|
|
33
|
-
const { presets } = merged
|
|
33
|
+
const { presets, trayKeys } = merged
|
|
34
34
|
const problems = [...broken, ...merged.problems]
|
|
35
35
|
const names = [UNASSIGNED, ...repos.map((r) => basename(r)).sort()]
|
|
36
|
-
return { presets, problems, repos: names, repo: UNASSIGNED, home: house ? homeUrl() : null }
|
|
36
|
+
return { presets, trayKeys, problems, repos: names, repo: UNASSIGNED, home: house ? homeUrl() : null }
|
|
37
37
|
}
|
package/src/recordings/model.ts
CHANGED
|
@@ -32,8 +32,15 @@ export type RecMeta = {
|
|
|
32
32
|
/** every Space key it had that its files no longer name (an export, a poster or a public copy replaced): a delete
|
|
33
33
|
* takes them too, so a link copied before an export dies with the rest */
|
|
34
34
|
former?: string[]
|
|
35
|
+
/** every save of its edit that changed something, oldest first (take.ts, versionsOf) */
|
|
36
|
+
versions?: RecVersion[]
|
|
35
37
|
}
|
|
36
38
|
|
|
39
|
+
/** one save of an edit: its number, when, the text that made it, and what it rendered (none for the take whole) */
|
|
40
|
+
export type RecVersion = { n: number; at: string; text: string; sha?: string; size?: number }
|
|
41
|
+
/** the saves kept: the oldest go first */
|
|
42
|
+
export const VERSIONS_KEPT = 50
|
|
43
|
+
|
|
37
44
|
export type Recording = RecMeta & { dir: string; root: string }
|
|
38
45
|
|
|
39
46
|
export const META = 'meta.json'
|
package/src/recordings/open.ts
CHANGED
|
@@ -26,6 +26,18 @@ export function recorderUrl(o: { preset?: string; spec?: RecPreset; repo?: strin
|
|
|
26
26
|
return `${RECORDER_SCHEME}://record?${q.toString()}`
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
/** the url that asks the app to copy a capture's file natively, confirmed and shown by its clipboard indicator:
|
|
30
|
+
* `png` and `webp-hq` a still as that image, `file` the file alone (a video). `keep`: where the still's WebP stays
|
|
31
|
+
* once made, so the next copy reads it instead of encoding again */
|
|
32
|
+
export function recorderCopyUrl(file: string, format: 'png' | 'webp-hq' | 'file', keep?: string): string {
|
|
33
|
+
return `${RECORDER_SCHEME}://copy?${new URLSearchParams({ file, format, ...(keep ? { keep } : {}) }).toString()}`
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** the same for a text (a link): `label` and `detail` are what the indicator says */
|
|
37
|
+
export function recorderCopyTextUrl(text: string, label: string, detail: string): string {
|
|
38
|
+
return `${RECORDER_SCHEME}://copy?${new URLSearchParams({ text, label, detail }).toString()}`
|
|
39
|
+
}
|
|
40
|
+
|
|
29
41
|
/** a folder to the Trash through the Finder: it works across drives, and it can be put back */
|
|
30
42
|
export async function trash(dir: string): Promise<void> {
|
|
31
43
|
const p = Bun.spawn(['osascript', '-e', 'on run argv', '-e', 'tell application "Finder" to delete (POSIX file (item 1 of argv) as alias)', '-e', 'end run', dir], { stdout: 'ignore', stderr: 'pipe' })
|
|
@@ -44,12 +44,18 @@ export type RecorderConfig = {
|
|
|
44
44
|
* used while the drive is mounted, else the Mac's disk takes the take, said loud */
|
|
45
45
|
dir?: string
|
|
46
46
|
presets?: Record<string, RecPreset>
|
|
47
|
+
/** the global hotkey (or several) that shows or hides the recent captures tray (house config only). Absent: shipkit's
|
|
48
|
+
* own when the house names no presets either, else none */
|
|
49
|
+
trayKey?: string | string[]
|
|
47
50
|
}
|
|
48
51
|
|
|
52
|
+
/** the tray's hotkey when the house names neither presets nor a tray key */
|
|
53
|
+
export const BUILTIN_TRAY_KEY = 'alt+shift+t'
|
|
54
|
+
|
|
49
55
|
/** what ships when the house names none: a video and a screenshot, each a window or an area, and a screenshot taken
|
|
50
56
|
* on the screen as it was the instant its hotkey was pressed */
|
|
51
57
|
export const BUILTIN_PRESETS: Record<string, RecPreset> = {
|
|
52
|
-
video: { key: 'alt+shift+r', label: 'Video', shoot: 'select', mic: true, clicks: true, after: ['upload', 'copy-link'] },
|
|
58
|
+
video: { key: 'alt+shift+r', label: 'Video', shoot: 'select', mic: true, clicks: true, after: ['upload', 'copy-link', 'open-editor'] },
|
|
53
59
|
still: { key: 'alt+shift+s', label: 'Screenshot', shoot: 'select', still: true, after: ['copy-file', 'upload', 'open-editor'] },
|
|
54
60
|
instant: { key: 'alt+shift+i', label: 'Screenshot, frozen', shoot: 'freeze', still: true, after: ['copy-file', 'upload', 'open-editor'] },
|
|
55
61
|
}
|
|
@@ -82,18 +88,19 @@ export function presetProblems(id: string, p: RecPreset): string[] {
|
|
|
82
88
|
|
|
83
89
|
/** the presets of the menu: the house's (or the built-in ones), then each repo's own as `<repo>/<name>`; a hotkey
|
|
84
90
|
* two presets claim is a problem */
|
|
85
|
-
export function mergePresets(house: RecorderConfig | undefined, repos: { root: string; recorder: RecorderConfig | undefined }[]): { presets: NamedPreset[]; problems: string[] } {
|
|
91
|
+
export function mergePresets(house: RecorderConfig | undefined, repos: { root: string; recorder: RecorderConfig | undefined }[]): { presets: NamedPreset[]; trayKeys: string[]; problems: string[] } {
|
|
86
92
|
const presets: NamedPreset[] = []
|
|
87
93
|
const base = house?.presets ?? BUILTIN_PRESETS
|
|
88
94
|
for (const [id, p] of Object.entries(base)) presets.push({ ...p, id, from: house?.presets ? 'house' : 'shipkit', keys: keysOf(p) })
|
|
89
95
|
for (const r of repos) for (const [n, p] of Object.entries(r.recorder?.presets ?? {})) presets.push({ ...p, id: `${basename(r.root)}/${n}`, from: basename(r.root), keys: keysOf(p) })
|
|
90
|
-
const
|
|
91
|
-
const
|
|
96
|
+
const trayKeys = keysOf({ key: house?.trayKey ?? (house?.presets ? undefined : BUILTIN_TRAY_KEY) })
|
|
97
|
+
const problems = [...trayKeys.filter((k) => !KEY.test(k)).map((k) => `tray: key ${k}: modifiers (cmd, ctrl, alt, shift) then one key, like alt+shift+t`), ...presets.flatMap((p) => presetProblems(p.id, p))]
|
|
98
|
+
const keys = new Map<string, string>(trayKeys.map((k) => [k, 'the tray']))
|
|
92
99
|
for (const p of presets)
|
|
93
100
|
for (const k of p.keys) {
|
|
94
101
|
const had = keys.get(k)
|
|
95
102
|
if (had) problems.push(`${p.id}: key ${k} is already ${had}'s`)
|
|
96
103
|
else keys.set(k, p.id)
|
|
97
104
|
}
|
|
98
|
-
return { presets, problems }
|
|
105
|
+
return { presets, trayKeys, problems }
|
|
99
106
|
}
|
|
@@ -75,9 +75,31 @@ func axSetFrame(_ w: AXUIElement, _ frame: NSRect) {
|
|
|
75
75
|
|
|
76
76
|
enum Grip { case move, n, s, e, w, ne, nw, se, sw }
|
|
77
77
|
|
|
78
|
+
/** the bar's mic and system sound as they were left for a preset: its next video starts with them again. The preset's
|
|
79
|
+
* own values hold only until the bar is touched once */
|
|
80
|
+
enum SoundChoice {
|
|
81
|
+
private static func key(_ what: String, _ preset: String) -> String { "barChoice.\(what).\(preset)" }
|
|
82
|
+
|
|
83
|
+
static func get(_ what: String, _ preset: String?, else preset0: Bool) -> Bool {
|
|
84
|
+
guard let preset, !preset.isEmpty, let v = UserDefaults.standard.object(forKey: key(what, preset)) as? Bool else { return preset0 }
|
|
85
|
+
return v
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
static func set(_ what: String, _ preset: String?, _ on: Bool) {
|
|
89
|
+
guard let preset, !preset.isEmpty else { return }
|
|
90
|
+
UserDefaults.standard.set(on, forKey: key(what, preset))
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
static func forget(_ preset: String) {
|
|
94
|
+
for w in ["mic", "sound"] { UserDefaults.standard.removeObject(forKey: key(w, preset)) }
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
78
98
|
@MainActor
|
|
79
99
|
final class Chooser {
|
|
80
100
|
let video: Bool
|
|
101
|
+
/** the preset whose bar this is: a switch flipped is kept for its next video */
|
|
102
|
+
let remember: String?
|
|
81
103
|
let windowsToo: Bool
|
|
82
104
|
var mic: Bool
|
|
83
105
|
var sound: Bool
|
|
@@ -97,8 +119,9 @@ final class Chooser {
|
|
|
97
119
|
/** a frozen screenshot's screen and its image of that instant: the overlay covers that screen alone, over it */
|
|
98
120
|
let frozen: (screen: NSScreen, image: CGImage)?
|
|
99
121
|
|
|
100
|
-
init(video: Bool, windowsToo: Bool, mic: Bool, sound: Bool, frozen: (screen: NSScreen, image: CGImage)? = nil) {
|
|
122
|
+
init(video: Bool, windowsToo: Bool, mic: Bool, sound: Bool, frozen: (screen: NSScreen, image: CGImage)? = nil, remember: String? = nil) {
|
|
101
123
|
self.video = video
|
|
124
|
+
self.remember = remember
|
|
102
125
|
self.windowsToo = windowsToo
|
|
103
126
|
self.mic = mic
|
|
104
127
|
self.sound = sound
|
|
@@ -322,8 +345,14 @@ final class Chooser {
|
|
|
322
345
|
|
|
323
346
|
@objc func recordClicked() { go() }
|
|
324
347
|
@objc func cancelClicked() { cancel() }
|
|
325
|
-
@objc func micClicked(_ b: NSButton) {
|
|
326
|
-
|
|
348
|
+
@objc func micClicked(_ b: NSButton) {
|
|
349
|
+
mic = b.state == .on
|
|
350
|
+
SoundChoice.set("mic", remember, mic)
|
|
351
|
+
}
|
|
352
|
+
@objc func soundClicked(_ b: NSButton) {
|
|
353
|
+
sound = b.state == .on
|
|
354
|
+
SoundChoice.set("sound", remember, sound)
|
|
355
|
+
}
|
|
327
356
|
}
|
|
328
357
|
|
|
329
358
|
/** a borderless window that still takes the keyboard */
|
|
@@ -409,9 +438,9 @@ final class ChooseView: NSView {
|
|
|
409
438
|
}
|
|
410
439
|
|
|
411
440
|
/** the person's choice: a window or an area, then (a video) adjusted and confirmed; nil when cancelled */
|
|
412
|
-
@MainActor func choose(video: Bool, windowsToo: Bool, mic: Bool, sound: Bool, frozen: (screen: NSScreen, image: CGImage)? = nil) async -> Picked? {
|
|
441
|
+
@MainActor func choose(video: Bool, windowsToo: Bool, mic: Bool, sound: Bool, frozen: (screen: NSScreen, image: CGImage)? = nil, remember: String? = nil) async -> Picked? {
|
|
413
442
|
await withCheckedContinuation { k in
|
|
414
|
-
let c = Chooser(video: video, windowsToo: windowsToo, mic: mic, sound: sound, frozen: frozen)
|
|
443
|
+
let c = Chooser(video: video, windowsToo: windowsToo, mic: mic, sound: sound, frozen: frozen, remember: remember)
|
|
415
444
|
c.done = { p in
|
|
416
445
|
k.resume(returning: p)
|
|
417
446
|
_ = c
|
|
@@ -3,9 +3,31 @@
|
|
|
3
3
|
// terminal pastes the image). The item is written at once with its data PROMISED: the PNG, the file and the WebP are
|
|
4
4
|
// made behind it, and a paste that comes first waits for them, so a ⌘V right after the shot never pastes the clipboard
|
|
5
5
|
// before it. Its format is the menu's choice; WebP is encoded by cwebp (Homebrew's webp), since ImageIO writes no
|
|
6
|
-
// WebP. The file a paste reads lives in the app's own cache folder, the newest few kept
|
|
6
|
+
// WebP. The file a paste reads lives in the app's own cache folder, the newest few kept. What the indicator says is
|
|
7
|
+
// read back from the clipboard, never assumed: the change count the write got, then the bytes the clipboard serves
|
|
7
8
|
import AppKit
|
|
8
9
|
|
|
10
|
+
/** what the clipboard holds once a job's data is made, read back from it */
|
|
11
|
+
enum ClipCheck: Equatable {
|
|
12
|
+
/** served byte for byte in the chosen format */
|
|
13
|
+
case ready(format: String, size: String)
|
|
14
|
+
/** served, but as the PNG: the chosen format could not be made */
|
|
15
|
+
case fallback(why: String, size: String)
|
|
16
|
+
/** another copy (a newer still, another app) took the clipboard before the data was made */
|
|
17
|
+
case replaced
|
|
18
|
+
/** the clipboard still holds the item, yet serves other bytes than the still's */
|
|
19
|
+
case unreadable(String)
|
|
20
|
+
|
|
21
|
+
var line: String {
|
|
22
|
+
switch self {
|
|
23
|
+
case let .ready(f, n): "ok: confirmed on the clipboard as \(f) (\(n))"
|
|
24
|
+
case let .fallback(why, n): "WARN: \(why): the clipboard has the PNG (\(n))"
|
|
25
|
+
case .replaced: "note: another copy took the clipboard before this still's data was made"
|
|
26
|
+
case let .unreadable(why): "FAIL: \(why)"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
9
31
|
enum ClipFormat: String, CaseIterable {
|
|
10
32
|
case png
|
|
11
33
|
case webpLossless = "webp-lossless"
|
|
@@ -41,12 +63,19 @@ final class ClipJob: NSObject, NSPasteboardItemDataProvider, @unchecked Sendable
|
|
|
41
63
|
private(set) var png = Data()
|
|
42
64
|
private(set) var file: URL?
|
|
43
65
|
private(set) var webp: Data?
|
|
44
|
-
/** why the chosen format could not be made; the PNG stands in */
|
|
66
|
+
/** why the chosen format could not be made; the PNG stands in, and ClipCheck says so */
|
|
45
67
|
private(set) var failure: String?
|
|
68
|
+
/** the clipboard it was written to and the change count that write got: the clipboard is still ours while it holds */
|
|
69
|
+
fileprivate(set) var board: NSPasteboard?
|
|
70
|
+
fileprivate(set) var count = -1
|
|
71
|
+
|
|
72
|
+
/** where this still's WebP is kept once made: read there when it is, so a second copy encodes nothing */
|
|
73
|
+
private let keep: URL?
|
|
46
74
|
|
|
47
75
|
/** from the image itself (a capture), or from a PNG on the disk (a tray copy) */
|
|
48
|
-
init(image: CGImage? = nil, pngFile: URL? = nil, format: ClipFormat) {
|
|
76
|
+
init(image: CGImage? = nil, pngFile: URL? = nil, format: ClipFormat, keep: URL? = nil) {
|
|
49
77
|
self.format = format
|
|
78
|
+
self.keep = format == .webpHigh ? keep : nil
|
|
50
79
|
super.init()
|
|
51
80
|
ready.enter()
|
|
52
81
|
DispatchQueue.global(qos: .userInitiated).async {
|
|
@@ -78,30 +107,39 @@ final class ClipJob: NSObject, NSPasteboardItemDataProvider, @unchecked Sendable
|
|
|
78
107
|
return
|
|
79
108
|
}
|
|
80
109
|
guard format != .png else { return }
|
|
110
|
+
let out = base.appendingPathExtension("webp")
|
|
111
|
+
if let keep, let d = try? Data(contentsOf: keep), !d.isEmpty, (try? d.write(to: out)) != nil {
|
|
112
|
+
webp = d
|
|
113
|
+
file = out
|
|
114
|
+
return
|
|
115
|
+
}
|
|
81
116
|
guard let bin = ["/opt/homebrew/bin/cwebp", "/usr/local/bin/cwebp"].first(where: { FileManager.default.isExecutableFile(atPath: $0) }) else {
|
|
82
|
-
failure = "\(format.label) needs cwebp (brew install webp)
|
|
117
|
+
failure = "\(format.label) needs cwebp (brew install webp)"
|
|
83
118
|
return
|
|
84
119
|
}
|
|
85
|
-
let out = base.appendingPathExtension("webp")
|
|
86
120
|
let r = Clip.runNow(bin, ["-quiet", "-mt"] + format.cwebp + [at.path, "-o", out.path])
|
|
87
121
|
guard r.code == 0, let d = try? Data(contentsOf: out) else {
|
|
88
|
-
failure = "cwebp: \(r.err.isEmpty ? "exit \(r.code)" : r.err)
|
|
122
|
+
failure = "cwebp: \(r.err.isEmpty ? "exit \(r.code)" : r.err)"
|
|
89
123
|
return
|
|
90
124
|
}
|
|
91
125
|
webp = d
|
|
92
126
|
file = out
|
|
127
|
+
if let keep { try? d.write(to: keep, options: .atomic) }
|
|
93
128
|
}
|
|
94
129
|
|
|
95
|
-
/**
|
|
96
|
-
func
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
done("on the clipboard as \(self.webp != nil ? self.format.label : "PNG") (\(size))", self.failure)
|
|
101
|
-
}
|
|
130
|
+
/** the WebP HQ this job made, written to `at` once it is made: a capture's own, kept beside it */
|
|
131
|
+
func keepWebp(at: URL) {
|
|
132
|
+
guard format == .webpHigh else { return }
|
|
133
|
+
ready.notify(queue: .global(qos: .utility)) {
|
|
134
|
+
if let d = self.webp { try? d.write(to: at, options: .atomic) }
|
|
102
135
|
}
|
|
103
136
|
}
|
|
104
137
|
|
|
138
|
+
/** waits for the data, then runs `done` on the main thread with what the clipboard serves now */
|
|
139
|
+
func whenReady(_ done: @escaping @MainActor (ClipCheck) -> Void) {
|
|
140
|
+
ready.notify(queue: .main) { MainActor.assumeIsolated { done(Clip.check(self)) } }
|
|
141
|
+
}
|
|
142
|
+
|
|
105
143
|
func pasteboard(_ pasteboard: NSPasteboard?, item: NSPasteboardItem, provideDataForType type: NSPasteboard.PasteboardType) {
|
|
106
144
|
// a paste that comes before the data waits for it: never the clipboard's older content
|
|
107
145
|
ready.wait()
|
|
@@ -125,17 +163,88 @@ enum Clip {
|
|
|
125
163
|
return d
|
|
126
164
|
}
|
|
127
165
|
|
|
128
|
-
/** the job's item on the clipboard now, every type promised: the file, the PNG and, for a WebP format, the WebP
|
|
129
|
-
|
|
166
|
+
/** the job's item on the clipboard now, every type promised: the file, the PNG and, for a WebP format, the WebP.
|
|
167
|
+
* Throws unless the clipboard reads back as this write: its change count, and every type promised */
|
|
168
|
+
@MainActor static func put(_ job: ClipJob, on pb: NSPasteboard = .general) throws {
|
|
130
169
|
let it = NSPasteboardItem()
|
|
131
170
|
let types: [NSPasteboard.PasteboardType] = job.format == .png ? [.fileURL, .png] : [.fileURL, WEBP_TYPE, .png]
|
|
132
171
|
guard it.setDataProvider(job, forTypes: types) else { throw Err("the clipboard took no promise") }
|
|
133
|
-
let
|
|
134
|
-
pb.clearContents()
|
|
172
|
+
let n = pb.clearContents()
|
|
135
173
|
if !pb.writeObjects([it]) { throw Err("the clipboard refused the still") }
|
|
174
|
+
guard pb.changeCount == n, let has = pb.types, types.allSatisfy(has.contains) else { throw Err("the clipboard does not read back as the still just written") }
|
|
175
|
+
job.board = pb
|
|
176
|
+
job.count = n
|
|
136
177
|
ClipJob.live.append(job)
|
|
137
178
|
}
|
|
138
179
|
|
|
180
|
+
/** the clipboard read back once the job's data is made: still this write (its change count), then the bytes and
|
|
181
|
+
* the file it serves compared with the job's own */
|
|
182
|
+
@MainActor static func check(_ job: ClipJob) -> ClipCheck {
|
|
183
|
+
guard let pb = job.board, pb.changeCount == job.count else { return .replaced }
|
|
184
|
+
let want = job.webp ?? job.png
|
|
185
|
+
let type = job.webp != nil ? WEBP_TYPE : .png
|
|
186
|
+
guard !want.isEmpty else { return .unreadable(job.failure ?? "the still did not encode") }
|
|
187
|
+
guard pb.data(forType: type) == want else { return .unreadable("the clipboard serves other bytes than the still's \(job.webp != nil ? job.format.label : "PNG")") }
|
|
188
|
+
guard let f = job.file, pb.string(forType: .fileURL) == f.absoluteString else { return .unreadable(job.failure ?? "the clipboard's file is not the still's") }
|
|
189
|
+
let size = ByteCountFormatter.string(fromByteCount: Int64(want.count), countStyle: .file)
|
|
190
|
+
if let why = job.failure { return .fallback(why: why, size: size) }
|
|
191
|
+
return .ready(format: job.webp != nil ? job.format.label : "PNG", size: size)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** the one way a still reaches the clipboard: written, confirmed, the indicator showing each step it read back.
|
|
195
|
+
* `onFail` hears a write or a read back that failed. False when the write did not land */
|
|
196
|
+
@MainActor @discardableResult static func copy(_ job: ClipJob, onFail: @escaping @MainActor (String) -> Void) -> Bool {
|
|
197
|
+
ClipHud.shared.begin(job)
|
|
198
|
+
do { try put(job) } catch {
|
|
199
|
+
ClipHud.shared.show(job, .failed(error.localizedDescription))
|
|
200
|
+
onFail("the clipboard: \(error.localizedDescription)")
|
|
201
|
+
return false
|
|
202
|
+
}
|
|
203
|
+
ClipHud.shared.show(job, .copied(job.format))
|
|
204
|
+
job.whenReady { r in
|
|
205
|
+
say(r.line)
|
|
206
|
+
ClipHud.shared.show(job, .checked(r))
|
|
207
|
+
if case let .unreadable(why) = r { onFail(why) }
|
|
208
|
+
}
|
|
209
|
+
return true
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** a file alone on the clipboard (a video), as Finder's Copy puts it: written, read back (this write's change count,
|
|
213
|
+
* this file's url), the indicator showing what it read. `onFail` hears a write or a read back that failed */
|
|
214
|
+
@MainActor static func copyFile(_ file: URL, on pb: NSPasteboard = .general, onFail: @escaping @MainActor (String) -> Void) {
|
|
215
|
+
let owner = NSObject()
|
|
216
|
+
ClipHud.shared.begin(owner)
|
|
217
|
+
let n = pb.clearContents()
|
|
218
|
+
let wrote = pb.writeObjects([file as NSURL])
|
|
219
|
+
let read = pb.string(forType: .fileURL).flatMap { URL(string: $0) }?.standardizedFileURL.path
|
|
220
|
+
guard wrote, pb.changeCount == n, read == file.standardizedFileURL.path else {
|
|
221
|
+
let why = "the clipboard does not read back as \(file.lastPathComponent)"
|
|
222
|
+
ClipHud.shared.show(owner, .failed(why))
|
|
223
|
+
onFail(why)
|
|
224
|
+
return
|
|
225
|
+
}
|
|
226
|
+
let bytes = (try? FileManager.default.attributesOfItem(atPath: file.path)[.size] as? Int) ?? 0
|
|
227
|
+
let r = ClipCheck.ready(format: "\(file.pathExtension.uppercased()) file", size: ByteCountFormatter.string(fromByteCount: Int64(bytes), countStyle: .file))
|
|
228
|
+
say(r.line)
|
|
229
|
+
ClipHud.shared.show(owner, .checked(r))
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** a text on the clipboard (a link), written and read back, the indicator saying `label` and `detail` */
|
|
233
|
+
@MainActor static func copyText(_ text: String, label: String, detail: String, on pb: NSPasteboard = .general, onFail: @escaping @MainActor (String) -> Void) {
|
|
234
|
+
let owner = NSObject()
|
|
235
|
+
ClipHud.shared.begin(owner)
|
|
236
|
+
let n = pb.clearContents()
|
|
237
|
+
guard pb.setString(text, forType: .string), pb.changeCount == n, pb.string(forType: .string) == text else {
|
|
238
|
+
let why = "the clipboard does not read back as the \(label.lowercased())"
|
|
239
|
+
ClipHud.shared.show(owner, .failed(why))
|
|
240
|
+
onFail(why)
|
|
241
|
+
return
|
|
242
|
+
}
|
|
243
|
+
let r = ClipCheck.ready(format: label, size: detail)
|
|
244
|
+
say(r.line)
|
|
245
|
+
ClipHud.shared.show(owner, .checked(r))
|
|
246
|
+
}
|
|
247
|
+
|
|
139
248
|
/** the newest KEEP stills and their WebP stay: a paste of an older clipboard still finds its file */
|
|
140
249
|
static func prune() {
|
|
141
250
|
let fm = FileManager.default
|
|
@@ -1,36 +1,206 @@
|
|
|
1
|
-
// the recorder's
|
|
2
|
-
// (`/recordings?solo=1#<repo>/<id>`)
|
|
3
|
-
// front when it opens, then a window like any other, behind what is picked next
|
|
4
|
-
//
|
|
1
|
+
// the recorder's window (wiki tools/shipkit/recordings.md, The recorder): the hub's editor for one capture
|
|
2
|
+
// (`/recordings?solo=1#<repo>/<id>`) with the recent captures under it, resizable, closable, where it was left:
|
|
3
|
+
// brought to the front when it opens, then a window like any other, behind what is picked next. It opens after a take
|
|
4
|
+
// whose preset ends with open-editor (a screenshot, by default) and on a click of a recent capture, so a capture is
|
|
5
|
+
// annotated without leaving what was being done. After a take it opens the instant the take ends, a spinner over it
|
|
6
|
+
// while the take is filed and the page loads, so no wait shows as nothing. While it is closed the recent captures are
|
|
7
|
+
// their own small panel (Tray.swift): never two windows at once
|
|
5
8
|
import AppKit
|
|
6
9
|
import WebKit
|
|
7
10
|
|
|
8
11
|
@MainActor
|
|
9
|
-
final class EditorWindow: NSObject, NSWindowDelegate {
|
|
12
|
+
final class EditorWindow: NSObject, NSWindowDelegate, WKNavigationDelegate {
|
|
10
13
|
var window: NSWindow?
|
|
11
14
|
var web: WKWebView?
|
|
15
|
+
private var cover: NSView?
|
|
16
|
+
private var coverText: NSTextField?
|
|
17
|
+
private var spin: NSProgressIndicator?
|
|
18
|
+
private var toastView: NSView?
|
|
19
|
+
private var toastHide: Timer?
|
|
20
|
+
/** the bottom of the window: where the recent captures sit, no height when they are switched off */
|
|
21
|
+
private var dock: NSView?
|
|
22
|
+
private var dockHeight: NSLayoutConstraint?
|
|
23
|
+
/** the window came on screen (true) or left it (false) */
|
|
24
|
+
var onVisible: ((Bool) -> Void)?
|
|
25
|
+
/** the capture the page shows now, `<repo>/<id>`, nil in its gallery: the page moves between captures itself */
|
|
26
|
+
var onCapture: ((String?) -> Void)?
|
|
27
|
+
private var urlWatch: NSKeyValueObservation?
|
|
28
|
+
|
|
29
|
+
/** the recent captures under the editor; nil takes them away, and the editor has the whole window */
|
|
30
|
+
func setStrip(_ v: NSView?) {
|
|
31
|
+
guard let dock else { return }
|
|
32
|
+
dock.subviews.forEach { $0.removeFromSuperview() }
|
|
33
|
+
guard let v else {
|
|
34
|
+
dockHeight?.constant = 0
|
|
35
|
+
dock.isHidden = true
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
v.translatesAutoresizingMaskIntoConstraints = false
|
|
39
|
+
dock.addSubview(v)
|
|
40
|
+
NSLayoutConstraint.activate([v.leadingAnchor.constraint(equalTo: dock.leadingAnchor), v.topAnchor.constraint(equalTo: dock.topAnchor), v.bottomAnchor.constraint(equalTo: dock.bottomAnchor)])
|
|
41
|
+
dockHeight?.constant = v.fittingSize.height
|
|
42
|
+
dock.isHidden = false
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** the recent captures show under the editor now */
|
|
46
|
+
var stripShown: Bool { window?.isVisible == true && (dockHeight?.constant ?? 0) > 0 }
|
|
47
|
+
|
|
48
|
+
/** the window off the screen, as its close button leaves it */
|
|
49
|
+
func hide() {
|
|
50
|
+
guard let w = window, w.isVisible else { return }
|
|
51
|
+
w.orderOut(nil)
|
|
52
|
+
onVisible?(false)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
nonisolated func windowWillClose(_ n: Notification) {
|
|
56
|
+
MainActor.assumeIsolated { onVisible?(false) }
|
|
57
|
+
}
|
|
58
|
+
/** the clipboard indicator's title shown in this window now: what a smoke reads */
|
|
59
|
+
private(set) var toastTitle: String?
|
|
60
|
+
|
|
61
|
+
/** the clipboard indicator's state, shown again at the top of this window while it is on screen */
|
|
62
|
+
func toast(_ s: HudState) {
|
|
63
|
+
guard let w = window, w.isVisible, let root = w.contentView else { return }
|
|
64
|
+
toastView?.removeFromSuperview()
|
|
65
|
+
let v = ClipHud.shared.content(s)
|
|
66
|
+
v.translatesAutoresizingMaskIntoConstraints = false
|
|
67
|
+
root.addSubview(v)
|
|
68
|
+
NSLayoutConstraint.activate([v.centerXAnchor.constraint(equalTo: root.centerXAnchor), v.topAnchor.constraint(equalTo: root.topAnchor, constant: 56)])
|
|
69
|
+
toastView = v
|
|
70
|
+
toastTitle = s.look.title
|
|
71
|
+
toastHide?.invalidate()
|
|
72
|
+
toastHide = Timer.scheduledTimer(withTimeInterval: s.final ? ClipHud.HOLD : 10, repeats: false) { [weak self, weak v] _ in
|
|
73
|
+
MainActor.assumeIsolated {
|
|
74
|
+
v?.removeFromSuperview()
|
|
75
|
+
if self?.toastView === v { self?.toastTitle = nil }
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** the cover is up: a take files or a page loads */
|
|
81
|
+
var covering: Bool { cover?.isHidden == false }
|
|
82
|
+
|
|
83
|
+
/** the window up now, its spinner saying `what`, before the take it will show is filed */
|
|
84
|
+
func opening(_ what: String) {
|
|
85
|
+
let w = window ?? make()
|
|
86
|
+
window = w
|
|
87
|
+
covered(what, spinning: true)
|
|
88
|
+
front(w)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** the take did not file: the window says why instead of spinning */
|
|
92
|
+
func failed(_ why: String) {
|
|
93
|
+
guard window?.isVisible == true, cover?.isHidden == false else { return }
|
|
94
|
+
covered("Not filed: \(why)", spinning: false)
|
|
95
|
+
}
|
|
12
96
|
|
|
13
97
|
func open(_ url: URL) {
|
|
14
98
|
let w = window ?? make()
|
|
15
99
|
window = w
|
|
100
|
+
// another capture of the editor already loaded is the same page at another fragment: WebKit moves within the
|
|
101
|
+
// document and never calls didFinish, and the page switches captures itself, so the cover lifts here
|
|
102
|
+
let samePage = web?.url.map { page($0) == page(url) } == true && web?.isLoading == false
|
|
16
103
|
web?.load(URLRequest(url: url))
|
|
104
|
+
if samePage {
|
|
105
|
+
spin?.stopAnimation(nil)
|
|
106
|
+
cover?.isHidden = true
|
|
107
|
+
} else {
|
|
108
|
+
covered("Opening the capture…", spinning: true)
|
|
109
|
+
}
|
|
110
|
+
front(w)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** a url without its fragment: the document it loads */
|
|
114
|
+
private func page(_ u: URL) -> URL? {
|
|
115
|
+
var c = URLComponents(url: u, resolvingAgainstBaseURL: false)
|
|
116
|
+
c?.fragment = nil
|
|
117
|
+
return c?.url
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private func front(_ w: NSWindow) {
|
|
121
|
+
if !w.isVisible { onVisible?(true) }
|
|
17
122
|
NSApp.activate()
|
|
18
123
|
w.makeKeyAndOrderFront(nil)
|
|
19
124
|
w.orderFrontRegardless()
|
|
20
125
|
}
|
|
21
126
|
|
|
127
|
+
private func covered(_ what: String, spinning: Bool) {
|
|
128
|
+
coverText?.stringValue = what
|
|
129
|
+
coverText?.textColor = spinning ? .secondaryLabelColor : .systemRed
|
|
130
|
+
spin?.isHidden = !spinning
|
|
131
|
+
if spinning { spin?.startAnimation(nil) } else { spin?.stopAnimation(nil) }
|
|
132
|
+
cover?.isHidden = false
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
nonisolated func webView(_ v: WKWebView, didFinish n: WKNavigation!) {
|
|
136
|
+
MainActor.assumeIsolated {
|
|
137
|
+
spin?.stopAnimation(nil)
|
|
138
|
+
cover?.isHidden = true
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
nonisolated func webView(_ v: WKWebView, didFail n: WKNavigation!, withError e: Error) {
|
|
143
|
+
MainActor.assumeIsolated { covered("The editor did not load: \(e.localizedDescription)", spinning: false) }
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
nonisolated func webView(_ v: WKWebView, didFailProvisionalNavigation n: WKNavigation!, withError e: Error) {
|
|
147
|
+
MainActor.assumeIsolated { covered("The editor did not load: \(e.localizedDescription)", spinning: false) }
|
|
148
|
+
}
|
|
149
|
+
|
|
22
150
|
private func make() -> NSWindow {
|
|
23
151
|
let config = WKWebViewConfiguration()
|
|
24
152
|
config.websiteDataStore = .default()
|
|
25
153
|
let v = WKWebView(frame: NSRect(x: 0, y: 0, width: 1100, height: 760), configuration: config)
|
|
26
154
|
v.setValue(false, forKey: "drawsBackground")
|
|
155
|
+
v.navigationDelegate = self
|
|
27
156
|
web = v
|
|
157
|
+
urlWatch = v.observe(\.url) { [weak self] v, _ in
|
|
158
|
+
MainActor.assumeIsolated {
|
|
159
|
+
let f = v.url?.fragment?.removingPercentEncoding ?? ""
|
|
160
|
+
self?.onCapture?(f.split(separator: "/").count == 2 ? f : nil)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
// the spinner's cover over the page, opaque, so an older capture never shows while the next one files
|
|
164
|
+
let c = NSView()
|
|
165
|
+
c.wantsLayer = true
|
|
166
|
+
c.layer?.backgroundColor = NSColor.windowBackgroundColor.cgColor
|
|
167
|
+
let sp = NSProgressIndicator()
|
|
168
|
+
sp.style = .spinning
|
|
169
|
+
let tx = NSTextField(labelWithString: "")
|
|
170
|
+
tx.font = .systemFont(ofSize: 13)
|
|
171
|
+
tx.alignment = .center
|
|
172
|
+
let col = NSStackView(views: [sp, tx])
|
|
173
|
+
col.orientation = .vertical
|
|
174
|
+
col.spacing = 10
|
|
175
|
+
col.translatesAutoresizingMaskIntoConstraints = false
|
|
176
|
+
c.addSubview(col)
|
|
177
|
+
NSLayoutConstraint.activate([col.centerXAnchor.constraint(equalTo: c.centerXAnchor), col.centerYAnchor.constraint(equalTo: c.centerYAnchor), tx.widthAnchor.constraint(lessThanOrEqualToConstant: 560)])
|
|
178
|
+
c.isHidden = true
|
|
179
|
+
(cover, coverText, spin) = (c, tx, sp)
|
|
180
|
+
// the recent captures' band under the page, dark as their own panel is, whatever the system's look
|
|
181
|
+
let d = NSView()
|
|
182
|
+
d.wantsLayer = true
|
|
183
|
+
d.layer?.backgroundColor = NSColor(white: 0.13, alpha: 1).cgColor
|
|
184
|
+
d.layer?.masksToBounds = true
|
|
185
|
+
d.appearance = NSAppearance(named: .darkAqua)
|
|
186
|
+
d.isHidden = true
|
|
187
|
+
d.translatesAutoresizingMaskIntoConstraints = false
|
|
188
|
+
let h = d.heightAnchor.constraint(equalToConstant: 0)
|
|
189
|
+
(dock, dockHeight) = (d, h)
|
|
190
|
+
let root = NSView(frame: v.frame)
|
|
191
|
+
root.addSubview(d)
|
|
192
|
+
NSLayoutConstraint.activate([d.leadingAnchor.constraint(equalTo: root.leadingAnchor), d.trailingAnchor.constraint(equalTo: root.trailingAnchor), d.bottomAnchor.constraint(equalTo: root.bottomAnchor), h])
|
|
193
|
+
for x in [v, c] {
|
|
194
|
+
x.translatesAutoresizingMaskIntoConstraints = false
|
|
195
|
+
root.addSubview(x)
|
|
196
|
+
NSLayoutConstraint.activate([x.leadingAnchor.constraint(equalTo: root.leadingAnchor), x.trailingAnchor.constraint(equalTo: root.trailingAnchor), x.topAnchor.constraint(equalTo: root.topAnchor), x.bottomAnchor.constraint(equalTo: d.topAnchor)])
|
|
197
|
+
}
|
|
28
198
|
let w = NSWindow(contentRect: v.frame, styleMask: [.titled, .closable, .resizable, .miniaturizable], backing: .buffered, defer: false)
|
|
29
199
|
w.title = "Capture"
|
|
30
|
-
w.contentView =
|
|
200
|
+
w.contentView = root
|
|
31
201
|
w.level = .normal
|
|
32
202
|
w.isReleasedWhenClosed = false
|
|
33
|
-
w.minSize = NSSize(width:
|
|
203
|
+
w.minSize = NSSize(width: 900, height: 520)
|
|
34
204
|
w.delegate = self
|
|
35
205
|
w.center()
|
|
36
206
|
w.setFrameAutosaveName("ShipkitCaptureEditor")
|