Enforce window appearance on 'Show' after closure

This commit is contained in:
Davide De Rosa 2022-07-16 21:24:53 +02:00
parent 9458c4f3a3
commit 781291940f
9 changed files with 106 additions and 5 deletions

View File

@ -11,6 +11,9 @@
0E021D9D284E68580077EF5D /* AppContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E021D9B284E68580077EF5D /* AppContext.swift */; };
0E0392772818732D00827C10 /* BuildProducts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0392762818732D00827C10 /* BuildProducts.swift */; };
0E039279281890B100827C10 /* AddHostView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E039278281890B100827C10 /* AddHostView.swift */; };
0E04F0062883462E00BFCE1C /* LightUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E04F0052883462E00BFCE1C /* LightUtils.swift */; };
0E04F0072883462E00BFCE1C /* LightUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E04F0052883462E00BFCE1C /* LightUtils.swift */; };
0E04F0092883466500BFCE1C /* DefaultLightUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E04F0082883466500BFCE1C /* DefaultLightUtils.swift */; };
0E065F112813269500062CAF /* WelcomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E065F102813269500062CAF /* WelcomeView.swift */; };
0E0838F22872C5FB00A34EC0 /* ItemGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0838F12872C5FB00A34EC0 /* ItemGroup.swift */; };
0E0838F82874147F00A34EC0 /* PassepartoutMenu+StatusButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0E0838F72874147F00A34EC0 /* PassepartoutMenu+StatusButton.swift */; };
@ -277,6 +280,8 @@
0E021D9B284E68580077EF5D /* AppContext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppContext.swift; sourceTree = "<group>"; };
0E0392762818732D00827C10 /* BuildProducts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuildProducts.swift; sourceTree = "<group>"; };
0E039278281890B100827C10 /* AddHostView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddHostView.swift; sourceTree = "<group>"; };
0E04F0052883462E00BFCE1C /* LightUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LightUtils.swift; sourceTree = "<group>"; };
0E04F0082883466500BFCE1C /* DefaultLightUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultLightUtils.swift; sourceTree = "<group>"; };
0E065F102813269500062CAF /* WelcomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WelcomeView.swift; sourceTree = "<group>"; };
0E0838F12872C5FB00A34EC0 /* ItemGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ItemGroup.swift; sourceTree = "<group>"; };
0E0838F72874147F00A34EC0 /* PassepartoutMenu+StatusButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PassepartoutMenu+StatusButton.swift"; sourceTree = "<group>"; };
@ -781,6 +786,7 @@
children = (
0E96D2F82871D874005EFBCF /* LightProfileManager.swift */,
0E0838F92877325A00A34EC0 /* LightProviderManager.swift */,
0E04F0052883462E00BFCE1C /* LightUtils.swift */,
0E96D30128720067005EFBCF /* LightVPNManager.swift */,
);
path = Models;
@ -791,6 +797,7 @@
children = (
0E96D2FB2871D94E005EFBCF /* DefaultLightProfileManager.swift */,
0E0838FC2877334300A34EC0 /* DefaultLightProviderManager.swift */,
0E04F0082883466500BFCE1C /* DefaultLightUtils.swift */,
0E96D3042872010A005EFBCF /* DefaultLightVPNManager.swift */,
);
path = Models;
@ -1304,6 +1311,7 @@
0E1F562B287F0EF100F8ADD7 /* ProviderProfileItem+ViewModel.swift in Sources */,
0E5468072867AEC500F74D1C /* MacMenu.swift in Sources */,
0E96D2EC2871A0AD005EFBCF /* HostProfileItem.swift in Sources */,
0E04F0072883462E00BFCE1C /* LightUtils.swift in Sources */,
0E96D2F22871C5CA005EFBCF /* StaticSystemMenu.swift in Sources */,
A3A7CC58287D576400172D7D /* ProviderLocationItem+ViewModel.swift in Sources */,
0E5467F02867A4C300F74D1C /* PassepartoutMac.swift in Sources */,
@ -1336,6 +1344,7 @@
0E7577D72816A3B200081CBE /* DestructiveButton.swift in Sources */,
0EF2212D27E66EB5001D0BD7 /* AddProviderView.swift in Sources */,
0E35C09A280E95BB0071FA35 /* ProviderProfileAvailability.swift in Sources */,
0E04F0092883466500BFCE1C /* DefaultLightUtils.swift in Sources */,
0E5349C827C176D100C71BB3 /* EndpointView+WireGuard.swift in Sources */,
0EBC076027EC587900208AD9 /* SwiftGen+Strings.swift in Sources */,
0E0392772818732D00827C10 /* BuildProducts.swift in Sources */,
@ -1403,6 +1412,7 @@
0E039279281890B100827C10 /* AddHostView.swift in Sources */,
0E5467F72867A57000F74D1C /* MacBridge.swift in Sources */,
0E9ED48127FD9BAE003B2316 /* CopySavingButton.swift in Sources */,
0E04F0062883462E00BFCE1C /* LightUtils.swift in Sources */,
0EE11CD2280D8317003BE431 /* InfoMenu.swift in Sources */,
0E44689C27B11B5300A14CE4 /* AboutView.swift in Sources */,
0E71ACF927C12E4800F85C4B /* CreditsView.swift in Sources */,

