Skip to content

Commit

Permalink
Make SwiftLint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
michyprima committed Oct 21, 2024
1 parent 733f140 commit f1833a1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Ice/Main/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class AppState: ObservableObject {

/// Global cache for menu bar item images.
private(set) lazy var imageCache = MenuBarItemImageCache(appState: self)

/// Global observer for auto expanding the bar based on the screens width
private(set) lazy var autoExpander = MenuBarAutoExpander(appState: self)

Expand Down
42 changes: 21 additions & 21 deletions Ice/MenuBar/MenuBarManagement/MenuBarAutoExpander.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import Cocoa
import Combine

final class MenuBarAutoExpander : ObservableObject {
final class MenuBarAutoExpander: ObservableObject {
/// The shared app state.
private weak var appState: AppState?

/// Storage for internal observers.
private var cancellables = Set<AnyCancellable>()

Expand Down Expand Up @@ -39,26 +39,26 @@ final class MenuBarAutoExpander : ObservableObject {
.throttle(for: 10.0, scheduler: DispatchQueue.main, latest: false)
.sink {
let advancedSettingsManager = appState.settingsManager.advancedSettingsManager
if(advancedSettingsManager.showHiddenSectionWhenWidthGreaterThanEnabled) {

if advancedSettingsManager.showHiddenSectionWhenWidthGreaterThanEnabled {
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) {
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()
}
guard let mainScreen = NSScreen.main else {
return
}

guard let section = await appState.menuBarManager.section(withName: .hidden) else {
return
}

let mainScreenWidth = mainScreen.frame.width
let setting = await advancedSettingsManager.showHiddenSectionWhenWidthGreaterThan

if mainScreenWidth >= setting {
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()
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Ice/Settings/SettingsManagers/AdvancedSettingsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ final class AdvancedSettingsManager: ObservableObject {
/// A Boolean value that indicates whether to show all sections when
/// the user is dragging items in the menu bar.
@Published var showAllSectionsOnUserDrag = true

/// A Boolean value that indicates whether to show all sections when
/// the screen width is greater than showHiddenSectionWhenWidthGreaterThan
@Published var showHiddenSectionWhenWidthGreaterThanEnabled = false

/// The minimum screen size showAllSectionOnScreenSize reacts to
@Published var showHiddenSectionWhenWidthGreaterThan: CGFloat = 3000

Expand Down Expand Up @@ -119,14 +119,14 @@ final class AdvancedSettingsManager: ObservableObject {
Defaults.set(showAll, forKey: .showAllSectionsOnUserDrag)
}
.store(in: &c)

$showHiddenSectionWhenWidthGreaterThanEnabled
.receive(on: DispatchQueue.main)
.sink { showAll in
Defaults.set(showAll, forKey: .showHiddenSectionWhenWidthGreaterThanEnabled)
}
.store(in: &c)

$showHiddenSectionWhenWidthGreaterThan
.receive(on: DispatchQueue.main)
.sink { width in
Expand Down
6 changes: 3 additions & 3 deletions Ice/Settings/SettingsPanes/AdvancedSettingsPane.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct AdvancedSettingsPane: View {
LocalizedStringKey(formatted + " seconds")
}
}

private func formattedToPx(_ px: CGFloat) -> LocalizedStringKey {
let formatted = px.formatted()
return LocalizedStringKey(formatted + " px")
Expand Down Expand Up @@ -143,12 +143,12 @@ struct AdvancedSettingsPane: View {
private var showAllSectionsOnUserDrag: some View {
Toggle("Show all sections when Command + dragging menu bar items", isOn: manager.bindings.showAllSectionsOnUserDrag)
}

@ViewBuilder
private var activeScreenWidthToggle: some View {
Toggle("Automatically unhide when active screen width is higher than the value below", isOn: manager.bindings.showHiddenSectionWhenWidthGreaterThanEnabled)
}

@ViewBuilder
private var activeScreenWidthSlider: some View {
if manager.showHiddenSectionWhenWidthGreaterThanEnabled {
Expand Down

0 comments on commit f1833a1

Please sign in to comment.