Skip to content

Instantly share code, notes, and snippets.

@arekt
Last active April 21, 2022 18:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arekt/f5b9fcfdcf6b0614c71581ef85cead71 to your computer and use it in GitHub Desktop.
Save arekt/f5b9fcfdcf6b0614c71581ef85cead71 to your computer and use it in GitHub Desktop.
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