View File

@ -39,6 +39,10 @@ class MacBundleDelegate: MacMenuDelegate {
var vpnManager: LightVPNManager {
DefaultLightVPNManager()
}
var utils: LightUtils {
DefaultLightUtils()
}
init(bundle: MacBundle?) {
self.bundle = bundle

View File

@ -0,0 +1,44 @@
//
// DefaultLightUtils.swift
// Passepartout
//
// Created by Davide De Rosa on 7/16/22.
// Copyright (c) 2022 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 Foundation
import UIKit
class DefaultLightUtils: LightUtils {
private let app: UIApplication
init() {
app = .shared
}
func requestScene() {
guard app.connectedScenes.isEmpty else {
return
}
app.requestSceneSessionActivation(nil, userActivity: nil, options: nil) { error in
//
}
}
}

View File

@ -39,4 +39,6 @@ public protocol MacMenuDelegate {
var providerManager: LightProviderManager { get }
var vpnManager: LightVPNManager { get }
var utils: LightUtils { get }
}

View File

@ -0,0 +1,31 @@
//
// LightUtils.swift
// Passepartout
//
// Created by Davide De Rosa on 7/16/22.
// Copyright (c) 2022 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 Foundation
@objc
public protocol LightUtils {
func requestScene()
}

View File

@ -24,6 +24,7 @@
//
import Foundation
import AppKit
class DefaultMacUtils: MacUtils {
private let transformer = ObservableProcessTransformer.shared

View File

@ -57,7 +57,7 @@ class PassepartoutMenu {
var children: [ItemGroup] = []
children.append(contentsOf: [
VisibilityItem {
VisibilityItem(utils: macMenuDelegate.utils) {
$0 ? L10n.Global.Strings.hide : L10n.Global.Strings.show
},
LaunchOnLoginItem(L10n.Preferences.Items.LaunchesOnLogin.caption),

View File

@ -24,15 +24,21 @@
//
import Foundation
import AppKit
extension VisibilityItem {
class ViewModel {
private let transformer = ObservableProcessTransformer.shared
private let transformer: ObservableProcessTransformer
private let utils: LightUtils
private let titleBlock: (Bool) -> String
init(titleBlock: @escaping (Bool) -> String) {
init(utils: LightUtils, titleBlock: @escaping (Bool) -> String) {
self.titleBlock = titleBlock
transformer = .shared
self.utils = utils
}
var title: String {
@ -41,6 +47,9 @@ extension VisibilityItem {
@objc func toggleForeground() {
transformer.toggleForeground()
if transformer.isForeground {
utils.requestScene()
}
}
func subscribe(_ block: @escaping () -> Void) {

View File

@ -29,8 +29,8 @@ import AppKit
struct VisibilityItem: Item {
private let viewModel: ViewModel
init(_ titleBlock: @escaping (Bool) -> String) {
viewModel = ViewModel(titleBlock: titleBlock)
init(utils: LightUtils, titleBlock: @escaping (Bool) -> String) {
viewModel = ViewModel(utils: utils, titleBlock: titleBlock)
}
func asMenuItem(withParent parent: NSMenu) -> NSMenuItem {