Skip to content

Commit

Permalink
registry: support saving dynamic resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
osy committed Nov 20, 2024
1 parent c4b7c14 commit 367008d
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions Services/UTMRegistryEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ import Combine
@Published private var _windowSettings: [Int: Window]

@Published private var _terminalSettings: [Int: Terminal]


@Published private var _resolutionSettings: [Int: Resolution]

@Published private var _hasMigratedConfig: Bool

@Published private var _macRecoveryIpsw: File?
Expand All @@ -50,6 +52,7 @@ import Combine
case sharedDirectories = "SharedDirectories"
case windowSettings = "WindowSettings"
case terminalSettings = "TerminalSettings"
case resolutionSettings = "ResolutionSettings"
case hasMigratedConfig = "MigratedConfig"
case macRecoveryIpsw = "MacRecoveryIpsw"
}
Expand All @@ -69,6 +72,7 @@ import Combine
_sharedDirectories = []
_windowSettings = [:]
_terminalSettings = [:]
_resolutionSettings = [:]
_hasMigratedConfig = false
}

Expand All @@ -89,6 +93,7 @@ import Combine
_sharedDirectories = try container.decode([File].self, forKey: .sharedDirectories).filter({ $0.isValid })
_windowSettings = try container.decode([Int: Window].self, forKey: .windowSettings)
_terminalSettings = try container.decodeIfPresent([Int: Terminal].self, forKey: .terminalSettings) ?? [:]
_resolutionSettings = try container.decodeIfPresent([Int: Resolution].self, forKey: .resolutionSettings) ?? [:]
_hasMigratedConfig = try container.decodeIfPresent(Bool.self, forKey: .hasMigratedConfig) ?? false
_macRecoveryIpsw = try container.decodeIfPresent(File.self, forKey: .macRecoveryIpsw)
}
Expand All @@ -103,6 +108,7 @@ import Combine
try container.encode(_sharedDirectories, forKey: .sharedDirectories)
try container.encode(_windowSettings, forKey: .windowSettings)
try container.encode(_terminalSettings, forKey: .terminalSettings)
try container.encode(_resolutionSettings, forKey: .resolutionSettings)
if _hasMigratedConfig {
try container.encode(_hasMigratedConfig, forKey: .hasMigratedConfig)
}
Expand Down Expand Up @@ -201,7 +207,17 @@ extension UTMRegistryEntry: UTMRegistryEntryDecodable {}
_terminalSettings = newValue
}
}


var resolutionSettings: [Int: Resolution] {
get {
_resolutionSettings
}

set {
_resolutionSettings = newValue
}
}

var hasMigratedConfig: Bool {
get {
_hasMigratedConfig
Expand Down Expand Up @@ -254,6 +270,7 @@ extension UTMRegistryEntry: UTMRegistryEntryDecodable {}
sharedDirectories = other.sharedDirectories
windowSettings = other.windowSettings
terminalSettings = other.terminalSettings
resolutionSettings = other.resolutionSettings
hasMigratedConfig = other.hasMigratedConfig
}

Expand Down Expand Up @@ -493,4 +510,29 @@ extension UTMRegistryEntry {
try container.encode(rows, forKey: .rows)
}
}

struct Resolution: Codable, Equatable {
var size: CGSize = .zero

var isFullscreen: Bool = false

private enum CodingKeys: String, CodingKey {
case size = "Size"
case isFullscreen = "Fullscreen"
}

init() {}

init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
size = try container.decode(CGSize.self, forKey: .size)
isFullscreen = try container.decode(Bool.self, forKey: .isFullscreen)
}

func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(size, forKey: .size)
try container.encode(isFullscreen, forKey: .isFullscreen)
}
}
}

0 comments on commit 367008d

Please sign in to comment.