2022-06-25 20:11:45 +00:00
|
|
|
//
|
|
|
|
// PassepartoutMenu.swift
|
|
|
|
// Passepartout
|
|
|
|
//
|
|
|
|
// Created by Davide De Rosa on 7/3/22.
|
2023-03-17 15:56:19 +00:00
|
|
|
// Copyright (c) 2023 Davide De Rosa. All rights reserved.
|
2022-06-25 20:11:45 +00:00
|
|
|
//
|
|
|
|
// 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 Foundation
|
|
|
|
import AppKit
|
|
|
|
|
2022-10-13 06:53:50 +00:00
|
|
|
@MainActor
|
2022-06-25 20:11:45 +00:00
|
|
|
class PassepartoutMenu {
|
|
|
|
private let macMenuDelegate: MacMenuDelegate
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-06-25 20:11:45 +00:00
|
|
|
private let profileManager: LightProfileManager
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-06-25 20:11:45 +00:00
|
|
|
private let providerManager: LightProviderManager
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-06-25 20:11:45 +00:00
|
|
|
private let statusButton: StatusButton
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-06-25 20:11:45 +00:00
|
|
|
init(macMenuDelegate: MacMenuDelegate) {
|
|
|
|
self.macMenuDelegate = macMenuDelegate
|
|
|
|
profileManager = macMenuDelegate.profileManager
|
|
|
|
providerManager = macMenuDelegate.providerManager
|
|
|
|
statusButton = StatusButton(
|
|
|
|
profileManager: profileManager,
|
|
|
|
vpnManager: macMenuDelegate.vpnManager
|
|
|
|
)
|
|
|
|
|
|
|
|
profileManager.delegate = self
|
|
|
|
providerManager.delegate = self
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-06-25 20:11:45 +00:00
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-06-25 20:11:45 +00:00
|
|
|
func install() {
|
|
|
|
statusButton.install(systemMenu: StaticSystemMenu(body))
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-06-25 20:11:45 +00:00
|
|
|
private var body: [ItemGroup] {
|
|
|
|
var children: [ItemGroup] = []
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-06-25 20:11:45 +00:00
|
|
|
children.append(contentsOf: [
|
2022-08-19 06:45:36 +00:00
|
|
|
VisibilityItem(
|
|
|
|
L10n.Global.Strings.show,
|
|
|
|
utils: macMenuDelegate.utils
|
|
|
|
),
|
2022-07-18 05:54:01 +00:00
|
|
|
LaunchOnLoginItem(
|
|
|
|
L10n.Preferences.Items.LaunchesOnLogin.caption,
|
|
|
|
utils: macMenuDelegate.utils
|
2023-03-17 20:55:47 +00:00
|
|
|
)
|
2022-06-25 20:11:45 +00:00
|
|
|
] as [ItemGroup])
|
|
|
|
|
|
|
|
if profileManager.hasProfiles {
|
|
|
|
children.append(contentsOf: [
|
|
|
|
SeparatorItem(),
|
|
|
|
ProfileItemGroup(
|
|
|
|
profileManager: macMenuDelegate.profileManager,
|
|
|
|
providerManager: macMenuDelegate.providerManager,
|
|
|
|
vpnManager: macMenuDelegate.vpnManager
|
|
|
|
)
|
|
|
|
] as [ItemGroup])
|
|
|
|
}
|
|
|
|
|
|
|
|
if let _ = profileManager.activeProfileId {
|
|
|
|
children.append(contentsOf: [
|
|
|
|
SeparatorItem(),
|
|
|
|
VPNItemGroup(
|
|
|
|
vpnManager: macMenuDelegate.vpnManager
|
|
|
|
) {
|
|
|
|
$0 ? L10n.Profile.Items.Vpn.TurnOff.caption : L10n.Profile.Items.Vpn.TurnOn.caption
|
|
|
|
} reconnectTitleBlock: {
|
|
|
|
L10n.Global.Strings.reconnect
|
2023-03-17 20:55:47 +00:00
|
|
|
}
|
2022-06-25 20:11:45 +00:00
|
|
|
] as [ItemGroup])
|
|
|
|
}
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-06-25 20:11:45 +00:00
|
|
|
children.append(contentsOf: [
|
|
|
|
SeparatorItem(),
|
|
|
|
// TextItem(L10n.Menu.All.About.title(Constants.Global.appName)) {
|
|
|
|
//
|
|
|
|
// // this does not work when app is in background
|
|
|
|
// NSApp.orderFrontStandardAboutPanel(nil)
|
|
|
|
// NSApp.activate(ignoringOtherApps: true)
|
|
|
|
// },
|
|
|
|
TextItem(L10n.Menu.System.Quit.title(Constants.Global.appName), key: "q") {
|
|
|
|
NSApp.terminate(nil)
|
|
|
|
}
|
|
|
|
] as [ItemGroup])
|
2023-03-17 20:55:47 +00:00
|
|
|
|
2022-06-25 20:11:45 +00:00
|
|
|
return children
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension PassepartoutMenu: LightProfileManagerDelegate {
|
|
|
|
func didUpdateProfiles() {
|
|
|
|
install()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension PassepartoutMenu: LightProviderManagerDelegate {
|
|
|
|
func didUpdateProviders() {
|
|
|
|
install()
|
|
|
|
}
|
|
|
|
}
|