Skip to content

Commit ef62916

Browse files
committed
fix: icons that may not appear due to blocking main thread
chore: some code cleanup
1 parent 5dc28df commit ef62916

File tree

8 files changed

+29
-57
lines changed

8 files changed

+29
-57
lines changed

Loader/AppDelegate.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1919
// MARK: UISceneSession Lifecycle
2020

2121
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
22-
// Called when a new scene session is being created.
23-
// Use this method to select a configuration to create the new scene with.
24-
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
25-
}
26-
27-
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
28-
// Called when the user discards a scene session.
29-
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
30-
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
22+
UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
3123
}
3224

3325
func applicationWillTerminate(_ application: UIApplication) {

Loader/Extensions/UIDevice/UIDevice+Info.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ extension UIDevice {
2727

2828
/// The devices architecture (e.g. arm64).
2929
var architecture: String {
30-
return String(cString: NXGetLocalArchInfo().pointee.name)
30+
String(cString: NXGetLocalArchInfo().pointee.name)
3131
}
3232

3333
/// The devices marketing model (e.g. iPhone 7)
3434
var marketingModel: String {
35-
return MGCopyAnswer(kMGPhysicalHardwareNameString)?.takeUnretainedValue() as? String ?? "Unknown"
35+
MGCopyAnswer(kMGPhysicalHardwareNameString)?.takeUnretainedValue() as? String ?? "Unknown"
3636
}
3737

3838
var kernelVersion: String {

Loader/Extensions/UIDevice/UIDevice+Jailbreak.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extension UIDevice {
2424

2525
/// See flags in string format
2626
var flags: String {
27-
return String(format: "0x%llx", LREnvironment.jbd.getFlags())
27+
String(format: "0x%llx", LREnvironment.jbd.getFlags())
2828
}
2929
/// See flags in a string-list format
3030
var flagsList: String {

Loader/SceneDelegate.swift

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import UIKit
99

1010
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
11-
1211
var window: UIWindow?
1312

1413
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
@@ -26,35 +25,5 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
2625
window.makeKeyAndVisible()
2726
self.window = window
2827
}
29-
30-
func sceneDidDisconnect(_ scene: UIScene) {
31-
// Called as the scene is being released by the system.
32-
// This occurs shortly after the scene enters the background, or when its session is discarded.
33-
// Release any resources associated with this scene that can be re-created the next time the scene connects.
34-
// The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
35-
}
36-
37-
func sceneDidBecomeActive(_ scene: UIScene) {
38-
// Called when the scene has moved from an inactive state to an active state.
39-
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
40-
}
41-
42-
func sceneWillResignActive(_ scene: UIScene) {
43-
// Called when the scene will move from an active state to an inactive state.
44-
// This may occur due to temporary interruptions (ex. an incoming phone call).
45-
}
46-
47-
func sceneWillEnterForeground(_ scene: UIScene) {
48-
// Called as the scene transitions from the background to the foreground.
49-
// Use this method to undo the changes made on entering the background.
50-
}
51-
52-
func sceneDidEnterBackground(_ scene: UIScene) {
53-
// Called as the scene transitions from the foreground to the background.
54-
// Use this method to save data, release shared resources, and store enough scene-specific state information
55-
// to restore the scene back to its current state.
56-
}
57-
58-
5928
}
6029

Loader/Utilities/Config/Models/LRConfig.swift

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,24 @@ struct LRManager: Codable {
131131
/// Package manager image representation uri
132132
let icon: URL
133133
/// Package manager install path
134-
/// Useful for detecting if it is installed, due to them having a common path we're able to keep track of
135134
let filePath: URL
136135

137-
func loadIconImage() -> UIImage {
138-
guard
139-
let data = try? Data(contentsOf: icon),
140-
let image = UIImage(data: data)
141-
else {
142-
return UIImage(named: "unknown")!
143-
}
144-
return image
136+
/// Asynchronously load the icon image
137+
func loadIconImage(completion: @escaping (UIImage) -> Void) {
138+
URLSession.shared.dataTask(with: icon) { data, response, error in
139+
if
140+
let data = data,
141+
let image = UIImage(data: data)
142+
{
143+
DispatchQueue.main.async {
144+
completion(image)
145+
}
146+
} else {
147+
DispatchQueue.main.async {
148+
completion(UIImage(named: "unknown")!)
149+
}
150+
}
151+
}.resume()
145152
}
146153
}
147154

Loader/Views/Selection/LRBootstrapViewController.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ extension LRBootstrapViewController {
149149

150150
cell.textLabel?.text = manager?.name
151151
cell.accessoryType = .disclosureIndicator
152-
cell.setSectionImage(with: manager?.loadIconImage() ?? UIImage(named: "unknown")!)
152+
cell.setSectionImage(with: UIImage(named: "unknown")!)
153+
154+
manager?.loadIconImage { image in
155+
cell.setSectionImage(with: image)
156+
}
153157

154158
return cell
155159
}

Loader/Views/Settings/Credits/LRSettingsCreditsViewController.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ class LRSettingsCreditsViewController: LRBaseTableViewController {
7474
// MARK: - Class extension: tableview
7575
extension LRSettingsCreditsViewController {
7676
override func numberOfSections(in tableView: UITableView) -> Int {
77-
return _data.count
77+
_data.count
7878
}
7979

8080
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
81-
return _data[section].data.count
81+
_data[section].data.count
8282
}
8383

8484
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
85-
return _data[section].name
85+
_data[section].name
8686
}
8787

8888
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

Loader/Views/Settings/LRSettingsViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class LRSettingsViewController: LRBaseStructuredTableViewController {
102102
}
103103
}
104104

105-
var style: UIAlertController.Style = UIDevice.current.userInterfaceIdiom == .pad
105+
let style: UIAlertController.Style = UIDevice.current.userInterfaceIdiom == .pad
106106
? .alert
107107
: .actionSheet
108108

0 commit comments

Comments
 (0)