Wheela Studio
Wheela Studio

Reputation: 131

How can i remove the "New window" option in macOS SwiftUI App?

I need to remove this option in my app

This is my app delegate:

import AppKit
public class AppDelegate: NSObject, NSApplicationDelegate {
    public func applicationWillTerminate(_ aNotification: Notification) {
        MainViewModel.shared.saveSettings()
    }
    public func applicationDidFinishLaunching(_ notification: Notification) {
        for window in NSApp.windows {
            var style = window.styleMask
            style.remove(.resizable)
            window.styleMask = style
            window.standardWindowButton(.zoomButton)?.isHidden = true
        }
    }
    public func applicationWillFinishLaunching(_ notification: Notification) {
        NSWindow.allowsAutomaticWindowTabbing = false
    }
}

How can i do this?

Upvotes: 4

Views: 1328

Answers (1)

Wheela Studio
Wheela Studio

Reputation: 131

Just add the commands modifier to WindowGroup, as here:

WindowGroup {
            MainView().frame(width: 300, height: 95)
        }.commands {
            CommandGroup(replacing: CommandGroupPlacement.newItem) {
            }
        }

Upvotes: 8

Related Questions