Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address UI race conditions #229

Merged
merged 6 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply MainActor to Mac menus
  • Loading branch information
keeshux committed Oct 13, 2022
commit 22a676d789d127ea9a2756828348e4ab1ae75e6e
1 change: 1 addition & 0 deletions Passepartout/App/Mac/MacBundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class MacBundle {

private lazy var bridgeDelegate = MacBundleDelegate(bundle: self)

@MainActor
func configure() {
guard let bundleURL = Bundle.main.builtInPlugInsURL?.appendingPathComponent(Constants.Plugins.macBridgeName) else {
fatalError("Unable to find Mac bundle in plugins")
Expand Down
1 change: 1 addition & 0 deletions Passepartout/AppShared/Mac/MacMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import Foundation

@MainActor
@objc
public protocol MacMenu {
var delegate: MacMenuDelegate? { get set }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ extension LightProfile {
}
}

@MainActor
@objc
public protocol LightProfileManager {
var hasProfiles: Bool { get }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public protocol LightProviderServer {
var serverId: String { get }
}

@MainActor
@objc
public protocol LightProviderManager {
var delegate: LightProviderManagerDelegate? { get set }
Expand Down
1 change: 1 addition & 0 deletions Passepartout/AppShared/Mac/Models/LightVPNManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public enum LightVPNStatus: Int {
case disconnected
}

@MainActor
@objc
public protocol LightVPNManager {
var isEnabled: Bool { get }
Expand Down
6 changes: 5 additions & 1 deletion Passepartout/Mac/Menu/HostProfileItem+ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import Foundation

extension HostProfileItem {

@MainActor
class ViewModel {
let profile: LightProfile

Expand All @@ -41,7 +43,9 @@ extension HostProfileItem {
}

deinit {
vpnManager.removeDelegate(withIdentifier: profile.id.uuidString)
Task { @MainActor in
vpnManager.removeDelegate(withIdentifier: profile.id.uuidString)
}
}

@objc func connectTo() {
Expand Down
6 changes: 5 additions & 1 deletion Passepartout/Mac/Menu/PassepartoutMenu+StatusButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import Foundation
import AppKit

extension PassepartoutMenu {

@MainActor
class StatusButton {
private lazy var statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)

Expand All @@ -50,7 +52,9 @@ extension PassepartoutMenu {
}

deinit {
vpnManager.removeDelegate(withIdentifier: "PassepartoutMenu")
Task { @MainActor in
vpnManager.removeDelegate(withIdentifier: "PassepartoutMenu")
}
}

func install(systemMenu: SystemMenu) {
Expand Down
1 change: 1 addition & 0 deletions Passepartout/Mac/Menu/PassepartoutMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import Foundation
import AppKit

@MainActor
class PassepartoutMenu {
private let macMenuDelegate: MacMenuDelegate

Expand Down
1 change: 1 addition & 0 deletions Passepartout/Mac/Menu/ProviderLocationItem+ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ extension ProviderLocationItem {
location.servers.count == 1
}

@MainActor
@objc func connectTo() {
guard isOnlyServer else {
fatalError("Connecting to a location with multiple servers?")
Expand Down
6 changes: 5 additions & 1 deletion Passepartout/Mac/Menu/ProviderProfileItem+ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import Foundation

extension ProviderProfileItem {

@MainActor
class ViewModel {
let profile: LightProfile

Expand All @@ -44,7 +46,9 @@ extension ProviderProfileItem {
}

deinit {
vpnManager.removeDelegate(withIdentifier: profile.id.uuidString)
Task { @MainActor in
vpnManager.removeDelegate(withIdentifier: profile.id.uuidString)
}
}

private var providerName: String {
Expand Down
1 change: 1 addition & 0 deletions Passepartout/Mac/Menu/ProviderServerItem+ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ extension ProviderServerItem {
server.serverId == profile.providerServer?.serverId
}

@MainActor
@objc func connectTo() {
vpnManager.connect(with: profile.id, to: server.serverId)
}
Expand Down
6 changes: 5 additions & 1 deletion Passepartout/Mac/Menu/VPNItemGroup+ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import Foundation
import Combine

extension VPNItemGroup {

@MainActor
class ViewModel {
private let vpnManager: LightVPNManager

Expand All @@ -51,7 +53,9 @@ extension VPNItemGroup {
}

deinit {
vpnManager.removeDelegate(withIdentifier: "VPNItemGroup")
Task { @MainActor in
vpnManager.removeDelegate(withIdentifier: "VPNItemGroup")
}
}

var toggleTitle: String {
Expand Down
1 change: 1 addition & 0 deletions Passepartout/Mac/Menu/VPNItemGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import Foundation
import AppKit

@MainActor
struct VPNItemGroup: ItemGroup {
private let viewModel: ViewModel

Expand Down
1 change: 1 addition & 0 deletions Passepartout/Mac/PassepartoutMac.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ class PassepartoutMac: NSObject, MacBridge {

let utils: MacUtils = DefaultMacUtils()

@MainActor
let menu: MacMenu = DefaultMacMenu()
}
1 change: 1 addition & 0 deletions Passepartout/Mac/Reusable/ItemGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import Foundation
import AppKit

@MainActor
protocol ItemGroup {
func asMenuItems(withParent parent: NSMenu) -> [NSMenuItem]
}
1 change: 1 addition & 0 deletions Passepartout/Mac/Reusable/SystemMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import Foundation
import AppKit

@MainActor
protocol SystemMenu {
var asMenu: NSMenu { get }
}