mirror of https://github.com/cirruslabs/tart.git
Merge 9fccb59c8e into 8aa377b71e
This commit is contained in:
commit
fcfd91e126
|
|
@ -9,6 +9,7 @@ fileprivate struct VMInfo: Encodable {
|
|||
let DiskFormat: String
|
||||
let Size: String
|
||||
let Display: String
|
||||
let HideTitleBar: Bool
|
||||
let Running: Bool
|
||||
let State: String
|
||||
}
|
||||
|
|
@ -27,7 +28,7 @@ struct Get: AsyncParsableCommand {
|
|||
let vmConfig = try VMConfig(fromURL: vmDir.configURL)
|
||||
let memorySizeInMb = vmConfig.memorySize / 1024 / 1024
|
||||
|
||||
let info = VMInfo(OS: vmConfig.os, CPU: vmConfig.cpuCount, Memory: memorySizeInMb, Disk: try vmDir.sizeGB(), DiskFormat: vmConfig.diskFormat.rawValue, Size: String(format: "%.3f", Float(try vmDir.allocatedSizeBytes()) / 1000 / 1000 / 1000), Display: vmConfig.display.description, Running: try vmDir.running(), State: try vmDir.state().rawValue)
|
||||
let info = VMInfo(OS: vmConfig.os, CPU: vmConfig.cpuCount, Memory: memorySizeInMb, Disk: try vmDir.sizeGB(), DiskFormat: vmConfig.diskFormat.rawValue, Size: String(format: "%.3f", Float(try vmDir.allocatedSizeBytes()) / 1000 / 1000 / 1000), Display: vmConfig.display.description, HideTitleBar: vmConfig.hideTitleBar, Running: try vmDir.running(), State: try vmDir.state().rawValue)
|
||||
print(format.renderSingle(info))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,21 @@ var vm: VM?
|
|||
struct IPNotFound: Error {
|
||||
}
|
||||
|
||||
extension View {
|
||||
/// Apply `transform` only if `condition` is true, otherwise leave self unchanged.
|
||||
@ViewBuilder
|
||||
func conditional<Content: View>(
|
||||
_ condition: Bool,
|
||||
_ transform: (Self) -> Content
|
||||
) -> some View {
|
||||
if condition {
|
||||
transform(self)
|
||||
} else {
|
||||
self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 14, *)
|
||||
extension VZDiskSynchronizationMode {
|
||||
public init(_ description: String) throws {
|
||||
|
|
@ -754,16 +769,12 @@ struct Run: AsyncParsableCommand {
|
|||
private func runUI(_ suspendable: Bool, _ captureSystemKeys: Bool) {
|
||||
MainApp.suspendable = suspendable
|
||||
MainApp.capturesSystemKeys = captureSystemKeys
|
||||
MainApp.hideTitleBar = vm!.config.hideTitleBar
|
||||
MainApp.main()
|
||||
}
|
||||
}
|
||||
|
||||
struct MainApp: App {
|
||||
static var suspendable: Bool = false
|
||||
static var capturesSystemKeys: Bool = false
|
||||
|
||||
@NSApplicationDelegateAdaptor private var appDelegate: AppDelegate
|
||||
|
||||
struct CommonScene: Scene {
|
||||
var body: some Scene {
|
||||
WindowGroup(vm!.name) {
|
||||
Group {
|
||||
|
|
@ -786,6 +797,7 @@ struct MainApp: App {
|
|||
idealHeight: CGFloat(vm!.config.display.height),
|
||||
maxHeight: .infinity
|
||||
)
|
||||
.conditional(MainApp.hideTitleBar) { $0.ignoresSafeArea() }
|
||||
}.commands {
|
||||
// Remove some standard menu options
|
||||
CommandGroup(replacing: .help, addition: {})
|
||||
|
|
@ -818,6 +830,38 @@ struct MainApp: App {
|
|||
}
|
||||
}
|
||||
|
||||
struct HideTitleBarApp: App {
|
||||
@NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
|
||||
|
||||
var body: some Scene {
|
||||
CommonScene()
|
||||
.windowStyle(.hiddenTitleBar)
|
||||
}
|
||||
}
|
||||
|
||||
struct ShowTitleBarApp: App {
|
||||
@NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate
|
||||
|
||||
var body: some Scene {
|
||||
CommonScene()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct MainApp {
|
||||
static var suspendable: Bool = false
|
||||
static var capturesSystemKeys: Bool = false
|
||||
static var hideTitleBar: Bool = false
|
||||
|
||||
static func main() {
|
||||
if hideTitleBar {
|
||||
HideTitleBarApp.main()
|
||||
} else {
|
||||
ShowTitleBarApp.main()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
|
||||
func applicationDidFinishLaunching(_ : Notification) {
|
||||
let nsApp = NSApplication.shared
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ struct Set: AsyncParsableCommand {
|
|||
"""))
|
||||
var diskSize: UInt16?
|
||||
|
||||
@Flag(inversion: .prefixedNo, help: ArgumentHelp("Whether to hide the title bar and ignore safe area for fullscreen style"))
|
||||
var hideTitleBar: Bool? = nil
|
||||
|
||||
func run() async throws {
|
||||
let vmDir = try VMStorageLocal().open(name)
|
||||
var vmConfig = try VMConfig(fromURL: vmDir.configURL)
|
||||
|
|
@ -61,6 +64,10 @@ struct Set: AsyncParsableCommand {
|
|||
|
||||
vmConfig.displayRefit = displayRefit
|
||||
|
||||
if let hideTitleBar = hideTitleBar {
|
||||
vmConfig.hideTitleBar = hideTitleBar
|
||||
}
|
||||
|
||||
if randomMAC {
|
||||
vmConfig.macAddress = VZMACAddress.randomLocallyAdministered()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ enum CodingKeys: String, CodingKey {
|
|||
case display
|
||||
case displayRefit
|
||||
case diskFormat
|
||||
case hideTitleBar
|
||||
|
||||
// macOS-specific keys
|
||||
case ecid
|
||||
|
|
@ -66,6 +67,7 @@ struct VMConfig: Codable {
|
|||
var display: VMDisplayConfig = VMDisplayConfig()
|
||||
var displayRefit: Bool?
|
||||
var diskFormat: DiskImageFormat = .raw
|
||||
var hideTitleBar: Bool = false
|
||||
|
||||
init(
|
||||
platform: Platform,
|
||||
|
|
@ -140,6 +142,7 @@ struct VMConfig: Codable {
|
|||
displayRefit = try container.decodeIfPresent(Bool.self, forKey: .displayRefit)
|
||||
let diskFormatString = try container.decodeIfPresent(String.self, forKey: .diskFormat) ?? "raw"
|
||||
diskFormat = DiskImageFormat(rawValue: diskFormatString) ?? .raw
|
||||
hideTitleBar = try container.decodeIfPresent(Bool.self, forKey: .hideTitleBar) ?? false
|
||||
}
|
||||
|
||||
func encode(to encoder: Encoder) throws {
|
||||
|
|
@ -159,6 +162,7 @@ struct VMConfig: Codable {
|
|||
try container.encode(displayRefit, forKey: .displayRefit)
|
||||
}
|
||||
try container.encode(diskFormat.rawValue, forKey: .diskFormat)
|
||||
try container.encode(hideTitleBar, forKey: .hideTitleBar)
|
||||
}
|
||||
|
||||
mutating func setCPU(cpuCount: Int) throws {
|
||||
|
|
|
|||
Loading…
Reference in New Issue