Skip to content

Commit

Permalink
removed unused import + added check on install
Browse files Browse the repository at this point in the history
  • Loading branch information
Catta1997 committed Aug 3, 2024
1 parent 8bcf74f commit 9f844e4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions PlayCover/AppInstaller/Downloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,44 @@ class DownloadApp {
let installVM = InstallVM.shared
let downloader = DownloadManager.shared

func hasMacVersion() -> Bool {
let noMacAlert = UserDefaults.standard.bool(forKey: "\(String(describing: app?.bundleID)).noMacAlert")
if let app = app, PlayApp.MACOS_APPS.contains(app.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: "\(app.bundleID).noMacAlert")
case .alertSecondButtonReturn:
Task {
let urlString = "https://itunes.apple.com/lookup?bundleId=\(app.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
}

Check failure on line 70 in PlayCover/AppInstaller/Downloader.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Trailing Whitespace Violation: Lines should not have trailing whitespace (trailing_whitespace)
func start() {
if installVM.inProgress {
Log.shared.error(PlayCoverError.waitInstallation)
} else {
if hasMacVersion() {return}
if let warningMessage = warning, let app = app {
let alert = NSAlert()
alert.messageText = NSLocalizedString(warningMessage, comment: "")
Expand Down
1 change: 0 additions & 1 deletion PlayCover/Model/PlayApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import Cocoa
import Foundation
import IOKit.pwr_mgt
import StoreKit

class PlayApp: BaseApp {
public static let bundleIDCacheURL = PlayTools.playCoverContainer.appendingPathComponent("CACHE")
Expand Down
1 change: 1 addition & 0 deletions PlayCover/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,5 @@

"macos.version" = "This app can be installed from Mac App Store";
"alert.start.anyway" = "Start Anyway";
"alert.install.anyway" = "Install Anyway";
"alert.open.appstore" = "Open Mac App Store";

0 comments on commit 9f844e4

Please sign in to comment.