From 7ef789db91f69a8a9fb19e121322e1243f3bf0d7 Mon Sep 17 00:00:00 2001 From: Davide De Rosa Date: Tue, 26 Jan 2021 20:39:37 +0100 Subject: [PATCH] Make "Confirm quit" a preference --- Passepartout/App/macOS/AppDelegate.swift | 14 +++++++++++++- Passepartout/App/macOS/CHANGELOG.md | 1 + Passepartout/App/macOS/Global/Macros.swift | 14 +++++++++----- Passepartout/Core/Sources/Model/Preferences.swift | 4 ++++ 4 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Passepartout/App/macOS/AppDelegate.swift b/Passepartout/App/macOS/AppDelegate.swift index a399518d..a1e4a356 100644 --- a/Passepartout/App/macOS/AppDelegate.swift +++ b/Passepartout/App/macOS/AppDelegate.swift @@ -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 } diff --git a/Passepartout/App/macOS/CHANGELOG.md b/Passepartout/App/macOS/CHANGELOG.md index f203be62..43c07258 100644 --- a/Passepartout/App/macOS/CHANGELOG.md +++ b/Passepartout/App/macOS/CHANGELOG.md @@ -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 diff --git a/Passepartout/App/macOS/Global/Macros.swift b/Passepartout/App/macOS/Global/Macros.swift index 99035fc9..61acfeab 100644 --- a/Passepartout/App/macOS/Global/Macros.swift +++ b/Passepartout/App/macOS/Global/Macros.swift @@ -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() } } diff --git a/Passepartout/Core/Sources/Model/Preferences.swift b/Passepartout/Core/Sources/Model/Preferences.swift index 69246516..96658ff8 100644 --- a/Passepartout/Core/Sources/Model/Preferences.swift +++ b/Passepartout/Core/Sources/Model/Preferences.swift @@ -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