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://open takes space=<id>: the link opens in that space (#168)
Victor3c0d0cb22548
diff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swiftindex 3ba92ea..1b3891b 100644--- a/Sources/Cra/App/AppDelegate.swift+++ b/Sources/Cra/App/AppDelegate.swift@@ -472,15 +472,15 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {}/// Creates a little window without showing it (`url` nil = popup host).- func makeLittleWindow(url: String?, opener: CraBrowser? = nil) -> LittleWindowController {- let w = LittleWindowController(app: self, url: url, opener: opener)+ func makeLittleWindow(url: String?, opener: CraBrowser? = nil, space: UUID? = nil) -> LittleWindowController {+ let w = LittleWindowController(app: self, url: url, opener: opener, space: space)littleWindows.append(w)return w}@discardableResult- func openLittleWindow(url: String, activate: Bool = true, opener: CraBrowser? = nil) -> LittleWindowController {- let w = makeLittleWindow(url: url, opener: opener)+ func openLittleWindow(url: String, activate: Bool = true, opener: CraBrowser? = nil, space: UUID? = nil) -> LittleWindowController {+ let w = makeLittleWindow(url: url, opener: opener, space: space)if activate { w.show() } else { w.window?.orderFront(nil) }return w}@@ -521,8 +521,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {}}- /// cra://commandbar?query=…&mode=edit, cra://action/<id>, cra://open?url=…,- /// cra://dismiss.+ /// cra://commandbar?query=…&mode=edit, cra://action/<id>,+ /// cra://open?url=…[&space=<space id>][&background=1|&little=1], cra://dismiss.func handleInternalURL(_ u: URL) {let comps = URLComponents(url: u, resolvingAgainstBaseURL: false)func q(_ name: String) -> String? { comps?.queryItems?.first { $0.name == name }?.value }@@ -543,12 +543,23 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {// Load a URL in the focused tab / split pane (scripting).if let url = q("url") { main.loadInSelectedTab(url) }case "open":- if let url = q("url"), q("little") == "1" {- openLittleWindow(url: url)- } else if let url = q("url") {+ guard let url = q("url") else { break }+ let background = q("background") == "1"+ // space=<id> (#168): a real, normal space, as Air Traffic Control routes to; an unknown+ // or incognito one opens where it did before, in the space in use.+ let space = q("space").flatMap(UUID.init(uuidString:)).flatMap { store.space($0) != nil && !store.isIncognito(space: $0) ? $0 : nil }+ if q("little") == "1" {+ openLittleWindow(url: url, space: space)+ } else if let space {+ // Held: useNormalWindow(forSpace:) can change which window is main.+ let target = useNormalWindow(forSpace: space)+ let tab = store.createTab(url: url, in: space, select: !background, window: target.windowID)+ if background { store.markUnread(tab.id, true); target.browsers.ensureRuntime(for: tab.id) }+ if !HitchMonitor.background { target.showWindow(nil) }+ } else {useNormalWindow()- let tab = store.createTab(url: url, select: q("background") != "1")- if q("background") == "1" { store.markUnread(tab.id, true); main.browsers.ensureRuntime(for: tab.id) }+ let tab = store.createTab(url: url, select: !background)+ if background { store.markUnread(tab.id, true); main.browsers.ensureRuntime(for: tab.id) }}case "key":// Scripted key press through the normal event path (testing).diff --git a/Sources/Cra/UI/Windows/LittleWindowController.swift b/Sources/Cra/UI/Windows/LittleWindowController.swiftindex ebff535..42c49bb 100644--- a/Sources/Cra/UI/Windows/LittleWindowController.swift+++ b/Sources/Cra/UI/Windows/LittleWindowController.swift@@ -145,6 +145,9 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @precoprivate var tooltip: LittleTooltipPanel?private var tooltipTimer: Timer?private let toast = ShinyToast()+ /// The space a cra://open named: "Open in" stays on it, matching the page's profile,+ /// until the user switches spaces from this window's command bar.+ private var requestedSpaceID: UUID?var store: SidebarStore { app.store }var currentURL: String { browser?.currentURL ?? state.url }@@ -153,14 +156,18 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco/// `url` nil makes a popup host: the browser adopts the next window.open/// CEF hands it (see `CraBrowserDelegate.browser:popupHostForURL:`)./// `opener` is the page a link or popup came from; `fromTab` the tab a Peek came from.- init(app: AppDelegate, url: String?, peekOver parent: MainWindowController? = nil, opener: CraBrowser? = nil, fromTab: UUID? = nil) {+ /// `space` is the space a cra://open asked for (#168).+ init(app: AppDelegate, url: String?, peekOver parent: MainWindowController? = nil, opener: CraBrowser? = nil, fromTab: UUID? = nil,+ space: UUID? = nil) {self.app = appisPopupHost = url == nilisPeek = parent != nilpeekParent = parent+ requestedSpaceID = parent == nil ? space : nil// Little Windows are normal browsing: they target the last normal window's space- // (a Peek: the space of the window it covers).- state = LittleWindowState(targetSpaceID: parent?.focusedSpaceID ?? app.store.focusedSpaceID(window: app.store.lastNormalWindowID))+ // (a Peek: the space of the window it covers; a cra://open: the space it names).+ state = LittleWindowState(targetSpaceID: parent?.focusedSpaceID ?? requestedSpaceID+ ?? app.store.focusedSpaceID(window: app.store.lastNormalWindowID))commandBar = CommandBarController(engine: app.engine, store: app.store)let size = app.store.prefs.littleWindowSize.map { NSSizeFromString($0) }.flatMap { $0 == LittleMetrics.legacyDefaultSize ? nil : $0 }@@ -609,6 +616,7 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @precoapp.perform(id)case .switchSpace(let id):store.focusSpace(id)+ requestedSpaceID = nilrefreshTarget()case .moveToSpace(let id):promote(to: id)@@ -708,7 +716,8 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco/// Arc's Little Arc names the space of the browser window used last and updates when it/// takes focus again (Arc 1.171: switched in the main window, "Open in" followed; #92).func refreshTarget() {- let id = peekParent?.focusedSpaceID ?? store.focusedSpaceID(window: store.lastNormalWindowID)+ if let r = requestedSpaceID, store.space(r) == nil { requestedSpaceID = nil }+ let id = peekParent?.focusedSpaceID ?? requestedSpaceID ?? store.focusedSpaceID(window: store.lastNormalWindowID)if state.targetSpaceID != id { state.targetSpaceID = id }}diff --git a/docs/development.md b/docs/development.mdindex ecaeef4..a0cc481 100644--- a/docs/development.md+++ b/docs/development.md@@ -181,6 +181,7 @@ Cra registers the `cra://` scheme so it can be driven from a shell:open "cra://commandbar?query=github" # open the command bar with textopen "cra://open?url=https://example.com&background=1"open "cra://open?url=https://example.com&little=1" # in a Little Window+ open "cra://open?url=https://example.com&space=<space id>" # in that space (its id in sidebar.json)open "cra://import?source=arc&archive=1&settings=1" # headless importopen "cra://dismiss" # close sheets, command bar, find bar