Skip to content

Commit

Permalink
wizard: refactor common code to VMWizardContent
Browse files Browse the repository at this point in the history
Also hide row separator which appears on macOS Sonoma.
  • Loading branch information
osy committed Sep 3, 2023
1 parent f4834cb commit cc582f5
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 69 deletions.
55 changes: 55 additions & 0 deletions Platform/Shared/VMWizardContent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// Copyright © 2023 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.
//

import SwiftUI

struct VMWizardContent<Content>: View where Content: View {
let titleKey: LocalizedStringKey
let content: Content

init(_ titleKey: LocalizedStringKey, @ViewBuilder content: () -> Content) {
self.titleKey = titleKey
self.content = content()
}

var body: some View {
#if os(macOS)
Text(titleKey)
.font(.largeTitle)
#endif
List {
#if os(macOS)
if #available(macOS 13, *) {
content.listRowSeparator(.hidden)
} else {
content
}
#else
content
#endif
}
#if os(iOS) || os(visionOS)
.navigationTitle(Text(titleKey))
#endif
}
}

#Preview {
VMWizardContent("Test") {
Text("Test 1")
Text("Test 2")
}
}
9 changes: 1 addition & 8 deletions Platform/Shared/VMWizardDrivesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ struct VMWizardDrivesView: View {
@ObservedObject var wizardState: VMWizardState

var body: some View {
#if os(macOS)
Text("Storage")
.font(.largeTitle)
#endif
List {
VMWizardContent("Storage") {
Section {
HStack {
Text("Specify the size of the drive where data will be stored into.")
Expand All @@ -43,9 +39,6 @@ struct VMWizardDrivesView: View {
}

}
#if os(iOS) || os(visionOS)
.navigationTitle(Text("Storage"))
#endif
}
}

Expand Down
9 changes: 1 addition & 8 deletions Platform/Shared/VMWizardHardwareView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ struct VMWizardHardwareView: View {
}

var body: some View {
#if os(macOS)
Text("Hardware")
.font(.largeTitle)
#endif
List {
VMWizardContent("Hardware") {
if !wizardState.useVirtualization {
Section {
VMConfigConstantPicker(selection: $wizardState.systemArchitecture)
Expand Down Expand Up @@ -120,9 +116,6 @@ struct VMWizardHardwareView: View {

}
}
#if os(iOS) || os(visionOS)
.navigationTitle(Text("Hardware"))
#endif
.textFieldStyle(.roundedBorder)
.onAppear {
if wizardState.useVirtualization {
Expand Down
9 changes: 1 addition & 8 deletions Platform/Shared/VMWizardOSLinuxView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ struct VMWizardOSLinuxView: View {
}

var body: some View {
#if os(macOS)
Text("Linux")
.font(.largeTitle)
#endif
List {
VMWizardContent("Linux") {
#if os(macOS)
if wizardState.useVirtualization {
DetailedSection("Virtualization Engine", description: "Apple Virtualization is experimental and only for advanced use cases. Leave unchecked to use QEMU, which is recommended.") {
Expand Down Expand Up @@ -144,9 +140,6 @@ struct VMWizardOSLinuxView: View {


}
#if os(iOS) || os(visionOS)
.navigationTitle(Text("Linux"))
#endif
.fileImporter(isPresented: $isFileImporterPresented, allowedContentTypes: [.data], onCompletion: processImage)
}

Expand Down
6 changes: 1 addition & 5 deletions Platform/Shared/VMWizardOSMacView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ struct VMWizardOSMacView: View {
@State private var isFileImporterPresented = false

var body: some View {
#if os(macOS)
Text("macOS")
.font(.largeTitle)
#endif
List {
VMWizardContent("macOS") {
Section {
Text("To install macOS, you need to download a recovery IPSW. If you do not select an existing IPSW, the latest macOS IPSW will be downloaded from Apple.")
Spacer()
Expand Down
9 changes: 1 addition & 8 deletions Platform/Shared/VMWizardOSOtherView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ struct VMWizardOSOtherView: View {
@State private var isFileImporterPresented: Bool = false

var body: some View {
#if os(macOS)
Text("Other")
.font(.largeTitle)
#endif
List {
VMWizardContent("Other") {
if !wizardState.isSkipBootImage {
Section {
FileBrowseField(url: $wizardState.bootImageURL, isFileImporterPresented: $isFileImporterPresented, hasClearButton: false)
Expand All @@ -43,9 +39,6 @@ struct VMWizardOSOtherView: View {
Text("Advanced")
}
}
#if os(iOS) || os(visionOS)
.navigationTitle(Text("Other"))
#endif
.fileImporter(isPresented: $isFileImporterPresented, allowedContentTypes: [.data], onCompletion: processImage)
}

Expand Down
9 changes: 1 addition & 8 deletions Platform/Shared/VMWizardOSView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ import SwiftUI
struct VMWizardOSView: View {
@ObservedObject var wizardState: VMWizardState
var body: some View {
#if os(macOS)
Text("Operating System")
.font(.largeTitle)
#endif
List {
VMWizardContent("Operating System") {
Section {
#if os(macOS) && arch(arm64)
if #available(macOS 12, *), wizardState.useVirtualization {
Expand Down Expand Up @@ -77,9 +73,6 @@ struct VMWizardOSView: View {
}

}
#if os(iOS) || os(visionOS)
.navigationTitle(Text("Operating System"))
#endif
.buttonStyle(.inList)
}
}
Expand Down
9 changes: 1 addition & 8 deletions Platform/Shared/VMWizardOSWindowsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ struct VMWizardOSWindowsView: View {
@State private var useVhdx: Bool = false

var body: some View {
#if os(macOS)
Text("Windows")
.font(.largeTitle)
#endif
List {
VMWizardContent("Windows") {
Section {
Toggle("Install Windows 10 or higher", isOn: $wizardState.isWindows10OrHigher)
.onChange(of: wizardState.isWindows10OrHigher) { newValue in
Expand Down Expand Up @@ -121,9 +117,6 @@ struct VMWizardOSWindowsView: View {
}
}
}
#if os(iOS) || os(visionOS)
.navigationTitle(Text("Windows"))
#endif
.fileImporter(isPresented: $isFileImporterPresented, allowedContentTypes: [.data], onCompletion: processImage)
}

Expand Down
9 changes: 1 addition & 8 deletions Platform/Shared/VMWizardSharingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ struct VMWizardSharingView: View {
@State private var isFileImporterPresented: Bool = false

var body: some View {
#if os(macOS)
Text("Shared Directory")
.font(.largeTitle)
#endif
List {
VMWizardContent("Shared Directory") {
DetailedSection("Shared Directory Path", description: "Optionally select a directory to make accessible inside the VM. Note that support for shared directories varies by the guest operating system and may require additional guest drivers to be installed. See UTM support pages for more details.") {
FileBrowseField(url: $wizardState.sharingDirectoryURL, isFileImporterPresented: $isFileImporterPresented)

Expand All @@ -38,9 +34,6 @@ struct VMWizardSharingView: View {
}
}
}
#if os(iOS) || os(visionOS)
.navigationTitle(Text("Shared Directory"))
#endif
.fileImporter(isPresented: $isFileImporterPresented, allowedContentTypes: [.folder], onCompletion: processDirectory)
}

Expand Down
9 changes: 1 addition & 8 deletions Platform/Shared/VMWizardStartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ struct VMWizardStartView: View {
}

var body: some View {
#if os(macOS)
Text("Start")
.font(.largeTitle)
#endif
List {
VMWizardContent("Start") {
Section {
let virtButton = Button {
wizardState.useVirtualization = true
Expand Down Expand Up @@ -130,9 +126,6 @@ struct VMWizardStartView: View {
}

}
#if os(iOS) || os(visionOS)
.navigationTitle(Text("Start"))
#endif
}

private func processIsTranslated() -> Bool {
Expand Down
8 changes: 8 additions & 0 deletions UTM.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@
84B36D2A27B790BE00C22685 /* DestructiveButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B36D2827B790BE00C22685 /* DestructiveButton.swift */; };
84B36D2B27B790BE00C22685 /* DestructiveButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B36D2827B790BE00C22685 /* DestructiveButton.swift */; };
84BB993A2899E8D500DF28B2 /* VMHeadlessSessionState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84BB99392899E8D500DF28B2 /* VMHeadlessSessionState.swift */; };
84C2E8652AA429E800B17308 /* VMWizardContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C2E8642AA429E800B17308 /* VMWizardContent.swift */; };
84C2E8662AA429E800B17308 /* VMWizardContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C2E8642AA429E800B17308 /* VMWizardContent.swift */; };
84C2E8672AA429E800B17308 /* VMWizardContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C2E8642AA429E800B17308 /* VMWizardContent.swift */; };
84C4D9022880CA8A00EC3B2B /* VMSettingsAddDeviceMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C4D9012880CA8A00EC3B2B /* VMSettingsAddDeviceMenuView.swift */; };
84C4D9032880CA8A00EC3B2B /* VMSettingsAddDeviceMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C4D9012880CA8A00EC3B2B /* VMSettingsAddDeviceMenuView.swift */; };
84C4D9042880CA8A00EC3B2B /* VMSettingsAddDeviceMenuView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C4D9012880CA8A00EC3B2B /* VMSettingsAddDeviceMenuView.swift */; };
Expand Down Expand Up @@ -1370,6 +1373,7 @@
84B36D2427B704C200C22685 /* UTMDownloadVMTask.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UTMDownloadVMTask.swift; sourceTree = "<group>"; };
84B36D2827B790BE00C22685 /* DestructiveButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DestructiveButton.swift; sourceTree = "<group>"; };
84BB99392899E8D500DF28B2 /* VMHeadlessSessionState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VMHeadlessSessionState.swift; sourceTree = "<group>"; };
84C2E8642AA429E800B17308 /* VMWizardContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VMWizardContent.swift; sourceTree = "<group>"; };
84C4D9012880CA8A00EC3B2B /* VMSettingsAddDeviceMenuView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VMSettingsAddDeviceMenuView.swift; sourceTree = "<group>"; };
84C505AB28C588EC007CE8FF /* SizeTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SizeTextField.swift; sourceTree = "<group>"; };
84C5068528CA5702007CE8FF /* Hypervisor.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Hypervisor.framework; path = "$(SYSROOT_DIR)/Frameworks/Hypervisor.framework"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2434,6 +2438,7 @@
84C4D9012880CA8A00EC3B2B /* VMSettingsAddDeviceMenuView.swift */,
CE8813D424CD265700532628 /* VMShareFileModifier.swift */,
CE2D953824AD4F980059923A /* VMToolbarModifier.swift */,
84C2E8642AA429E800B17308 /* VMWizardContent.swift */,
CEBE820226A4C1B5007AAB12 /* VMWizardDrivesView.swift */,
CEF0307326A2B40B00667B63 /* VMWizardHardwareView.swift */,
CEF0305726A2AFDE00667B63 /* VMWizardOSLinuxView.swift */,
Expand Down Expand Up @@ -2945,6 +2950,7 @@
84B36D2527B704C200C22685 /* UTMDownloadVMTask.swift in Sources */,
8432329828C3017F00CFBC97 /* GlobalFileImporter.swift in Sources */,
84CE3DAE2904C17C00FF068B /* IASKAppSettings.swift in Sources */,
84C2E8652AA429E800B17308 /* VMWizardContent.swift in Sources */,
841E58CB28937EE200137A20 /* UTMExternalSceneDelegate.swift in Sources */,
CEB63A7A24F469E300CAF323 /* UTMJailbreak.m in Sources */,
841619B228431DA5000034B2 /* UTMQemuConfigurationQEMU.swift in Sources */,
Expand Down Expand Up @@ -3139,6 +3145,7 @@
848A98BA286A17A8006F0550 /* UTMAppleConfigurationNetwork.swift in Sources */,
84018699288B71BF0050AC51 /* BusyIndicator.swift in Sources */,
CEB54C852931E32F000D2AA9 /* UTMPatches.swift in Sources */,
84C2E8672AA429E800B17308 /* VMWizardContent.swift in Sources */,
848A98C0286A20E3006F0550 /* UTMAppleConfigurationBoot.swift in Sources */,
848D99B6286300160055C215 /* QEMUArgument.swift in Sources */,
CE2D958A24AD4F990059923A /* VMConfigSystemView.swift in Sources */,
Expand Down Expand Up @@ -3221,6 +3228,7 @@
CEA45E63263519B5002FA97D /* UTMLegacyViewState.m in Sources */,
CEA45E64263519B5002FA97D /* UTMLoggingSwift.swift in Sources */,
841619A7284315C1000034B2 /* UTMQemuConfiguration.swift in Sources */,
84C2E8662AA429E800B17308 /* VMWizardContent.swift in Sources */,
CEF0305F26A2AFDF00667B63 /* VMWizardState.swift in Sources */,
CEA45E69263519B5002FA97D /* VMConfigQEMUView.swift in Sources */,
CEA45E6A263519B5002FA97D /* VMDisplayMetalViewController+Touch.m in Sources */,
Expand Down

0 comments on commit cc582f5

Please sign in to comment.