Skip to content

Commit

Permalink
Add custom delay for show on hover
Browse files Browse the repository at this point in the history
Closes #229
  • Loading branch information
jordanbaird committed Jul 23, 2024
1 parent b1f5f62 commit ac33716
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Ice/Events/EventManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,15 @@ extension EventManager {
return
}

let delay = appState.settingsManager.advancedSettingsManager.showOnHoverDelay

Task {
do {
if hiddenSection.isHidden {
guard self.isMouseInsideEmptyMenuBarSpace else {
return
}
try await Task.sleep(for: .seconds(0.2))
try await Task.sleep(for: .seconds(delay))
// make sure the mouse is still inside
guard self.isMouseInsideEmptyMenuBarSpace else {
return
Expand All @@ -367,7 +369,7 @@ extension EventManager {
else {
return
}
try await Task.sleep(for: .seconds(0.2))
try await Task.sleep(for: .seconds(delay))
// make sure the mouse is still outside
guard
!self.isMouseInsideMenuBar,
Expand Down
11 changes: 11 additions & 0 deletions Ice/Settings/SettingsManagers/AdvancedSettingsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ final class AdvancedSettingsManager: ObservableObject {
/// can be toggled by holding down the Option key.
@Published var canToggleAlwaysHiddenSection = true

/// The delay before showing on hover.
@Published var showOnHoverDelay: TimeInterval = 0.2

private var cancellables = Set<AnyCancellable>()

private(set) weak var appState: AppState?
Expand All @@ -46,6 +49,7 @@ final class AdvancedSettingsManager: ObservableObject {
Defaults.ifPresent(key: .showSectionDividers, assign: &showSectionDividers)
Defaults.ifPresent(key: .enableAlwaysHiddenSection, assign: &enableAlwaysHiddenSection)
Defaults.ifPresent(key: .canToggleAlwaysHiddenSection, assign: &canToggleAlwaysHiddenSection)
Defaults.ifPresent(key: .showOnHoverDelay, assign: &showOnHoverDelay)
}

private func configureCancellables() {
Expand Down Expand Up @@ -79,6 +83,13 @@ final class AdvancedSettingsManager: ObservableObject {
}
.store(in: &c)

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

cancellables = c
}
}
Expand Down
33 changes: 33 additions & 0 deletions Ice/Settings/SettingsPanes/AdvancedSettingsPane.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Ice
//

import CompactSlider
import SwiftUI

struct AdvancedSettingsPane: View {
Expand All @@ -16,6 +17,15 @@ struct AdvancedSettingsPane: View {
appState.settingsManager.advancedSettingsManager
}

private var showOnHoverDelay: LocalizedStringKey {
let formatted = manager.showOnHoverDelay.formatted()
return if manager.showOnHoverDelay == 1 {
LocalizedStringKey(formatted + " second")
} else {
LocalizedStringKey(formatted + " seconds")
}
}

var body: some View {
Form {
Section {
Expand All @@ -26,6 +36,9 @@ struct AdvancedSettingsPane: View {
enableAlwaysHiddenSection
canToggleAlwaysHiddenSection
}
Section("Other") {
showOnHoverDelaySlider
}
}
.formStyle(.grouped)
.scrollContentBackground(.hidden)
Expand Down Expand Up @@ -80,6 +93,26 @@ struct AdvancedSettingsPane: View {
}
}
}

@ViewBuilder
private var showOnHoverDelaySlider: some View {
LabeledContent {
CompactSlider(
value: manager.bindings.showOnHoverDelay,
in: 0...1,
step: 0.1,
handleVisibility: .hovering(width: 1)
) {
Text(showOnHoverDelay)
.textSelection(.disabled)
}
.compactSliderDisabledHapticFeedback(true)
} label: {
Text("Show on hover delay")
.frame(minHeight: .compactSliderMinHeight)
Text("The amount of time to wait before showing on hover")
}
}
}

#Preview {
Expand Down
1 change: 1 addition & 0 deletions Ice/Utilities/Defaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ extension Defaults {
case useIceBar = "UseIceBar"
case showOnClick = "ShowOnClick"
case showOnHover = "ShowOnHover"
case showOnHoverDelay = "ShowOnHoverDelay"
case showOnScroll = "ShowOnScroll"
case autoRehide = "AutoRehide"
case rehideStrategy = "RehideStrategy"
Expand Down

0 comments on commit ac33716

Please sign in to comment.