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.

Arc parity: "When opening Cra, restore windows from previous session"

Victor337d5f871dc7
diff --git a/Packages/CraCore/Sources/CraCore/SidebarModel.swift b/Packages/CraCore/Sources/CraCore/SidebarModel.swift
index 86d8a85..7a6b731 100644
--- a/Packages/CraCore/Sources/CraCore/SidebarModel.swift
+++ b/Packages/CraCore/Sources/CraCore/SidebarModel.swift
@@ -519,6 +519,8 @@ public struct AppSettings: Codable, Equatable {
public var mediaFolders: [MediaLibrary.Folder] = MediaLibrary.Folder.allCases
/// Arc's Settings ▸ Links ▸ "Archive Little Arcs after:".
public var littleWindowArchiveAfter: LittleWindowArchive = .sixHours
+ /// Arc's Settings ▸ Advanced "When opening Arc, restore windows from previous session", on by default.
+ public var restoreWindows: Bool = true
/// Arc's searchSuggestEnabled: the command bar asks the search engine for suggestions
/// as you type and fills its rows with them.
public var searchSuggestions: Bool = true
@@ -727,6 +729,7 @@ extension AppSettings {
mediaLibraryEnabled = try c.decodeIfPresent(Bool.self, forKey: .mediaLibraryEnabled) ?? false
mediaFolders = (try? c.decodeIfPresent([MediaLibrary.Folder].self, forKey: .mediaFolders)) ?? MediaLibrary.Folder.allCases
littleWindowArchiveAfter = (try? c.decodeIfPresent(LittleWindowArchive.self, forKey: .littleWindowArchiveAfter)) ?? .sixHours
+ restoreWindows = try c.decodeIfPresent(Bool.self, forKey: .restoreWindows) ?? true
searchSuggestions = try c.decodeIfPresent(Bool.self, forKey: .searchSuggestions) ?? true
showSpaceHeaderOnSingleSpace = try c.decodeIfPresent(Bool.self, forKey: .showSpaceHeaderOnSingleSpace) ?? true
sharedFavorites = try c.decodeIfPresent(Bool.self, forKey: .sharedFavorites) ?? false
diff --git a/Packages/CraCore/Tests/CraCoreTests/WebsiteAppearanceTests.swift b/Packages/CraCore/Tests/CraCoreTests/WebsiteAppearanceTests.swift
index 4c3c2c2..1c884ac 100644
--- a/Packages/CraCore/Tests/CraCoreTests/WebsiteAppearanceTests.swift
+++ b/Packages/CraCore/Tests/CraCoreTests/WebsiteAppearanceTests.swift
@@ -10,6 +10,7 @@ struct WebsiteAppearanceTests {
let s = try JSONDecoder().decode(AppSettings.self, from: Data(#"{"httpsOnly": true}"#.utf8))
#expect(s.websiteAppearance == .automatic)
#expect(s.soundEffects)
+ #expect(s.restoreWindows, "Arc restores windows unless told not to")
}
@Test func aChoiceSurvivesASave() throws {
diff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swift
index ebb43db..60c1bc4 100644
--- a/Sources/Cra/App/AppDelegate.swift
+++ b/Sources/Cra/App/AppDelegate.swift
@@ -72,6 +72,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
NotificationCenter.default.addObserver(forName: .craKeyBindingsChanged, object: nil, queue: .main) { [weak self] _ in
Task { @MainActor in self?.buildMenus() }
}
+ // Arc's "When opening Arc, restore windows from previous session", off: one window comes back.
+ if !store.settings.restoreWindows { store.keepOnlyActiveWindow() }
mainWindows = store.prefs.windows.map { MainWindowController(app: self, session: $0) }
followKeyWindow()
// First launch: the default browser step and the import are the onboarding and
@@ -984,6 +986,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
}
// browserWindows=<label>: each browser window's kind, space, tabs (URLs), open tab and frame (#219, #220).
if let label = dict["browserWindows"] {
+ CraLog.note("browser windows \(label): count=\(mainWindows.filter { $0.window?.isVisible == true }.count)")
for m in mainWindows {
let space = m.focusedSpace
let tabs = (store.tabs(under: space.pinnedContainerID) + store.tabs(under: space.todayContainerID)).compactMap { $0.tab?.url }
diff --git a/Sources/Cra/Services/SidebarStore.swift b/Sources/Cra/Services/SidebarStore.swift
index 553475f..f756d77 100644
--- a/Sources/Cra/Services/SidebarStore.swift
+++ b/Sources/Cra/Services/SidebarStore.swift
@@ -281,6 +281,16 @@ final class SidebarStore {
return w
}
+ /// Arc's "When opening Arc, restore windows from previous session" turned off: launch keeps
+ /// one window, the one in use last (a normal one when that was a Blank or incognito window).
+ func keepOnlyActiveWindow() {
+ let keep = prefs.windows.first { $0.id == activeWindowID && !isStandalone(window: $0.id) }
+ ?? prefs.windows.first { !isStandalone(window: $0.id) } ?? prefs.windows.first
+ guard let keep else { return }
+ for w in prefs.windows where w.id != keep.id { removeWindow(w.id) }
+ activeWindowID = keep.id
+ }
+
/// The last window is never removed: closing it only hides it. An incognito or Blank
/// Window's tabs go with it (not to the Library): Arc drops a Blank Window's sidebar.
func removeWindow(_ id: UUID) {
diff --git a/Sources/Cra/UI/Settings/AdvancedPane.swift b/Sources/Cra/UI/Settings/AdvancedPane.swift
index 3f15ec3..3a225dc 100644
--- a/Sources/Cra/UI/Settings/AdvancedPane.swift
+++ b/Sources/Cra/UI/Settings/AdvancedPane.swift
@@ -34,6 +34,8 @@ struct AdvancedPane: View {
}
SettingsFormRow(label: "When quitting Cra:") {
SettingsCheckbox(title: "Warn before quitting", isOn: $store.settings.warnBeforeQuitting)
+ // Arc: Settings ▸ Advanced "When opening Arc, restore windows from previous session".
+ SettingsCheckbox(title: "When opening Cra, restore windows from previous session", isOn: $store.settings.restoreWindows)
}
SettingsFormRow(label: "Import:") {
Button("Import from Another Browser…") { actions.importData() }
diff --git a/Tests/Scenarios/restore-windows-off.scenario b/Tests/Scenarios/restore-windows-off.scenario
new file mode 100644
index 0000000..11b73f4
--- /dev/null
+++ b/Tests/Scenarios/restore-windows-off.scenario
@@ -0,0 +1,14 @@
+# Arc's Settings ▸ Advanced "When opening Arc, restore windows from previous session" (Arc 1.172.1,
+# docs/arc-parity.md), turned off: after a relaunch only the window in use last comes back.
+budget rss=700 stalls50=10
+seed settings.json {"hasSeenImportPrompt": true, "toolbarDefaultMigrated": true, "showToolbar": false, "restoreWindows": false}
+cra://open?url=${PAGE}?n=one
+expect-log loaded 127\.0\.0\.1 \(HTTP 200\)
+cra://action/newWindow
+wait 2
+cra://debug?browserWindows=before
+expect-log browser windows before: count=2
+relaunch
+wait 4
+cra://debug?browserWindows=after
+expect-log browser windows after: count=1
diff --git a/Tests/StoreTests.swift b/Tests/StoreTests.swift
index 2cc1233..f93023d 100644
--- a/Tests/StoreTests.swift
+++ b/Tests/StoreTests.swift
@@ -61,6 +61,7 @@ enum StoreTests {
archiveTabsBelow()
allFoldersExpanded()
revealInSidebar()
+ oneWindowAtLaunch()
print("Store: \(checks) checks passed")
}
@@ -1629,6 +1630,22 @@ enum StoreTests {
expect(!store.isExpanded(elsewhere.id), "another space's folders stay as they were")
}
+ /// Arc's Settings ▸ Advanced "When opening Arc, restore windows from previous session", off:
+ /// launch keeps one window, the one in use last; a Blank Window's own space goes with it.
+ @MainActor
+ private static func oneWindowAtLaunch() {
+ let store = AppComposition(clock: ManualScheduler()).store
+ let sid = store.focusedSpace.id
+ let second = store.addWindow(spaceID: sid, frame: nil)
+ let blank = store.addBlankWindow(frame: nil)
+ let blankSpace = store.window(blank.id).focusedSpaceID!
+ store.activeWindowID = second.id
+ store.keepOnlyActiveWindow()
+ expect(store.prefs.windows.map(\.id) == [second.id], "only the window in use last stays")
+ expect(store.space(blankSpace) == nil, "the Blank Window's own space goes with it")
+ expect(store.integrityProblems().isEmpty, "and the sidebar stays sound")
+ }
+
/// Arc's Reveal Tab in Sidebar (⌃Space): the folders around the tab open, and a collapsed
/// pinned section opens when the tab is in it.
@MainActor
diff --git a/docs/arc-parity.md b/docs/arc-parity.md
index 1533ee1..6613352 100644
--- a/docs/arc-parity.md
+++ b/docs/arc-parity.md
@@ -31,7 +31,7 @@ or Arc-only service), per CONTRIBUTING.md.
| Sound effects | Settings ▸ Advanced "Play Arc sound effects" | done | Settings ▸ Advanced ▸ Play Cra sound effects gates the capture shutter. |
| Theme data for websites | Settings ▸ Advanced "Allow websites to get your theme data" | missing | Arc exposes the space's palette to pages. |
| Window dragging from the top of webpages | Settings ▸ Advanced | missing | |
-| Restore windows from previous session | Settings ▸ Advanced | partial | Cra has "Quit and Keep Windows" only. |
+| Restore windows from previous session | Settings ▸ Advanced | done | Settings ▸ Advanced; off keeps the window in use last. |
| Block Cookie Banners | Settings ▸ General | missing | Cra blocks ads and trackers only. |
| Archive Little Arcs after | Settings ▸ Links (6 hours default) | done | Settings ▸ Tabs ▸ Links; a Little Window left alone that long closes into the archive. |
| Previews (Gmail, Calendar on Favorites) | Settings ▸ General ▸ Previews Settings… | missing | Fetches through the browser session; nothing leaves the Mac. |
@@ -86,7 +86,7 @@ gains "New Profile".
| General | Previews Settings…, Block Cookie Banners |
| Profiles | "New documents" app (Arc's Notes/Easels); Privacy, Passwords, Credit Cards and Notifications done |
| Links | "Open Little Arc when clicking on links with ⌥⌘ held"; Archive Little Windows after done |
-| Advanced | Play sound effects, restore windows from previous session, window dragging from the top of webpages, Shared Quotes, websites get theme data, Enable Boosts |
+| Advanced | window dragging from the top of webpages, Shared Quotes (arc.net), websites get theme data, Enable Boosts (sound effects and restore windows done) |
| Icon | Cra has its own icon picker |
## 5. Animations and styling
@@ -116,6 +116,8 @@ in this sweep (Essential Shortcuts window, Library pages).
Your Data and Settings (Chromium's privacy, passwords, cards and notifications pages per profile).
- Sidebar tab menu: Add Split View on the open tab, Open in Split View on any other.
- View ▸ Cast… and Help ▸ Troubleshooting ▸ Open Task Manager, Chrome's own (ExecuteChromeCommand).
+- Sidebar tab menu: Change Icon… and Share ▸.
+- Settings ▸ Advanced ▸ "When opening Cra, restore windows from previous session".
## Left for later, and why