How to have right-click option on menuBarExtra in SwiftUI?

257 views Asked by At

I've been able to make right-click menus in the Storyboard interface but I'm not able to achieve the same in a SwiftUI interface. Basically when you right-click the status bar icon and there is a Settings menu is what I'm aiming for. This is what I have:

import SwiftUI

class AppSettings: ObservableObject {
    @Published var sendText = true {
        didSet {
            if !sendText {
                playSound = true
            }
        }
    }
    @Published var playSound = true {
        didSet {
            if !playSound {
                sendText = true
            }
        }
    }
}

@main
struct SudoApp: App {
    @StateObject var settings = AppSettings()
    @State var myText = "Fred"
    
    var body: some Scene {
        MenuBarExtra("App") {
            Button(action:{}) { 
                HStack {
                    Image(systemName: "alarm")
                    Text("Toggle")
                    Spacer()
                }
            }
        }
    }
}
0

There are 0 answers