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

Remove keymap checks #517

Merged
merged 7 commits into from Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
41 changes: 34 additions & 7 deletions PlayCover/Model/Keymapping.swift
Expand Up @@ -9,6 +9,27 @@ import AppKit
import Foundation
import UniformTypeIdentifiers

extension NSAlert {
static func differentBundleIdKeymap() -> Bool {
ZhichGaming marked this conversation as resolved.
Show resolved Hide resolved
let alert = NSAlert()
alert.messageText = NSLocalizedString("alert.differentBundleIdKeymap.message", comment: "")
alert.informativeText = NSLocalizedString("alert.differentBundleIdKeymap.text", comment: "")
alert.alertStyle = .warning
alert.addButton(withTitle: NSLocalizedString("button.Proceed", comment: ""))
alert.addButton(withTitle: NSLocalizedString("button.Cancel", comment: ""))

let result = alert.runModal()
switch result {
case .alertFirstButtonReturn:
return true
case .alertSecondButtonReturn:
return false
default:
return false
}
}
}

struct KeyModelTransform: Codable {
var size: CGFloat
var xCoord: CGFloat
Expand Down Expand Up @@ -117,21 +138,27 @@ class Keymapping {
self.keymap = importedKeymap
success(true)
} else {
Log.shared.error("Keymapping created for different app!")
success(false)
if NSAlert.differentBundleIdKeymap() {
self.keymap = importedKeymap
success(true)
} else {
success(false)
}
}
}
} catch {
if let selectedPath = openPanel.url {
if let keymap = LegacySettings.convertLegacyKeymapFile(selectedPath) {
if keymap.bundleIdentifier == self.keymap.bundleIdentifier {
self.keymap = keymap
success(true)
} else {
Log.shared.error("Keymapping created for different app! " +
"Legacy keymap files must be named after " +
"the Bundle ID of the intended application!")
success(false)
} else {
if NSAlert.differentBundleIdKeymap() {
self.keymap = keymap
success(true)
} else {
success(false)
}
}
} else {
success(false)
Expand Down
2 changes: 2 additions & 0 deletions PlayCover/en.lproj/Localizable.strings
Expand Up @@ -97,6 +97,8 @@
"alert.install.injectPlayToolsQuestion" = "Do you want to inject PlayTools into this application?";
"alert.install.playToolsInformative" = "PlayTools is a tool that allows you to bind keys to screen touches, custom display resolutions, and more, but it may break certain apps";
"alert.supression" = "You can change this in the PlayCover preferences";
"alert.differentBundleIdKeymap.message" = "The name of the keymap is different from the bundle ID of the app!";
ZhichGaming marked this conversation as resolved.
Show resolved Hide resolved
"alert.differentBundleIdKeymap.text" = "The keymap may have been created for another application.";

"button.OK" = "OK";
"button.Proceed" = "Proceed";
Expand Down