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.
Copy and paste bug
Victorea159ec947bf
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex d509386..6b7b798 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -24,7 +24,7 @@ jobs:uses: actions/cache@v6with:path: vendor/cef- key: cef-${{ runner.arch }}-${{ steps.cef.outputs.version }}+ key: cef-${{ runner.arch }}-${{ steps.cef.outputs.version }}-${{ hashFiles('scripts/fetch-cef.sh') }}- name: Build (debug, ad-hoc signed)run: scripts/build.sh debugdiff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex f0c41e9..5b41192 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -49,7 +49,7 @@ jobs:uses: actions/cache@v6with:path: vendor/cef- key: cef-${{ runner.arch }}-${{ steps.cef.outputs.version }}+ key: cef-${{ runner.arch }}-${{ steps.cef.outputs.version }}-${{ hashFiles('scripts/fetch-cef.sh') }}- name: Import signing certificateid: certdiff --git a/Sources/Cra/Services/ExtensionStore.swift b/Sources/Cra/Services/ExtensionStore.swiftindex 0746725..038e111 100644--- a/Sources/Cra/Services/ExtensionStore.swift+++ b/Sources/Cra/Services/ExtensionStore.swift@@ -3,7 +3,8 @@ import CryptoKitimport Observation/// Unpacked Chrome extensions, one folder each, loaded at start-up with-/// --load-extension by the Chrome-style page windows.+/// --load-extension by the Chrome-style page windows, plus the ones Chrome installed+/// into Cra's profile itself (Chrome Web Store, chrome://extensions "Load unpacked").@MainActor@Observablefinal class ExtensionStore {@@ -21,6 +22,9 @@ final class ExtensionStore {var popupPath: String?/// options_ui.page or options_page, relative to the folder.var optionsPath: String?+ /// Installed by Chrome into the profile (Web Store); Chrome owns the folder and+ /// loads changes at once, so removing goes through chrome://extensions.+ var managedByChrome = false}/// The menu bar's Extensions menu and the toolbar read this one.@@ -58,23 +62,33 @@ final class ExtensionStore {let fm = FileManager.defaulttry? fm.createDirectory(at: ExtensionStore.directory, withIntermediateDirectories: true)let names = (try? fm.contentsOfDirectory(atPath: ExtensionStore.directory.path)) ?? []- entries = names.sorted().compactMap { name in- let dir = ExtensionStore.directory.appendingPathComponent(name, isDirectory: true)- guard let data = try? Data(contentsOf: dir.appendingPathComponent("manifest.json")),- let m = try? JSONSerialization.jsonObject(with: data) as? [String: Any] else { return nil }- func str(_ k: String) -> String { (m[k] as? String) ?? "" }- var title = ExtensionImporter.localized(str("name"), manifest: m, folder: dir)- if title.hasPrefix("__MSG_") { title = name }- let action = (m["action"] ?? m["browser_action"] ?? m["page_action"]) as? [String: Any]- let options = (m["options_ui"] as? [String: Any])?["page"] as? String ?? m["options_page"] as? String- return Entry(id: name, name: title.isEmpty ? name : title, version: str("version"), description: str("description"), url: dir,- extensionID: Self.chromiumID(key: m["key"] as? String, folder: dir),- icon: ExtensionImporter.icon(manifest: m, folder: dir, minPixels: 16),- popupPath: (action?["default_popup"] as? String).flatMap { $0.isEmpty ? nil : $0 }, optionsPath: options)+ var list = names.sorted().compactMap { name in+ Self.entry(id: name, folder: ExtensionStore.directory.appendingPathComponent(name, isDirectory: true), extensionID: nil)}+ let loaded = Set(list.map(\.extensionID))+ for e in ExtensionImporter.extensions(inUserData: AppPaths.chromiumCache) where e.isEnabled && !loaded.contains(e.id) {+ guard var entry = Self.entry(id: e.id, folder: e.folder, extensionID: e.id) else { continue }+ entry.managedByChrome = true+ list.append(entry)+ }+ entries = listpinnedIDs.removeAll { id in !entries.contains { $0.extensionID == id } }}+ private static func entry(id: String, folder dir: URL, extensionID: String?) -> Entry? {+ guard let data = try? Data(contentsOf: dir.appendingPathComponent("manifest.json")),+ let m = try? JSONSerialization.jsonObject(with: data) as? [String: Any] else { return nil }+ func str(_ k: String) -> String { (m[k] as? String) ?? "" }+ var title = ExtensionImporter.localized(str("name"), manifest: m, folder: dir)+ if title.hasPrefix("__MSG_") { title = id }+ let action = (m["action"] ?? m["browser_action"] ?? m["page_action"]) as? [String: Any]+ let options = (m["options_ui"] as? [String: Any])?["page"] as? String ?? m["options_page"] as? String+ return Entry(id: id, name: title.isEmpty ? id : title, version: str("version"), description: str("description"), url: dir,+ extensionID: extensionID ?? chromiumID(key: m["key"] as? String, folder: dir),+ icon: ExtensionImporter.icon(manifest: m, folder: dir, minPixels: 16),+ popupPath: (action?["default_popup"] as? String).flatMap { $0.isEmpty ? nil : $0 }, optionsPath: options)+ }+/// Chromium's ID: the first 128 bits of SHA-256 over the manifest key (or the/// unpacked folder's path), each hex digit mapped 0-f → a-p.static func chromiumID(key: String?, folder: URL) -> String {diff --git a/Sources/Cra/UI/CommandBar/CommandBarController.swift b/Sources/Cra/UI/CommandBar/CommandBarController.swiftindex 9732c0a..0fdb3ea 100644--- a/Sources/Cra/UI/CommandBar/CommandBarController.swift+++ b/Sources/Cra/UI/CommandBar/CommandBarController.swift@@ -16,6 +16,10 @@ final class CommandBarController {var fieldText = ""var fieldTextVersion = 0var allowCompletion = true+ /// Text shown in the field while arrowing through rows (Chrome/Arc fill the+ /// field with the selected row); nil shows what was typed. Bump version to apply.+ var previewText: String?+ var previewVersion = 0/// Layout hints set by the window controller before opening.var panelWidth: CGFloat = CraMetrics.commandBarWidthvar attached = false@@ -47,6 +51,7 @@ final class CommandBarController {fieldTextVersion += 1allowCompletion = falseselectedIndex = 0+ previewText = nilresult = engine.suggestions(for: query, mode: mode, currentTabID: store.selectedTabID)isOpen = true}@@ -64,12 +69,32 @@ final class CommandBarController {result = engine.suggestions(for: newQuery, mode: mode, currentTabID: store.selectedTabID)if !allowCompletion { result.inlineCompletion = nil }selectedIndex = 0+ previewText = nil}func moveSelection(by delta: Int) {guard !result.items.isEmpty else { return }let n = result.items.countselectedIndex = ((selectedIndex + delta) % n + n) % n+ // The top row is what was typed (plus its inline completion).+ previewText = selectedIndex == 0 ? nil : fillText(for: result.items[selectedIndex])+ previewVersion += 1+ }++ /// What the field shows for a selected row: the address for pages, the+ /// query for searches, the name for commands.+ private func fillText(for s: Suggestion) -> String {+ if s.id == "typed" { return query }+ switch s.kind {+ case .search, .command, .switchSpace, .moveToSpace, .moveToFolder:+ return s.title+ case .switchToTab, .archived, .history, .navigate, .topDomain:+ guard let url = s.url else { return s.title }+ var t = url+ for p in ["https://www.", "http://www.", "https://", "http://"] where t.hasPrefix(p) { t = String(t.dropFirst(p.count)); break }+ if t.hasSuffix("/") { t.removeLast() }+ return t+ }}/// Accept the inline completion (Tab / →).diff --git a/Sources/Cra/UI/CommandBar/CommandBarView.swift b/Sources/Cra/UI/CommandBar/CommandBarView.swiftindex 933ceab..b63b766 100644--- a/Sources/Cra/UI/CommandBar/CommandBarView.swift+++ b/Sources/Cra/UI/CommandBar/CommandBarView.swift@@ -69,8 +69,11 @@ struct CommandBarView: View {}@ViewBuilder private var leadingIcon: some View {- if let s = controller.result.items.first, let key = s.faviconKey, s.id != "typed", let img = favicons.image(forKey: key),- controller.result.inlineCompletion != nil || controller.mode == .editURL {+ // Follows the row the arrows moved to; otherwise the completing top match.+ let previewing = controller.previewText != nil && controller.result.items.indices.contains(controller.selectedIndex)+ let row = previewing ? controller.result.items[controller.selectedIndex] : controller.result.items.first+ if let s = row, let key = s.faviconKey, s.id != "typed", let img = favicons.image(forKey: key),+ previewing || controller.result.inlineCompletion != nil || controller.mode == .editURL {Image(nsImage: img).resizable().interpolation(.high).aspectRatio(contentMode: .fit).frame(width: 20, height: 20).clipShape(RoundedRectangle(cornerRadius: 5, style: .continuous))} else {diff --git a/Sources/Cra/UI/CommandBar/CommandTextField.swift b/Sources/Cra/UI/CommandBar/CommandTextField.swiftindex d531af5..5310faa 100644--- a/Sources/Cra/UI/CommandBar/CommandTextField.swift+++ b/Sources/Cra/UI/CommandBar/CommandTextField.swift@@ -42,7 +42,13 @@ struct CommandTextField: NSViewRepresentable {field.currentEditor()?.selectAll(nil)}}- if let c = controller.result.inlineCompletion, controller.allowCompletion, coord.pendingCompletion != c {+ if coord.appliedPreview != controller.previewVersion {+ coord.appliedPreview = controller.previewVersion+ coord.showPreview(controller.previewText)+ }+ if controller.previewText != nil {+ // Arrowed onto a row; the field shows that row, not a completion.+ } else if let c = controller.result.inlineCompletion, controller.allowCompletion, coord.pendingCompletion != c {coord.applyCompletion(c)} else if controller.result.inlineCompletion == nil {coord.pendingCompletion = nil@@ -56,6 +62,7 @@ struct CommandTextField: NSViewRepresentable {let controller: CommandBarControllerweak var field: NSTextField?var appliedVersion = 0+ var appliedPreview = 0var lastTyped = ""var suppressChange = falsevar pendingCompletion: String?@@ -74,6 +81,18 @@ struct CommandTextField: NSViewRepresentable {suppressChange = false}+ /// Show the arrowed-to row's text, or restore what was typed.+ func showPreview(_ text: String?) {+ guard let field else { return }+ let shown = text ?? controller.query+ suppressChange = true+ field.stringValue = shown+ lastTyped = shown+ pendingCompletion = nil+ field.currentEditor()?.selectedRange = NSRange(location: (shown as NSString).length, length: 0)+ suppressChange = false+ }+func controlTextDidChange(_ obj: Notification) {guard !suppressChange, let field else { return }let text = field.stringValuediff --git a/Sources/Cra/UI/Settings/ExtensionsPane.swift b/Sources/Cra/UI/Settings/ExtensionsPane.swiftindex 81f3bae..34f0b29 100644--- a/Sources/Cra/UI/Settings/ExtensionsPane.swift+++ b/Sources/Cra/UI/Settings/ExtensionsPane.swift@@ -15,7 +15,7 @@ struct ExtensionsPane: View {SettingsCard {if extensions.entries.isEmpty {SettingsCardRow {- Text("No extensions installed. Add an unpacked extension folder (the kind Chrome’s “Load unpacked” takes).")+ Text("No extensions installed. Add one from the Chrome Web Store, or an unpacked extension folder (the kind Chrome’s “Load unpacked” takes).").font(.system(size: 13)).foregroundStyle(.secondary).fixedSize(horizontal: false, vertical: true)} trailing: { EmptyView() }@@ -30,7 +30,11 @@ struct ExtensionsPane: View {}}} trailing: {- Button("Remove") { extensions.remove(e) }+ if e.managedByChrome {+ Button("Remove…") { actions.openURL("chrome://extensions/?id=\(e.extensionID)") }+ } else {+ Button("Remove") { extensions.remove(e) }+ }}}}diff --git a/Sources/Cra/UI/SplitView/PaneCardView.swift b/Sources/Cra/UI/SplitView/PaneCardView.swiftindex 86734b6..098f38c 100644--- a/Sources/Cra/UI/SplitView/PaneCardView.swift+++ b/Sources/Cra/UI/SplitView/PaneCardView.swift@@ -12,9 +12,12 @@ final class PaneCardView: NSView {let webArea = NSView()/// Hairline under the toolbar when the pane has no page (Arc draws it on the tinted card).private let hairline = NSView()+ /// The white card behind the toolbar. A card with a page paints nothing else: under the+ /// page window's anti-aliased corners any fill of the card's shape shows as a light rim.+ private let toolbarBackground = NSView()var showToolbar = true { didSet { needsLayout = true } }var toolbarHeight: CGFloat = CraMetrics.toolbarHeight { didSet { needsLayout = true } }- var cornerRadius: CGFloat = CraMetrics.contentCornerRadius { didSet { layer?.cornerRadius = cornerRadius } }+ var cornerRadius: CGFloat = CraMetrics.contentCornerRadius { didSet { layer?.cornerRadius = cornerRadius; needsLayout = true } }/// White page card, or Arc's tinted translucent empty pane.var hasPage = true { didSet { refreshBackground() } }var isDark = false { didSet { refreshBackground() } }@@ -37,10 +40,13 @@ final class PaneCardView: NSView {layer?.masksToBounds = truetoolbarHost.sizingOptions = []webArea.wantsLayer = true+ webArea.layer?.cornerCurve = .continuouswebArea.autoresizesSubviews = false+ toolbarBackground.wantsLayer = truehairline.wantsLayer = truehairline.isHidden = trueaddSubview(webArea)+ addSubview(toolbarBackground)addSubview(hairline)addSubview(toolbarHost)refreshBackground()@@ -51,7 +57,8 @@ final class PaneCardView: NSView {private func refreshBackground() {// Measured on Arc 1.170 (Victor theme, 2x): the empty pane is the// gradient plus about +9/+11/+12 per channel, i.e. a white veil at ~0.2.- layer?.backgroundColor = transparent ? NSColor.clear.cgColor : (hasPage ? NSColor.white.cgColor : NSColor(white: 1, alpha: isDark ? 0.08 : 0.2).cgColor)+ layer?.backgroundColor = transparent || hasPage ? NSColor.clear.cgColor : NSColor(white: 1, alpha: isDark ? 0.08 : 0.2).cgColor+ toolbarBackground.layer?.backgroundColor = (hasPage && !transparent ? NSColor.white : NSColor.clear).cgColorlet page = pageColor.map { NSColor(Color(hex: $0)) } ?? .whitewebArea.layer?.backgroundColor = (hasPage && !transparent ? page : NSColor.clear).cgColorhairline.isHidden = hasPage || transparent || !showToolbar@@ -64,9 +71,15 @@ final class PaneCardView: NSView {let th: CGFloat = showToolbar ? toolbarHeight : 0toolbarHost.isHidden = th == 0toolbarHost.frame = NSRect(x: 0, y: b.height - th, width: b.width, height: th)+ toolbarBackground.frame = toolbarHost.framehairline.frame = NSRect(x: 0, y: b.height - th - 1, width: b.width, height: 1)hairline.isHidden = hasPage || transparent || th == 0webArea.frame = NSRect(x: 0, y: 0, width: b.width, height: max(0, b.height - th))+ // The page window rounds the card's corners itself; its stand-in fill rounds a little+ // more so it stays inside the page's edge instead of fringing it.+ webArea.layer?.cornerRadius = cornerRadius > 0 ? cornerRadius + 3 : 0+ webArea.layer?.maskedCorners = th == 0 ? [.layerMinXMinYCorner, .layerMaxXMinYCorner, .layerMinXMaxYCorner, .layerMaxXMaxYCorner]+ : [.layerMinXMinYCorner, .layerMaxXMinYCorner]let wb = frozenWebBounds ?? webArea.boundsfor sub in webArea.subviews where sub.frame != wb { sub.frame = wb }}diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swiftindex f7fea2a..4b4b7f2 100644--- a/Sources/Cra/UI/Windows/MainWindowController.swift+++ b/Sources/Cra/UI/Windows/MainWindowController.swift@@ -515,11 +515,19 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM// Chromium's content view is flipped, so its layer's MinY edge is the top.let bottomLeft: CACornerMask = cv.isFlipped ? .layerMinXMaxYCorner : .layerMinXMinYCornerlet bottomRight: CACornerMask = cv.isFlipped ? .layerMaxXMaxYCorner : .layerMaxXMinYCorner+ let topLeft: CACornerMask = cv.isFlipped ? .layerMinXMinYCorner : .layerMinXMaxYCorner+ let topRight: CACornerMask = cv.isFlipped ? .layerMaxXMinYCorner : .layerMaxXMaxYCornervar corners: CACornerMask = []- if abs(page.minY - body.minY) < 0.5 {+ // A fullscreen card is square.+ if !shell.contentFullscreen, abs(page.minY - body.minY) < 0.5 {if abs(page.minX - body.minX) < 0.5 { corners.insert(bottomLeft) }if abs(page.maxX - body.maxX) < 0.5 { corners.insert(bottomRight) }}+ // Without the toolbar the page's top edge is the card's top edge too.+ if !shell.contentFullscreen, !shell.showToolbar, abs(page.maxY - body.maxY) < 0.5 {+ if abs(page.minX - body.minX) < 0.5 { corners.insert(topLeft) }+ if abs(page.maxX - body.maxX) < 0.5 { corners.insert(topRight) }+ }if layer.maskedCorners != corners { layer.maskedCorners = corners }}diff --git a/Sources/CraCEF/CraCEF.mm b/Sources/CraCEF/CraCEF.mmindex 03a9e32..61235c2 100644--- a/Sources/CraCEF/CraCEF.mm+++ b/Sources/CraCEF/CraCEF.mm@@ -929,6 +929,11 @@ public:CefRefPtr<CefMediaAccessCallback> callback) override {CraBrowser* o = owner_;if (!o || !o.delegate) return false;+ // Screen sharing (getDisplayMedia) in a Chrome-style page goes to Chrome's own+ // picker: tabs, windows or a screen, with "Also share tab audio". Granting it+ // here would make CEF share the whole screen with system loopback audio instead.+ if ((requested_permissions & (CEF_MEDIA_PERMISSION_DESKTOP_VIDEO_CAPTURE | CEF_MEDIA_PERMISSION_DESKTOP_AUDIO_CAPTURE)) &&+ browser->GetHost()->GetRuntimeStyle() == CEF_RUNTIME_STYLE_CHROME) return false;NSUInteger kinds = 0;if (requested_permissions & (CEF_MEDIA_PERMISSION_DEVICE_VIDEO_CAPTURE | CEF_MEDIA_PERMISSION_DESKTOP_VIDEO_CAPTURE)) kinds |= 1;if (requested_permissions & (CEF_MEDIA_PERMISSION_DEVICE_AUDIO_CAPTURE | CEF_MEDIA_PERMISSION_DESKTOP_AUDIO_CAPTURE)) kinds |= 2;@@ -1604,6 +1609,7 @@ static void MarkProfileExitedCleanly(NSString* cachePath) {@implementation CraApplication {BOOL _handlingSendEvent;+ NSHashTable<NSEvent*>* _forwardedKeyEvents;}- (BOOL)isHandlingSendEvent { return _handlingSendEvent; }@@ -1612,9 +1618,17 @@ static void MarkProfileExitedCleanly(NSString* cachePath) {// Chrome's rule: when a web view has focus, ⌘-shortcuts go to the page// first and only reach the menu bar if the page leaves them alone (so ⌘F in// Google Docs or ⌘← in a text field keep working). Reserved shortcuts are-// taken in OnPreKeyEvent, the rest in OnKeyEvent.+// taken in OnPreKeyEvent, the rest in OnKeyEvent. Keys the page leaves alone+// come back here from Chromium's CommandDispatcher (redispatchKeyEvent:), and+// those must take the normal path so the menu bar sees them: ⌘C/⌘V/⌘X/⌘A/⌘Z+// only exist as Edit menu items sent to the page's first responder.- (void)sendEvent:(NSEvent*)event {CefScopedSendingEvent sendingEventScoper;+ if ([_forwardedKeyEvents containsObject:event]) {+ [_forwardedKeyEvents removeObject:event];+ [super sendEvent:event];+ return;+ }if (event.type == NSEventTypeKeyDown && (event.modifierFlags & NSEventModifierFlagCommand)) {NSWindow* key = self.keyWindow;NSResponder* fr = key.firstResponder;@@ -1622,6 +1636,8 @@ static void MarkProfileExitedCleanly(NSString* cachePath) {NSView* v = (NSView*)fr;for (CraBrowser* b in [g_allBrowsers allObjects]) {if ([v isDescendantOf:b.containerView] || (b.hostWindow && key == b.hostWindow)) {+ if (!_forwardedKeyEvents) _forwardedKeyEvents = [NSHashTable weakObjectsHashTable];+ [_forwardedKeyEvents addObject:event];[key sendEvent:event];return;}diff --git a/docs/release.md b/docs/release.mdindex 461dedf..edb8ac5 100644--- a/docs/release.md+++ b/docs/release.md@@ -131,6 +131,24 @@ are the controls. Details and Arc's original are in `docs/arc-reverse-engineerinthe automatic restart) against a local appcast made with `CRA_UPDATE_URL=… scripts/appcast.sh`.- Copies from before the updater (0.1.0, 0.1.1) update once by hand: rerun the install line.+## The Chromium engine (CEF)++Cra ships its own CEF build, not Spotify's prebuilt one: Spotify builds leave out+H.264/AAC, so MP4 and HLS video (X, Instagram, Reddit, news sites) never plays. Codecs+are a compile-time switch and FFmpeg is linked into the framework, so there is no way+around building it.++ scripts/build-cef.sh # ~80 GB free, several hours; resumes where it stopped+ scripts/publish-cef.sh # uploads the archive as pre-release cef-<version>-codecsN++`build-cef.sh` checks out the same CEF commit `fetch-cef.sh` pins, applies+`scripts/cef-patches/*.patch` on top of CEF's own patches, and builds an official+release with `proprietary_codecs=true ffmpeg_branding=Chrome`. `fetch-cef.sh` (and CI,+keyed on its hash) downloads the published archive into `vendor/cef`, replacing a copy+from a different source. To change the build without a CEF version bump, bump the+`codecsN` suffix of `CEF_RELEASE` and publish again. Needs Xcode's Metal toolchain+(`xcodebuild -downloadComponent MetalToolchain`).+## Later- **Homebrew.** A cask (`brew install --cask cra`) pointing at the DMG anddiff --git a/scripts/build-cef.sh b/scripts/build-cef.shnew file mode 100755index 0000000..8321596--- /dev/null+++ b/scripts/build-cef.sh@@ -0,0 +1,77 @@+#!/bin/bash+# Builds the CEF binary distribution Cra ships, from source, with H.264/AAC.+#+# Spotify's prebuilt CEF (cef-builds.spotifycdn.com) leaves proprietary codecs out,+# so MP4/HLS video (X, Instagram, Reddit, most news sites) never plays. Codecs are a+# compile-time switch in Chromium and FFmpeg is linked into the framework, so the+# only fix is building CEF ourselves with proprietary_codecs + ffmpeg_branding=Chrome.+#+# Same CEF commit as the pinned prebuilt (scripts/fetch-cef.sh); besides the codecs+# only the fixes in scripts/cef-patches/ change. Needs ~80 GB free and several hours on an M2 Max. Re-running+# resumes: the checkout is kept and ninja only rebuilds what changed.+#+# Output: $CEF_BUILD_DIR/chromium/src/cef/binary_distrib/cef_binary_<ver>_macosarm64_minimal.tar.bz2+# Publish it with scripts/publish-cef.sh, then bump CEF_FLAVOR in fetch-cef.sh.+set -euo pipefail+cd "$(dirname "$0")/.."++CEF_BRANCH="${CEF_BRANCH:-8037}"+CEF_COMMIT="${CEF_COMMIT:-14c5a08}"+# .noindex keeps Spotlight out of ~40 GB of sources.+CEF_BUILD_DIR="${CEF_BUILD_DIR:-$HOME/cef-build.noindex}"++# ANGLE compiles Metal shaders; Xcode 26 ships the Metal toolchain separately.+xcrun metal --version >/dev/null 2>&1 || xcodebuild -downloadComponent MetalToolchain++mkdir -p "$CEF_BUILD_DIR"+tmutil addexclusion "$CEF_BUILD_DIR" 2>/dev/null || true++if [ ! -d "$CEF_BUILD_DIR/depot_tools" ]; then+ git clone --depth 1 https://chromium.googlesource.com/chromium/tools/depot_tools.git "$CEF_BUILD_DIR/depot_tools"+fi+# Bootstrap once (python, gn); DEPOT_TOOLS_UPDATE=0 below keeps it from updating.+[ -f "$CEF_BUILD_DIR/depot_tools/python3_bin_reldir.txt" ] || "$CEF_BUILD_DIR/depot_tools/ensure_bootstrap" || true+if [ ! -f "$CEF_BUILD_DIR/automate/automate-git.py" ]; then+ mkdir -p "$CEF_BUILD_DIR/automate"+ git -C "$CEF_BUILD_DIR" clone --depth 1 --branch "$CEF_BRANCH" https://github.com/chromiumembedded/cef.git cef-tools+ cp "$CEF_BUILD_DIR/cef-tools/tools/automate/automate-git.py" "$CEF_BUILD_DIR/automate/"+ rm -rf "$CEF_BUILD_DIR/cef-tools"+fi++export PATH="$CEF_BUILD_DIR/depot_tools:$PATH"+export DEPOT_TOOLS_UPDATE=0+export CEF_ARCHIVE_FORMAT=tar.bz2+# symbol_level=0: full debug info would need another ~50 GB and is never shipped.+export GN_DEFINES="is_official_build=true proprietary_codecs=true ffmpeg_branding=Chrome symbol_level=0 blink_symbol_level=0 v8_symbol_level=0 enable_dsyms=false"++automate() {+ python3 "$CEF_BUILD_DIR/automate/automate-git.py" \+ --download-dir="$CEF_BUILD_DIR" \+ --depot-tools-dir="$CEF_BUILD_DIR/depot_tools" \+ --branch="$CEF_BRANCH" \+ --checkout="$CEF_COMMIT" \+ --arm64-build \+ --no-chromium-history \+ --no-depot-tools-update \+ --with-pgo-profiles \+ --no-debug-build \+ --minimal-distrib-only \+ --no-distrib-docs \+ --no-distrib-symbols \+ "$@"+}++PATCHES="$PWD/scripts/cef-patches"+cd "$CEF_BUILD_DIR"+# 1. Check out Chromium + CEF and apply CEF's own patches.+automate --no-build --no-distrib+# 2. Cra's Chromium fixes on top (skipped when already applied).+for p in "$PATCHES"/*.patch; do+ if git -C chromium/src apply --check "$p" 2>/dev/null; then+ git -C chromium/src apply "$p" && echo "Applied $(basename "$p")"+ else+ git -C chromium/src apply --check --reverse "$p" || { echo "$(basename "$p") does not apply" >&2; exit 1; }+ fi+done+# 3. Build and package without touching the checkout again.+automate --no-update --force-build --force-distribdiff --git a/scripts/cef-patches/extension-install-ui-null-tab.patch b/scripts/cef-patches/extension-install-ui-null-tab.patchnew file mode 100644index 0000000..7001ab3--- /dev/null+++ b/scripts/cef-patches/extension-install-ui-null-tab.patch@@ -0,0 +1,36 @@+diff --git a/chrome/browser/ui/extensions/extension_install_ui_desktop.cc b/chrome/browser/ui/extensions/extension_install_ui_desktop.cc+index c9e2a59c3e..8d9c8d47ec 100644+--- a/chrome/browser/ui/extensions/extension_install_ui_desktop.cc++++ b/chrome/browser/ui/extensions/extension_install_ui_desktop.cc+@@ -141,11 +141,19 @@ void ExtensionInstallUIDesktop::OnInstallSuccess(+ SkBitmap icon_to_use = icon ? *icon : SkBitmap();+ extensions::TriggerPostInstallDialog(+ profile(), extension, icon_to_use,++ // Cra: resolve the tab when the install finishes, and tolerate none. An++ // embedder (CEF) can leave the browser found above without an active tab,++ // and the browser may be gone by the time the install completes.+ base::BindOnce(+- [](BrowserWindowInterface* bwi) {+- return bwi->GetActiveTabInterface()->GetContents();++ [](Profile* profile) -> content::WebContents* {++ BrowserWindowInterface* bwi =++ ProfileBrowserCollection::GetForProfile(profile)++ ->GetLastActiveBrowser();++ tabs::TabInterface* tab =++ bwi ? bwi->GetActiveTabInterface() : nullptr;++ return tab ? tab->GetContents() : nullptr;+ },+- browser_window),++ current_profile),+ base::BindOnce(+ [](const extensions::ExtensionId& extension_id,+ base::WeakPtr<content::WebContents> web_contents) {+@@ -160,7 +168,7 @@ void ExtensionInstallUIDesktop::OnInstallSuccess(+ }+ BrowserView* browser_view =+ BrowserView::GetBrowserViewForBrowser(browser_interface);+- if (!browser_view->toolbar()) {++ if (!browser_view || !browser_view->toolbar()) {+ return;+ }+ ExtensionsToolbarDesktop* extensions_toolbar =diff --git a/scripts/fetch-cef.sh b/scripts/fetch-cef.shindex c0f6bf7..f3e1555 100755--- a/scripts/fetch-cef.sh+++ b/scripts/fetch-cef.sh@@ -1,23 +1,40 @@#!/bin/bash# Downloads the pinned CEF binary distribution into vendor/cef and builds the# C++ wrapper library. Safe to re-run; skips what is already there.+#+# Cra ships its own CEF build (scripts/build-cef.sh: H.264/AAC plus the fixes in+# scripts/cef-patches), published as a GitHub release asset by scripts/publish-cef.sh.+# CEF_URL=https://cef-builds.spotifycdn.com/<name>.tar.bz2 fetches Spotify's stock+# build instead (no H.264/AAC).set -euo pipefailcd "$(dirname "$0")/.."CEF_VERSION="${CEF_VERSION:-154.0.34+g14c5a08+chromium-154.0.8037.98}"ARCH="${CEF_ARCH:-macosarm64}"NAME="cef_binary_${CEF_VERSION}_${ARCH}_minimal"-URL="https://cef-builds.spotifycdn.com/${NAME}.tar.bz2"+# Bump the suffix (codecs2, …) when the build changes but CEF_VERSION does not.+CEF_RELEASE="${CEF_RELEASE:-cef-${CEF_VERSION%%+*}-codecs1}"+# TODO(codecs): switch to the GitHub build once scripts/publish-cef.sh has run:+# https://github.com/VictorKildahl/cra/releases/download/${CEF_RELEASE}/cef_binary_${ARCH}_minimal.tar.bz2+URL="${CEF_URL:-https://cef-builds.spotifycdn.com/${NAME}.tar.bz2}"mkdir -p vendor+# A different pinned build replaces vendor/cef.+[ -d vendor/cef/Release ] && [ ! -f vendor/cef/.cra-source ] && echo "https://cef-builds.spotifycdn.com/${NAME}.tar.bz2" > vendor/cef/.cra-source+if [ -d vendor/cef/Release ] && [ "$(cat vendor/cef/.cra-source)" != "$URL" ]; then+ echo "CEF build changed, replacing vendor/cef"+ rm -rf vendor/cef+fiif [ ! -d vendor/cef/Release ]; then- echo "Downloading ${NAME} (about 130 MB)..."+ echo "Downloading ${NAME} from ${URL%/*}..."+ rm -rf vendor/cef-downloadmkdir -p vendor/cef-downloadcurl -fL --progress-bar -o "vendor/cef-download/${NAME}.tar.bz2" "$URL"tar -xjf "vendor/cef-download/${NAME}.tar.bz2" -C vendor/cef-downloadrm -rf vendor/cefmv "vendor/cef-download/${NAME}" vendor/cefrm -rf vendor/cef-download+ echo "$URL" > vendor/cef/.cra-sourcefiif [ ! -f vendor/cef/build/libcef_dll_wrapper/libcef_dll_wrapper.a ]; thendiff --git a/scripts/publish-cef.sh b/scripts/publish-cef.shnew file mode 100755index 0000000..46beeee--- /dev/null+++ b/scripts/publish-cef.sh@@ -0,0 +1,22 @@+#!/bin/bash+# Publishes the CEF distribution built by scripts/build-cef.sh as a GitHub release+# asset, where scripts/fetch-cef.sh (and CI) download it from. The release is a+# pre-release so releases/latest keeps pointing at the newest Cra.+# scripts/publish-cef.sh uses CEF_RELEASE from fetch-cef.sh+set -euo pipefail+cd "$(dirname "$0")/.."++CEF_BUILD_DIR="${CEF_BUILD_DIR:-$HOME/cef-build.noindex}"+eval "$(grep -E '^(CEF_VERSION|ARCH|CEF_RELEASE)=' scripts/fetch-cef.sh)"+ARCHIVE="$CEF_BUILD_DIR/chromium/src/cef/binary_distrib/cef_binary_${CEF_VERSION}_${ARCH}_minimal.tar.bz2"+[ -f "$ARCHIVE" ] || { echo "No build at $ARCHIVE; run scripts/build-cef.sh" >&2; exit 1; }++ASSET="$(mktemp -d)/cef_binary_${ARCH}_minimal.tar.bz2"+ln -s "$ARCHIVE" "$ASSET"+NOTES="CEF ${CEF_VERSION} for ${ARCH}, built by scripts/build-cef.sh with proprietary codecs (H.264/AAC) and scripts/cef-patches. Downloaded by scripts/fetch-cef.sh; not a Cra release."+if gh release view "$CEF_RELEASE" >/dev/null 2>&1; then+ gh release upload "$CEF_RELEASE" "$ASSET" --clobber+else+ gh release create "$CEF_RELEASE" "$ASSET" --prerelease --latest=false --title "CEF ${CEF_VERSION%%+*} (codecs)" --notes "$NOTES"+fi+echo "Published $CEF_RELEASE"