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.

Little Windows and Peeks load in their space's profile (#172) (#177)

Victor Kildahl66c5ebc53001
diff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swift
index 48cd4c5..3ba92ea 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?) -> LittleWindowController {
- let w = LittleWindowController(app: self, url: url)
+ func makeLittleWindow(url: String?, opener: CraBrowser? = nil) -> LittleWindowController {
+ let w = LittleWindowController(app: self, url: url, opener: opener)
littleWindows.append(w)
return w
}
@discardableResult
- func openLittleWindow(url: String, activate: Bool = true) -> LittleWindowController {
- let w = makeLittleWindow(url: url)
+ func openLittleWindow(url: String, activate: Bool = true, opener: CraBrowser? = nil) -> LittleWindowController {
+ let w = makeLittleWindow(url: url, opener: opener)
if activate { w.show() } else { w.window?.orderFront(nil) }
return w
}
@@ -488,7 +488,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
/// Arc's Peek: a Little Window over `parent` that closes when a click lands past it.
func openPeek(url: String, over parent: MainWindowController, fromTab tabID: UUID? = nil) {
for p in littleWindows where p.peekParent === parent { p.closeWindow() }
- let w = LittleWindowController(app: self, url: url, peekOver: parent)
+ let w = LittleWindowController(app: self, url: url, peekOver: parent, fromTab: tabID)
littleWindows.append(w)
// Arc badges the tab the Peek came from with the peeked page's favicon (modalIcon).
parent.sidebarUI.peekBadge = tabID.map { .init(tabID: $0, iconKey: FaviconKey.key(for: url)) }
diff --git a/Sources/Cra/UI/Windows/LittleWindowController.swift b/Sources/Cra/UI/Windows/LittleWindowController.swift
index 094a5f8..ebff535 100644
--- a/Sources/Cra/UI/Windows/LittleWindowController.swift
+++ b/Sources/Cra/UI/Windows/LittleWindowController.swift
@@ -152,7 +152,8 @@ 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:`).
- init(app: AppDelegate, url: String?, peekOver parent: MainWindowController? = nil) {
+ /// `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) {
self.app = app
isPopupHost = url == nil
isPeek = parent != nil
@@ -230,7 +231,20 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
commandBar.onClose = { [weak self] in self?.hideCommandPanel() }
commandBar.spaceName = { [weak self] id in self?.store.space(id)?.title ?? "" }
- let b = CraBrowser(frame: shell.page.bounds, url: url.map { $0.isEmpty ? "about:blank" : $0 }, delegate: self)
+ // The page's sign-ins (#172). Arc's Little Arc takes the profile of the space it opens into
+ // and keeps it; a Peek uses its tab's, so a shared favorite peeks in its list's profile. A
+ // link from a Little Window stays in its page's profile, and a popup has to: Chromium
+ // hosts a popup in its opener's profile. nil is the Default profile.
+ let profilePath: String?
+ if let opener {
+ profilePath = opener.profilePath
+ } else if let fromTab, app.store.item(fromTab) != nil {
+ profilePath = app.store.profilePath(item: fromTab)
+ } else {
+ profilePath = app.store.profilePath(space: state.targetSpaceID)
+ }
+ let b = CraBrowser(frame: shell.page.bounds, url: url.map { $0.isEmpty ? "about:blank" : $0 }, delegate: self,
+ incognito: false, profilePath: profilePath)
attach(b)
state.url = (url == "about:blank" ? "" : url) ?? ""
}
@@ -933,13 +947,13 @@ final class LittleWindowController: NSWindowController, NSWindowDelegate, @preco
func browser(_ browser: CraBrowser, requestsNewTabWithURL url: String, inBackground background: Bool) {
// cra:// is Cra's scripting scheme; a page must not drive it.
if url.lowercased().hasPrefix("cra:") { return }
- app.openLittleWindow(url: url, activate: !background)
+ app.openLittleWindow(url: url, activate: !background, opener: browser)
if background { window?.makeKeyAndOrderFront(nil) }
}
func browser(_ browser: CraBrowser, popupHostForURL url: String, inBackground background: Bool) -> CraBrowser? {
if url.lowercased().hasPrefix("cra:") { return nil }
- let w = app.makeLittleWindow(url: nil)
+ let w = app.makeLittleWindow(url: nil, opener: browser)
w.state.url = url
w.show()
if background { window?.makeKeyAndOrderFront(nil) }