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.

Keep Cra in the menu bar after ⌘Q (#231)

Victor96c0255f9273
diff --git a/Packages/CraCore/Sources/CraCore/MenuBarMode.swift b/Packages/CraCore/Sources/CraCore/MenuBarMode.swift
new file mode 100644
index 0000000..dba55d2
--- /dev/null
+++ b/Packages/CraCore/Sources/CraCore/MenuBarMode.swift
@@ -0,0 +1,66 @@
+import Foundation
+
+/// Settings ▸ Advanced ▸ "Keep Cra in the menu bar" (GitHub #231, not in Arc, where ⌘Q quits):
+/// ⌘Q closes the pages and windows as a quit would, but Cra keeps running behind a menu bar item,
+/// so ⌥⌘N from any app opens a Little Window without waiting for Chromium to start.
+public enum MenuBarMode {
+ /// Where a quit came from.
+ public enum QuitSource: Equatable, Sendable {
+ /// Cra ▸ Quit Cra, or ⌘Q.
+ case appMenu
+ /// Quit Cra in the menu bar item's menu: the way out of the menu bar.
+ case menuBarItem
+ /// A quit Apple Event: logout, restart, shutdown, the Dock's Quit, a script, a newer copy
+ /// of Cra replacing this one.
+ case appleEvent
+ /// Restarting into an update or another page engine.
+ case relaunch
+ }
+
+ public enum QuitOutcome: Equatable, Sendable {
+ case quit
+ case stayInMenuBar
+ }
+
+ /// Only Cra's own Quit stays in the menu bar: macOS logging out, a script or the updater
+ /// must get a real quit, and the menu bar item's Quit is how the user asks for one.
+ public static func outcome(enabled: Bool, source: QuitSource) -> QuitOutcome {
+ enabled && source == .appMenu ? .stayInMenuBar : .quit
+ }
+
+ /// Cra has a Dock icon unless it was put in the menu bar and nothing of it is on screen. A
+ /// Little Window from ⌥⌘N or Settings from the menu bar item bring the icon back while open,
+ /// as any app's window would; closing the last one puts Cra back in the menu bar.
+ public static func showsInDock(inMenuBar: Bool, windowsOpen: Bool) -> Bool {
+ !inMenuBar || windowsOpen
+ }
+
+ public enum WindowKind: Equatable, Sendable { case normal, blank, incognito }
+
+ public struct Window: Equatable, Sendable {
+ public var id: UUID
+ public var kind: WindowKind
+ public init(id: UUID, kind: WindowKind) {
+ self.id = id
+ self.kind = kind
+ }
+ }
+
+ /// What ⌘Q does to the browser windows when Cra stays: the ones a relaunch would bring back are
+ /// put away (`keep`, opened again together), the rest close (`close`). Incognito windows always
+ /// close, ending their session as a quit does. With "restore windows from previous session"
+ /// off, only the window in use last is kept, or a normal one when that was a Blank Window
+ /// (SidebarStore.keepOnlyActiveWindow).
+ public static func windowsOnQuit(_ windows: [Window], active: UUID?, restoreWindows: Bool) -> (keep: [UUID], close: [UUID]) {
+ let kept: [Window]
+ if restoreWindows {
+ kept = windows.filter { $0.kind != .incognito }
+ } else {
+ let one = windows.first { $0.id == active && $0.kind == .normal } ?? windows.first { $0.kind == .normal }
+ ?? windows.first { $0.kind != .incognito }
+ kept = one.map { [$0] } ?? []
+ }
+ let keep = kept.map(\.id)
+ return (keep, windows.map(\.id).filter { !keep.contains($0) })
+ }
+}
diff --git a/Packages/CraCore/Sources/CraCore/SidebarModel.swift b/Packages/CraCore/Sources/CraCore/SidebarModel.swift
index acb88d9..cb85050 100644
--- a/Packages/CraCore/Sources/CraCore/SidebarModel.swift
+++ b/Packages/CraCore/Sources/CraCore/SidebarModel.swift
@@ -497,6 +497,9 @@ public struct AppSettings: Codable, Equatable {
public var hapticFeedbackOnReorder: Bool = true
/// Dia's Advanced ▸ "Warn before quitting" (shouldWarnBeforeQuitting, off by default).
public var warnBeforeQuitting: Bool = false
+ /// GitHub #231, not in Arc (Arc quits on ⌘Q): ⌘Q puts the pages away and Cra stays in the menu
+ /// bar, so ⌥⌘N opens a Little Window without a launch. Off, ⌘Q quits as in Arc (MenuBarMode).
+ public var keepInMenuBar: Bool = false
/// Dia's Tabs ▸ "Clean up tabs I haven't used in:" checkbox; `autoArchive` keeps the
/// threshold while this is off.
public var autoArchiveEnabled: Bool = true
@@ -727,6 +730,7 @@ extension AppSettings {
folderPreviews = try c.decodeIfPresent(Bool.self, forKey: .folderPreviews) ?? true
hapticFeedbackOnReorder = try c.decodeIfPresent(Bool.self, forKey: .hapticFeedbackOnReorder) ?? true
warnBeforeQuitting = try c.decodeIfPresent(Bool.self, forKey: .warnBeforeQuitting) ?? false
+ keepInMenuBar = try c.decodeIfPresent(Bool.self, forKey: .keepInMenuBar) ?? false
autoArchiveEnabled = try c.decodeIfPresent(Bool.self, forKey: .autoArchiveEnabled) ?? true
tabSleepTimerEnabled = try c.decodeIfPresent(Bool.self, forKey: .tabSleepTimerEnabled) ?? true
tabSleepAfter = (try? c.decodeIfPresent(TabSleepThreshold.self, forKey: .tabSleepAfter)) ?? .fourHours
diff --git a/Packages/CraCore/Tests/CraCoreTests/MenuBarModeTests.swift b/Packages/CraCore/Tests/CraCoreTests/MenuBarModeTests.swift
new file mode 100644
index 0000000..a7bdc94
--- /dev/null
+++ b/Packages/CraCore/Tests/CraCoreTests/MenuBarModeTests.swift
@@ -0,0 +1,54 @@
+import CraCore
+import Foundation
+import Testing
+
+/// "Keep Cra in the menu bar" (GitHub #231): ⌘Q stays in the menu bar; everything else quits.
+struct MenuBarModeTests {
+ @Test(.bug("https://github.com/VictorKildahl/cra/issues/231")) func onlyCrasOwnQuitStaysInTheMenuBar() {
+ #expect(MenuBarMode.outcome(enabled: true, source: .appMenu) == .stayInMenuBar)
+ for source: MenuBarMode.QuitSource in [.menuBarItem, .appleEvent, .relaunch] {
+ #expect(MenuBarMode.outcome(enabled: true, source: source) == .quit)
+ }
+ }
+
+ /// Off (the default), ⌘Q quits as in Arc.
+ @Test(.bug("https://github.com/VictorKildahl/cra/issues/231")) func offEveryQuitQuits() {
+ for source: MenuBarMode.QuitSource in [.appMenu, .menuBarItem, .appleEvent, .relaunch] {
+ #expect(MenuBarMode.outcome(enabled: false, source: source) == .quit)
+ }
+ #expect(AppSettings().keepInMenuBar == false)
+ let old = try! JSONDecoder().decode(AppSettings.self, from: Data(#"{"warnBeforeQuitting": true}"#.utf8))
+ #expect(old.keepInMenuBar == false)
+ }
+
+ @Test(.bug("https://github.com/VictorKildahl/cra/issues/231")) func theDockIconGoesOnlyWhileNothingIsOpen() {
+ #expect(MenuBarMode.showsInDock(inMenuBar: false, windowsOpen: false))
+ #expect(MenuBarMode.showsInDock(inMenuBar: false, windowsOpen: true))
+ #expect(MenuBarMode.showsInDock(inMenuBar: true, windowsOpen: true))
+ #expect(!MenuBarMode.showsInDock(inMenuBar: true, windowsOpen: false))
+ }
+
+ /// The windows a relaunch would bring back are put away; incognito ones close like on a quit.
+ @Test(.bug("https://github.com/VictorKildahl/cra/issues/231")) func incognitoWindowsCloseTheRestArePutAway() {
+ let normal = UUID(), blank = UUID(), incognito = UUID(), second = UUID()
+ let windows: [MenuBarMode.Window] = [.init(id: normal, kind: .normal), .init(id: incognito, kind: .incognito),
+ .init(id: blank, kind: .blank), .init(id: second, kind: .normal)]
+ let all = MenuBarMode.windowsOnQuit(windows, active: incognito, restoreWindows: true)
+ #expect(all.keep == [normal, blank, second])
+ #expect(all.close == [incognito])
+ }
+
+ /// "Restore windows from previous session" off: one window comes back, as after a relaunch.
+ @Test(.bug("https://github.com/VictorKildahl/cra/issues/231")) func withoutRestoringWindowsOnlyTheOneInUseIsKept() {
+ let normal = UUID(), blank = UUID(), incognito = UUID(), second = UUID()
+ let windows: [MenuBarMode.Window] = [.init(id: normal, kind: .normal), .init(id: incognito, kind: .incognito),
+ .init(id: blank, kind: .blank), .init(id: second, kind: .normal)]
+ let active = MenuBarMode.windowsOnQuit(windows, active: second, restoreWindows: false)
+ #expect(active.keep == [second])
+ #expect(active.close == [normal, incognito, blank])
+ // A Blank or incognito window in use: a normal one is kept instead.
+ #expect(MenuBarMode.windowsOnQuit(windows, active: blank, restoreWindows: false).keep == [normal])
+ #expect(MenuBarMode.windowsOnQuit(windows, active: incognito, restoreWindows: false).keep == [normal])
+ #expect(MenuBarMode.windowsOnQuit([.init(id: blank, kind: .blank)], active: blank, restoreWindows: false).keep == [blank])
+ }
+}
diff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swift
index a7e3a8e..fa52775 100644
--- a/Sources/Cra/App/AppDelegate.swift
+++ b/Sources/Cra/App/AppDelegate.swift
@@ -55,6 +55,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
CraCEFRuntime.setDocumentStartScript(PageScript.mainWorld, isolatedScript: PageScript.isolatedWorld, world: PageScript.world)
startContentBlocking()
observeGlobalShortcut()
+ observeMenuBarMode()
SoftwareUpdater.shared.start(app: self)
buildMenus()
store.hasPage = { [unowned self] in self.runtime(for: $0).map { !$0.discarded } ?? false }
@@ -303,12 +304,17 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
}
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
+ leaveMenuBarForWindow()
if main?.raiseImport() == true { return true }
main?.showWindow(nil)
return true
}
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
+ if MenuBarMode.outcome(enabled: store.settings.keepInMenuBar, source: quitSource()) == .stayInMenuBar {
+ stayInMenuBar()
+ return .terminateCancel
+ }
// Dia: Advanced ▸ "Warn before quitting". Engine relaunches skip it.
if store.settings.warnBeforeQuitting, !isRelaunching, !confirmQuit() { return .terminateCancel }
// Little Windows are not in the sidebar; keep their pages in the Library.
@@ -378,6 +384,101 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
NSApp.activate(ignoringOtherApps: true)
}
+ // MARK: Menu bar (#231)
+
+ /// Settings ▸ Advanced ▸ "Keep Cra in the menu bar": the item is there while the setting is
+ /// on. A test copy in the background leaves the menu bar to the installed Cra.
+ private func observeMenuBarMode() {
+ observeChanges(of: { [store] in store.settings.keepInMenuBar }) { [weak self] on in
+ guard let self else { return }
+ if on, menuBarItem == nil, !HitchMonitor.background {
+ menuBarItem = MenuBarItem { [weak self] menu in self?.buildMenuBarItemMenu(menu) }
+ } else if !on {
+ menuBarItem?.remove()
+ menuBarItem = nil
+ // Turned off from Settings opened in the menu bar: the windows come back, or
+ // nothing of Cra would be left to click.
+ if inMenuBar { main.showWindow(nil) }
+ }
+ }
+ }
+
+ private func buildMenuBarItemMenu(_ menu: NSMenu) {
+ for id in ["newWindow", "newIncognitoWindow", "newLittleWindow"] { menu.addItem(item(id)) }
+ menu.addItem(.separator())
+ menu.addItem(item("settings"))
+ menu.addItem(.separator())
+ menu.addItem(withTitle: "Quit Cra", action: #selector(quitFromMenuBar), keyEquivalent: "").target = self
+ }
+
+ /// The menu bar item's Quit, and `cra://debug?quit=1`: Cra quits for real.
+ @objc func quitFromMenuBar() {
+ quittingFromMenuBar = true
+ NSApp.terminate(nil)
+ }
+
+ private var menuBarItem: MenuBarItem?
+ private var quittingFromMenuBar = false
+ /// ⌘Q put Cra in the menu bar, and no browser window has been opened since.
+ private(set) var inMenuBar = false
+
+ private func quitSource() -> MenuBarMode.QuitSource {
+ if isRelaunching { return .relaunch }
+ if quittingFromMenuBar { return .menuBarItem }
+ if let e = NSAppleEventManager.shared().currentAppleEvent,
+ e.eventClass == AEEventClass(kCoreEventClass), e.eventID == AEEventID(kAEQuitApplication) { return .appleEvent }
+ return .appMenu
+ }
+
+ /// ⌘Q with the setting on: what a quit would close closes (Little Windows into the Library,
+ /// incognito windows with their session, every page), the browser windows a relaunch would
+ /// bring back are put away, and Cra leaves the Dock. Chromium keeps running, so ⌥⌘N and the
+ /// menu bar item open a window at once.
+ private func stayInMenuBar() {
+ CraLog.note("menu bar: quit keeps Cra in the menu bar")
+ closeLittleWindows()
+ settingsWindow?.close()
+ let plan = MenuBarMode.windowsOnQuit(mainWindows.map { .init(id: $0.windowID, kind: $0.isIncognito ? .incognito : $0.isBlank ? .blank : .normal) },
+ active: store.activeWindowID, restoreWindows: store.settings.restoreWindows)
+ for c in mainWindows where plan.close.contains(c.windowID) { c.window?.close() }
+ for c in mainWindows {
+ c.saveFrameNow()
+ c.putAway()
+ }
+ store.saveAll()
+ inMenuBar = true
+ settleDockIcon()
+ }
+
+ /// A browser window is about to show: the ones put away come back with it, as after a launch.
+ func browserWindowWillShow(_ c: MainWindowController) {
+ guard inMenuBar else { return c.bringBack() }
+ inMenuBar = false
+ leaveMenuBarForWindow()
+ CraLog.note("menu bar: browser windows back")
+ for w in mainWindows {
+ w.bringBack()
+ if w !== c { w.window?.orderFront(nil) }
+ }
+ }
+
+ /// Any window of Cra's about to show: the Dock icon and the app menu come back first, or the
+ /// window would come up in an app macOS treats as menu-bar-only.
+ private func leaveMenuBarForWindow() {
+ guard NSApp.activationPolicy() != .regular else { return }
+ NSApp.setActivationPolicy(.regular)
+ if NSApp.isHidden { NSApp.unhide(nil) }
+ }
+
+ /// In the menu bar with nothing open: no Dock icon, and the app in front before ⌘Q gets the keyboard.
+ private func settleDockIcon() {
+ let open = littleWindows.contains { $0.window?.isVisible == true } || settingsWindow?.isVisible == true
+ || mainWindows.contains { $0.window?.isVisible == true }
+ guard !MenuBarMode.showsInDock(inMenuBar: inMenuBar, windowsOpen: open), NSApp.activationPolicy() == .regular else { return }
+ NSApp.hide(nil)
+ NSApp.setActivationPolicy(.accessory)
+ }
+
// MARK: Browser windows
/// Menu commands and new tabs follow the browser window the user is in. Its key
@@ -587,6 +688,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
/// Creates a little window without showing it (`url` nil = popup host).
func makeLittleWindow(url: String?, opener: CraBrowser? = nil, space: UUID? = nil) -> LittleWindowController {
+ leaveMenuBarForWindow()
let w = LittleWindowController(app: self, url: url, opener: opener, space: space)
littleWindows.append(w)
return w
@@ -611,6 +713,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
func removeLittleWindow(_ w: LittleWindowController) {
littleWindows.removeAll { $0 === w }
+ if inMenuBar { DispatchQueue.main.async { [weak self] in self?.settleDockIcon() } }
if let parent = w.peekParent, !littleWindows.contains(where: { $0.peekParent === parent }) { parent.sidebarUI.peekBadge = nil }
}
@@ -847,7 +950,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
return
}
if dict["relaunch"] != nil { relaunch(); return }
- if dict["quit"] != nil { NSApp.terminate(nil); return }
+ // quit=1 quits for real, as the menu bar item's Quit; quit=menu is ⌘Q (#231).
+ if let q = dict["quit"] { q == "menu" ? NSApp.terminate(nil) : quitFromMenuBar(); return }
if let t = dict["selectTab"].flatMap(UUID.init(uuidString:)) { store.selectTab(t, window: main.windowID); return }
// Tab freezing with a short threshold (seconds) from now on, so it can be tried without
// waiting: the minute's pass would otherwise take the votes back.
@@ -1494,7 +1598,15 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {
let c = SettingsWindowController(store: store, bindings: bindings, actions: actions)
settingsController = c
settingsWindow = c.window
+ // Settings opened from the menu bar item: closing it puts Cra back in the menu bar.
+ NotificationCenter.default.addObserver(forName: NSWindow.willCloseNotification, object: c.window, queue: .main) { [weak self] _ in
+ MainActor.assumeIsolated {
+ guard self?.inMenuBar == true else { return }
+ DispatchQueue.main.async { self?.settleDockIcon() }
+ }
+ }
}
+ leaveMenuBarForWindow()
settingsController?.didShow()
settingsWindow?.makeKeyAndOrderFront(nil)
}
diff --git a/Sources/Cra/App/MenuBarItem.swift b/Sources/Cra/App/MenuBarItem.swift
new file mode 100644
index 0000000..f02585b
--- /dev/null
+++ b/Sources/Cra/App/MenuBarItem.swift
@@ -0,0 +1,48 @@
+import AppKit
+
+/// The menu bar item of Settings ▸ Advanced ▸ "Keep Cra in the menu bar" (GitHub #231). Arc has
+/// none, so it is a plain macOS status item: Cra's C mark as a template image, and a menu that
+/// AppDelegate builds each time it opens (the shortcuts follow Settings ▸ Shortcuts).
+@MainActor
+final class MenuBarItem: NSObject, NSMenuDelegate {
+ private let item: NSStatusItem
+ private let build: (NSMenu) -> Void
+
+ init(build: @escaping (NSMenu) -> Void) {
+ self.build = build
+ item = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
+ super.init()
+ item.button?.image = Self.icon
+ item.button?.setAccessibilityLabel("Cra")
+ item.button?.toolTip = "Cra"
+ let menu = NSMenu()
+ menu.delegate = self
+ item.menu = menu
+ }
+
+ func remove() { NSStatusBar.system.removeStatusItem(item) }
+
+ func menuNeedsUpdate(_ menu: NSMenu) {
+ menu.removeAllItems()
+ build(menu)
+ }
+
+ /// resources/brand/cra-mark-mono: one arc of radius 18 and width 19 on a 64-point square,
+ /// open to the right between ±52°, with round ends. 16 pt, like the system's own items.
+ static let icon: NSImage = {
+ let side: CGFloat = 16
+ let image = NSImage(size: NSSize(width: side, height: side), flipped: false) { rect in
+ let scale = rect.height / 55 // the ink is 55 tall and 48 wide, its middle 3.5 left of the arc's centre
+ let path = NSBezierPath()
+ path.appendArc(withCenter: NSPoint(x: rect.midX + 3.5 * scale, y: rect.midY), radius: 18 * scale,
+ startAngle: 52, endAngle: 308)
+ path.lineWidth = 19 * scale
+ path.lineCapStyle = .round
+ NSColor.black.setStroke()
+ path.stroke()
+ return true
+ }
+ image.isTemplate = true
+ return image
+ }()
+}
diff --git a/Sources/Cra/UI/Settings/AdvancedPane.swift b/Sources/Cra/UI/Settings/AdvancedPane.swift
index 263d925..6bbfe95 100644
--- a/Sources/Cra/UI/Settings/AdvancedPane.swift
+++ b/Sources/Cra/UI/Settings/AdvancedPane.swift
@@ -40,6 +40,12 @@ struct AdvancedPane: View {
}
SettingsFormRow(label: "When quitting Cra:") {
SettingsCheckbox(title: "Warn before quitting", isOn: $store.settings.warnBeforeQuitting)
+ .disabled(store.settings.keepInMenuBar)
+ // GitHub #231, not in Arc: ⌘Q puts Cra in the menu bar instead of quitting.
+ SettingsCheckbox(title: "Keep Cra in the menu bar", isOn: $store.settings.keepInMenuBar)
+ Text("⌘Q closes Cra’s windows and pages but leaves it running in the menu bar, so \(KeyBindingRegistry.shared.action("newLittleWindow")?.primary?.display ?? "⌥⌘N") opens a Little Window at once. Quit it from the menu bar.")
+ .font(.system(size: 11)).foregroundStyle(.secondary)
+ .fixedSize(horizontal: false, vertical: true)
// 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)
}
diff --git a/Sources/Cra/UI/Windows/MainWindowController.swift b/Sources/Cra/UI/Windows/MainWindowController.swift
index f9090d5..8826704 100644
--- a/Sources/Cra/UI/Windows/MainWindowController.swift
+++ b/Sources/Cra/UI/Windows/MainWindowController.swift
@@ -418,7 +418,7 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
}
func refresh() {
- guard !isTornDown else { return }
+ guard !isTornDown, !isPutAway else { return }
let space = focusedSpace
let palette = space.theme.palette
// Its extensions belong to the space's profile.
@@ -3508,6 +3508,50 @@ final class MainWindowController: NSWindowController, NSWindowDelegate, BrowserM
app.mainWindowWillClose(self)
}
+ override func showWindow(_ sender: Any?) {
+ app.browserWindowWillShow(self)
+ super.showWindow(sender)
+ }
+
+ /// ⌘Q put Cra in the menu bar (#231): the window is out of sight and its pages are closed, as
+ /// on a quit; the tabs stay. No page opens until `bringBack`.
+ private(set) var isPutAway = false
+
+ func putAway() {
+ guard !isPutAway else { return }
+ isPutAway = true
+ dismissTransientUI()
+ sidePanel.hide()
+ for p in peeks { p.closeWindow() }
+ browsers.closeAll()
+ guard let window else { return }
+ // Out of full screen first: a full-screen window ordered out leaves its Space behind.
+ if window.styleMask.contains(.fullScreen) {
+ fullScreenExit = NotificationCenter.default.addObserver(forName: NSWindow.didExitFullScreenNotification, object: window,
+ queue: .main) { [weak self] _ in
+ MainActor.assumeIsolated { self?.orderOutPutAway() }
+ }
+ window.toggleFullScreen(nil)
+ } else {
+ window.orderOut(nil)
+ }
+ }
+
+ private var fullScreenExit: NSObjectProtocol?
+
+ private func orderOutPutAway() {
+ if let fullScreenExit { NotificationCenter.default.removeObserver(fullScreenExit) }
+ fullScreenExit = nil
+ if isPutAway { window?.orderOut(nil) }
+ }
+
+ /// Back from the menu bar: the open tab's page loads again, as after a launch.
+ func bringBack() {
+ guard isPutAway else { return }
+ isPutAway = false
+ refresh()
+ }
+
/// The window closed while others stay open: its pages close (the tabs stay in
/// the sidebar) and it lets go of everything that would keep it alive.
func tearDown() {
diff --git a/Tests/Scenarios/menu-bar-mode.scenario b/Tests/Scenarios/menu-bar-mode.scenario
new file mode 100644
index 0000000..0ad472f
--- /dev/null
+++ b/Tests/Scenarios/menu-bar-mode.scenario
@@ -0,0 +1,27 @@
+# Settings ▸ Advanced ▸ "Keep Cra in the menu bar" (GitHub #231): ⌘Q closes the incognito window and
+# every page and puts the browser window away, and Cra keeps running. New Window brings the window
+# back with its tab, whose page loads again; the incognito window stays closed. The scenario's own
+# quit at the end (cra://debug?quit=1, the menu bar item's Quit) still quits.
+# promise: #231
+budget rss=700 stalls50=10
+seed settings.json {"hasSeenImportPrompt": true, "toolbarDefaultMigrated": true, "showToolbar": false, "keepInMenuBar": true}
+cra://open?url=${PAGE}?n=kept
+expect-log loaded 127\.0\.0\.1 \(HTTP 200\)
+cra://action/newIncognitoWindow
+wait 2
+cra://debug?browserWindows=before
+expect-log browser windows before: count=2
+cra://debug?quit=menu
+wait 2
+expect-log menu bar: quit keeps Cra in the menu bar
+cra://debug?browserWindows=away
+expect-log browser windows away: count=0
+expect-log Cra browser windows away: kind=normal .*open=\S*n=kept page=0
+reject-log Cra browser windows away: kind=incognito
+cra://action/newWindow
+wait 3
+expect-log menu bar: browser windows back
+cra://debug?browserWindows=back
+expect-log browser windows back: count=1
+expect-log Cra browser windows back: kind=normal .*open=\S*n=kept page=1
+reject-log Cra browser windows back: kind=incognito
diff --git a/Tests/promises.lock b/Tests/promises.lock
index 80f6be5..ee7c24b 100644
--- a/Tests/promises.lock
+++ b/Tests/promises.lock
@@ -355,6 +355,12 @@
#226 Packages/CraCore/Tests/CraCoreTests/ToolbarCompositionTests.swift::theURLFieldHasTheSlidersWithoutExtensions a7173c578717
#226 Tests/Scenarios/site-controls-no-extensions.scenario c1c5b5365539
#227 Tests/Scenarios/quit-during-web-store-install.scenario a3e3b0c8eb2b
+#231 Packages/CraCore/Tests/CraCoreTests/MenuBarModeTests.swift::incognitoWindowsCloseTheRestArePutAway 017bb7d06672
+#231 Packages/CraCore/Tests/CraCoreTests/MenuBarModeTests.swift::offEveryQuitQuits f494762d7992
+#231 Packages/CraCore/Tests/CraCoreTests/MenuBarModeTests.swift::onlyCrasOwnQuitStaysInTheMenuBar 93aebb57b7ca
+#231 Packages/CraCore/Tests/CraCoreTests/MenuBarModeTests.swift::theDockIconGoesOnlyWhileNothingIsOpen ec75d372a707
+#231 Packages/CraCore/Tests/CraCoreTests/MenuBarModeTests.swift::withoutRestoringWindowsOnlyTheOneInUseIsKept 0f137ea8ee8d
+#231 Tests/Scenarios/menu-bar-mode.scenario 13a0ab0aae03
#233 Packages/CraCore/Tests/CraCoreTests/MouseButtonSpaceSwitchTests.swift::backGoesToThePreviousSpaceAndForwardToTheNext 10b4dc8a4a65
#233 Packages/CraCore/Tests/CraCoreTests/MouseButtonSpaceSwitchTests.swift::otherButtonsDoNotSwitch 07b725a8e6f5
#233 Tests/Scenarios/mouse-buttons-switch-spaces.scenario 79148e8b3ebb
diff --git a/docs/release-checklist.md b/docs/release-checklist.md
index a7f1e4d..5cd0676 100644
--- a/docs/release-checklist.md
+++ b/docs/release-checklist.md
@@ -81,6 +81,11 @@ built release app with a test profile. Note anything that fails in the release's
the window closes it.
- **#186:** send a link from a full-screen app. The Little Window opens centred on that Space
with no switch to the desktop, and a video in it can still go full screen.
+- **#231:** with Keep Cra in the menu bar on, the C shows in the menu bar in light and dark.
+ ⌘Q takes the windows and the Dock icon away, and focus goes to the app behind. A full-screen
+ window leaves its Space first. ⌥⌘N from another app opens a Little Window at once, with the
+ Dock icon. Closing it takes the icon away again. New Window in the item's menu brings the
+ windows back, and Quit Cra there quits.
- **#172:** with a space on its own profile, a Little Window from that space and a Peek from its
tab see that profile's cookies. The chip names the profile; switching it reloads the page in
the other profile.