Skip to content

Commit

Permalink
config: reset new drive config each time
Browse files Browse the repository at this point in the history
This also fixes the bug where on iOS, it was not possible to change the
interface for a new drive.

Fixes #2384
  • Loading branch information
osy committed Mar 16, 2021
1 parent ac80212 commit d82ce72
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
5 changes: 1 addition & 4 deletions Platform/Shared/VMConfigDriveCreateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ struct VMConfigDriveCreateView: View {
Toggle(isOn: $driveImage.removable.animation(), label: {
Text("Removable")
}).onChange(of: driveImage.removable) { removable in
driveImage.imageType = removable ? .CD : .disk
driveImage.interface = UTMConfiguration.defaultDriveInterface(forTarget: target, type: driveImage.imageType)
driveImage.reset(forSystemTarget: target, removable: removable)
}
VMConfigStringPicker(selection: $driveImage.interface, label: Text("Interface"), rawValues: UTMConfiguration.supportedDriveInterfaces(), displayValues: UTMConfiguration.supportedDriveInterfacesPretty())
if !driveImage.removable {
Expand All @@ -50,8 +49,6 @@ struct VMConfigDriveCreateView: View {
}).buttonStyle(PlainButtonStyle())
}
}
}.onAppear() {
driveImage.interface = UTMConfiguration.defaultDriveInterface(forTarget: target, type: driveImage.imageType)
}
}

Expand Down
7 changes: 7 additions & 0 deletions Platform/Shared/VMDriveImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,11 @@ class VMDriveImage: ObservableObject {
imageTypeString = newValue.description
}
}

func reset(forSystemTarget target: String?, removable: Bool) {
self.removable = removable
self.imageType = removable ? .CD : .disk
self.interface = UTMConfiguration.defaultDriveInterface(forTarget: target, type: imageType)
self.size = removable ? 0 : 10240
}
}
3 changes: 3 additions & 0 deletions Platform/iOS/VMConfigDrivesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ private struct CreateDrive: View {
Text("Done")
}))
}.navigationViewStyle(StackNavigationViewStyle())
.onAppear {
driveImage.reset(forSystemTarget: target, removable: false)
}
}

private func cancel() {
Expand Down
5 changes: 5 additions & 0 deletions Platform/macOS/VMConfigDrivesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ struct VMConfigDrivesView: View {
Button(action: { newDrivePopover.toggle() }, label: {
Label("New Drive", systemImage: "plus").labelStyle(TitleOnlyLabelStyle())
})
.onChange(of: newDrivePopover, perform: { showPopover in
if showPopover {
newDrive.reset(forSystemTarget: config.systemTarget, removable: false)
}
})
.popover(isPresented: $newDrivePopover, arrowEdge: .bottom) {
VStack {
VMConfigDriveCreateView(target: config.systemTarget, driveImage: newDrive)
Expand Down

0 comments on commit d82ce72

Please sign in to comment.