Setting your app’s icon on the menu bar as a template makes it to adapt to light and dark modes automatically without you doing anything. To do this, you have to use this constructor of MenuBarExtra class.
The code would look like this:
import SwiftUI
@main
struct ToDoBarApp: App {
var body: some Scene {
MenuBarExtra {
YourView()
} label: {
Image("MenuBarIcon").renderingMode(.template)
}
}
}