No longer set default urgency

This commit is contained in:
2025-11-27 13:04:55 +01:00
parent da3a5563da
commit 1bbaad3769
3 changed files with 17 additions and 25 deletions

View File

@@ -17,26 +17,21 @@ NVAlert().withInformation(
description: NSLocalizedString("lite_mode_explanation.description", nil)
)
.withPrimary(text: NSLocalizedString("generic.ok", nil))
.show()
.show(urgency: .bringToFront)
```
### Understanding urgency
By default, `NVAlert` will show any modal with `NVAlertUrgency.normalRequestAttention`, which will display and bounce the Dock icon. You can change the urgency when displaying the modal:
```
NVAlert() // create your modal here
.show(urgency: .none) // <--
```
You must set the `urgency` when attempting to display an alert.
No matter what, presenting an alert will cause the Dock icon to appear (`NSApp.activationPolicy` becomes `.regular`), and the window will be visible in Mission Control.
Here's how the urgency states differ:
- `.none`: No attention is requested.
- `.normalRequestAttention`: The Dock icon will bounce momentarily. **The default if not specified.**
- `.normalRequestAttention`: The Dock icon will bounce momentarily.
- `.urgentRequestAttention`: The Dock icon will bounce for a longer time.
- `.alwaysBringToFront`: The application will be focused (become the foreground application) with `NSApp.activate(ignoringOtherApps: true)`. Use this with caution, because it can be perceived as annoying to users!
- `.bringToFront`: The application will be focused (become the foreground application) with `NSApp.activate(ignoringOtherApps: true)`. May be necessary for applications that run in accessory mode (e.g. menu bar apps) if you don't want the modal to be immediately unfocused after user interaction with a menu.
### Additional buttons

View File

@@ -76,9 +76,7 @@ open class NVAlert {
Shows the modal and returns a ModalResponse.
If you wish to simply show the alert and disregard the outcome, use `show`.
*/
@MainActor public func runModal(
urgency: NVAlertUrgency = .normalRequestAttention
) -> NSApplication.ModalResponse {
@MainActor public func runModal(urgency: NVAlertUrgency) -> NSApplication.ModalResponse {
let activationPolicy = NSApp.activationPolicy()
if !Thread.isMainThread {
@@ -95,7 +93,7 @@ open class NVAlert {
NSApp.requestUserAttention(.informationalRequest)
} else if urgency == .urgentRequestAttention {
NSApp.requestUserAttention(.criticalRequest)
} else if urgency == .alwaysBringToFront {
} else if urgency == .bringToFront {
NSApp.activate(ignoringOtherApps: true)
}
@@ -128,18 +126,14 @@ open class NVAlert {
}
/** Shows the modal and returns true if the user pressed the primary button. */
@MainActor public func didSelectPrimary(
urgency: NVAlertUrgency = .normalRequestAttention
) -> Bool {
@MainActor public func didSelectPrimary(urgency: NVAlertUrgency) -> Bool {
return self.runModal(urgency: urgency) == .alertFirstButtonReturn
}
/**
Shows the modal and does not return anything.
*/
@MainActor public func show(
urgency: NVAlertUrgency = .normalRequestAttention
) {
@MainActor public func show(urgency: NVAlertUrgency) {
_ = self.runModal(urgency: urgency)
}

View File

@@ -6,18 +6,21 @@
//
public enum NVAlertUrgency {
/// This is low urgency.
/// The user will not be prompted for attention.
/// Use for background alerts.
/// No user attention is requested.
case none
/// The application requests attention.
/// The default for alerts.
/// Use for background alerts.
/// Requests user attention w/ `.informationalRequest`
case normalRequestAttention
/// The application urgently demands attention.
/// Use for background alerts.
/// Requests user attention w/ `.criticalRequest`
case urgentRequestAttention
/// The application will steal focus.
/// Don't do this unless necessary!
case alwaysBringToFront
/// The application will be focused.
/// Use when immediate user interaction is expected.
case bringToFront
}