Skip to content

Commit

Permalink
Merge pull request #1 from lgarron/optional-unhide-on-screen-width-ov…
Browse files Browse the repository at this point in the history
…erriding-use-ice-bar

When showing items due to wide screen, always show inline and never hide.
  • Loading branch information
michyprima authored Nov 23, 2024
2 parents f1833a1 + bc7c50d commit 96e4480
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion Ice/MenuBar/MenuBarManagement/MenuBarSection.swift
Original file line number Diff line number Diff line change
@@ -127,6 +127,23 @@ final class MenuBarSection {
self.init(name: name, controlItem: controlItem, appState: appState)
}

func forceShowDueToWideScreen() -> Bool {
// TODO: deduplicate with `MenuBarAutoExpander`.
guard
let appState
else {
return false
}
let advancedSettingsManager = appState.settingsManager.advancedSettingsManager;
guard let mainScreen = NSScreen.main else {
return false
}

let mainScreenWidth = mainScreen.frame.width;
let setting = advancedSettingsManager.showHiddenSectionWhenWidthGreaterThan;
return mainScreenWidth >= setting;
}

/// Shows the section.
func show() {
guard
@@ -140,8 +157,9 @@ final class MenuBarSection {
// TODO: Can we use isEnabled for this check?
return
}
let useIceBarExceptOnWideScreen = useIceBar && !self.forceShowDueToWideScreen();
switch name {
case .visible where useIceBar, .hidden where useIceBar:
case .visible where useIceBarExceptOnWideScreen, .hidden where useIceBarExceptOnWideScreen:
Task {
if let screenForIceBar {
await iceBarPanel?.show(section: .hidden, on: screenForIceBar)
@@ -196,6 +214,9 @@ final class MenuBarSection {
else {
return
}
if self.forceShowDueToWideScreen() {
return;
}
iceBarPanel?.close()
switch name {
case _ where useIceBar:
2 changes: 1 addition & 1 deletion Ice/Settings/SettingsPanes/AdvancedSettingsPane.swift
Original file line number Diff line number Diff line change
@@ -147,6 +147,7 @@ struct AdvancedSettingsPane: View {
@ViewBuilder
private var activeScreenWidthToggle: some View {
Toggle("Automatically unhide when active screen width is higher than the value below", isOn: manager.bindings.showHiddenSectionWhenWidthGreaterThanEnabled)
.annotation("This will always show the items in the menu bar (ignoring the \"Use Ice Bar\" setting.")
}

@ViewBuilder
@@ -167,7 +168,6 @@ struct AdvancedSettingsPane: View {
maxSliderLabelWidth = max(maxSliderLabelWidth, frame.width)
}
}
.annotation("You may want to disable automatically rehide in General.")
}
}
}

0 comments on commit 96e4480

Please sign in to comment.