-
Notifications
You must be signed in to change notification settings - Fork 3
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
How to integrate with a pure SwiftUI app? #4
Comments
Thank you for the compliments!
First the obvious thing: Does your If the project is in a public repo, providing the link would allow me to answer a lot of questions myself from your specific project. Otherwise could you confirm my suspicion is correct? |
Thanks for your reply. PS: Unfortunately I do not have my project in a public repo, but you could generate a new Xcode 'pure' SwiftUI project, add your project package and set it up with something like:
|
Any progress here? I'm running into a similar issue in trying to integrate MacMenuBar with a pure SwiftUI App. @main
struct TestStuffApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
|
I have found a solution, but it feels like a hack, so I haven't decided yet if I want to incorporate it directly into MacMenuBar. The problem boils down to SwiftUI overwriting MacMenuBar's setting The solution I found is to wait to set it until the main run loop starts processing In the mean time, you can easily do it in your own code: import SwiftUI
import MacMenuBar
@main
struct TestStuffApp: App {
init()
{
DispatchQueue.main.async {
NSApplication.shared.delegate?.setMenuBar(to: MainMenuBar())
}
}
var body: some Scene {
WindowGroup {
return ContentView()
}
}
} Successfully setting |
I decided to incorporate the change into SwiftUI in v0.0.12. I also added an extension on SwiftUI's import SwiftUI
import MacMenuBar
@main
struct TestStuffApp: App {
init() { setMenuBar(to: MainMenuBar()) }
var body: some Scene {
WindowGroup {
return ContentView()
}
}
} @mgriebling from my tests, this should fix the issue, but I still would like to get confirmation as to whether this solves problem for you before I close the issue. @hk05 I also updated the README to reflect this set up. |
MacMenuBar looks great, so I wanted to try it on one of my apps. Since it is an existing app, I cannot use the templates. I have not been able to run MacMenuBar in in a "pure swiftUI" environment with an entry point like:
@main
struct MyApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
}
Following instructions in this situation did not yield success.
Would it be possible to extend the (otherwise excellent) documentation with a setup instruction for configs like the above?
The text was updated successfully, but these errors were encountered: