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.

Edit Pinned Page for pinned tabs and favorites, as in Arc (#55)

Anoninz8fc03505ba55
diff --git a/Packages/CraCore/Sources/CraCore/TypedURL.swift b/Packages/CraCore/Sources/CraCore/TypedURL.swift
new file mode 100644
index 0000000..bfd23e2
--- /dev/null
+++ b/Packages/CraCore/Sources/CraCore/TypedURL.swift
@@ -0,0 +1,37 @@
+import Foundation
+
+/// What typed text means as an address: the command bar's rule for telling a URL from a search,
+/// and the scheme it gets when it has none.
+public enum TypedURL {
+ public static func looksLikeURL(_ s: String) -> Bool {
+ let t = s.trimmingCharacters(in: .whitespaces)
+ if t.isEmpty || t.contains(" ") { return false }
+ if t.range(of: #"^[a-zA-Z][a-zA-Z0-9+.\-]*://"#, options: .regularExpression) != nil { return true }
+ if t.hasPrefix("localhost") || t.hasPrefix("about:") || t.hasPrefix("view-source:") || t.hasPrefix("data:") || t.hasPrefix("file:") { return true }
+ if t.range(of: #"^(\d{1,3}\.){3}\d{1,3}(:\d+)?(/.*)?$"#, options: .regularExpression) != nil { return true }
+ // host.tld[:port][/path]
+ return t.range(of: #"^[\w\-]+(\.[\w\-]+)+(:\d+)?(/\S*)?$"#, options: .regularExpression) != nil
+ }
+
+ public static func fromInput(_ s: String) -> String {
+ let t = s.trimmingCharacters(in: .whitespaces)
+ if t.range(of: #"^[a-zA-Z][a-zA-Z0-9+.\-]*://"#, options: .regularExpression) != nil { return t }
+ // Before the bare-scheme check: "localhost:3000" is a host and port, not a "localhost:" URL.
+ if t.hasPrefix("localhost") || t.range(of: #"^(\d{1,3}\.){3}\d{1,3}"#, options: .regularExpression) != nil {
+ return "http://" + t
+ }
+ if t.range(of: #"^[a-zA-Z][a-zA-Z0-9+.\-]*:"#, options: .regularExpression) != nil { return t }
+ return "https://" + t
+ }
+
+ /// Arc's Edit Pinned URL dialog: the address a pinned tab or favorite gets from the typed text,
+ /// or nil when it isn't one (a search, a script, a web address without a host).
+ public static func pinnedDestination(_ s: String) -> String? {
+ let input = s.trimmingCharacters(in: .whitespacesAndNewlines)
+ guard looksLikeURL(input) else { return nil }
+ let url = fromInput(input)
+ guard let parsed = URL(string: url) else { return nil }
+ if ["http", "https"].contains(parsed.scheme?.lowercased() ?? ""), parsed.host?.isEmpty != false { return nil }
+ return url
+ }
+}
diff --git a/Packages/CraCore/Tests/CraCoreTests/TypedURLTests.swift b/Packages/CraCore/Tests/CraCoreTests/TypedURLTests.swift
new file mode 100644
index 0000000..21fb160
--- /dev/null
+++ b/Packages/CraCore/Tests/CraCoreTests/TypedURLTests.swift
@@ -0,0 +1,31 @@
+import CraCore
+import Testing
+
+struct TypedURLTests {
+ @Test(arguments: [
+ ("example.org/new?q=1", "https://example.org/new?q=1" as String?),
+ (" https://Example.com/a#b ", "https://Example.com/a#b"),
+ ("localhost:3000", "http://localhost:3000"),
+ ("192.168.1.1/admin", "http://192.168.1.1/admin"),
+ ("file:///tmp/a.html", "file:///tmp/a.html"),
+ ("about:blank", "about:blank"),
+ ("", nil),
+ ("hello world", nil),
+ ("notes", nil),
+ ("javascript:alert(1)", nil),
+ ("https://", nil),
+ ("http:///path", nil),
+ ])
+ func pinnedDestination(input: String, url: String?) {
+ #expect(TypedURL.pinnedDestination(input) == url)
+ }
+
+ @Test func searchesAreNotAddresses() {
+ #expect(!TypedURL.looksLikeURL("cra browser"))
+ #expect(TypedURL.looksLikeURL("view-source:https://example.com"))
+ #expect(TypedURL.fromInput("example.com") == "https://example.com")
+ #expect(TypedURL.fromInput("localhost:3000/a") == "http://localhost:3000/a")
+ #expect(TypedURL.fromInput("http://localhost:3000") == "http://localhost:3000")
+ #expect(TypedURL.fromInput("mailto:[email protected]") == "mailto:[email protected]")
+ }
+}
diff --git a/Sources/Cra/Services/SidebarStore.swift b/Sources/Cra/Services/SidebarStore.swift
index 400e78b..d93ebce 100644
--- a/Sources/Cra/Services/SidebarStore.swift
+++ b/Sources/Cra/Services/SidebarStore.swift
@@ -511,6 +511,23 @@ final class SidebarStore {
touch()
}
+ /// Arc's Edit Pinned Page ▸ Edit…: a new pinned URL for a pinned tab or favorite (#54). A tab
+ /// on its pinned page goes with it; one navigated away keeps its page until Back to Pinned Page.
+ @discardableResult
+ func setPinnedURL(_ id: UUID, to url: String) -> Bool {
+ guard var it = items[id], var t = it.tab, isPinned(id), t.liveItemURL == nil else { return false }
+ if t.url == t.savedURL, t.url != url {
+ t.url = url
+ t.savedTitle = ""
+ t.faviconKey = FaviconKey.key(for: url)
+ }
+ t.savedURL = url
+ it.data = .tab(t)
+ items[id] = it
+ touch()
+ return true
+ }
+
func duplicateTab(_ id: UUID) -> SidebarItem? {
guard let it = items[id], let t = it.tab, let parent = it.parentID else { return nil }
let idx = (items[parent]?.children.firstIndex(of: id) ?? 0) + 1
diff --git a/Sources/Cra/Services/SuggestionEngine.swift b/Sources/Cra/Services/SuggestionEngine.swift
index 6064e6e..70c89c4 100644
--- a/Sources/Cra/Services/SuggestionEngine.swift
+++ b/Sources/Cra/Services/SuggestionEngine.swift
@@ -230,24 +230,9 @@ final class SuggestionEngine {
// MARK: Typed text
- static func looksLikeURL(_ s: String) -> Bool {
- let t = s.trimmingCharacters(in: .whitespaces)
- if t.isEmpty || t.contains(" ") { return false }
- if t.range(of: #"^[a-zA-Z][a-zA-Z0-9+.\-]*://"#, options: .regularExpression) != nil { return true }
- if t.hasPrefix("localhost") || t.hasPrefix("about:") || t.hasPrefix("view-source:") || t.hasPrefix("data:") || t.hasPrefix("file:") { return true }
- if t.range(of: #"^(\d{1,3}\.){3}\d{1,3}(:\d+)?(/.*)?$"#, options: .regularExpression) != nil { return true }
- // host.tld[:port][/path]
- return t.range(of: #"^[\w\-]+(\.[\w\-]+)+(:\d+)?(/\S*)?$"#, options: .regularExpression) != nil
- }
+ static func looksLikeURL(_ s: String) -> Bool { TypedURL.looksLikeURL(s) }
- static func urlFromInput(_ s: String) -> String {
- let t = s.trimmingCharacters(in: .whitespaces)
- if t.range(of: #"^[a-zA-Z][a-zA-Z0-9+.\-]*:"#, options: .regularExpression) != nil { return t }
- if t.hasPrefix("localhost") || t.range(of: #"^(\d{1,3}\.){3}\d{1,3}"#, options: .regularExpression) != nil {
- return "http://" + t
- }
- return "https://" + t
- }
+ static func urlFromInput(_ s: String) -> String { TypedURL.fromInput(s) }
private func typedRow(query: String) -> Suggestion {
if Self.looksLikeURL(query) {
diff --git a/Sources/Cra/UI/Sidebar/List/SidebarMenus.swift b/Sources/Cra/UI/Sidebar/List/SidebarMenus.swift
index 7121f80..6c8654a 100644
--- a/Sources/Cra/UI/Sidebar/List/SidebarMenus.swift
+++ b/Sources/Cra/UI/Sidebar/List/SidebarMenus.swift
@@ -80,10 +80,10 @@ enum SidebarMenus {
store.setMuted(id, !tab.muted)
actions.performAction("muteTab:\(id)")
}
- if m.pinned {
+ if m.pinned, tab.liveItemURL == nil { editPinnedPage(menu, id, navigatedAway: m.navigatedAway, store: store, actions: actions) }
+ if m.pinned, m.navigatedAway {
menu.addItem(.separator())
- if m.navigatedAway { add(menu, "Back to Pinned Page") { actions.resetPinnedTab(id) } }
- add(menu, "Make This the Pinned Page") { store.setPinnedHomeToCurrent(id) }
+ add(menu, "Back to Pinned Page") { actions.resetPinnedTab(id) }
}
menu.addItem(.separator())
let spaces = submenu(menu, "Move to Space")
@@ -104,6 +104,14 @@ enum SidebarMenus {
return menu
}
+ /// Arc's Edit Pinned Page submenu on pinned tabs and favorites (#54). Replace is greyed out
+ /// while the tab is on its pinned page, as in Arc.
+ static func editPinnedPage(_ menu: NSMenu, _ id: UUID, navigatedAway: Bool, store: SidebarStore, actions: SidebarActions) {
+ let sub = submenu(menu, "Edit Pinned Page")
+ add(sub, "Replace Pinned URL with Current", enabled: navigatedAway) { store.setPinnedHomeToCurrent(id) }
+ add(sub, "Edit…") { actions.editPinnedURL(id) }
+ }
+
/// Move to Folder / New Folder for this tab, or for every picked tab.
private static func folderItems(_ menu: NSMenu, _ ids: [UUID], list: SpaceListView) {
let store = list.store, ui = list.ui
diff --git a/Sources/Cra/UI/Sidebar/List/SpaceColumnView.swift b/Sources/Cra/UI/Sidebar/List/SpaceColumnView.swift
index 311f09f..7425c71 100644
--- a/Sources/Cra/UI/Sidebar/List/SpaceColumnView.swift
+++ b/Sources/Cra/UI/Sidebar/List/SpaceColumnView.swift
@@ -886,8 +886,10 @@ final class FavoriteTileView: NSView, ArcTooltipTarget, NSDraggingSource {
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(item.tab?.url ?? "", forType: .string)
}
+ if let t = item.tab, t.liveItemURL == nil {
+ SidebarMenus.editPinnedPage(m, id, navigatedAway: t.url != t.savedURL, store: store, actions: actions)
+ }
if let t = item.tab, t.url != t.savedURL { MenuItems.add(m, "Back to Pinned Page") { actions.resetPinnedTab(id) } }
- MenuItems.add(m, "Make This the Pinned Page") { store.setPinnedHomeToCurrent(id) }
m.addItem(.separator())
MenuItems.add(m, "Change Icon…") { [weak self] in self?.pickIcon() }
if let key = item.tab?.customIconKey {
diff --git a/Sources/Cra/UI/SidebarUIState.swift b/Sources/Cra/UI/SidebarUIState.swift
index 04e38ef..effb01e 100644
--- a/Sources/Cra/UI/SidebarUIState.swift
+++ b/Sources/Cra/UI/SidebarUIState.swift
@@ -206,6 +206,7 @@ final class SidebarActions {
var closeLibrary: () -> Void = {}
var restoreArchived: (UUID) -> Void = { _ in }
var resetPinnedTab: (UUID) -> Void = { _ in }
+ var editPinnedURL: (UUID) -> Void = { _ in }
var openURL: (String) -> Void = { _ in }
var performAction: (String) -> Void = { _ in }
/// Double-click on an empty part of the header strip (sidebar title row or toolbar).
diff --git a/Sources/Cra/UI/Windows/EditPinnedURLDialog.swift b/Sources/Cra/UI/Windows/EditPinnedURLDialog.swift
new file mode 100644
index 0000000..757a971
--- /dev/null
+++ b/Sources/Cra/UI/Windows/EditPinnedURLDialog.swift
@@ -0,0 +1,69 @@
+import SwiftUI
+
+/// Arc 1.171's "Edit Pinned URL" dialog (a pinned tab's or favorite's Edit Pinned Page ▸ Edit…),
+/// measured from a 2x capture (1 Nov, #54): a 393 × 265 pt navy card over the dimmed window, the
+/// saved URL selected in its field. Arc enables Save for any text; Cra only for an address
+/// (TypedURL.pinnedDestination), so a search or a script can't become the pinned page.
+struct EditPinnedURLDialog: View {
+ let onSave: (String) -> Void
+ let onCancel: () -> Void
+ @State private var text: String
+ @FocusState private var focused: Bool
+
+ private static let card = Color(hex: "#161C2F")
+ private static let body = Color(hex: "#B8B9C4")
+
+ init(url: String, onSave: @escaping (String) -> Void, onCancel: @escaping () -> Void) {
+ self.onSave = onSave
+ self.onCancel = onCancel
+ _text = State(initialValue: url)
+ }
+
+ private var destination: String? { TypedURL.pinnedDestination(text) }
+
+ var body: some View {
+ VStack(alignment: .leading, spacing: 0) {
+ Text("Edit Pinned URL")
+ .font(.system(size: 17.5, weight: .semibold))
+ .foregroundStyle(.white)
+ .frame(height: 21, alignment: .top)
+ .padding(.top, 55)
+ .padding(.leading, 37.5)
+ Text("This is what opens first when you click this tab or its favicon.")
+ .font(.system(size: 14))
+ .lineSpacing(0.8)
+ .foregroundStyle(Self.body)
+ .fixedSize(horizontal: false, vertical: true)
+ .frame(width: 304, height: 35, alignment: .topLeading)
+ .padding(.top, 16)
+ .padding(.leading, 37.5)
+ TextField("", text: $text, prompt: Text("Enter a URL…").foregroundStyle(Color(hex: "#A6A8B0")))
+ .textFieldStyle(.plain)
+ .font(.system(size: 14))
+ .foregroundStyle(.white)
+ .focused($focused)
+ .onSubmit { if let destination { onSave(destination) } }
+ .padding(.horizontal, 8.5)
+ .frame(width: 318, height: 37)
+ .background(RoundedRectangle(cornerRadius: 5.5, style: .continuous).fill(Color(hex: "#383E4F")))
+ .overlay(RoundedRectangle(cornerRadius: 5.5, style: .continuous).strokeBorder(Color(hex: "#737884"), lineWidth: 1))
+ .padding(.top, 15.5)
+ .padding(.leading, 37.5)
+ HStack(spacing: 7) {
+ Spacer()
+ DialogButton(title: "Cancel", key: "ESC", enabled: true, style: .secondary, badge: CGSize(width: 35, height: 20), action: onCancel)
+ .keyboardShortcut(.cancelAction)
+ DialogButton(title: "Save", key: "↩", enabled: destination != nil, style: .accent, badge: CGSize(width: 27, height: 20)) {
+ if let destination { onSave(destination) }
+ }
+ }
+ .padding(.top, 21)
+ .padding(.trailing, 28)
+ Spacer(minLength: 0)
+ }
+ .frame(width: 393, height: 265)
+ .background(Self.card, in: RoundedRectangle(cornerRadius: 24, style: .continuous))
+ .environment(\.colorScheme, .dark)
+ .onAppear { focused = true }
+ }
+}
diff --git a/Sources/Cra/UI/Windows/MainWindowController+SpaceMenu.swift b/Sources/Cra/UI/Windows/MainWindowController+SpaceMenu.swift
index c55fad7..91e68ce 100644
--- a/Sources/Cra/UI/Windows/MainWindowController+SpaceMenu.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController+SpaceMenu.swift
@@ -57,24 +57,14 @@ extension MainWindowController {
/// Set Profile ▸ New Profile…: Arc's dialog over the dimmed window; Next makes the profile and
/// moves the space into it (pages already open reload in it, BrowserManager).
func showNewProfileDialog(forSpace id: UUID) {
- guard let window, window.childWindows?.contains(where: { $0 is DialogOverlayWindow }) != true else { return }
- var overlay: DialogOverlayWindow?
- let close = { [weak window] in
- guard let o = overlay else { return }
- window?.removeChildWindow(o)
- o.orderOut(nil)
- overlay = nil
- window?.makeKey()
- }
+ guard let window else { return }
let store = self.store
- let dialog = NewProfileDialog(onCreate: { name in
- store.setProfile(store.createProfile(name: name).id, forSpace: id)
- close()
- }, onCancel: close)
- let o = DialogOverlayWindow(over: window, content: dialog)
- overlay = o
- window.addChildWindow(o, ordered: .above)
- o.makeKeyAndOrderFront(nil)
+ DialogOverlayWindow.present(over: window) { close in
+ NewProfileDialog(onCreate: { name in
+ store.setProfile(store.createProfile(name: name).id, forSpace: id)
+ close()
+ }, onCancel: close)
+ }
}
/// Manage Spaces…: the Library on its Spaces page, every space side by side.
func showManageSpaces() { showLibrary(.spaces) }
diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swift
index 3f67e4b..96a75c0 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -217,6 +217,7 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
self.closeLibrary()
}
sidebarActions.resetPinnedTab = { [weak self] id in self?.resetPinnedTab(id) }
+ sidebarActions.editPinnedURL = { [weak self] id in self?.editPinnedURL(id) }
sidebarActions.openURL = { [weak self] url in
guard let self else { return }
self.store.createTab(url: url, window: self.windowID)
@@ -1335,6 +1336,20 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
app.runtime(for: id)?.browser.loadURL(home)
}
+ /// Edit Pinned Page ▸ Edit… (#54): Arc's dialog with the pinned URL. A page showing the old
+ /// pinned URL loads the new one; one navigated away stays where it is.
+ func editPinnedURL(_ id: UUID) {
+ guard let window, let tab = store.item(id)?.tab, store.isPinned(id), tab.liveItemURL == nil else { return }
+ DialogOverlayWindow.present(over: window) { [weak self] close in
+ EditPinnedURLDialog(url: tab.savedURL, onSave: { url in
+ close()
+ guard let self, let before = self.store.item(id)?.tab, self.store.setPinnedURL(id, to: url),
+ before.url == before.savedURL, before.url != url else { return }
+ self.app.runtime(for: id)?.browser.loadURL(url)
+ }, onCancel: close)
+ }
+ }
+
func cycleTab(_ delta: Int) {
let tabs = store.visibleTabs(in: focusedSpaceID)
guard !tabs.isEmpty else { return }
diff --git a/Sources/Cra/UI/Windows/NewProfileDialog.swift b/Sources/Cra/UI/Windows/NewProfileDialog.swift
index 507ad1d..bd26033 100644
--- a/Sources/Cra/UI/Windows/NewProfileDialog.swift
+++ b/Sources/Cra/UI/Windows/NewProfileDialog.swift
@@ -66,36 +66,64 @@ struct NewProfileDialog: View {
}
}
-/// Arc's dialog button: a label and its key in a small badge.
-private struct DialogButton: View {
+/// Arc's dialog button: a label and its key in a small badge. `.accent` is the vivid blue of
+/// Edit Pinned URL's Save (measured 1 Nov); disabled it looks like `.primary`.
+struct DialogButton: View {
+ enum Style { case secondary, primary, accent }
let title: String
let key: String
let enabled: Bool
- let primary: Bool
+ let style: Style
+ /// The key badge's size where it was measured (Edit Pinned URL); otherwise it fits the key.
+ var badge: CGSize?
let action: () -> Void
+ init(title: String, key: String, enabled: Bool, primary: Bool, action: @escaping () -> Void) {
+ self.init(title: title, key: key, enabled: enabled, style: primary ? .primary : .secondary, action: action)
+ }
+
+ init(title: String, key: String, enabled: Bool, style: Style, badge: CGSize? = nil, action: @escaping () -> Void) {
+ self.title = title
+ self.key = key
+ self.enabled = enabled
+ self.style = style
+ self.badge = badge
+ self.action = action
+ }
+
+ private var accent: Bool { style == .accent && enabled }
+ private var primary: Bool { style != .secondary }
+
var body: some View {
Button(action: action) {
HStack(spacing: 9) {
Text(title).font(.system(size: 13, weight: .medium))
- .foregroundStyle(enabled ? Color(hex: "#EBEBEF") : Color(hex: "#5B5C7F"))
+ .foregroundStyle(accent ? .white : enabled ? Color(hex: "#EBEBEF") : Color(hex: "#5B5C7F"))
Text(key).font(.system(size: key == "↩" ? 13 : 11, weight: .bold))
- .foregroundStyle(enabled ? Color(hex: "#B7B7DD") : Color(hex: "#5F6193"))
- .frame(minWidth: 27, minHeight: 19)
- .padding(.horizontal, key == "↩" ? 0 : 2)
- .background(RoundedRectangle(cornerRadius: 5, style: .continuous)
- .fill(primary ? Color(hex: enabled ? "#4E4C9A" : "#222469") : Color(hex: "#4E4C77")))
+ .foregroundStyle(accent ? Color(hex: "#EDEDFF") : enabled ? Color(hex: "#B7B7DD") : Color(hex: "#5F6193"))
+ .frame(minWidth: badge?.width ?? 27, maxWidth: badge?.width, minHeight: badge?.height ?? 19, maxHeight: badge?.height)
+ .padding(.horizontal, badge != nil || key == "↩" ? 0 : 2)
+ .background(RoundedRectangle(cornerRadius: badge == nil ? 5 : 3, style: .continuous)
+ .fill(accent ? Color(hex: "#464DFB") : primary ? Color(hex: enabled ? "#4E4C9A" : "#222469") : Color(hex: "#4E4C77")))
+ .overlay(RoundedRectangle(cornerRadius: badge == nil ? 5 : 3, style: .continuous)
+ .strokeBorder(accent ? Color(hex: "#6B71FE") : .clear, lineWidth: 1))
}
.padding(.leading, 12.5)
.padding(.trailing, 12)
.frame(height: 37)
.background(
RoundedRectangle(cornerRadius: 8, style: .continuous)
- .fill(primary ? Color(hex: enabled ? "#3B3C8F" : "#1C1D4C") : Color(hex: "#302F60"))
+ .fill(accent ? Color(hex: "#3239FB") : primary ? Color(hex: enabled ? "#3B3C8F" : "#1C1D4C") : Color(hex: "#302F60"))
)
.overlay(
RoundedRectangle(cornerRadius: 8, style: .continuous)
- .strokeBorder(primary ? (enabled ? Color(hex: "#6362A9") : .clear) : Color(hex: "#6362A9"), lineWidth: 1)
+ .strokeBorder(accent ? Color(hex: "#5B61FD") : primary ? (enabled ? Color(hex: "#6362A9") : .clear) : Color(hex: "#6362A9"), lineWidth: 1)
+ )
+ // Arc's Save sits on a darker blue lip, ~1.5 pt below it.
+ .background(
+ RoundedRectangle(cornerRadius: 8, style: .continuous)
+ .fill(style == .accent ? Color(hex: enabled ? "#2C3475" : "#1D2259") : .clear)
+ .offset(y: 1.5)
)
}
.buttonStyle(.plain)
@@ -154,8 +182,26 @@ final class DialogOverlayWindow: NSWindow {
let root = ZStack {
// Arc darkens the window to about 35% under its dialogs (sampled on 1 Nov).
Color(white: 0.1).opacity(0.65)
- content.shadow(color: .black.opacity(0.35), radius: 24, y: 8)
+ // One shadow for the card: without the group SwiftUI shadows every text and field on it.
+ content.compositingGroup().shadow(color: .black.opacity(0.35), radius: 24, y: 8)
}
contentView = NSHostingView(rootView: root)
}
+
+ /// Shows a dialog over `parent` (one at a time); `content` gets the closure that dismisses it.
+ static func present<Content: View>(over parent: NSWindow, _ content: (@escaping () -> Void) -> Content) {
+ guard parent.childWindows?.contains(where: { $0 is DialogOverlayWindow }) != true else { return }
+ var overlay: DialogOverlayWindow?
+ let close = { [weak parent] in
+ guard let o = overlay else { return }
+ parent?.removeChildWindow(o)
+ o.orderOut(nil)
+ overlay = nil
+ parent?.makeKey()
+ }
+ let o = DialogOverlayWindow(over: parent, content: content(close))
+ overlay = o
+ parent.addChildWindow(o, ordered: .above)
+ o.makeKeyAndOrderFront(nil)
+ }
}
diff --git a/Tests/StoreTests.swift b/Tests/StoreTests.swift
index 15cab02..340d2d8 100644
--- a/Tests/StoreTests.swift
+++ b/Tests/StoreTests.swift
@@ -24,6 +24,7 @@ enum StoreTests {
stampsUseTheClock()
persistenceFaults()
incognitoStaysOffDisk()
+ pinnedURL()
print("Store: \(checks) checks passed")
}
@@ -240,6 +241,60 @@ enum StoreTests {
expect(store.integrityProblems().isEmpty, "and the sidebar stays sound")
}
+ /// Arc's Edit Pinned Page ▸ Edit… (#54, PR #55 by Anoninz): a new pinned URL keeps the item's
+ /// name, icon, colour and place, and survives a relaunch.
+ @MainActor
+ private static func pinnedURL() {
+ let store = AppComposition(clock: ManualScheduler()).store
+ let folder = store.createFolder(named: "Links", in: store.focusedSpace.pinnedContainerID)
+ let pinned = store.createTab(url: "https://example.com/old", title: "Old page", pinned: true, select: false, parent: folder.id)
+ store.rename(pinned.id, to: "My link")
+ store.setCustomIcon("custom-test", for: pinned.id)
+ store.setTileColor("#123456", for: [pinned.id])
+ let before = store.item(pinned.id)!
+ let order = store.children(of: folder.id).map(\.id)
+ expect(store.setPinnedURL(pinned.id, to: "https://example.org/new?q=1#section"), "a pinned tab takes a new pinned URL")
+ let after = store.item(pinned.id)!
+ expect(after.tab?.savedURL == "https://example.org/new?q=1#section" && after.tab?.url == after.tab?.savedURL,
+ "a tab on its pinned page goes to the new one")
+ expect(after.tab?.savedTitle == "" && after.tab?.faviconKey == "example.org", "and drops the old page's title and icon")
+ expect(after.title == before.title && after.parentID == before.parentID && after.tab?.customIconKey == before.tab?.customIconKey
+ && after.tab?.tileColor == before.tab?.tileColor && store.children(of: folder.id).map(\.id) == order,
+ "its name, icon, colour and place stay")
+
+ store.updateTab(pinned.id, url: "https://example.org/elsewhere", title: "Elsewhere")
+ expect(store.setPinnedURL(pinned.id, to: "https://example.org/newer"), "a tab navigated away takes one too")
+ expect(store.item(pinned.id)?.tab?.url == "https://example.org/elsewhere" && store.item(pinned.id)?.tab?.savedTitle == "Elsewhere",
+ "and keeps the page it is on")
+ expect(store.resetPinnedTab(pinned.id) == "https://example.org/newer", "Back to Pinned Page goes to the new URL")
+ store.updateTab(pinned.id, url: "https://example.org/current")
+ store.setPinnedHomeToCurrent(pinned.id)
+ expect(store.item(pinned.id)?.tab?.savedURL == "https://example.org/current", "Replace Pinned URL with Current still works")
+
+ let favorite = store.createTab(url: "https://example.com/favorite", select: false)
+ store.addToFavorites(favorite.id)
+ expect(store.setPinnedURL(favorite.id, to: "https://example.org/favorite") && store.isFavorite(favorite.id),
+ "a favorite takes a new pinned URL and stays a favorite")
+ let today = store.createTab(url: "https://example.com/today", select: false)
+ expect(!store.setPinnedURL(today.id, to: "https://example.org/") && store.item(today.id)?.tab?.url == "https://example.com/today",
+ "a Today tab has no pinned URL to edit")
+ expect(!store.setPinnedURL(folder.id, to: "https://example.org/") && !store.setPinnedURL(UUID(), to: "https://example.org/"),
+ "nor has a folder or a missing item")
+ let live = store.createTab(url: "https://github.com/example/repo/pull/1", pinned: true, select: false)
+ if var t = store.item(live.id)?.tab, var it = store.item(live.id) {
+ t.liveItemURL = t.url
+ it.data = .tab(t)
+ store.items[live.id] = it
+ }
+ expect(!store.setPinnedURL(live.id, to: "https://example.org/"), "nor has a live folder's entry")
+
+ store.saveAll()
+ let restored = AppComposition(clock: ManualScheduler()).store
+ expect([pinned.id, favorite.id].allSatisfy { restored.item($0)?.tab?.savedURL == store.item($0)?.tab?.savedURL },
+ "the pinned URLs read back after a relaunch")
+ expect(store.integrityProblems().isEmpty, "and the sidebar stays sound")
+ }
+
private static func expect(_ condition: @autoclosure () -> Bool, _ message: String) {
guard condition() else {
FileHandle.standardError.write(Data("FAIL: \(message)\n".utf8))