Skip to content

armgit / cra

Public Imported from GitHub
0

The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.

Cra 0.1.24: Arc's space menu, % tab search and the developer bar (#74)

Victor Kildahlc3b4677ea21b
diff --git a/Packages/CraCore/Sources/CraCore/DiagnosticsRedaction.swift b/Packages/CraCore/Sources/CraCore/DiagnosticsRedaction.swift
new file mode 100644
index 0000000..b64fbf9
--- /dev/null
+++ b/Packages/CraCore/Sources/CraCore/DiagnosticsRedaction.swift
@@ -0,0 +1,29 @@
+import Foundation
+
+/// What Help ▸ Export Diagnostics keeps. The zip goes to a public GitHub issue, so it names
+/// sites, not pages, and not the user.
+public enum DiagnosticsRedaction {
+ /// Addresses keep their scheme and host, without a `user:password@`; the home folder becomes
+ /// `~`, also in the `\/`-escaped form JSON (crash reports) writes. The single sign-on hosts IT
+ /// allowlisted (Chromium's command line in gpu.json) name the user's employer.
+ public static func redact(_ text: String, home: String) -> String {
+ var s = text
+ if !home.isEmpty {
+ s = s.replacingOccurrences(of: home, with: "~")
+ .replacingOccurrences(of: home.replacingOccurrences(of: "/", with: #"\/"#), with: "~")
+ }
+ for (pattern, template) in [(#"\b([A-Za-z][A-Za-z0-9+.-]*://)[^/\s"'<>)\]@]*@"#, "$1"),
+ (#"\b((?:https?|wss?|ftp|chrome-extension)://[^/\s"'<>)\]]+)[/?#][^\s"'<>)\]]*"#, "$1/…"),
+ (#"(--auth-server-allowlist=)[^\s"]+"#, "$1(set by IT)")] {
+ guard let re = try? NSRegularExpression(pattern: pattern) else { continue }
+ s = re.stringByReplacingMatches(in: s, range: NSRange(s.startIndex..., in: s), withTemplate: template)
+ }
+ return s
+ }
+
+ /// macOS names a crash report after the process that crashed: `Cra-<date>.ips` and
+ /// `Cra Helper (Renderer)-<date>.ips`. Other apps' names can start with "Cra" too (Craft).
+ public static func isCraCrashReport(_ fileName: String) -> Bool {
+ fileName.hasPrefix("Cra-") || fileName.hasPrefix("Cra Helper")
+ }
+}
diff --git a/Packages/CraCore/Tests/CraCoreTests/DiagnosticsRedactionTests.swift b/Packages/CraCore/Tests/CraCoreTests/DiagnosticsRedactionTests.swift
new file mode 100644
index 0000000..dbada30
--- /dev/null
+++ b/Packages/CraCore/Tests/CraCoreTests/DiagnosticsRedactionTests.swift
@@ -0,0 +1,46 @@
+import CraCore
+import Testing
+
+/// Help ▸ Export Diagnostics: what a zip attached to a public issue keeps.
+struct DiagnosticsRedactionTests {
+ let home = "/Users/someone"
+
+ @Test(arguments: [
+ ("loaded https://mail.example.com/inbox/123?q=secret", "loaded https://mail.example.com/…"),
+ ("ws wss://live.example.com:8443/socket#x", "ws wss://live.example.com:8443/…"),
+ ("\"url\":\"chrome-extension://abcdef/options.html\"", "\"url\":\"chrome-extension://abcdef/…\""),
+ ("https://example.com", "https://example.com"),
+ ])
+ func addressesKeepOnlyTheirSite(line: String, kept: String) {
+ #expect(DiagnosticsRedaction.redact(line, home: home) == kept)
+ }
+
+ @Test(arguments: [
+ ("https://user:[email protected]/a", "https://intranet.example.com/…"),
+ ("ftp://[email protected]", "ftp://files.example.com"),
+ ])
+ func credentialsAreDropped(line: String, kept: String) {
+ #expect(DiagnosticsRedaction.redact(line, home: home) == kept)
+ }
+
+ @Test func homeFolderBecomesTilde() {
+ let report = #"{"path":"\/Users\/someone\/Applications\/Cra.app"} /Users/someone/Library/Logs"#
+ #expect(DiagnosticsRedaction.redact(report, home: home) == #"{"path":"~\/Applications\/Cra.app"} ~/Library/Logs"#)
+ }
+
+ @Test func singleSignOnHostsAreHidden() {
+ let line = #"--flag --auth-server-allowlist=*.corp.example.com,sso.example.com --other"#
+ #expect(DiagnosticsRedaction.redact(line, home: home) == "--flag --auth-server-allowlist=(set by IT) --other")
+ }
+
+ @Test(arguments: [
+ ("Cra-2026-11-01-120000.ips", true),
+ ("Cra Helper (Renderer)-2026-11-01-120000.ips", true),
+ ("Craft-2026-11-01-120000.ips", false),
+ ("CraClip-2026-11-01-120000.ips", false),
+ ("Safari-2026-11-01-120000.ips", false),
+ ])
+ func onlyCrasOwnCrashReports(name: String, isCra: Bool) {
+ #expect(DiagnosticsRedaction.isCraCrashReport(name) == isCra)
+ }
+}
diff --git a/Sources/Cra/Services/Diagnostics.swift b/Sources/Cra/Services/Diagnostics.swift
index b1ee13f..9f8fa38 100644
--- a/Sources/Cra/Services/Diagnostics.swift
+++ b/Sources/Cra/Services/Diagnostics.swift
@@ -63,7 +63,10 @@ enum Diagnostics {
let staging = fm.temporaryDirectory.appendingPathComponent(UUID().uuidString, isDirectory: true)
let folder = staging.appendingPathComponent(name, isDirectory: true)
try? fm.createDirectory(at: folder, withIntermediateDirectories: true)
- func write(_ text: String, _ file: String) { try? Data(redact(text).utf8).write(to: folder.appendingPathComponent(file)) }
+ let home = NSHomeDirectory()
+ func write(_ text: String, _ file: String) {
+ try? Data(DiagnosticsRedaction.redact(text, home: home).utf8).write(to: folder.appendingPathComponent(file))
+ }
CraLog.flush()
write(summary(store: store), "summary.txt")
@@ -77,7 +80,7 @@ enum Diagnostics {
let reports = fm.homeDirectoryForCurrentUser.appendingPathComponent("Library/Logs/DiagnosticReports", isDirectory: true)
let weekAgo = Date().addingTimeInterval(-7 * 86400)
let crashes = ((try? fm.contentsOfDirectory(at: reports, includingPropertiesForKeys: [.contentModificationDateKey])) ?? []).filter {
- $0.lastPathComponent.hasPrefix("Cra") && ((try? $0.resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate) ?? .distantPast) > weekAgo
+ DiagnosticsRedaction.isCraCrashReport($0.lastPathComponent) && ((try? $0.resourceValues(forKeys: [.contentModificationDateKey]).contentModificationDate) ?? .distantPast) > weekAgo
}
if !crashes.isEmpty {
try? fm.createDirectory(at: folder.appendingPathComponent("crashes"), withIntermediateDirectories: true)
@@ -156,16 +159,4 @@ enum Diagnostics {
}
return lines.joined(separator: "\n") + "\n"
}
-
- /// Addresses keep their scheme and host; the home folder becomes `~`. The single sign-on
- /// hosts IT allowlisted (Chromium's command line in gpu.json) name the user's employer.
- nonisolated static func redact(_ text: String) -> String {
- var s = text.replacingOccurrences(of: NSHomeDirectory(), with: "~")
- for (pattern, template) in [(#"\b((?:https?|wss?|ftp|chrome-extension)://[^/\s"'<>)\]]+)[/?#][^\s"'<>)\]]*"#, "$1/…"),
- (#"(--auth-server-allowlist=)[^\s"]+"#, "$1(set by IT)")] {
- guard let re = try? NSRegularExpression(pattern: pattern) else { continue }
- s = re.stringByReplacingMatches(in: s, range: NSRange(s.startIndex..., in: s), withTemplate: template)
- }
- return s
- }
}
diff --git a/scripts/clips/seed-demo.py b/scripts/clips/seed-demo.py
index 24f9c1f..3039266 100644
--- a/scripts/clips/seed-demo.py
+++ b/scripts/clips/seed-demo.py
@@ -47,7 +47,7 @@ def theme(colors, intensity, noise, appearance): return {"colors": colors, "inte
space("Studio", "🎨", theme(["#C7CAFF", "#FFE5E5"], 0.5, 0.1, "light"),
[("https://github.com/", "GitHub"), ("https://www.figma.com/", "Figma"), ("https://linear.app/", "Linear"), ("https://www.notion.com/", "Notion"),
("https://vercel.com/", "Vercel"), ("https://open.spotify.com/", "Spotify"), ("https://en.wikipedia.org/wiki/Main_Page", "Wikipedia"), ("https://www.apple.com/", "Apple")],
- [("https://crabrowser.app/", "Cra — A calmer way to browse"),
+ [("https://crabrowser.app/", "Cra - Free, open-source Arc replacement for macOS"),
lambda p: folder("Launch", p, [("https://github.com/VictorKildahl/cra", "VictorKildahl/cra"),
("https://developer.apple.com/documentation/swiftui", "SwiftUI | Apple Developer Documentation"),
("https://crabrowser.app/roadmap", "Roadmap")]),
@@ -73,9 +73,9 @@ json.dump({"hasSeenImportPrompt": True, "warnBeforeQuitting": False, "blockAdsAn
"showToolbar": True, "showStatusBar": True}, open(f"{out}/settings.json", "w"))
frame = sys.argv[2] if len(sys.argv) > 2 else "{{0, 0}, {1280, 800}}"
pick = lambda t: next(i["id"] for i in items if i.get("title") == t)
-sel = [x for sid, t in zip(order, ["Cra — A calmer way to browse", "Copenhagen", "Faroe Islands", "Arc (web browser)"]) for x in (sid, pick(t))]
+sel = [x for sid, t in zip(order, ["Cra - Free, open-source Arc replacement for macOS", "Copenhagen", "Faroe Islands", "Arc (web browser)"]) for x in (sid, pick(t))]
launch = next(i["id"] for i in items if i.get("title") == "Launch")
-first_tab = next(i["id"] for i in items if i.get("title") == "Cra — A calmer way to browse")
+first_tab = next(i["id"] for i in items if i.get("title") == "Cra - Free, open-source Arc replacement for macOS")
json.dump({"littleWindowSize": "{780, 520}", "sidebarWidth": 260, "expandedFolders": [launch], "collapsedPinnedSpaces": [],
"windows": [{"id": U(), "focusedSpaceID": order[0], "selectedTabPerSpace": sel, "frame": frame,
"sidebarVisible": True, "isIncognito": False}]}, open(f"{out}/windows.json", "w"))