Skip to content

Instantly share code, notes, and snippets.

@arekt
Last active Apr 21, 2022
Embed
What would you like to do?
main.swift
import Cocoa
import SwiftUI
import Combine
class AppState: ObservableObject {
@Published var isRescaling = false
@Published var scaleCurrent: CGFloat = 1.0
@Published var scaleFinal: CGFloat = 1.0
func rescaling(_ enabled: Bool) {
self.isRescaling = enabled
}
}
@main
struct MyApp: App {
//@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@StateObject var appState = AppState()
@SceneBuilder var body: some Scene {
WindowGroup("Foo Bar") {
ContentView()
.environmentObject(appState)
.onAppear {
NSApp.setActivationPolicy(.regular)
NSApp.activate(ignoringOtherApps: true)
let _ = NSApplication.shared.windows.map {
$0.styleMask = [ .titled, .closable, .miniaturizable, .resizable, .fullSizeContentView]
$0.setFrameAutosaveName("Main Window")
$0.title = "Awesome Drawing App"
$0.center()
//$0.makeMain()
$0.makeKeyAndOrderFront(nil)
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
.windowStyle(DefaultWindowStyle())
.commands {
AppCommands()
}
#if os(macOS)
Settings {
SettingsView()
}
#endif
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment