rvlib-shipkit 2.19.0 → 2.21.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 +32 -0
- package/package.json +1 -1
- package/src/annex/annex.ts +227 -0
- package/src/annex/offload.ts +279 -0
- package/src/checks/SK004-gitignore-policy.check.ts +6 -3
- package/src/checks/SK040-release-words.check.ts +43 -0
- package/src/checks/SK041-annex-links.check.ts +28 -0
- package/src/checks/SK042-post-kinds.check.ts +73 -0
- package/src/cli/cmd_Annex.ts +179 -0
- package/src/cli/cmd_Commands.ts +4 -1
- package/src/cli/cmd_GlobalProcesses.ts +2 -107
- package/src/cli/cmd_Home.ts +4 -3
- package/src/cli/cmd_Messages.ts +155 -0
- package/src/cli/cmd_Overview.ts +2 -1
- package/src/cli/cmd_Releases.ts +84 -0
- package/src/cli/cmd_Review.ts +176 -12
- package/src/cli/cmd_Shot.ts +4 -4
- package/src/cli/cmd_Social.ts +151 -8
- package/src/cli/cmd_Sound.ts +17 -4
- package/src/cli/cmd_Trailer.ts +67 -1
- package/src/cli/family-pages.ts +2 -0
- package/src/cli/kit/index.ts +1 -1
- package/src/cli/kit/verb.ts +11 -3
- package/src/cli/registry.ts +7 -1
- package/src/collections/collection-types.ts +8 -1
- package/src/collections/providers.ts +4 -1
- package/src/collections/review.ts +23 -4
- package/src/commands/model.ts +36 -0
- package/src/commands/registry.ts +49 -0
- package/src/commands/routes.ts +59 -0
- package/src/commands/runner.ts +35 -0
- package/src/commands/runs.ts +112 -0
- package/src/core/app-icon.ts +4 -3
- package/src/core/icon-type.ts +8 -0
- package/src/core/jobs.ts +4 -3
- package/src/core/layout.ts +11 -2
- package/src/core/squircle.ts +95 -0
- package/src/home/daemon-jobs.ts +26 -2
- package/src/home/global-units.ts +3 -0
- package/src/home/gui-app/ShipkitGui.swift +337 -5
- package/src/home/gui-app.ts +64 -33
- package/src/home/hmr-keep.ts +134 -0
- package/src/home/home-start.ts +2 -2
- package/src/home/lib-watch.ts +21 -11
- package/src/home/pm-switch.ts +112 -0
- package/src/home/pm.ts +1 -1
- package/src/home/process-apps.ts +181 -0
- package/src/home/resources.ts +3 -3
- package/src/home/run-web.ts +7 -4
- package/src/home/serve-web.ts +64 -14
- package/src/identities/collection.ts +49 -0
- package/src/identities/identities.ts +121 -14
- package/src/identities/machine.ts +4 -3
- package/src/identities/rating.ts +33 -0
- package/src/identities/shown.ts +170 -0
- package/src/identities/steps.ts +5 -0
- package/src/media-store/purge.ts +15 -1
- package/src/media-store/remote.ts +22 -6
- package/src/messages/brief.ts +117 -0
- package/src/messages/collection.ts +40 -0
- package/src/messages/model.ts +171 -0
- package/src/messages/routes.ts +15 -0
- package/src/messages/score.ts +182 -0
- package/src/messages/tabs.ts +13 -0
- package/src/release/notes.ts +130 -0
- package/src/release/run-bump.ts +41 -18
- package/src/release/run-release.ts +22 -4
- package/src/release/run-releases.ts +17 -15
- package/src/release/unit-resolve.ts +9 -0
- package/src/releases/add.ts +94 -0
- package/src/releases/before.ts +31 -0
- package/src/releases/collection.ts +36 -0
- package/src/releases/from-card.ts +151 -0
- package/src/releases/model.ts +327 -0
- package/src/releases/pictures.ts +110 -0
- package/src/releases/routes.ts +36 -0
- package/src/releases/store.ts +71 -0
- package/src/repo-config.ts +5 -0
- package/src/review/cells.ts +0 -11
- package/src/review/format.ts +10 -6
- package/src/review/http.ts +1 -1
- package/src/review/model.ts +102 -3
- package/src/review/notes.ts +2 -48
- package/src/review/routes.ts +28 -10
- package/src/review/stage-card.ts +197 -0
- package/src/review/stage-routes.ts +123 -0
- package/src/review/store.ts +47 -1
- package/src/review/trailer-card.ts +99 -0
- package/src/review/trailer-desk.ts +76 -4
- package/src/review/trailer-model.ts +106 -7
- package/src/review/trailer-notes.ts +45 -0
- package/src/review/trailer-routes.ts +119 -13
- package/src/review/trailer-voices.ts +144 -0
- package/src/review/watchers.ts +58 -1
- package/src/serve/hub-app/app-bridge.ts +71 -0
- package/src/serve/hub-app/benign-errors.ts +22 -0
- package/src/serve/hub-app/commands/commands-page.tsx +122 -0
- package/src/serve/hub-app/commands/commands-st.ts +177 -0
- package/src/serve/hub-app/commands.css +24 -0
- package/src/serve/hub-app/hash-route.ts +59 -8
- package/src/serve/hub-app/home-st.ts +19 -2
- package/src/serve/hub-app/home.html +3 -0
- package/src/serve/hub-app/hub-app.tsx +8 -0
- package/src/serve/hub-app/icons.tsx +5 -0
- package/src/serve/hub-app/identities-view.tsx +4 -1
- package/src/serve/hub-app/identities.css +1 -0
- package/src/serve/hub-app/index.html +3 -0
- package/src/serve/hub-app/keys.ts +2 -2
- package/src/serve/hub-app/machine-st.ts +41 -10
- package/src/serve/hub-app/messages/messages-page.tsx +354 -0
- package/src/serve/hub-app/messages/messages-st.ts +74 -0
- package/src/serve/hub-app/messages.css +35 -0
- package/src/serve/hub-app/project-list.css +7 -2
- package/src/serve/hub-app/project-list.tsx +9 -0
- package/src/serve/hub-app/projects-svc.ts +16 -6
- package/src/serve/hub-app/releases/releases-page.tsx +187 -0
- package/src/serve/hub-app/releases/releases-st.ts +111 -0
- package/src/serve/hub-app/releases.css +52 -0
- package/src/serve/hub-app/repo-sections.ts +16 -2
- package/src/serve/hub-app/repo-st.ts +66 -10
- package/src/serve/hub-app/review/clip-st.ts +34 -4
- package/src/serve/hub-app/review/kit.tsx +3 -3
- package/src/serve/hub-app/review/note-place.ts +31 -0
- package/src/serve/hub-app/review/review-cells.tsx +27 -3
- package/src/serve/hub-app/review/review-st.ts +77 -2
- package/src/serve/hub-app/review/review-thread.tsx +9 -31
- package/src/serve/hub-app/review/review-views.tsx +164 -58
- package/src/serve/hub-app/review/thread-st.ts +108 -41
- package/src/serve/hub-app/review/trailer-card.tsx +187 -0
- package/src/serve/hub-app/review/trailer-page.tsx +92 -36
- package/src/serve/hub-app/review/trailer-st.ts +306 -34
- package/src/serve/hub-app/review/trailer-timeline.tsx +68 -23
- package/src/serve/hub-app/review/trailer-voices-st.ts +370 -0
- package/src/serve/hub-app/review/trailer-voices.tsx +574 -0
- package/src/serve/hub-app/review.css +137 -6
- package/src/serve/hub-app/social/comms-page.tsx +65 -28
- package/src/serve/hub-app/social/identity-pictures.ts +46 -8
- package/src/serve/hub-app/social/kit.tsx +9 -6
- package/src/serve/hub-app/social/next-release.tsx +118 -0
- package/src/serve/hub-app/social/post-card.tsx +10 -2
- package/src/serve/hub-app/social/social-model.ts +39 -3
- package/src/serve/hub-app/social/social-page.tsx +179 -65
- package/src/serve/hub-app/social/social-st.ts +117 -27
- package/src/serve/hub-app/social/stage-popup.tsx +268 -0
- package/src/serve/hub-app/social/stage-st.ts +310 -0
- package/src/serve/hub-app/social/step-layout.ts +42 -0
- package/src/serve/hub-app/social.css +68 -1
- package/src/serve/hub-app/tree-build.ts +40 -1
- package/src/serve/hub-app/tree-svc.ts +10 -3
- package/src/serve/project-gutter-route.ts +12 -2
- package/src/serve/project-gutter.ts +4 -2
- package/src/serve/same-origin.ts +24 -1
- package/src/serve/serve-hub.ts +15 -1
- package/src/shipkit-files.ts +9 -7
- package/src/shot/box.ts +33 -12
- package/src/shot/client.ts +1 -1
- package/src/shot/shooter.ts +22 -12
- package/src/shot/shot-ask.ts +14 -3
- package/src/shot/shot.shipkit.ts +1 -1
- package/src/social/desk-index.ts +49 -8
- package/src/social/discord-layout.ts +54 -7
- package/src/social/drafts.ts +1 -1
- package/src/social/fit.ts +84 -0
- package/src/social/identity-words.ts +74 -0
- package/src/social/kind-pages.ts +41 -0
- package/src/social/kinds.ts +93 -0
- package/src/social/load.ts +125 -10
- package/src/social/media-limit.ts +63 -2
- package/src/social/presence.ts +1 -1
- package/src/social/publish/bluesky.ts +58 -19
- package/src/social/publish/index.ts +47 -6
- package/src/social/reach.ts +49 -0
- package/src/social/release-stage.ts +277 -0
- package/src/social/routes.ts +44 -8
- package/src/social/stage.ts +246 -0
- package/src/social/strip.ts +85 -0
- package/src/social/text.ts +6 -2
- package/src/social/unit.ts +57 -1
- package/src/social/writes.ts +11 -0
- package/src/trailer/bed.ts +111 -0
- package/src/trailer/build.ts +72 -40
- package/src/trailer/ffmpeg.ts +6 -0
- package/src/trailer/grammar.ts +37 -6
- package/src/trailer/graph.ts +12 -1
- package/src/trailer/public-words.ts +41 -0
- package/src/trailer/shot-plan.ts +75 -0
- package/src/trailer/shot-state.ts +191 -0
- package/src/trailer/sound/audio.ts +28 -0
- package/src/trailer/sound/brand.ts +53 -3
- package/src/trailer/sound/gen.ts +61 -2
- package/src/trailer/sound/index.ts +25 -11
- package/src/trailer/sound/presets.ts +86 -5
- package/src/trailer/sound/run.ts +1 -1
- package/src/trailer/sound/takes.ts +94 -0
- package/src/trailer/titles.ts +36 -0
- package/src/trailer/url.ts +1 -1
|
@@ -5,12 +5,50 @@
|
|
|
5
5
|
// a bare launch opens (ShipkitStartURL). One WKWebView per window; every
|
|
6
6
|
// `open -a <app> <url>` opens one more window, cmd-n too. A link to another
|
|
7
7
|
// site opens in the default browser, and a download lands in ~/Downloads.
|
|
8
|
+
// The shipkit app alone wears the Dock badge of the review cards waiting for
|
|
9
|
+
// the owner and notifies each new one, as its page posts them (`shipkit`
|
|
10
|
+
// message handler, serve/hub-app/app-bridge.ts).
|
|
8
11
|
import AppKit
|
|
12
|
+
import UserNotifications
|
|
9
13
|
import WebKit
|
|
10
14
|
|
|
11
15
|
let info = Bundle.main.infoDictionary ?? [:]
|
|
12
16
|
let appName = (info["CFBundleName"] as? String) ?? "shipkit"
|
|
13
17
|
let startURL = URL(string: (info["ShipkitStartURL"] as? String) ?? "") ?? URL(string: "http://127.0.0.1:4799/")!
|
|
18
|
+
/** the shipkit app itself (home/gui-app.ts BUNDLE_ID), never a process app */
|
|
19
|
+
let isShipkit = Bundle.main.bundleIdentifier == "dev.shipkit.gui"
|
|
20
|
+
|
|
21
|
+
/** a card that started waiting, as the page posts it */
|
|
22
|
+
struct Card {
|
|
23
|
+
let id: String, title: String, repo: String, url: String
|
|
24
|
+
var key: String { "\(repo)/\(id)" }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** one notification: a card, or the line for the rest of a burst, which opens the inbox of the home they came from */
|
|
28
|
+
enum Note {
|
|
29
|
+
case card(Card)
|
|
30
|
+
case more([Card], inbox: URL?)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** what a burst of new cards shows: each card up to `cap`, then one line for the rest */
|
|
34
|
+
func notesOf(_ cards: [Card], cap: Int = 3) -> [Note] {
|
|
35
|
+
if cards.count <= cap { return cards.map { .card($0) } }
|
|
36
|
+
let inbox = URL(string: cards[cap].url).flatMap { URL(string: "/inbox", relativeTo: $0)?.absoluteURL }
|
|
37
|
+
return cards.prefix(cap).map { .card($0) } + [.more(Array(cards.dropFirst(cap)), inbox: inbox)]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** a notification's identifier: its card's key, so the banner can be taken back once the card stops waiting */
|
|
41
|
+
func idOf(_ note: Note) -> String {
|
|
42
|
+
switch note {
|
|
43
|
+
case .card(let c): return c.key
|
|
44
|
+
case .more(let cards, _): return "more:" + cards.map(\.key).joined(separator: ",")
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** the banners to take back: a card's once it no longer waits, a burst line's once none of its cards does */
|
|
49
|
+
func staleOf(_ delivered: [(id: String, cards: [String])], waiting: Set<String>) -> [String] {
|
|
50
|
+
delivered.filter { $0.cards.allSatisfy { !waiting.contains($0) } }.map(\.id)
|
|
51
|
+
}
|
|
14
52
|
|
|
15
53
|
/** a url that stays in the app: the machine itself, or the host the app is for */
|
|
16
54
|
func stays(_ url: URL) -> Bool {
|
|
@@ -124,15 +162,33 @@ final class Pane: NSView, NSSearchFieldDelegate {
|
|
|
124
162
|
}
|
|
125
163
|
}
|
|
126
164
|
|
|
127
|
-
final class Delegate: NSObject, NSApplicationDelegate, WKNavigationDelegate, WKUIDelegate, WKDownloadDelegate, NSWindowDelegate, NSMenuItemValidation {
|
|
165
|
+
final class Delegate: NSObject, NSApplicationDelegate, WKNavigationDelegate, WKUIDelegate, WKDownloadDelegate, NSWindowDelegate, NSMenuItemValidation, WKScriptMessageHandler, UNUserNotificationCenterDelegate {
|
|
128
166
|
var windows: [NSWindow] = []
|
|
129
167
|
var opened = false
|
|
130
168
|
|
|
169
|
+
// a click on a notification can launch the app: its delegate is set before launch ends
|
|
170
|
+
func applicationWillFinishLaunching(_ note: Notification) {
|
|
171
|
+
if isShipkit && !CommandLine.arguments.contains(where: { $0.hasPrefix("--self-test") }) { UNUserNotificationCenter.current().delegate = self }
|
|
172
|
+
}
|
|
173
|
+
|
|
131
174
|
func applicationDidFinishLaunching(_ note: Notification) {
|
|
132
175
|
if CommandLine.arguments.contains("--self-test-find") { return selfTestFind() }
|
|
176
|
+
if CommandLine.arguments.contains("--self-test-mic") { return selfTestMic() }
|
|
133
177
|
if CommandLine.arguments.contains("--self-test-panels") { return selfTestPanels() }
|
|
134
178
|
if CommandLine.arguments.contains("--self-test-download") { return selfTestDownload() }
|
|
179
|
+
if CommandLine.arguments.contains("--self-test-badge") { return selfTestBadge() }
|
|
135
180
|
buildMenu()
|
|
181
|
+
// the system asks the owner once; refused, the badge still counts and each notification says why it did not show
|
|
182
|
+
if isShipkit {
|
|
183
|
+
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound]) { ok, err in
|
|
184
|
+
if !ok { NSLog("shipkit: notifications are off for this app (System Settings, Notifications, shipkit)\(err.map { ": \($0.localizedDescription)" } ?? "")") }
|
|
185
|
+
}
|
|
186
|
+
// `--background`: running with no window from the start, the badge live, as after the last window closed
|
|
187
|
+
if CommandLine.arguments.contains("--background") {
|
|
188
|
+
opened = true
|
|
189
|
+
keep(home: startURL)
|
|
190
|
+
}
|
|
191
|
+
}
|
|
136
192
|
// esc closes the find bar of the key window, and reaches the page otherwise
|
|
137
193
|
NSEvent.addLocalMonitorForEvents(matching: .keyDown) { e in
|
|
138
194
|
if e.keyCode == 53, let pane = self.keyPane(), pane.isFindBarVisible {
|
|
@@ -154,7 +210,8 @@ final class Delegate: NSObject, NSApplicationDelegate, WKNavigationDelegate, WKU
|
|
|
154
210
|
for u in urls { open(u) }
|
|
155
211
|
}
|
|
156
212
|
|
|
157
|
-
|
|
213
|
+
// the shipkit app stays running with no window, as a mail or chat app does, so its badge stays live; Quit ends it
|
|
214
|
+
func applicationShouldTerminateAfterLastWindowClosed(_ app: NSApplication) -> Bool { !isShipkit }
|
|
158
215
|
|
|
159
216
|
func applicationShouldHandleReopen(_ app: NSApplication, hasVisibleWindows: Bool) -> Bool {
|
|
160
217
|
if !hasVisibleWindows { open(startURL) }
|
|
@@ -214,11 +271,31 @@ final class Delegate: NSObject, NSApplicationDelegate, WKNavigationDelegate, WKU
|
|
|
214
271
|
return true
|
|
215
272
|
}
|
|
216
273
|
|
|
217
|
-
func
|
|
218
|
-
opened = true
|
|
274
|
+
func webConfig() -> WKWebViewConfiguration {
|
|
219
275
|
let config = WKWebViewConfiguration()
|
|
220
276
|
config.preferences.setValue(true, forKey: "developerExtrasEnabled")
|
|
221
|
-
|
|
277
|
+
if isShipkit {
|
|
278
|
+
config.userContentController.add(self, name: "shipkit")
|
|
279
|
+
// the badge's poll keeps its pace while the window is hidden or covered
|
|
280
|
+
if #available(macOS 14.0, *) { config.preferences.inactiveSchedulingPolicy = .none }
|
|
281
|
+
}
|
|
282
|
+
return config
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** the page of the home the app keeps loaded while no window is open: it alone keeps the badge and the
|
|
286
|
+
* notifications live, and leaves once a window's page posts again */
|
|
287
|
+
var keeper: WKWebView?
|
|
288
|
+
|
|
289
|
+
func keep(home: URL) {
|
|
290
|
+
let web = WKWebView(frame: NSRect(x: 0, y: 0, width: 1400, height: 900), configuration: webConfig())
|
|
291
|
+
web.navigationDelegate = self
|
|
292
|
+
web.load(URLRequest(url: home))
|
|
293
|
+
keeper = web
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
func open(_ url: URL) {
|
|
297
|
+
opened = true
|
|
298
|
+
let web = WKWebView(frame: .zero, configuration: webConfig())
|
|
222
299
|
if #available(macOS 13.3, *) { web.isInspectable = true }
|
|
223
300
|
web.navigationDelegate = self
|
|
224
301
|
web.uiDelegate = self
|
|
@@ -269,6 +346,32 @@ final class Delegate: NSObject, NSApplicationDelegate, WKNavigationDelegate, WKU
|
|
|
269
346
|
web.loadHTMLString("<p>one needle, two needle</p>", baseURL: nil)
|
|
270
347
|
}
|
|
271
348
|
|
|
349
|
+
// `--self-test-mic`: a window's own web view on a page of the machine, then on a page of another host, each
|
|
350
|
+
// printing whether the page can reach the microphone api (`getUserMedia`); no capture is asked, so no prompt
|
|
351
|
+
func selfTestMic() {
|
|
352
|
+
let web = WKWebView(frame: NSRect(x: 0, y: 0, width: 400, height: 300), configuration: webConfig())
|
|
353
|
+
web.navigationDelegate = self
|
|
354
|
+
web.uiDelegate = self
|
|
355
|
+
windows.append(NSWindow(contentRect: NSRect(x: -4000, y: -4000, width: 400, height: 300), styleMask: [.titled], backing: .buffered, defer: false))
|
|
356
|
+
windows.last?.contentView = web
|
|
357
|
+
let probe = "typeof (navigator.mediaDevices && navigator.mediaDevices.getUserMedia)"
|
|
358
|
+
onLoad = { _ in
|
|
359
|
+
web.evaluateJavaScript(probe) { local, _ in
|
|
360
|
+
print("local=\(local as? String ?? "error")")
|
|
361
|
+
self.onLoad = { _ in
|
|
362
|
+
web.evaluateJavaScript(probe) { other, _ in
|
|
363
|
+
print("other=\(other as? String ?? "error")")
|
|
364
|
+
exit((local as? String) == "function" ? 0 : 1)
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
web.loadHTMLString("<p>other</p>", baseURL: URL(string: "http://example.invalid/"))
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
// the page the test serves on the machine, loaded over http as a window loads the home
|
|
371
|
+
let served = CommandLine.arguments.last.flatMap { URL(string: $0) }.flatMap { $0.scheme == "http" ? $0 : nil }
|
|
372
|
+
if let url = served { web.load(URLRequest(url: url)) } else { web.loadHTMLString("<p>local</p>", baseURL: URL(string: "http://127.0.0.1:9/")) }
|
|
373
|
+
}
|
|
374
|
+
|
|
272
375
|
/** hears every js panel once it shows: the self test answers it */
|
|
273
376
|
var onPanel: ((NSAlert) -> Void)?
|
|
274
377
|
|
|
@@ -325,7 +428,16 @@ final class Delegate: NSObject, NSApplicationDelegate, WKNavigationDelegate, WKU
|
|
|
325
428
|
}
|
|
326
429
|
|
|
327
430
|
func windowWillClose(_ note: Notification) {
|
|
431
|
+
let pane = (note.object as? NSWindow)?.contentView as? Pane
|
|
328
432
|
windows.removeAll { $0 === note.object as? NSWindow }
|
|
433
|
+
guard let pane else { return }
|
|
434
|
+
// the last window leaves the home loaded with no window, on the home that window was on; its count holds
|
|
435
|
+
// until that page posts its own
|
|
436
|
+
if isShipkit && windows.isEmpty && keeper == nil {
|
|
437
|
+
keep(home: pane.web.url.flatMap { stays($0) ? URL(string: "/", relativeTo: $0)?.absoluteURL : nil } ?? startURL)
|
|
438
|
+
return
|
|
439
|
+
}
|
|
440
|
+
dropCount(pane.web)
|
|
329
441
|
}
|
|
330
442
|
|
|
331
443
|
// the page title names the window, so cmd-tab and the window menu tell pages apart
|
|
@@ -430,6 +542,218 @@ final class Delegate: NSObject, NSApplicationDelegate, WKNavigationDelegate, WKU
|
|
|
430
542
|
web.loadHTMLString("<body data-page=here><a id=a href='data:text/plain,hello' download='hello.txt'>save</a></body>", baseURL: nil)
|
|
431
543
|
}
|
|
432
544
|
|
|
545
|
+
// the Dock badge and the notifications: every window's page posts the same house count, the cards waiting at its
|
|
546
|
+
// first answer (the seed) and those it saw start waiting after; the app owns the one set of cards notified, so a
|
|
547
|
+
// card notifies once whatever the number of windows or reloads, a burst gathered for half a second
|
|
548
|
+
|
|
549
|
+
/** the cards already notified or already waiting at start, for the life of the app */
|
|
550
|
+
var notified = Set<String>()
|
|
551
|
+
/** the first seed of the app's life is the backlog: it never notifies */
|
|
552
|
+
var seeded = false
|
|
553
|
+
var burst: [Card] = []
|
|
554
|
+
/** each web view's last count: a page that leaves the home, or a closed window, drops out of the badge */
|
|
555
|
+
var counts: [ObjectIdentifier: Int] = [:]
|
|
556
|
+
/** hears every notification instead of the system: the self test reads it */
|
|
557
|
+
var deliver: ((Note) -> Void)?
|
|
558
|
+
|
|
559
|
+
func userContentController(_ controller: WKUserContentController, didReceive message: WKScriptMessage) {
|
|
560
|
+
guard message.frameInfo.isMainFrame, let body = message.body as? [String: Any] else { return }
|
|
561
|
+
if let n = body["waiting"] as? Int, let web = message.webView {
|
|
562
|
+
// a window's page posts again: the page kept with no window leaves
|
|
563
|
+
if let k = keeper, k !== web {
|
|
564
|
+
keeper = nil
|
|
565
|
+
k.stopLoading()
|
|
566
|
+
}
|
|
567
|
+
let live = Set((windows.compactMap { ($0.contentView as? Pane)?.web } + [web]).map(ObjectIdentifier.init))
|
|
568
|
+
counts = counts.filter { live.contains($0.key) }
|
|
569
|
+
counts[ObjectIdentifier(web)] = n
|
|
570
|
+
drawBadge()
|
|
571
|
+
if let keys = body["keys"] as? [String] { takeBack(waiting: Set(keys)) }
|
|
572
|
+
}
|
|
573
|
+
if let seed = body["seed"] as? [[String: Any]] {
|
|
574
|
+
let cards = seed.compactMap(cardOf)
|
|
575
|
+
if !seeded {
|
|
576
|
+
seeded = true
|
|
577
|
+
for c in cards { notified.insert("\(c.repo)/\(c.id)") }
|
|
578
|
+
} else {
|
|
579
|
+
// a reloaded page or a later window: what waits that the app never saw arrived in between
|
|
580
|
+
cards.forEach(arrived)
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
if let c = (body["card"] as? [String: Any]).flatMap(cardOf) { arrived(c) }
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
func cardOf(_ c: [String: Any]) -> Card? {
|
|
587
|
+
guard let id = c["id"] as? String, let repo = c["repo"] as? String else { return nil }
|
|
588
|
+
return Card(id: id, title: (c["title"] as? String) ?? id, repo: repo, url: (c["url"] as? String) ?? "")
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
func arrived(_ c: Card) {
|
|
592
|
+
if !notified.insert("\(c.repo)/\(c.id)").inserted { return }
|
|
593
|
+
burst.append(c)
|
|
594
|
+
if burst.count == 1 { DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { self.flush() } }
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
func drawBadge() {
|
|
598
|
+
let n = counts.values.max() ?? 0
|
|
599
|
+
NSApp.dockTile.badgeLabel = n > 0 ? String(n) : nil
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
func dropCount(_ web: WKWebView) {
|
|
603
|
+
if counts.removeValue(forKey: ObjectIdentifier(web)) != nil { drawBadge() }
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// a new page in a window: its count is gone until the page posts one
|
|
607
|
+
func webView(_ web: WKWebView, didCommit nav: WKNavigation!) { dropCount(web) }
|
|
608
|
+
|
|
609
|
+
/** the banners of the cards that no longer wait leave Notification Center */
|
|
610
|
+
func takeBack(waiting: Set<String>) {
|
|
611
|
+
guard isShipkit, deliver == nil else { return }
|
|
612
|
+
let center = UNUserNotificationCenter.current()
|
|
613
|
+
center.getDeliveredNotifications { delivered in
|
|
614
|
+
let ids = staleOf(delivered.map { ($0.request.identifier, ($0.request.content.userInfo["cards"] as? [String]) ?? [$0.request.identifier]) }, waiting: waiting)
|
|
615
|
+
if !ids.isEmpty { center.removeDeliveredNotifications(withIdentifiers: ids) }
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
func flush() {
|
|
620
|
+
let notes = notesOf(burst)
|
|
621
|
+
burst = []
|
|
622
|
+
for n in notes { (deliver ?? notify)(n) }
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
func notify(_ note: Note) {
|
|
626
|
+
let content = UNMutableNotificationContent()
|
|
627
|
+
switch note {
|
|
628
|
+
case .card(let c):
|
|
629
|
+
content.title = c.title
|
|
630
|
+
content.body = c.repo
|
|
631
|
+
content.threadIdentifier = c.repo
|
|
632
|
+
content.userInfo = ["repo": c.repo, "id": c.id, "url": c.url, "cards": [c.key]]
|
|
633
|
+
case .more(let cards, let inbox):
|
|
634
|
+
content.title = "\(cards.count) more card\(cards.count == 1 ? "" : "s") wait for you"
|
|
635
|
+
content.body = "open the inbox"
|
|
636
|
+
content.userInfo = ["inbox": true, "url": inbox?.absoluteString ?? "", "cards": cards.map(\.key)]
|
|
637
|
+
}
|
|
638
|
+
content.sound = .default
|
|
639
|
+
UNUserNotificationCenter.current().add(UNNotificationRequest(identifier: idOf(note), content: content, trigger: nil)) { err in
|
|
640
|
+
if let err { NSLog("shipkit: a notification did not show: \(err.localizedDescription)") }
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// the app in front shows its banners too
|
|
645
|
+
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler done: @escaping (UNNotificationPresentationOptions) -> Void) {
|
|
646
|
+
done([.banner, .list, .sound])
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler done: @escaping () -> Void) {
|
|
650
|
+
route(response.notification.request.content.userInfo)
|
|
651
|
+
done()
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/** a click: a window forward on the card (or the inbox), in place through the page's hooks; a page without them,
|
|
655
|
+
* or no window at all, loads the address */
|
|
656
|
+
func route(_ info: [AnyHashable: Any]) {
|
|
657
|
+
let win = (NSApp.keyWindow?.contentView is Pane ? NSApp.keyWindow : nil) ?? windows.first
|
|
658
|
+
guard let win, let pane = win.contentView as? Pane else {
|
|
659
|
+
if let url = fallbackOf(info) { open(url) }
|
|
660
|
+
return
|
|
661
|
+
}
|
|
662
|
+
if win.isMiniaturized { win.deminiaturize(nil) }
|
|
663
|
+
win.makeKeyAndOrderFront(nil)
|
|
664
|
+
NSApp.activate(ignoringOtherApps: true)
|
|
665
|
+
openIn(pane.web, info)
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/** the address a click loads where the page has no hooks: the card's review page, or the inbox of the home the
|
|
669
|
+
* cards came from */
|
|
670
|
+
func fallbackOf(_ info: [AnyHashable: Any]) -> URL? {
|
|
671
|
+
let url = URL(string: (info["url"] as? String) ?? "")
|
|
672
|
+
return (info["inbox"] as? Bool) == true && url == nil ? URL(string: "/inbox", relativeTo: startURL)?.absoluteURL : url
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
/** the page's own hooks open the card in place; `done` hears whether they did */
|
|
676
|
+
func openIn(_ web: WKWebView, _ info: [AnyHashable: Any], done: ((Bool) -> Void)? = nil) {
|
|
677
|
+
let inbox = (info["inbox"] as? Bool) == true
|
|
678
|
+
let js = inbox ? "if (!window.shipkitApp) return false; shipkitApp.openInbox(); return true" : "if (!window.shipkitApp) return false; shipkitApp.openCard(repo, id); return true"
|
|
679
|
+
web.callAsyncJavaScript(js, arguments: ["repo": (info["repo"] as? String) ?? "", "id": (info["id"] as? String) ?? ""], in: nil, in: .page) { r in
|
|
680
|
+
if case .success(let v) = r, (v as? Bool) == true {
|
|
681
|
+
done?(true)
|
|
682
|
+
return
|
|
683
|
+
}
|
|
684
|
+
if let url = self.fallbackOf(info) { web.load(URLRequest(url: url)) }
|
|
685
|
+
done?(false)
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// `--self-test-badge`: an offscreen page posts as the hub does: the seed and a count, cards (one twice), the seed
|
|
690
|
+
// of a reload, a burst of five, the count back to zero, then a notification's click opens a card through the
|
|
691
|
+
// page's hook; the badge, the planned
|
|
692
|
+
// notifications and the card opened printed, exit 0 only when each one is as the owner would see it. Nothing
|
|
693
|
+
// reaches the system's notification center, and the test never takes the focus
|
|
694
|
+
func selfTestBadge() {
|
|
695
|
+
let config = WKWebViewConfiguration()
|
|
696
|
+
config.userContentController.add(self, name: "shipkit")
|
|
697
|
+
let web = WKWebView(frame: .zero, configuration: config)
|
|
698
|
+
web.navigationDelegate = self
|
|
699
|
+
let win = NSWindow(contentRect: NSRect(x: -4000, y: -4000, width: 600, height: 400), styleMask: [.titled], backing: .buffered, defer: false)
|
|
700
|
+
win.contentView = Pane(web: web)
|
|
701
|
+
win.orderFrontRegardless()
|
|
702
|
+
windows.append(win)
|
|
703
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 15) { print("timeout"); exit(1) }
|
|
704
|
+
var notes: [String] = []
|
|
705
|
+
deliver = { n in
|
|
706
|
+
switch n {
|
|
707
|
+
case .card(let c): notes.append("\(c.repo)/\(c.id):\(c.title)")
|
|
708
|
+
case .more(let cards, let inbox): notes.append("more:\(cards.count):\(inbox?.absoluteString ?? "none")")
|
|
709
|
+
}
|
|
710
|
+
notes[notes.count - 1] += "@" + idOf(n)
|
|
711
|
+
}
|
|
712
|
+
let post = { (js: String, then: @escaping () -> Void) in
|
|
713
|
+
web.evaluateJavaScript("(() => { const p = (m) => webkit.messageHandlers.shipkit.postMessage(m); \(js) })(); 0") { _, _ in
|
|
714
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.8, execute: then)
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
let row = { (repo: String, id: String) in "{id: '\(id)', title: 't\(id)', repo: '\(repo)', url: 'http://127.0.0.1:9/r/\(repo)/'}" }
|
|
718
|
+
let card = { (repo: String, id: String) in "p({card: \(row(repo, id))})" }
|
|
719
|
+
// the second seed is a reloaded page: a/0 waited at start, a/1 was notified, d/1 arrived during the reload
|
|
720
|
+
let reload = "p({seed: [\(row("a", "0")), \(row("a", "1")), \(row("d", "1"))]})"
|
|
721
|
+
var started = false
|
|
722
|
+
onLoad = { _ in
|
|
723
|
+
if started { return }
|
|
724
|
+
started = true
|
|
725
|
+
post("p({seed: [\(row("a", "0"))]}); p({waiting: 2})") {
|
|
726
|
+
let two = NSApp.dockTile.badgeLabel ?? "none"
|
|
727
|
+
post([card("a", "1"), card("a", "1"), card("b", "1"), reload].joined(separator: "; ")) {
|
|
728
|
+
let few = notes
|
|
729
|
+
notes = []
|
|
730
|
+
post((1...5).map { card("c", "\($0)") }.joined(separator: "; ") + "; " + card("a", "1")) {
|
|
731
|
+
let many = notes
|
|
732
|
+
post("p({waiting: 0})") {
|
|
733
|
+
let zero = NSApp.dockTile.badgeLabel ?? "none"
|
|
734
|
+
// a click on the notification of card b/1: the page's hook opens it in place
|
|
735
|
+
self.openIn(web, ["repo": "b", "id": "1", "url": "http://127.0.0.1:9/"]) { ok in
|
|
736
|
+
web.evaluateJavaScript("document.body.dataset.opened") { opened, _ in
|
|
737
|
+
let o = (opened as? String) ?? "none"
|
|
738
|
+
// the banners taken back once a/1 and c/5 alone still wait: b/1's, and one left by an older build
|
|
739
|
+
let stale = staleOf([("a/1", ["a/1"]), ("b/1", ["b/1"]), ("more:c/4,c/5", ["c/4", "c/5"]), ("F09E-0F96", ["F09E-0F96"])], waiting: ["a/1", "c/5"])
|
|
740
|
+
print("badge-two=\(two)")
|
|
741
|
+
print("few=\(few.joined(separator: ","))")
|
|
742
|
+
print("burst=\(many.joined(separator: ","))")
|
|
743
|
+
print("badge-zero=\(zero)")
|
|
744
|
+
print("click-opened=\(ok ? o : "fallback")")
|
|
745
|
+
print("stale=\(stale.joined(separator: ","))")
|
|
746
|
+
exit(two == "2" && few == ["a/1:t1@a/1", "b/1:t1@b/1", "d/1:t1@d/1"] && many == ["c/1:t1@c/1", "c/2:t2@c/2", "c/3:t3@c/3", "more:2:http://127.0.0.1:9/inbox@more:c/4,c/5"] && zero == "none" && ok && o == "b/1" && stale == ["b/1", "F09E-0F96"] ? 0 : 1)
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
web.loadHTMLString("<body><script>window.shipkitApp = { openCard: (r, i) => { document.body.dataset.opened = r + '/' + i }, openInbox: () => { document.body.dataset.opened = 'inbox' } }</script><p>badge</p></body>", baseURL: nil)
|
|
755
|
+
}
|
|
756
|
+
|
|
433
757
|
// window.open and target=_blank: one more window of this app for its own pages
|
|
434
758
|
func webView(_ web: WKWebView, createWebViewWith config: WKWebViewConfiguration, for action: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
|
|
435
759
|
if let url = action.request.url {
|
|
@@ -443,6 +767,14 @@ final class Delegate: NSObject, NSApplicationDelegate, WKNavigationDelegate, WKU
|
|
|
443
767
|
// WebKit throws when a handler is dropped or called twice: `panel` calls
|
|
444
768
|
// `done` exactly once on every path
|
|
445
769
|
|
|
770
|
+
// a page of the machine asks for the microphone (the trailer page records a voice line): granted, the system's
|
|
771
|
+
// own prompt (NSMicrophoneUsageDescription) still asks the owner once; any other ask goes to WebKit's prompt
|
|
772
|
+
@available(macOS 12.0, *)
|
|
773
|
+
func webView(_ web: WKWebView, requestMediaCapturePermissionFor origin: WKSecurityOrigin, initiatedByFrame frame: WKFrameInfo, type: WKMediaCaptureType, decisionHandler: @escaping (WKPermissionDecision) -> Void) {
|
|
774
|
+
let local = origin.host == "127.0.0.1" || origin.host == "localhost" || origin.host == startURL.host
|
|
775
|
+
decisionHandler(local && type == .microphone ? .grant : .prompt)
|
|
776
|
+
}
|
|
777
|
+
|
|
446
778
|
/** one js panel: a sheet on the page's window, a modal where there is
|
|
447
779
|
* none. Return is OK, esc is Cancel; `done` hears whether OK was pressed */
|
|
448
780
|
func panel(_ web: WKWebView, _ message: String, cancel: Bool, field: NSTextField? = nil, done: @escaping (Bool) -> Void) {
|
package/src/home/gui-app.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
// the macOS apps shipkit opens web pages in: ONE source, ShipkitGui.swift,
|
|
2
2
|
// built with swiftc into a bundle per page it serves. `shipkit gui` is that
|
|
3
3
|
// app pointed at the home; each global process with a url gets its own, named
|
|
4
|
-
// and iconed after it, in
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
// and iconed after it, in ~/Applications, where Spotlight and Launchpad find
|
|
5
|
+
// it (home/process-apps.ts builds them all and removes the stale ones). The
|
|
6
|
+
// bundle's Info.plist carries what differs (name, bundle id, start url), so a
|
|
7
|
+
// fix to the window (find, the inspector, zoom) lands in every app at its next
|
|
8
|
+
// build. The binary is compiled once per source and copied into each bundle.
|
|
9
|
+
// The icon is core/app-icon.ts: the repo's mark, its margin cut, on a plate in
|
|
10
|
+
// the repo's colour. Rebuilt only when the source, the icon, the colours or the
|
|
11
|
+
// start url changed (a stamp in the bundle). No compiler, or not macOS: the caller falls back.
|
|
12
|
+
import { createHash } from 'crypto'
|
|
13
|
+
import { chmodSync, copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'fs'
|
|
12
14
|
import { dirname, join } from 'path'
|
|
13
|
-
import { fileURLToPath } from 'url'
|
|
14
15
|
import { appIconOf, appIconPngs, identityOfRoot } from '../core/app-icon.ts'
|
|
15
16
|
import { identityOfName, type Identity } from '../core/identity-color.ts'
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
const SOURCE = fileURLToPath(new URL('./gui-app/ShipkitGui.swift', import.meta.url))
|
|
17
|
+
import { homeDir } from './home-paths.ts'
|
|
18
|
+
import { appNameOf, appsDir, GUI_SOURCE as SOURCE, shipkitBundleOf, wrapperBundleId, wrapperPath, type AppOf } from './process-apps.ts'
|
|
19
19
|
|
|
20
20
|
export const BUNDLE_ID = 'dev.shipkit.gui'
|
|
21
|
-
export const guiAppPath = (): string => process.env.SHIPKIT_GUI_APP ?? join(
|
|
21
|
+
export const guiAppPath = (): string => process.env.SHIPKIT_GUI_APP ?? join(appsDir(), 'Shipkit.app')
|
|
22
22
|
|
|
23
23
|
/** what one app bundle is: the rest comes from the shared source */
|
|
24
24
|
export type AppSpec = {
|
|
@@ -63,6 +63,7 @@ export function infoPlist(o: Omit<AppSpec, 'app' | 'icon' | 'identity'>): string
|
|
|
63
63
|
\t<key>CFBundleVersion</key><string>${xml(o.version)}</string>
|
|
64
64
|
${o.url == null ? '' : `\t<key>ShipkitStartURL</key><string>${xml(o.url)}</string>\n`}\t<key>LSMinimumSystemVersion</key><string>12.0</string>
|
|
65
65
|
\t<key>NSHighResolutionCapable</key><true/>
|
|
66
|
+
\t<key>NSMicrophoneUsageDescription</key><string>A page you open here records your voice, a trailer's lines for one.</string>
|
|
66
67
|
\t<key>NSAppTransportSecurity</key>${atsOf(o.url)}
|
|
67
68
|
</dict>
|
|
68
69
|
</plist>
|
|
@@ -86,15 +87,33 @@ export function stampOf(source: string, icon: string | null, identity = ''): str
|
|
|
86
87
|
return h.digest('hex').slice(0, 16)
|
|
87
88
|
}
|
|
88
89
|
|
|
90
|
+
/** the window's binary, compiled once per source text into `bins`: swiftc
|
|
91
|
+
* takes about a minute, and every bundle runs the same binary */
|
|
92
|
+
function compiledGui(source: string, text: string, run: Run, bins: string): string {
|
|
93
|
+
const bin = join(bins, `shipkit-gui-${createHash('sha256').update(text).digest('hex').slice(0, 16)}`)
|
|
94
|
+
if (existsSync(bin)) return bin
|
|
95
|
+
mkdirSync(bins, { recursive: true })
|
|
96
|
+
const tmp = `${bin}.building-${process.pid}`
|
|
97
|
+
const built = run(['swiftc', '-O', '-o', tmp, source])
|
|
98
|
+
if (built.code !== 0 || !existsSync(tmp)) {
|
|
99
|
+
rmSync(tmp, { force: true })
|
|
100
|
+
throw new Error(`swiftc could not build the window: ${built.err.slice(0, 400)}`)
|
|
101
|
+
}
|
|
102
|
+
renameSync(tmp, bin)
|
|
103
|
+
return bin
|
|
104
|
+
}
|
|
105
|
+
|
|
89
106
|
/** one app, built or rebuilt when stale. Throws with the step that failed.
|
|
90
107
|
* `rebuilt` tells the caller a running copy is now the old one */
|
|
91
|
-
export async function ensureApp(spec: AppSpec, o: { run?: Run; source?: string } = {}): Promise<{ app: string; rebuilt: boolean }> {
|
|
108
|
+
export async function ensureApp(spec: AppSpec, o: { run?: Run; source?: string; bins?: string } = {}): Promise<{ app: string; rebuilt: boolean }> {
|
|
92
109
|
const { app, icon } = spec
|
|
93
110
|
const run = o.run ?? runSync
|
|
94
111
|
const source = o.source ?? SOURCE
|
|
95
|
-
const
|
|
112
|
+
const text = readFileSync(source, 'utf8')
|
|
113
|
+
const stamp = stampOf(text, icon, JSON.stringify([spec.name, spec.bundleId, spec.url, spec.identity, ICON_DRAWING]))
|
|
96
114
|
const stampFile = join(app, 'Contents', 'Resources', 'stamp')
|
|
97
115
|
if (existsSync(stampFile) && readFileSync(stampFile, 'utf8') === stamp) return { app, rebuilt: false }
|
|
116
|
+
const bin = compiledGui(source, text, run, o.bins ?? join(homeDir(), 'gui-bin'))
|
|
98
117
|
const tmp = `${app}.building-${process.pid}`
|
|
99
118
|
const fail = (msg: string): never => { rmSync(tmp, { recursive: true, force: true }); throw new Error(msg) }
|
|
100
119
|
rmSync(tmp, { recursive: true, force: true })
|
|
@@ -102,8 +121,9 @@ export async function ensureApp(spec: AppSpec, o: { run?: Run; source?: string }
|
|
|
102
121
|
mkdirSync(join(tmp, 'Contents', 'MacOS'), { recursive: true })
|
|
103
122
|
mkdirSync(res, { recursive: true })
|
|
104
123
|
writeFileSync(join(tmp, 'Contents', 'Info.plist'), infoPlist(spec))
|
|
105
|
-
const
|
|
106
|
-
|
|
124
|
+
const exe = join(tmp, 'Contents', 'MacOS', 'shipkit-gui')
|
|
125
|
+
copyFileSync(bin, exe)
|
|
126
|
+
chmodSync(exe, 0o755)
|
|
107
127
|
if (icon != null) {
|
|
108
128
|
const set = join(res, 'AppIcon.iconset')
|
|
109
129
|
mkdirSync(set, { recursive: true })
|
|
@@ -116,9 +136,20 @@ export async function ensureApp(spec: AppSpec, o: { run?: Run; source?: string }
|
|
|
116
136
|
if (r.code !== 0) fail(`iconutil could not build the icon: ${r.err.slice(0, 200)}`)
|
|
117
137
|
}
|
|
118
138
|
writeFileSync(join(res, 'stamp'), stamp)
|
|
139
|
+
// signed as the bundle it is, never as the bare binary: macOS refuses notifications to a bundle its signature does not name
|
|
140
|
+
const signed = run(['codesign', '--force', '--sign', '-', tmp])
|
|
141
|
+
if (signed.code !== 0) fail(`codesign could not sign the bundle: ${signed.err.slice(0, 200)}`)
|
|
119
142
|
mkdirSync(dirname(app), { recursive: true })
|
|
120
|
-
|
|
121
|
-
|
|
143
|
+
// a rename, never `mv`: a build that lands in between would get this one nested inside it
|
|
144
|
+
for (let tries = 0; ; tries++) {
|
|
145
|
+
rmSync(app, { recursive: true, force: true })
|
|
146
|
+
try {
|
|
147
|
+
renameSync(tmp, app)
|
|
148
|
+
break
|
|
149
|
+
} catch (e) {
|
|
150
|
+
if (tries >= 2) fail(`could not move the built bundle to ${app}: ${(e as Error).message}`)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
122
153
|
// launch services caches icons by bundle: tell it this one changed
|
|
123
154
|
run(['/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister', '-f', app])
|
|
124
155
|
return { app, rebuilt: true }
|
|
@@ -129,31 +160,31 @@ export function ensureGuiApp(o: { root: string | null; version: string; app?: st
|
|
|
129
160
|
return ensureApp({ name: 'shipkit', bundleId: BUNDLE_ID, url: null, icon: o.root == null ? null : appIconOf(o.root), identity: o.root == null ? identityOfName('shipkit') : identityOfRoot(o.root), app: o.app ?? guiAppPath(), version: o.version }, { run: o.run })
|
|
130
161
|
}
|
|
131
162
|
|
|
132
|
-
/** what a global process gives its app */
|
|
133
|
-
export type WrapperOf =
|
|
163
|
+
/** what a global process gives its app. `app`: its declared app name, else the label */
|
|
164
|
+
export type WrapperOf = AppOf
|
|
134
165
|
|
|
135
166
|
/** the images the icon renderer reads; an emoji or an svg leaves the repo's mark */
|
|
136
167
|
const RASTER = /\.(png|jpe?g|gif|webp)$/i
|
|
137
168
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
* else its repo's mark, in its repo's `.shipkit/wrapper/`. Throws for a
|
|
143
|
-
* process with no url: there is no page to wrap */
|
|
144
|
-
export function wrapperSpec(d: WrapperOf, version: string): AppSpec {
|
|
169
|
+
/** the spec of a process's own app: its app name, its declared image icon
|
|
170
|
+
* or else its repo's mark, in ~/Applications. Throws for a process with no
|
|
171
|
+
* url: there is no page to wrap */
|
|
172
|
+
export function wrapperSpec(d: WrapperOf, version: string, dir = appsDir()): AppSpec {
|
|
145
173
|
if (d.url == null) throw new Error(`${d.id} declares no url: there is no page to open as an app`)
|
|
146
174
|
const declared = d.icon != null && RASTER.test(d.icon) && existsSync(join(d.root, d.icon)) ? join(d.root, d.icon) : null
|
|
147
|
-
return { name: d
|
|
175
|
+
return { name: appNameOf(d), bundleId: wrapperBundleId(d.id), url: d.url, icon: declared ?? appIconOf(d.root), identity: identityOfRoot(d.root), app: wrapperPath(d, dir), version }
|
|
148
176
|
}
|
|
149
177
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
178
|
+
/** builds a process's app when it is missing or stale. Refuses to replace
|
|
179
|
+
* an app at its path that shipkit did not build */
|
|
180
|
+
export const ensureWrapperApp = async (d: WrapperOf, o: { version: string; run?: Run; dir?: string; bins?: string }): Promise<{ app: string; rebuilt: boolean; bundleId: string }> => {
|
|
181
|
+
const spec = wrapperSpec(d, o.version, o.dir)
|
|
182
|
+
if (existsSync(spec.app) && shipkitBundleOf(spec.app) == null) throw new Error(`${spec.app} is an app shipkit did not build: give ${d.id} another app name (app: in its unit file)`)
|
|
183
|
+
return { ...(await ensureApp(spec, { run: o.run, bins: o.bins })), bundleId: spec.bundleId }
|
|
153
184
|
}
|
|
154
185
|
|
|
155
186
|
/** quits a running copy of an app, and launches nothing when none runs */
|
|
156
187
|
export const quitCmd = (bundleId: string): string[] => ['osascript', '-e', `if application id "${bundleId}" is running then quit application id "${bundleId}"`]
|
|
157
188
|
|
|
158
189
|
/** true when this machine can build the app */
|
|
159
|
-
export const canBuildGui = (platform = process.platform): boolean => platform === 'darwin' &&
|
|
190
|
+
export const canBuildGui = (platform = process.platform): boolean => platform === 'darwin' && ['swiftc', 'iconutil', 'codesign'].every((t) => Bun.which(t) != null)
|