-
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements autounhide when screen is wider than set width
- Loading branch information
1 parent
d89de0f
commit 733f140
Showing
5 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// MenuBarAutoExpander.swift | ||
// Ice | ||
// | ||
// Created by Michele Primavera on 21/10/24. | ||
// | ||
|
||
import Cocoa | ||
import Combine | ||
|
||
final class MenuBarAutoExpander : ObservableObject { | ||
/// The shared app state. | ||
private weak var appState: AppState? | ||
|
||
/// Storage for internal observers. | ||
private var cancellables = Set<AnyCancellable>() | ||
|
||
/// Creates a cache with the given app state. | ||
init(appState: AppState) { | ||
self.appState = appState | ||
} | ||
|
||
/// Sets up the cache. | ||
@MainActor | ||
func performSetup() { | ||
configureCancellables() | ||
} | ||
|
||
/// Configures the internal observers for the cache. | ||
@MainActor | ||
private func configureCancellables() { | ||
var c = Set<AnyCancellable>() | ||
|
||
if let appState { | ||
Publishers.Merge( | ||
NotificationCenter.default.publisher(for: NSApplication.didChangeScreenParametersNotification).mapToVoid(), | ||
Just(()) | ||
) | ||
.throttle(for: 10.0, scheduler: DispatchQueue.main, latest: false) | ||
.sink { | ||
let advancedSettingsManager = appState.settingsManager.advancedSettingsManager | ||
|
||
if(advancedSettingsManager.showHiddenSectionWhenWidthGreaterThanEnabled) { | ||
Check warning on line 43 in Ice/MenuBar/MenuBarManagement/MenuBarAutoExpander.swift GitHub Actions / swiftlint
|
||
Task.detached { | ||
let mainScreen = NSScreen.main | ||
if mainScreen != nil { | ||
let mainScreenWidth = mainScreen!.frame.width | ||
|
||
guard let section = await appState.menuBarManager.section(withName: .hidden) else { | ||
return | ||
} | ||
|
||
let setting = await advancedSettingsManager.showHiddenSectionWhenWidthGreaterThan | ||
|
||
if (mainScreenWidth >= setting) { | ||
Check warning on line 55 in Ice/MenuBar/MenuBarManagement/MenuBarAutoExpander.swift GitHub Actions / swiftlint
|
||
Logger.autoExpander.info("Showing hidden section because mainScreenWidth (\(mainScreenWidth)) >= showHiddenSectionWhenWidthGreaterThan (\(setting)") | ||
await section.show() | ||
} else { | ||
Logger.autoExpander.info("Hiding hidden section because mainScreenWidth (\(mainScreenWidth)) < showHiddenSectionWhenWidthGreaterThan (\(setting)") | ||
await section.hide() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
.store(in: &c) | ||
} | ||
|
||
cancellables = c | ||
} | ||
} | ||
|
||
// MARK: - Logger | ||
private extension Logger { | ||
static let autoExpander = Logger(category: "MenuBarAutoExpander") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters