rvlib-shipkit 2.22.1 → 2.24.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 +44 -0
- package/package.json +1 -1
- package/src/agent-time/render.ts +28 -14
- package/src/agent-time/report.ts +46 -25
- package/src/agent-time/store.ts +30 -10
- package/src/agent-time/timeline.ts +43 -15
- 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/asks/asks-queue.ts +32 -11
- package/src/checks/SK041-annex-links.check.ts +4 -2
- package/src/checks/SK043-scratch-on-the-mac.check.ts +45 -0
- package/src/checks/SK044-behind-upstream.check.ts +38 -0
- package/src/cli/cmd_Annex.ts +60 -9
- package/src/cli/cmd_Asks.ts +2 -0
- package/src/cli/cmd_Backup.ts +7 -5
- package/src/cli/cmd_Bump.ts +1 -0
- package/src/cli/cmd_Capacity.ts +26 -0
- package/src/cli/cmd_Check.ts +1 -0
- package/src/cli/cmd_Checks.ts +1 -0
- package/src/cli/cmd_Ci.ts +1 -0
- package/src/cli/cmd_Commands.ts +50 -14
- package/src/cli/cmd_Home.ts +0 -1
- package/src/cli/cmd_Hooks.ts +1 -0
- package/src/cli/cmd_Mv.ts +1 -0
- package/src/cli/cmd_Rec.ts +17 -7
- package/src/cli/cmd_Reflect.ts +1 -0
- package/src/cli/cmd_Releases.ts +1 -0
- package/src/cli/cmd_Review.ts +124 -17
- package/src/cli/cmd_Secret.ts +41 -2
- package/src/cli/cmd_Shot.ts +1 -0
- package/src/cli/cmd_Status.ts +1 -0
- package/src/cli/cmd_Time.ts +3 -1
- package/src/cli/cmd_Tmp.ts +82 -0
- package/src/cli/cmd_Wiki.ts +1 -0
- package/src/cli/registry.ts +13 -1
- package/src/collections/pings.ts +1 -1
- package/src/core/capacity.ts +71 -0
- package/src/core/check-runner.ts +86 -15
- package/src/core/machine-db.ts +8 -0
- package/src/core/motherhome.ts +67 -9
- package/src/core/slots.ts +49 -12
- package/src/core/trace-audit.ts +4 -1
- package/src/drill/run.ts +5 -2
- package/src/home/daemon-jobs.ts +10 -3
- package/src/home/global-units.ts +3 -0
- package/src/home/gui-app/ShipkitGui.swift +1 -0
- package/src/home/home-launchd.ts +11 -3
- package/src/home/home-routes.ts +11 -4
- package/src/home/machine-host.ts +65 -0
- package/src/home/machine-stores.ts +30 -4
- package/src/home/machine-temp.ts +493 -0
- package/src/home/other-macs.ts +74 -0
- package/src/home/pm.ts +4 -1
- package/src/home/run-daemon.ts +10 -2
- package/src/home/run-pm.ts +1 -0
- package/src/home/serve-web.ts +2 -2
- package/src/home/via-hub.ts +6 -1
- package/src/identities/identities.ts +92 -24
- package/src/init-repo.ts +7 -3
- package/src/ledger/ledger.ts +6 -0
- package/src/ledger/store.ts +6 -0
- package/src/media-store/backup/keys.ts +21 -6
- package/src/media-store/backup/manifest.ts +52 -11
- package/src/media-store/backup/restore.ts +17 -10
- package/src/media-store/backup/run.ts +5 -2
- package/src/media-store/backup/sources.ts +2 -1
- package/src/media-store/daemon.ts +2 -2
- package/src/media-store/purge.ts +4 -0
- package/src/mv/mv-md.ts +121 -42
- 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/reflect/transcript.ts +56 -11
- package/src/releases/from-card.ts +45 -3
- package/src/releases/model.ts +6 -0
- package/src/releases/store.ts +8 -1
- package/src/repo-config.ts +14 -4
- package/src/review/cells.ts +24 -3
- package/src/review/format.ts +33 -9
- package/src/review/media-kind.ts +14 -11
- package/src/review/media-read.ts +6 -5
- package/src/review/model.ts +104 -7
- package/src/review/paste.ts +2 -1
- package/src/review/previews.ts +123 -36
- package/src/review/routes.ts +29 -18
- package/src/review/store.ts +74 -12
- package/src/review/threads.ts +7 -5
- package/src/secrets/copy.ts +110 -0
- package/src/secrets/list.ts +17 -7
- package/src/serve/hub-app/home-strip.css +5 -0
- package/src/serve/hub-app/home-strip.tsx +18 -0
- package/src/serve/hub-app/hub-app.tsx +2 -1
- package/src/serve/hub-app/hub.css +18 -0
- package/src/serve/hub-app/inbox.css +1 -0
- package/src/serve/hub-app/pull-refresh.tsx +88 -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/serve/hub-app/review/review-cells.tsx +52 -13
- package/src/serve/hub-app/review/review-list.tsx +6 -1
- package/src/serve/hub-app/review/review-st.ts +6 -5
- package/src/serve/hub-app/review/review-thread.tsx +3 -1
- package/src/serve/hub-app/review/review-views.tsx +18 -11
- package/src/serve/hub-app/review/thread-st.ts +82 -14
- package/src/serve/hub-app/review.css +15 -2
- package/src/serve/hub-runtime.ts +2 -1
- package/src/serve/run-serve.ts +4 -2
- package/src/serve/serve-hub.ts +9 -2
- 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/suite/child-tools.ts +45 -0
- package/src/suite/judge-suites.ts +10 -22
- package/src/suite/select.ts +83 -8
- package/src/suite/suite-cli.ts +38 -14
- package/src/suite/suite-cores.ts +68 -0
- package/src/suite/suite-reads-preload.ts +8 -6
- package/src/ts/config.ts +44 -0
- package/src/ts/rename.ts +11 -1
|
@@ -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")
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// the clipboard indicator (wiki tools/shipkit/recordings.md, The recorder): a small bezel at the top right of the
|
|
2
|
+
// screen under the pointer, never taking a click or the focus. It shows only what Clip read back: « Copied » once
|
|
3
|
+
// the write is confirmed, then the format and size the clipboard serves once its data is made. It follows the newest
|
|
4
|
+
// still only: a stale job's answer never reaches it
|
|
5
|
+
import AppKit
|
|
6
|
+
|
|
7
|
+
enum HudState {
|
|
8
|
+
/** the write landed and reads back; the data is still being made */
|
|
9
|
+
case copied(ClipFormat)
|
|
10
|
+
/** the clipboard read back once the data was made */
|
|
11
|
+
case checked(ClipCheck)
|
|
12
|
+
/** the write did not land */
|
|
13
|
+
case failed(String)
|
|
14
|
+
|
|
15
|
+
var look: (symbol: String, tint: NSColor, title: String, detail: String) {
|
|
16
|
+
switch self {
|
|
17
|
+
case let .copied(f):
|
|
18
|
+
("doc.on.clipboard", .white, "Copied", f == .png ? "making the PNG…" : "making the \(f.label)…")
|
|
19
|
+
case let .checked(.ready(f, n)):
|
|
20
|
+
("checkmark.circle.fill", .systemGreen, "\(f) on the clipboard", n)
|
|
21
|
+
case let .checked(.fallback(why, n)):
|
|
22
|
+
("exclamationmark.triangle.fill", .systemOrange, "PNG on the clipboard · \(n)", why)
|
|
23
|
+
case .checked(.replaced):
|
|
24
|
+
("arrow.triangle.2.circlepath", .systemGray, "Clipboard replaced", "another copy came before this still was ready")
|
|
25
|
+
case let .checked(.unreadable(why)), let .failed(why):
|
|
26
|
+
("xmark.octagon.fill", .systemRed, "Not on the clipboard", why)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
var final: Bool { if case .copied = self { false } else { true } }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** the bezel's ground, drawn rather than a layer's: its corners stay clear on screen and in a drawn proof alike */
|
|
34
|
+
final class Bezel: NSView {
|
|
35
|
+
override var isOpaque: Bool { false }
|
|
36
|
+
override func draw(_ r: NSRect) {
|
|
37
|
+
let p = NSBezierPath(roundedRect: bounds.insetBy(dx: 0.5, dy: 0.5), xRadius: 12, yRadius: 12)
|
|
38
|
+
NSColor(white: 0.12, alpha: 0.92).setFill()
|
|
39
|
+
p.fill()
|
|
40
|
+
NSColor(white: 1, alpha: 0.12).setStroke()
|
|
41
|
+
p.stroke()
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@MainActor
|
|
46
|
+
final class ClipHud {
|
|
47
|
+
static let shared = ClipHud()
|
|
48
|
+
/** how long a final state stays */
|
|
49
|
+
static let HOLD: TimeInterval = 1.8
|
|
50
|
+
private var panel: NSPanel?
|
|
51
|
+
/** whose states it shows: the newest copy's token */
|
|
52
|
+
private weak var job: AnyObject?
|
|
53
|
+
private var hide: Timer?
|
|
54
|
+
/** the title on screen now, nil when hidden: what a smoke reads */
|
|
55
|
+
private(set) var shownTitle: String?
|
|
56
|
+
|
|
57
|
+
/** every state drawn is handed here too: the editor window shows it, for eyes that are not on the corner */
|
|
58
|
+
var mirror: ((HudState) -> Void)?
|
|
59
|
+
|
|
60
|
+
/** a new copy starts: from now on only `owner`'s states show, so an older copy's late answer is dropped */
|
|
61
|
+
func begin(_ owner: AnyObject) { job = owner }
|
|
62
|
+
|
|
63
|
+
/** `owner`'s state, shown while it is the newest copy */
|
|
64
|
+
func show(_ owner: AnyObject, _ s: HudState) {
|
|
65
|
+
guard job === owner else { return }
|
|
66
|
+
draw(s)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** a state on screen with no still behind it, for the on-screen proof; where it sits, in global points */
|
|
70
|
+
func demo(_ s: HudState) -> NSRect {
|
|
71
|
+
job = nil
|
|
72
|
+
draw(s)
|
|
73
|
+
return panel!.frame
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private func draw(_ s: HudState) {
|
|
77
|
+
shownTitle = s.look.title
|
|
78
|
+
mirror?(s)
|
|
79
|
+
let p = panel ?? makePanel()
|
|
80
|
+
panel = p
|
|
81
|
+
p.contentView = content(s)
|
|
82
|
+
p.setContentSize(p.contentView!.fittingSize)
|
|
83
|
+
place(p)
|
|
84
|
+
p.alphaValue = 1
|
|
85
|
+
p.orderFrontRegardless()
|
|
86
|
+
hide?.invalidate()
|
|
87
|
+
hide = Timer.scheduledTimer(withTimeInterval: s.final ? ClipHud.HOLD : 10, repeats: false) { _ in
|
|
88
|
+
MainActor.assumeIsolated { self.fadeOut() }
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private func fadeOut() {
|
|
93
|
+
guard let p = panel else { return }
|
|
94
|
+
NSAnimationContext.runAnimationGroup({ c in
|
|
95
|
+
c.duration = 0.25
|
|
96
|
+
p.animator().alphaValue = 0
|
|
97
|
+
}, completionHandler: { MainActor.assumeIsolated { p.orderOut(nil) } })
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private func makePanel() -> NSPanel {
|
|
101
|
+
let p = NSPanel(contentRect: NSRect(x: 0, y: 0, width: 240, height: 56), styleMask: [.borderless, .nonactivatingPanel], backing: .buffered, defer: false)
|
|
102
|
+
p.level = .statusBar
|
|
103
|
+
p.isOpaque = false
|
|
104
|
+
p.backgroundColor = .clear
|
|
105
|
+
p.hasShadow = true
|
|
106
|
+
p.ignoresMouseEvents = true
|
|
107
|
+
p.isReleasedWhenClosed = false
|
|
108
|
+
p.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary, .stationary, .ignoresCycle]
|
|
109
|
+
return p
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private func place(_ p: NSPanel) {
|
|
113
|
+
let screen = NSScreen.screens.first { $0.frame.contains(NSEvent.mouseLocation) } ?? NSScreen.main ?? NSScreen.screens[0]
|
|
114
|
+
let v = screen.visibleFrame
|
|
115
|
+
p.setFrameOrigin(NSPoint(x: v.maxX - p.frame.width - 12, y: v.maxY - p.frame.height - 12))
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** one state's bezel, for this panel and for the editor window */
|
|
119
|
+
func content(_ s: HudState) -> NSView {
|
|
120
|
+
let l = s.look
|
|
121
|
+
let icon = NSImageView(image: NSImage(systemSymbolName: l.symbol, accessibilityDescription: l.title)!)
|
|
122
|
+
icon.symbolConfiguration = .init(pointSize: 22, weight: .semibold)
|
|
123
|
+
icon.contentTintColor = l.tint
|
|
124
|
+
let title = NSTextField(labelWithString: l.title)
|
|
125
|
+
title.font = .systemFont(ofSize: 13, weight: .semibold)
|
|
126
|
+
title.textColor = .white
|
|
127
|
+
let detail = NSTextField(labelWithString: l.detail)
|
|
128
|
+
detail.font = .systemFont(ofSize: 11)
|
|
129
|
+
detail.textColor = NSColor(white: 1, alpha: 0.7)
|
|
130
|
+
detail.lineBreakMode = .byTruncatingTail
|
|
131
|
+
detail.preferredMaxLayoutWidth = 320
|
|
132
|
+
let text = NSStackView(views: [title, detail])
|
|
133
|
+
text.orientation = .vertical
|
|
134
|
+
text.alignment = .leading
|
|
135
|
+
text.spacing = 1
|
|
136
|
+
let row = NSStackView(views: [icon, text])
|
|
137
|
+
row.orientation = .horizontal
|
|
138
|
+
row.alignment = .centerY
|
|
139
|
+
row.spacing = 10
|
|
140
|
+
row.edgeInsets = NSEdgeInsets(top: 10, left: 12, bottom: 10, right: 16)
|
|
141
|
+
let ground = Bezel()
|
|
142
|
+
row.translatesAutoresizingMaskIntoConstraints = false
|
|
143
|
+
ground.addSubview(row)
|
|
144
|
+
NSLayoutConstraint.activate([
|
|
145
|
+
row.leadingAnchor.constraint(equalTo: ground.leadingAnchor), row.trailingAnchor.constraint(equalTo: ground.trailingAnchor),
|
|
146
|
+
row.topAnchor.constraint(equalTo: ground.topAnchor), row.bottomAnchor.constraint(equalTo: ground.bottomAnchor),
|
|
147
|
+
row.widthAnchor.constraint(lessThanOrEqualToConstant: 400),
|
|
148
|
+
])
|
|
149
|
+
return ground
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** every state drawn to `<dir>/hud-<state>.png`, over a light and a dark desktop: the card's proof, no screen grant */
|
|
153
|
+
func drawStates(to dir: URL) throws {
|
|
154
|
+
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
|
|
155
|
+
let states: [(String, HudState)] = [
|
|
156
|
+
("1-copied", .copied(.webpHigh)),
|
|
157
|
+
("2-ready", .checked(.ready(format: "WebP HQ", size: "41 KB"))),
|
|
158
|
+
("3-fallback", .checked(.fallback(why: "WebP HQ needs cwebp (brew install webp)", size: "7.2 MB"))),
|
|
159
|
+
("4-replaced", .checked(.replaced)),
|
|
160
|
+
("5-failed", .failed("the clipboard refused the still")),
|
|
161
|
+
]
|
|
162
|
+
for (name, s) in states {
|
|
163
|
+
let v = content(s)
|
|
164
|
+
v.frame = NSRect(origin: .zero, size: v.fittingSize)
|
|
165
|
+
v.layoutSubtreeIfNeeded()
|
|
166
|
+
let pad: CGFloat = 16
|
|
167
|
+
let size = NSSize(width: v.frame.width + pad * 2, height: (v.frame.height + pad) * 2 + pad)
|
|
168
|
+
guard let rep = v.bitmapImageRepForCachingDisplay(in: v.bounds) else { throw Err("the indicator drew nothing") }
|
|
169
|
+
v.cacheDisplay(in: v.bounds, to: rep)
|
|
170
|
+
let img = NSImage(size: size)
|
|
171
|
+
img.lockFocus()
|
|
172
|
+
NSColor(white: 0.93, alpha: 1).setFill()
|
|
173
|
+
NSRect(x: 0, y: size.height / 2, width: size.width, height: size.height / 2).fill()
|
|
174
|
+
NSColor(white: 0.2, alpha: 1).setFill()
|
|
175
|
+
NSRect(x: 0, y: 0, width: size.width, height: size.height / 2).fill()
|
|
176
|
+
// an offscreen draw fills the bezel's corners: clipped to its own shape, as the clear panel shows it
|
|
177
|
+
for y in [size.height / 2 + pad / 2, pad / 2] {
|
|
178
|
+
let r = NSRect(x: pad, y: y, width: v.frame.width, height: v.frame.height)
|
|
179
|
+
NSGraphicsContext.saveGraphicsState()
|
|
180
|
+
NSBezierPath(roundedRect: r, xRadius: 12, yRadius: 12).addClip()
|
|
181
|
+
rep.draw(in: r)
|
|
182
|
+
NSGraphicsContext.restoreGraphicsState()
|
|
183
|
+
}
|
|
184
|
+
img.unlockFocus()
|
|
185
|
+
guard let tiff = img.tiffRepresentation, let png = NSBitmapImageRep(data: tiff)?.representation(using: .png, properties: [:]) else { throw Err("the indicator drew nothing") }
|
|
186
|
+
try png.write(to: dir.appendingPathComponent("hud-\(name).png"))
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|