Skip to content

Commit

Permalink
onInstall check
Browse files Browse the repository at this point in the history
  • Loading branch information
Catta1997 committed Aug 13, 2024
1 parent 76be3b5 commit cb68a16
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions PlayCover/AppInstaller/Installer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,40 @@ import Foundation

class Installer {

@MainActor
static func hasMacVersion(bundleID: String) async -> Bool {
let noMacAlert = UserDefaults.standard.bool(forKey: "\(bundleID).noMacAlert")
if PlayApp.MACOS_APPS.contains(bundleID), !noMacAlert {
let alert = NSAlert()
alert.messageText = NSLocalizedString("alert.error", comment: "")
alert.informativeText = String(
format: NSLocalizedString("macos.version", comment: "")
)
alert.alertStyle = .warning
alert.addButton(withTitle: NSLocalizedString("alert.install.anyway", comment: ""))
alert.addButton(withTitle: NSLocalizedString("alert.open.appstore", comment: ""))
alert.addButton(withTitle: NSLocalizedString("button.Cancel", comment: ""))
let result = alert.runModal()
switch result {
case .alertFirstButtonReturn:
UserDefaults.standard.set(true, forKey: "\(bundleID).noMacAlert")
case .alertSecondButtonReturn:
Task {
let urlString = "https://itunes.apple.com/lookup?bundleId=\(bundleID)"
let itunes: ITunesResponse? = await getITunesData(urlString)
guard let appID = itunes?.results.first?.trackId else {return}
if let appLink: URL = URL(string: "itms-apps://apps.apple.com/app/id\(appID)") {
NSWorkspace.shared.open(appLink)
}
}
return true
default:
return true
}
}
return false
}

static func installPlayToolsPopup() -> Bool {
let alert = NSAlert()
alert.messageText = NSLocalizedString("alert.install.injectPlayToolsQuestion", comment: "")
Expand Down Expand Up @@ -59,6 +93,12 @@ class Installer {
try ipa.allocateTempDir()

let app = try ipa.unzip()
if await hasMacVersion(bundleID: app.info.bundleIdentifier) {
ipa.releaseTempDir()
InstallVM.shared.next(.failed, 0.95, 1.0)
returnCompletion(nil)
return
}
InstallVM.shared.next(.library, 0.5, 0.55)
try saveEntitlements(app)
let machos = resolveValidMachOs(app)
Expand Down

0 comments on commit cb68a16

Please sign in to comment.