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.

Download location per profile: a folder, or ask where to save each file

Victoref42649e8bbe
diff --git a/Packages/CraCore/Sources/CraCore/DownloadLocation.swift b/Packages/CraCore/Sources/CraCore/DownloadLocation.swift
new file mode 100644
index 0000000..c46f29e
--- /dev/null
+++ b/Packages/CraCore/Sources/CraCore/DownloadLocation.swift
@@ -0,0 +1,52 @@
+import Foundation
+
+/// Arc's per-profile "Download location" (Settings ▸ Profiles, `DownloadLocationView`): a folder,
+/// or ask where to save each file (`arc.promptForDownload`). GitHub #190.
+public struct DownloadLocation: Codable, Equatable, Sendable {
+ /// The folder downloads go to; nil is the user's Downloads folder.
+ public var folder: String?
+ /// Show a save panel for each download, starting in `folder`.
+ public var askWhereToSave: Bool
+
+ public init(folder: String? = nil, askWhereToSave: Bool = false) {
+ self.folder = folder
+ self.askWhereToSave = askWhereToSave
+ }
+
+ public init(from decoder: Decoder) throws {
+ let c = try decoder.container(keyedBy: CodingKeys.self)
+ folder = try c.decodeIfPresent(String.self, forKey: .folder).flatMap { $0.hasPrefix("/") ? $0 : nil }
+ askWhereToSave = try c.decodeIfPresent(Bool.self, forKey: .askWhereToSave) ?? false
+ }
+
+ /// The key AppSettings.downloadLocations files a profile under (nil is Default).
+ public static func key(profileID: UUID?) -> String { profileID?.uuidString ?? "Default" }
+
+ /// The folder to use: the chosen one, or `downloads` when none is chosen or it's gone.
+ public func folderURL(downloads: URL, exists: (String) -> Bool) -> URL {
+ guard let folder, exists(folder) else { return downloads }
+ return URL(fileURLWithPath: folder, isDirectory: true)
+ }
+}
+
+/// The file a download is saved as: only a name inside `folder` (no path, no "." or "..",
+/// not hidden), " (n)" before the extension while the name is taken.
+public enum DownloadFileName {
+ public static func sanitized(_ suggested: String) -> String {
+ var name = suggested.replacingOccurrences(of: "/", with: "-").replacingOccurrences(of: ":", with: "-")
+ while name.hasPrefix(".") { name.removeFirst() }
+ return name.trimmingCharacters(in: .whitespaces).isEmpty ? "download" : name
+ }
+
+ public static func unique(_ suggested: String, in folder: URL, exists: (String) -> Bool) -> URL {
+ let name = sanitized(suggested)
+ var dest = folder.appendingPathComponent(name)
+ let base = dest.deletingPathExtension().lastPathComponent, ext = dest.pathExtension
+ var n = 1
+ while exists(dest.path) {
+ dest = folder.appendingPathComponent(ext.isEmpty ? "\(base) (\(n))" : "\(base) (\(n)).\(ext)")
+ n += 1
+ }
+ return dest
+ }
+}
diff --git a/Packages/CraCore/Sources/CraCore/SidebarModel.swift b/Packages/CraCore/Sources/CraCore/SidebarModel.swift
index ee80e98..4188e54 100644
--- a/Packages/CraCore/Sources/CraCore/SidebarModel.swift
+++ b/Packages/CraCore/Sources/CraCore/SidebarModel.swift
@@ -533,6 +533,17 @@ public struct AppSettings: Codable, Equatable {
/// Arc Max's Tidy Downloads (renameDownloadsEnabled): a finished download gets a readable name from
/// the Mac's Apple Intelligence model. Off by default, like Arc Max.
public var tidyDownloads: Bool = false
+ /// Arc's per-profile Download location (#190), by DownloadLocation.key(profileID:). A profile
+ /// that isn't here saves to the Downloads folder without asking.
+ public var downloadLocations: [String: DownloadLocation] = [:]
+
+ public func downloadLocation(profileID: UUID?) -> DownloadLocation {
+ downloadLocations[DownloadLocation.key(profileID: profileID)] ?? DownloadLocation()
+ }
+
+ public mutating func setDownloadLocation(_ location: DownloadLocation, profileID: UUID?) {
+ downloadLocations[DownloadLocation.key(profileID: profileID)] = location == DownloadLocation() ? nil : location
+ }
public init() {}
@@ -706,6 +717,7 @@ extension AppSettings {
tidyTabs = try c.decodeIfPresent(Bool.self, forKey: .tidyTabs) ?? true
tidyTabTitles = try c.decodeIfPresent(Bool.self, forKey: .tidyTabTitles) ?? false
tidyDownloads = try c.decodeIfPresent(Bool.self, forKey: .tidyDownloads) ?? false
+ downloadLocations = (try? c.decodeIfPresent([String: DownloadLocation].self, forKey: .downloadLocations)) ?? [:]
}
}
diff --git a/Packages/CraCore/Tests/CraCoreTests/DownloadLocationTests.swift b/Packages/CraCore/Tests/CraCoreTests/DownloadLocationTests.swift
new file mode 100644
index 0000000..acde511
--- /dev/null
+++ b/Packages/CraCore/Tests/CraCoreTests/DownloadLocationTests.swift
@@ -0,0 +1,70 @@
+import CraCore
+import Foundation
+import Testing
+
+/// Arc's per-profile Download location (#190) and the name a download is saved as.
+struct DownloadLocationTests {
+ let downloads = URL(fileURLWithPath: "/Users/me/Downloads", isDirectory: true)
+
+ @Test func profilesWithoutAChoiceUseDownloadsWithoutAsking() {
+ let s = AppSettings()
+ #expect(s.downloadLocation(profileID: nil) == DownloadLocation())
+ #expect(s.downloadLocation(profileID: UUID()).folderURL(downloads: downloads) { _ in true } == downloads)
+ }
+
+ @Test func eachProfileKeepsItsOwn() throws {
+ var s = AppSettings()
+ let work = UUID()
+ s.setDownloadLocation(DownloadLocation(folder: "/Volumes/Work", askWhereToSave: false), profileID: work)
+ s.setDownloadLocation(DownloadLocation(askWhereToSave: true), profileID: nil)
+ #expect(s.downloadLocation(profileID: work).folder == "/Volumes/Work")
+ #expect(s.downloadLocation(profileID: nil).askWhereToSave)
+ #expect(s.downloadLocation(profileID: UUID()) == DownloadLocation())
+ // Saved and loaded again.
+ let back = try JSONDecoder().decode(AppSettings.self, from: JSONEncoder().encode(s))
+ #expect(back.downloadLocations == s.downloadLocations)
+ #expect(Set(back.downloadLocations.keys) == [work.uuidString, "Default"])
+ }
+
+ @Test func goingBackToTheDefaultDropsTheEntry() {
+ var s = AppSettings()
+ s.setDownloadLocation(DownloadLocation(askWhereToSave: true), profileID: nil)
+ s.setDownloadLocation(DownloadLocation(), profileID: nil)
+ #expect(s.downloadLocations.isEmpty)
+ }
+
+ @Test func aMissingFolderFallsBackToDownloads() {
+ let l = DownloadLocation(folder: "/Volumes/Unplugged")
+ #expect(l.folderURL(downloads: downloads) { _ in false } == downloads)
+ #expect(l.folderURL(downloads: downloads) { _ in true }.path == "/Volumes/Unplugged")
+ }
+
+ @Test func aRelativeFolderInTheFileIsIgnored() throws {
+ let json = #"{"downloadLocations": {"Default": {"folder": "../etc", "askWhereToSave": true}, "x": 3}}"#
+ let s = try JSONDecoder().decode(AppSettings.self, from: Data(json.utf8))
+ // A bad entry drops the whole map rather than the settings file.
+ #expect(s.downloadLocations.isEmpty)
+ let one = try JSONDecoder().decode(DownloadLocation.self, from: Data(#"{"folder": "../etc"}"#.utf8))
+ #expect(one.folder == nil && !one.askWhereToSave)
+ }
+
+ @Test(arguments: [
+ ("report.pdf", "report.pdf"),
+ ("../../.ssh/config", "-..-.ssh-config"),
+ (".hidden", "hidden"),
+ ("a:b/c.txt", "a-b-c.txt"),
+ (" ", "download"),
+ ("", "download"),
+ ])
+ func names(suggested: String, saved: String) {
+ let url = DownloadFileName.unique(suggested, in: downloads) { _ in false }
+ #expect(url.lastPathComponent == saved)
+ #expect(url.deletingLastPathComponent().path == downloads.path)
+ }
+
+ @Test func takenNamesGetANumber() {
+ let taken: Set = ["/Users/me/Downloads/a.zip", "/Users/me/Downloads/a (1).zip", "/Users/me/Downloads/README"]
+ #expect(DownloadFileName.unique("a.zip", in: downloads) { taken.contains($0) }.lastPathComponent == "a (2).zip")
+ #expect(DownloadFileName.unique("README", in: downloads) { taken.contains($0) }.lastPathComponent == "README (1)")
+ }
+}
diff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swift
index 75a2ab1..215877b 100644
--- a/Sources/Cra/App/AppDelegate.swift
+++ b/Sources/Cra/App/AppDelegate.swift
@@ -104,6 +104,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
let installed = ExtensionStore.shared.entries.map(\.extensionID)
let hasNewExtension = !Set(installed).isSubset(of: welcomed)
try? JSONEncoder().encode(installed.sorted()).write(to: welcomedFile, options: .atomic)
+ DownloadDestinations.install(store: store)
CraCEFRuntime.setStrayPageHandler { [weak self] url, profile in
Task { @MainActor in
guard let self else { return }
diff --git a/Sources/Cra/Services/DownloadDestinations.swift b/Sources/Cra/Services/DownloadDestinations.swift
new file mode 100644
index 0000000..8e2b2af
--- /dev/null
+++ b/Sources/Cra/Services/DownloadDestinations.swift
@@ -0,0 +1,83 @@
+import AppKit
+import CraCEF
+
+/// Where a download is saved (GitHub #190): the profile's Download location from Settings ▸
+/// Profiles (Arc keeps one per profile), or a save panel when that profile asks for each file.
+/// CEF pages come in through CraCEFRuntime's download destination handler, WebKit pages
+/// through WebKitBrowser.
+@MainActor
+enum DownloadDestinations {
+ private static weak var store: SidebarStore?
+
+ static func install(store: SidebarStore) {
+ self.store = store
+ CraCEFRuntime.setDownloadDestinationHandler { profilePath, name, completion in
+ MainActor.assumeIsolated {
+ destination(profilePath: profilePath, suggestedName: name) { completion($0?.path) }
+ }
+ }
+ }
+
+ static var downloadsFolder: URL { FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask)[0] }
+
+ /// The profile a Chromium profile folder belongs to; nil is Default (and off the record).
+ static func profileID(profilePath: String?) -> UUID? {
+ guard let profilePath else { return nil }
+ let dir = URL(fileURLWithPath: profilePath).lastPathComponent
+ return store?.profiles.first { $0.directoryName == dir }?.id
+ }
+
+ static func location(profileID: UUID?) -> DownloadLocation {
+ store?.settings.downloadLocation(profileID: profileID) ?? DownloadLocation()
+ }
+
+ /// The folder a profile saves to (the Library's Open Downloads Folder opens it too).
+ static func folder(profileID: UUID?) -> URL {
+ location(profileID: profileID).folderURL(downloads: downloadsFolder) { path in
+ var dir: ObjCBool = false
+ return FileManager.default.fileExists(atPath: path, isDirectory: &dir) && dir.boolValue
+ }
+ }
+
+ /// The file to save as, or nil when the user cancelled the save panel.
+ static func destination(profilePath: String?, suggestedName: String, completion: @escaping @MainActor (URL?) -> Void) {
+ let id = profileID(profilePath: profilePath)
+ let folder = folder(profileID: id)
+ guard location(profileID: id).askWhereToSave else {
+ completion(DownloadFileName.unique(suggestedName, in: folder) { FileManager.default.fileExists(atPath: $0) })
+ return
+ }
+ asks.append { done in
+ let panel = NSSavePanel()
+ panel.directoryURL = folder
+ panel.nameFieldStringValue = DownloadFileName.sanitized(suggestedName)
+ panel.canCreateDirectories = true
+ let finish: (NSApplication.ModalResponse) -> Void = { response in
+ MainActor.assumeIsolated {
+ completion(response == .OK ? panel.url : nil)
+ // The sheet is still attached while its handler runs: the next one next turn.
+ DispatchQueue.main.async { done() }
+ }
+ }
+ // On the window the download came from: a page's Chrome-style window is a child of
+ // it. Cra in the background has no key or main window: the frontmost of its own.
+ var window = NSApp.keyWindow ?? NSApp.mainWindow
+ ?? NSApp.orderedWindows.first { $0.isVisible && $0.parent == nil && $0.canBecomeMain }
+ while let parent = window?.parent { window = parent }
+ if let window, window.isVisible, window.attachedSheet == nil {
+ panel.beginSheetModal(for: window, completionHandler: finish)
+ } else {
+ panel.begin(completionHandler: finish)
+ }
+ }
+ if asks.count == 1 { asks[0](next) }
+ }
+
+ /// Save panels one at a time: a second download asks once the first panel has closed.
+ private static var asks: [(@escaping @MainActor () -> Void) -> Void] = []
+
+ private static func next() {
+ asks.removeFirst()
+ if let ask = asks.first { ask(next) }
+ }
+}
diff --git a/Sources/Cra/Services/SidebarStore.swift b/Sources/Cra/Services/SidebarStore.swift
index 7f9b118..bcf379d 100644
--- a/Sources/Cra/Services/SidebarStore.swift
+++ b/Sources/Cra/Services/SidebarStore.swift
@@ -1969,6 +1969,7 @@ final class SidebarStore {
drop(l.containerID)
}
profileFavorites.removeAll { $0.profileID == id }
+ settings.downloadLocations[DownloadLocation.key(profileID: id)] = nil
ProfileCleanup.schedule(p.directoryName)
touch()
}
diff --git a/Sources/Cra/Services/WebKit/WebKitBrowser.swift b/Sources/Cra/Services/WebKit/WebKitBrowser.swift
index 83cfeb9..5a713fb 100644
--- a/Sources/Cra/Services/WebKit/WebKitBrowser.swift
+++ b/Sources/Cra/Services/WebKit/WebKitBrowser.swift
@@ -987,18 +987,20 @@ final class WebKitBrowser: CraBrowser, WKNavigationDelegate, WKUIDelegate, WKDow
func download(_ download: WKDownload, decideDestinationUsing response: URLResponse, suggestedFilename: String,
completionHandler: @escaping @MainActor (URL?) -> Void) {
- let folder = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask)[0]
- // Only a file name in Downloads: no path, no "." or "..", no hidden file.
- var name = suggestedFilename.replacingOccurrences(of: "/", with: "-").replacingOccurrences(of: ":", with: "-")
- while name.hasPrefix(".") { name.removeFirst() }
- if name.trimmingCharacters(in: .whitespaces).isEmpty { name = "download" }
- var dest = folder.appendingPathComponent(name)
- let base = dest.deletingPathExtension().lastPathComponent, ext = dest.pathExtension
- var n = 1
- while FileManager.default.fileExists(atPath: dest.path) {
- dest = folder.appendingPathComponent(ext.isEmpty ? "\(base) (\(n))" : "\(base) (\(n)).\(ext)")
- n += 1
+ // The profile's Download location, or a save panel when it asks for each file (#190).
+ let profilePath = incognitoPage ? nil : profile
+ let asked = DownloadDestinations.location(profileID: DownloadDestinations.profileID(profilePath: profilePath)).askWhereToSave
+ DownloadDestinations.destination(profilePath: profilePath, suggestedName: suggestedFilename) { [weak self] dest in
+ guard let self, let dest else { return completionHandler(nil) }
+ // A save panel picks a taken name only after the user agreed to replace it, and
+ // WebKit won't write over a file. (Without a panel the name is a free one.)
+ if asked, FileManager.default.fileExists(atPath: dest.path) { try? FileManager.default.trashItem(at: dest, resultingItemURL: nil) }
+ self.startDownload(download, response: response, to: dest, completionHandler: completionHandler)
}
+ }
+
+ private func startDownload(_ download: WKDownload, response: URLResponse, to dest: URL,
+ completionHandler: @escaping @MainActor (URL?) -> Void) {
Self.nextDownloadID &+= 1
let info = CraDownloadInfo()
info.identifier = Self.nextDownloadID
diff --git a/Sources/Cra/UI/Settings/ProfilesPane.swift b/Sources/Cra/UI/Settings/ProfilesPane.swift
index daa13fd..81d6a99 100644
--- a/Sources/Cra/UI/Settings/ProfilesPane.swift
+++ b/Sources/Cra/UI/Settings/ProfilesPane.swift
@@ -1,3 +1,4 @@
+import AppKit
import SwiftUI
/// Dia's Profiles pane (and Arc's Profiles preferences): the profiles and how many spaces
@@ -35,6 +36,17 @@ struct ProfilesPane: View {
}
.padding(.top, 7.5)
SettingsFootnote("Profiles help keep your data separate across Spaces, like logins, cookies and site data. You can use any Profile across one or more Spaces: choose Spaces ▸ Change Profile, or Set Profile on a Space's menu. Spaces on the same Profile share their logins. Only Profiles not assigned to any Spaces can be deleted.")
+ // Arc's per-profile Download location (DownloadLocationView: the folder, Ask
+ // Where to Save, Other…), GitHub #190.
+ SettingsHeader("Downloads").padding(.top, 20)
+ SettingsCard {
+ downloadRow(name: "Default", profileID: nil)
+ ForEach(store.profiles) { p in
+ SettingsCardDivider()
+ downloadRow(name: p.name, profileID: p.id)
+ }
+ }
+ SettingsFootnote("Where each Profile saves downloaded files. Choose Ask Where to Save Each File to pick a place every time.")
}
.alert("Rename Profile", isPresented: Binding(get: { naming != nil }, set: { if !$0 { naming = nil } })) {
TextField("Profile name", text: $name)
@@ -49,6 +61,50 @@ struct ProfilesPane: View {
}
}
+ private enum DownloadChoice: Hashable { case folder, ask, other }
+
+ private func downloadRow(name: String, profileID: UUID?) -> some View {
+ let location = store.settings.downloadLocation(profileID: profileID)
+ let folder = DownloadDestinations.folder(profileID: profileID)
+ let choice = Binding<DownloadChoice>(
+ get: { location.askWhereToSave ? .ask : .folder },
+ set: { picked in
+ var l = store.settings.downloadLocation(profileID: profileID)
+ switch picked {
+ case .folder: l.askWhereToSave = false
+ case .ask: l.askWhereToSave = true
+ case .other:
+ let panel = NSOpenPanel()
+ panel.canChooseDirectories = true
+ panel.canChooseFiles = false
+ panel.canCreateDirectories = true
+ panel.directoryURL = folder
+ panel.prompt = "Select"
+ panel.message = "Choose where \(name) saves downloaded files."
+ guard panel.runModal() == .OK, let url = panel.url else { return }
+ l.folder = url.standardizedFileURL.path == DownloadDestinations.downloadsFolder.standardizedFileURL.path ? nil : url.path
+ l.askWhereToSave = false
+ }
+ store.settings.setDownloadLocation(l, profileID: profileID)
+ })
+ return SettingsCardRow {
+ VStack(alignment: .leading, spacing: 2) {
+ Text(name).font(.system(size: 13))
+ Text("Download location").font(.system(size: 11)).foregroundStyle(.secondary)
+ }
+ } trailing: {
+ Picker("Download location", selection: choice) {
+ Label(FileManager.default.displayName(atPath: folder.path), systemImage: "folder").tag(DownloadChoice.folder)
+ Text("Ask Where to Save Each File").tag(DownloadChoice.ask)
+ Divider()
+ Text("Other…").tag(DownloadChoice.other)
+ }
+ .labelsHidden()
+ .frame(width: 200)
+ .help(folder.path)
+ }
+ }
+
private var trimmed: String { name.trimmingCharacters(in: .whitespaces) }
private func row<Trailing: View>(name: String, profileID: UUID?, @ViewBuilder trailing: () -> Trailing) -> some View {
diff --git a/Sources/Cra/UI/Sidebar/LibraryView.swift b/Sources/Cra/UI/Sidebar/LibraryView.swift
index 4856aba..81ef31c 100644
--- a/Sources/Cra/UI/Sidebar/LibraryView.swift
+++ b/Sources/Cra/UI/Sidebar/LibraryView.swift
@@ -459,8 +459,10 @@ private final class LibraryListView: NSView, NSTextFieldDelegate, NSTableViewDat
menu.autoenablesItems = false
switch page {
case .downloads:
+ // The folder the window's profile downloads to (#190).
+ let profile = (window?.windowController as? MainWindowController)?.profileDirectoryName
MenuItems.add(menu, "Open Downloads Folder") {
- NSWorkspace.shared.open(FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask)[0])
+ NSWorkspace.shared.open(DownloadDestinations.folder(profileID: DownloadDestinations.profileID(profilePath: profile)))
}
case .archive:
let store = store
diff --git a/Sources/CraCEF/CraCEF.mm b/Sources/CraCEF/CraCEF.mm
index 9f89cd4..735a511 100644
--- a/Sources/CraCEF/CraCEF.mm
+++ b/Sources/CraCEF/CraCEF.mm
@@ -71,6 +71,9 @@ static NSHashTable<CraBrowser*>* g_allBrowsers = nil;
/// Closed tabs whose page stays alive until its downloads end (see -[CraBrowser close]).
static NSMutableSet<CraBrowser*>* g_parkedBrowsers = nil;
static void (^g_strayPageHandler)(NSString*, NSString*) = nil;
+// Downloads whose save panel was cancelled (#190): cancelled on their next update, never shown.
+static std::set<uint32_t> g_cancelledDownloads;
+static void (^g_downloadDestinationHandler)(NSString*, NSString*, void (^)(NSString*)) = nil;
static void (^g_processEventHandler)(NSString*, NSString*, NSString*) = nil;
static NSString* NSStringFromCef(const CefString& s) {
@@ -1702,6 +1705,21 @@ public:
const CefString& suggested_name, CefRefPtr<CefBeforeDownloadCallback> callback) override {
NSString* name = NSStringFromCef(suggested_name);
if (name.length == 0) name = @"download";
+ // Cra picks the profile's folder, or asks with a save panel; the callback waits for it.
+ if (auto handler = g_downloadDestinationHandler) {
+ CraBrowser* o = owner_;
+ NSString* profile = o && !o.isIncognito ? o.profilePath : nil;
+ __block CefRefPtr<CefBeforeDownloadCallback> cb = callback;
+ uint32_t downloadID = download_item->GetId();
+ handler(profile, name, ^(NSString* path) {
+ if (!cb) return;
+ if (path.length) cb->Continue(CefStringFromNS(path), false);
+ // Dropping the callback unanswered cancels in CEF; the next update makes sure.
+ else g_cancelledDownloads.insert(downloadID);
+ cb = nullptr;
+ });
+ return true;
+ }
NSString* dir = [NSSearchPathForDirectoriesInDomains(NSDownloadsDirectory, NSUserDomainMask, YES) firstObject];
NSString* path = [dir stringByAppendingPathComponent:name];
NSFileManager* fm = [NSFileManager defaultManager];
@@ -1720,6 +1738,11 @@ public:
void OnDownloadUpdated(CefRefPtr<CefBrowser> browser, CefRefPtr<CefDownloadItem> item,
CefRefPtr<CefDownloadItemCallback> callback) override {
+ if (g_cancelledDownloads.count(item->GetId())) {
+ if (item->IsInProgress()) callback->Cancel();
+ else g_cancelledDownloads.erase(item->GetId());
+ return;
+ }
CraBrowser* o = owner_;
if (!o) return;
CraDownloadInfo* info = [CraDownloadInfo new];
@@ -2626,6 +2649,7 @@ static void MarkProfileExitedCleanly(NSString* profileDir) {
+ (BOOL)anotherInstanceWasNotified { return g_alreadyRunning; }
+ (void)setRelaunchHandler:(void (^)(NSArray<NSString*>*))handler { g_relaunchHandler = [handler copy]; }
+ (void)setStrayPageHandler:(void (^)(NSString*, NSString*))handler { g_strayPageHandler = [handler copy]; }
++ (void)setDownloadDestinationHandler:(void (^)(NSString*, NSString*, void (^)(NSString*)))handler { g_downloadDestinationHandler = [handler copy]; }
+ (void)setProcessEventHandler:(void (^)(NSString*, NSString*, NSString*))handler { g_processEventHandler = [handler copy]; }
+ (BOOL)isExtensionWindow:(NSWindow*)window { return window && [g_extensionWindows containsObject:window]; }
+ (BOOL)isPageWindow:(NSWindow*)window {
diff --git a/Sources/CraCEF/include/CraCEF.h b/Sources/CraCEF/include/CraCEF.h
index bce1110..d997d48 100644
--- a/Sources/CraCEF/include/CraCEF.h
+++ b/Sources/CraCEF/include/CraCEF.h
@@ -312,6 +312,12 @@ typedef NS_ENUM(NSInteger, CraDownloadState) {
/// ("Default", "Profile <id>"; nil off the record); Chrome's own window for it is closed.
/// Popup-type windows (windows.create({type: "popup"})) stay Chrome's windows.
+ (void)setStrayPageHandler:(void (^)(NSString *url, NSString * _Nullable profile))handler;
+/// Where a page's download is saved (GitHub #190): the handler gets the browser's profile folder
+/// (nil for Default and off the record) and the file name Chromium suggests, and calls `completion`
+/// on the main thread with the full path to save to, or nil to cancel the download (a save panel
+/// the user closed). Without a handler downloads go to ~/Downloads.
++ (void)setDownloadDestinationHandler:(void (^)(NSString * _Nullable profilePath, NSString *suggestedName,
+ void (^completion)(NSString * _Nullable path)))handler;
/// Renderer trouble and failed loads, for Cra's performance recorder (GitHub #91): `kind` is
/// terminated, unresponsive, responsive or loadError; `detail` how it ended or the net error
/// code; `site` the host (nil for incognito, Cra's own pages or a closed tab). Never a URL.
diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.md
index 438810b..4e0aab2 100644
--- a/docs/arc-reverse-engineering.md
+++ b/docs/arc-reverse-engineering.md
@@ -3182,3 +3182,25 @@ Arc Max's renameDownloads: a finished download is renamed on disk and a card abo
window under a press key first (installChildClickMonitor), but a Peek's page is a grandchild of the browser window, and a
Little Window has no such monitor. LittleWindow.sendEvent now does the same for its children. A press while the browser
window itself was key always worked (its monitor made the Peek key), which is why it looked intermittent.
+
+## Theme editor hover, tab-on-tab drops, Download location (Arc 1.171, static, 5 Nov 2026, #189–#191)
+Read from the arm64 slice's Swift field metadata (`__swift5_fieldmd`, case and field names only; no numbers).
+- [O metadata] SpaceStyleEditor module: `ColorPillButtonStyle { colorSet, _isHovered, addComplimentary }` (the preset
+ swatches are a ButtonStyle with a hover state), `SpaceStyleButtonStyle { _isHovered, _isEnabled, hoverColor,
+ hoverStyleEnabled }` (paging arrows, `EditColorButtonsView` − / +, `LightDarkToggleView`, each with
+ `shouldEnableButtonHover`), `PadWheel { _isDraggingKnob, _isKnobHovered, _knobPositionAtDragBegin }`,
+ `SpaceStyleColorPadView { _isPadButtonsHovered, _isDraggingKnob, _isKnobHovered }`.
+ [?] Not measured: the hover/press scales and the hover colour. Cra (#189): swatches and knobs scale 1.08 hovered,
+ 0.92 pressed (ease-out 0.12 / 0.10 s, the reporter's estimates); arrows, − / +, Auto / Light / Dark get +0.3 white
+ on hover; pointing hand on the arrows, open hand over a knob, closed hand while dragging one; none with Reduce Motion.
+- [O metadata] Sidebar drops: `SidebarDropTarget = tabList(…) | appTray`, `SidebarDropTargetRegion = left | right`,
+ `SidebarDropOperation = move | copy`, the window action `draggedToCombineSplitCompatibleItems(…)`. No drop makes a
+ folder: `createFolderFromItems` / `createFolderFromSelection` are the menus' "New Folder with N Items". Cra (#191):
+ a tab dropped on the middle of any tab row, pinned or Today, offers the split (the pinned tab stays, the split
+ opens in Today with a copy, `SidebarStore.createSplit`); Cra's own "New Folder" drop on pinned rows is gone.
+ [?] Not observed live: Arc's drop on a pinned row.
+- [O strings/metadata] Settings ▸ Profiles "Download location" is per profile: `DownloadLocationView { store,
+ _selectedTag, _panelOpen }` with tags `arc.folder`, `arc.promptForDownload`, `arc.other` ("Button to confirm
+ selection of directory for file downloads"). [?] The menu's own labels aren't in the strings. Cra (#190):
+ AppSettings.downloadLocations per profile (folder or ask), a Downloads card under Profiles with the folder,
+ "Ask Where to Save Each File" and "Other…"; save panels queue one at a time as sheets on Cra's window.