Make "Confirm quit" a preference

This commit is contained in:
Davide De Rosa 2021-01-26 20:39:37 +01:00
parent 946158f14a
commit 7ef789db91
4 changed files with 27 additions and 6 deletions

View File

@ -84,12 +84,24 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
// TransientStore.shared.service.preferences.confirmsQuit = true
guard TransientStore.shared.service.preferences.confirmsQuit ?? true else {
return .terminateNow
}
let alert = Macros.warning(
L10n.App.Menu.Quit.title(GroupConstants.App.name),
L10n.App.Menu.Quit.Messages.confirm
)
guard alert.presentModally(withOK: L10n.Core.Global.ok, cancel: L10n.Core.Global.cancel) else {
switch alert.presentModallyEx(withOK: L10n.Core.Global.ok, other1: L10n.Core.Global.cancel, other2: L10n.Core.Reddit.Buttons.never) {
case .alertSecondButtonReturn:
return .terminateCancel
case .alertThirdButtonReturn:
TransientStore.shared.service.preferences.confirmsQuit = false
break
default:
break
}
return .terminateNow
}

View File

@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Country flags in provider infrastructure menu.
- Support DNS over HTTPS/TLS in "Network settings". [#91](https://github.com/passepartoutvpn/passepartout-apple/issues/91)
- Menu tooltip describing active profile and status.
- Make "Confirm quit" a preference.
### Changed

View File

@ -74,14 +74,18 @@ extension NSAlert {
}
func presentModally(withOK okTitle: String, cancel cancelTitle: String?, dummy dummyTitle: String? = nil) -> Bool {
return presentModallyEx(withOK: okTitle, other1: cancelTitle, other2: dummyTitle) == .alertFirstButtonReturn
}
func presentModallyEx(withOK okTitle: String, other1 other1Title: String?, other2 other2Title: String? = nil) -> NSApplication.ModalResponse {
addButton(withTitle: okTitle)
if let cancelTitle = cancelTitle {
addButton(withTitle: cancelTitle)
if let other1Title = other1Title {
addButton(withTitle: other1Title)
}
if let dummyTitle = dummyTitle {
addButton(withTitle: dummyTitle)
if let other2Title = other2Title {
addButton(withTitle: other2Title)
}
return runModal() == .alertFirstButtonReturn
return runModal()
}
}

View File

@ -28,6 +28,8 @@ import Foundation
public protocol Preferences {
var launchesOnLogin: Bool? { get }
var confirmsQuit: Bool? { get }
var resolvesHostname: Bool { get }
var disconnectsOnSleep: Bool { get }
@ -35,6 +37,8 @@ public protocol Preferences {
public class EditablePreferences: Preferences, Codable {
public var launchesOnLogin: Bool? = false
public var confirmsQuit: Bool? = true
public var resolvesHostname: Bool = true