2021-01-01 10:13:41 +00:00
|
|
|
//
|
|
|
|
// PreferencesGeneralViewController.swift
|
2021-01-01 16:53:28 +00:00
|
|
|
// Passepartout
|
2021-01-01 10:13:41 +00:00
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 5/31/19.
|
|
|
|
// Copyright (c) 2021 Davide De Rosa. All rights reserved.
|
|
|
|
//
|
|
|
|
// https://github.com/passepartoutvpn
|
|
|
|
//
|
|
|
|
// This file is part of Passepartout.
|
|
|
|
//
|
|
|
|
// Passepartout is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Passepartout is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
import PassepartoutCore
|
|
|
|
import ServiceManagement
|
|
|
|
|
|
|
|
class PreferencesGeneralViewController: NSViewController {
|
|
|
|
@IBOutlet private weak var checkLaunchOnLogin: NSButton!
|
|
|
|
|
|
|
|
@IBOutlet private weak var labelLaunchOnLogin: NSTextField!
|
|
|
|
|
2021-01-26 19:45:21 +00:00
|
|
|
@IBOutlet private weak var checkConfirmQuit: NSButton!
|
|
|
|
|
|
|
|
@IBOutlet private weak var labelConfirmQuit: NSTextField!
|
|
|
|
|
2021-01-01 10:13:41 +00:00
|
|
|
@IBOutlet private weak var checkResolveHostname: NSButton!
|
|
|
|
|
|
|
|
@IBOutlet private weak var labelResolveHostname: NSTextField!
|
|
|
|
|
|
|
|
private let service = TransientStore.shared.service
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
|
2021-08-07 10:23:17 +00:00
|
|
|
checkLaunchOnLogin.title = L10n.Core.Preferences.Cells.LaunchesOnLogin.caption
|
|
|
|
labelLaunchOnLogin.stringValue = L10n.Core.Preferences.Cells.LaunchesOnLogin.footer
|
|
|
|
checkConfirmQuit.title = L10n.Core.Preferences.Cells.ConfirmQuit.caption
|
|
|
|
labelConfirmQuit.stringValue = L10n.Core.Preferences.Cells.ConfirmQuit.footer
|
2021-01-01 10:13:41 +00:00
|
|
|
checkResolveHostname.title = L10n.Core.Service.Cells.VpnResolvesHostname.caption
|
|
|
|
labelResolveHostname.stringValue = L10n.Core.Service.Sections.VpnResolvesHostname.footer
|
|
|
|
|
|
|
|
checkLaunchOnLogin.state = (service.preferences.launchesOnLogin ?? true) ? .on : .off
|
2021-01-26 19:45:21 +00:00
|
|
|
checkConfirmQuit.state = (service.preferences.confirmsQuit ?? true) ? .on : .off
|
2021-01-01 10:13:41 +00:00
|
|
|
checkResolveHostname.state = service.preferences.resolvesHostname ? .on : .off
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewWillDisappear() {
|
|
|
|
super.viewWillDisappear()
|
|
|
|
|
|
|
|
TransientStore.shared.serialize(withProfiles: false) // close preferences
|
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction private func toggleLaunchesOnLogin(_ sender: Any?) {
|
|
|
|
service.preferences.launchesOnLogin = (checkLaunchOnLogin.state == .on)
|
|
|
|
SMLoginItemSetEnabled(AppConstants.App.appLauncherId as CFString, service.preferences.launchesOnLogin ?? true)
|
|
|
|
}
|
|
|
|
|
2021-01-26 19:45:21 +00:00
|
|
|
@IBAction private func toggleConfirmQuit(_ sender: Any?) {
|
|
|
|
service.preferences.confirmsQuit = (checkConfirmQuit.state == .on)
|
|
|
|
}
|
|
|
|
|
2021-01-01 10:13:41 +00:00
|
|
|
@IBAction private func toggleResolvesHostname(_ sender: Any?) {
|
|
|
|
service.preferences.resolvesHostname = (checkResolveHostname.state == .on)
|
|
|
|
cycleVPNIfNeeded()
|
|
|
|
}
|
|
|
|
|
|
|
|
private func cycleVPNIfNeeded() {
|
|
|
|
let vpn = GracefulVPN(service: service)
|
|
|
|
guard vpn.isEnabled else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// guard vpn.status == .disconnected else {
|
|
|
|
// confirmVpnReconnection()
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
vpn.reinstall(completionHandler: nil)
|
|
|
|
}
|
|
|
|
}
|