-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e87bbe0
commit c3ce997
Showing
37 changed files
with
750 additions
and
2,178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// Features.swift | ||
// Pearcleaner | ||
// | ||
// Created by Alin Lupascu on 3/1/24. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
func getFeatures(appState: AppState, show: Binding<Bool>, features: Binding<String>) { | ||
|
||
let url = URL(string: "https://api.github.com/repos/alienator88/Pearcleaner/contents/features.json")! | ||
var request = URLRequest(url: url) | ||
request.setValue("application/vnd.github.VERSION.raw", forHTTPHeaderField: "Accept") | ||
request.setValue("2022-11-28", forHTTPHeaderField: "X-GitHub-Api-Version") | ||
|
||
URLSession.shared.dataTask(with: request) { data, response, error in | ||
if let data = data { | ||
do { | ||
let jsonObject = try JSONSerialization.jsonObject(with: data, options: []) | ||
if let jsonDict = jsonObject as? [String: String], | ||
let bundleVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String, | ||
let featureText = jsonDict[bundleVersion] { | ||
if features.wrappedValue != featureText.featureFormat() { | ||
updateOnMain { | ||
features.wrappedValue = featureText.featureFormat() | ||
show.wrappedValue = true | ||
} | ||
} else { | ||
show.wrappedValue = false | ||
// print("Same version") | ||
} | ||
|
||
} else { | ||
show.wrappedValue = false | ||
// print("No features for version found") | ||
} | ||
} catch { | ||
show.wrappedValue = false | ||
printOS("Error reading features JSON from GitHub: \(error.localizedDescription)") | ||
} | ||
} else { | ||
show.wrappedValue = false | ||
printOS("Error reading features JSON from GitHub: \(error?.localizedDescription ?? "Unknown error")") | ||
} | ||
}.resume() | ||
} | ||
|
Oops, something went wrong.