Issue with modifying WindowGroup in SwiftUI lifecycle macOS in removing titlebar and background

Viewed 137

I am trying to make my title and background disappear.

I am using the code below for this goal, but it has 2 big issues with it:

  • First, there is still some shadow existing from the title.
  • Second, when I run my code, for some short time (about 0.1-0.2 sec) it shows a window with background and title and once NotificationCenter sends the notification it start working.

How can I solve this issue?

  @main
struct Work_Space_macOSApp: App {
    
    var body: some Scene {
        WindowGroup {
            ContentView()
                .onReceive(NotificationCenter.default.publisher(for: NSApplication.willUpdateNotification), perform: { _ in
                    makeWindow()
                })
        }
    }
}


struct ContentView: View {
    var body: some View {
        Circle()
            .fill(Color.black)
    }
}

func makeWindow() {
    for window in NSApplication.shared.windows {
        window.titleVisibility = .hidden
        window.titlebarAppearsTransparent = true
        window.backgroundColor = NSColor.clear
        window.standardWindowButton(NSWindow.ButtonType.zoomButton)!.isHidden = true
        window.standardWindowButton(NSWindow.ButtonType.closeButton)!.isHidden = true
        window.standardWindowButton(NSWindow.ButtonType.miniaturizeButton)!.isHidden = true
    }
}

enter image description here

0 Answers
Related