From cb68a16be2e0096ea1a3d94ba03fd506a2fee7ba Mon Sep 17 00:00:00 2001 From: Catta1997 Date: Tue, 13 Aug 2024 21:25:38 +0200 Subject: [PATCH] onInstall check --- PlayCover/AppInstaller/Installer.swift | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/PlayCover/AppInstaller/Installer.swift b/PlayCover/AppInstaller/Installer.swift index 4ed7981d2..f2bb327ee 100644 --- a/PlayCover/AppInstaller/Installer.swift +++ b/PlayCover/AppInstaller/Installer.swift @@ -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: "") @@ -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)