Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix keymapping not updating #405

Merged
merged 1 commit into from Oct 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 23 additions & 34 deletions PlayCover/Model/Keymapping.swift
Expand Up @@ -60,50 +60,39 @@ class Keymapping {
let keymapURL: URL
var container: AppContainer?
var keymap: Keymap {
didSet {
encode()
get {
do {
let data = try Data(contentsOf: keymapURL)
let map = try PropertyListDecoder().decode(Keymap.self, from: data)
return map
} catch {
print(error)
return reset()
}
}
set {
let encoder = PropertyListEncoder()
encoder.outputFormat = .xml

do {
let data = try encoder.encode(newValue)
try data.write(to: keymapURL)
} catch {
print(error)
}
}
}

init(_ info: AppInfo, container: AppContainer?) {
self.info = info
self.container = container
keymapURL = Keymapping.keymappingDir.appendingPathComponent("\(info.bundleIdentifier).plist")
keymap = Keymap(bundleIdentifier: info.bundleIdentifier)
if !decode() {
encode()
}
}

public func reset() {
keymap = Keymap(bundleIdentifier: info.bundleIdentifier)
}

@discardableResult
public func decode() -> Bool {
do {
let data = try Data(contentsOf: keymapURL)
keymap = try PropertyListDecoder().decode(Keymap.self, from: data)
return true
} catch {
print(error)
return false
}
}

@discardableResult
public func encode() -> Bool {
let encoder = PropertyListEncoder()
encoder.outputFormat = .xml

do {
let data = try encoder.encode(keymap)
try data.write(to: keymapURL)
return true
} catch {
print(error)
return false
}
public func reset() -> Keymap {
keymap = Keymap(bundleIdentifier: info.bundleIdentifier)
return keymap
}

public func importKeymap(success: @escaping (Bool) -> Void) {
Expand Down