Skip to content

Commit

Permalink
ui: auto-quit when last window is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
osy committed Feb 23, 2021
1 parent 9d885c2 commit 6437ad7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Platform/UTMApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import SwiftUI
@available(iOS 14, macOS 11, *)
struct UTMApp: App {
@StateObject var data = UTMData()
#if os(macOS)
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate: AppDelegate
#endif

var body: some Scene {
WindowGroup {
Expand Down
21 changes: 21 additions & 0 deletions Platform/macOS/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Copyright © 2021 osy. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

class AppDelegate: NSObject, NSApplicationDelegate {
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
true
}
}
4 changes: 4 additions & 0 deletions UTM.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@
CEDF83F9258AE24E0030E4AC /* UTMPasteboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEDF83F8258AE24E0030E4AC /* UTMPasteboard.swift */; };
CEDF83FA258AE24E0030E4AC /* UTMPasteboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEDF83F8258AE24E0030E4AC /* UTMPasteboard.swift */; };
CEEC811B24E48EC700ACB0B3 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEEC811A24E48EC600ACB0B3 /* SettingsView.swift */; };
CEECE13C25E47D9500A2AAB8 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CEECE13B25E47D9500A2AAB8 /* AppDelegate.swift */; };
CEF83EBA24F9ABEA00557D15 /* UTMQemuManager+BlockDevices.m in Sources */ = {isa = PBXBuildFile; fileRef = CEF83EB924F9ABEA00557D15 /* UTMQemuManager+BlockDevices.m */; };
CEF83EBB24F9ABEA00557D15 /* UTMQemuManager+BlockDevices.m in Sources */ = {isa = PBXBuildFile; fileRef = CEF83EB924F9ABEA00557D15 /* UTMQemuManager+BlockDevices.m */; };
CEF83EBE24F9C3BF00557D15 /* UTMVirtualMachine+Drives.m in Sources */ = {isa = PBXBuildFile; fileRef = CEF83EBD24F9C3BF00557D15 /* UTMVirtualMachine+Drives.m */; };
Expand Down Expand Up @@ -1495,6 +1496,7 @@
CEEB66442284B942002737B2 /* VMKeyboardButton.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = VMKeyboardButton.h; sourceTree = "<group>"; };
CEEB66452284B942002737B2 /* VMKeyboardButton.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VMKeyboardButton.m; sourceTree = "<group>"; };
CEEC811A24E48EC600ACB0B3 /* SettingsView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
CEECE13B25E47D9500A2AAB8 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
CEF83EB824F9ABEA00557D15 /* UTMQemuManager+BlockDevices.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UTMQemuManager+BlockDevices.h"; sourceTree = "<group>"; };
CEF83EB924F9ABEA00557D15 /* UTMQemuManager+BlockDevices.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "UTMQemuManager+BlockDevices.m"; sourceTree = "<group>"; };
CEF83EBC24F9C3BF00557D15 /* UTMVirtualMachine+Drives.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UTMVirtualMachine+Drives.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1813,6 +1815,7 @@
isa = PBXGroup;
children = (
CE1BD9FA24F4825C0022A468 /* Display */,
CEECE13B25E47D9500A2AAB8 /* AppDelegate.swift */,
CEEC811A24E48EC600ACB0B3 /* SettingsView.swift */,
CE8813D724CD2A8B00532628 /* SharingServicePicker.swift */,
CE93759124BA775C0074066F /* ToolbarTabView.swift */,
Expand Down Expand Up @@ -3056,6 +3059,7 @@
CE0B6D5A24AD584C00FE012D /* qapi-events-trace.c in Sources */,
CE0B6CFD24AD569A00FE012D /* gst_ios_init.m in Sources */,
CEF83EBB24F9ABEA00557D15 /* UTMQemuManager+BlockDevices.m in Sources */,
CEECE13C25E47D9500A2AAB8 /* AppDelegate.swift in Sources */,
CE0B6CF724AD568400FE012D /* UTMConfiguration+Display.m in Sources */,
CE0B6D6F24AD584D00FE012D /* qapi-events-transaction.c in Sources */,
CE0B6D0F24AD56E500FE012D /* UTMRenderer.m in Sources */,
Expand Down

0 comments on commit 6437ad7

Please sign in to comment.