ENH: Fixed sizing of the main window.
This commit is contained in:
parent
9caec8c99b
commit
a3a858a891
3 changed files with 144 additions and 134 deletions
|
@ -59,12 +59,14 @@ func runShellCommandAsync(command: String, outputText: Binding<String>?, showBut
|
|||
}
|
||||
|
||||
class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
var window: NSWindow!
|
||||
|
||||
func applicationWillTerminate(_ notification: Notification) {
|
||||
runShellCommandAsync(command: "msg machine stop", outputText: nil, showButton: nil)
|
||||
runShellCommandAsync(command: "kill $(ps aux | grep '[g]uile' | awk '{print $2}')", outputText: nil, showButton: nil)
|
||||
runShellCommandAsync(command: "kill $(ps aux | grep '[q]emu' | awk '{print $2}')", outputText: nil, showButton: nil)
|
||||
}
|
||||
|
||||
|
||||
func saveAppState() {
|
||||
print("App is terminating. Saving state...")
|
||||
UserDefaults.standard.set(Date(), forKey: "lastClosed")
|
||||
|
@ -73,44 +75,54 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
var statusBarItem: NSStatusItem!
|
||||
|
||||
func applicationDidFinishLaunching(_ notification: Notification) {
|
||||
statusBarItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
|
||||
|
||||
if let button = statusBarItem.button {
|
||||
button.title = "MSG"
|
||||
button.toolTip = "MSG App"
|
||||
}
|
||||
|
||||
let menu = NSMenu()
|
||||
|
||||
menu.addItem(NSMenuItem(title: "Quit", action: #selector(quitApp), keyEquivalent: "q"))
|
||||
|
||||
statusBarItem.menu = menu
|
||||
statusBarItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
|
||||
|
||||
let contentView = ContentView()
|
||||
window = NSWindow(
|
||||
contentRect: NSRect(x: 0, y: 0, width: 800, height: 600),
|
||||
styleMask: [.titled, .closable, .resizable, .miniaturizable],
|
||||
backing: .buffered,
|
||||
defer: false
|
||||
)
|
||||
window.center()
|
||||
//window.setFrameAutosaveName("MSG App") // to retain size after quitting
|
||||
window.contentView = NSHostingView(rootView: contentView)
|
||||
window.makeKeyAndOrderFront(nil)
|
||||
|
||||
if let button = statusBarItem.button {
|
||||
button.title = "MSG"
|
||||
button.toolTip = "MSG App"
|
||||
}
|
||||
|
||||
@objc func quitApp() {
|
||||
let alert = NSAlert()
|
||||
alert.messageText = "Are you sure you want to quit?"
|
||||
alert.informativeText = "Do you want to quit the app and exit?"
|
||||
alert.alertStyle = .warning
|
||||
|
||||
alert.addButton(withTitle: "Quit")
|
||||
alert.addButton(withTitle: "Cancel")
|
||||
|
||||
let response = alert.runModal()
|
||||
|
||||
if response == .alertFirstButtonReturn {
|
||||
NSApplication.shared.terminate(nil)
|
||||
}
|
||||
let menu = NSMenu()
|
||||
|
||||
menu.addItem(NSMenuItem(title: "Quit", action: #selector(quitApp), keyEquivalent: "q"))
|
||||
|
||||
statusBarItem.menu = menu
|
||||
}
|
||||
|
||||
@objc func quitApp() {
|
||||
let alert = NSAlert()
|
||||
alert.messageText = "Are you sure you want to quit?"
|
||||
alert.informativeText = "Do you want to quit the app and exit?"
|
||||
alert.alertStyle = .warning
|
||||
|
||||
alert.addButton(withTitle: "Quit")
|
||||
alert.addButton(withTitle: "Cancel")
|
||||
|
||||
let response = alert.runModal()
|
||||
|
||||
if response == .alertFirstButtonReturn {
|
||||
NSApplication.shared.terminate(nil)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
class AppState: ObservableObject {
|
||||
@Published var output: String = "Please select an option \n"
|
||||
|
||||
static let shared = AppState()
|
||||
static let shared = AppState()
|
||||
}
|
||||
|
||||
@main
|
||||
|
@ -118,8 +130,6 @@ struct MSG_DesktopApp: App {
|
|||
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
|
||||
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
ContentView()
|
||||
}
|
||||
Settings {} // prevents crash on some macOS version
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue