Skip to content

Commit 9afcb06

Browse files
committed
Minor tweaks
1 parent 79eeed0 commit 9afcb06

14 files changed

+135
-52
lines changed

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ UpgradeAlert.showAlert(appInfo: .init(version: "1.0.1", trackViewUrl: "https://a
9797
- Doc params
9898
- Clean up comments
9999
- Add support for swiftui
100-
101-
## License
102-
This project is licensed under the terms of the MIT license. See the [LICENSE](LICENSE) file.
100+
- Error Handling and Reporting: The current implementation of error handling in various parts of the codebase could be improved for better clarity and functionality. For instance: UpgradeAlert.swift: The method checkForUpdates uses a simple closure that returns an optional error. This could be enhanced by using a Result type to make the success and error handling paths clearer and more robust.
101+
- UIAlertController+Ext.swift: The present method does not handle the scenario where there is no view controller available to present the alert. This could lead to silent failures in presenting critical update alerts.
102+
- Refactoring and Code Simplification_ Refactoring some parts of the code could improve readability and maintainability. For example: UpgradeAlert+Variables.swift: The method for generating the request URL could be simplified or made more robust by handling potential errors more gracefully.
103+
- NSAlert+Ext.swift: The method for presenting alerts in macOS could be refactored to reduce duplication and improve error handling.
104+
- Testing and Coverage Improving tests to cover edge cases and error scenarios would enhance the reliability of the application. For instance:
105+
- UpgradeAlertTests.swift: The test cases could be expanded to cover more scenarios, including error handling and user interaction outcomes.

Sources/UpgradeAlert/UpgradeAlert+Variables.swift

+16-8
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import Foundation
55
extension UpgradeAlert {
66
/**
77
* Computed property to generate the request URL for app information.
8-
* It uses the bundle identifier of the current app to create the URL.
9-
* - Description: This property constructs a URL used to fetch information about the application from the iTunes API based on the application's bundle identifier.
8+
* - Note: It uses the bundle identifier of the current app to create the URL.
9+
* - Description: This property constructs a URL used to fetch information
10+
* about the application from the iTunes API based on the
11+
* application's bundle identifier.
1012
* - Returns: A URL pointing to the app's information on iTunes.
1113
* - Note: This URL might need a country code for region-specific apps.
1214
* - Fixme: ⚠️️ Consider renaming this to appInfoRequestURL for clarity.
@@ -24,7 +26,8 @@ extension UpgradeAlert {
2426
extension UpgradeAlert {
2527
/**
2628
* Typealias for a function that generates an alert message.
27-
* - Description: Defines a function type used to generate a custom alert message based on the app's name and version.
29+
* - Description: Defines a function type used to generate a custom alert
30+
* message based on the app's name and version.
2831
* - Parameters:
2932
* - appName: The name of the app. This can be nil.
3033
* - version: The version of the app.
@@ -34,16 +37,20 @@ extension UpgradeAlert {
3437
public typealias AlertMessage = (_ appName: String?, _ version: String) -> String
3538
/**
3639
* Typealias for a completion handler function.
37-
* - Description: Defines a closure used as a completion handler to process the outcome of an update check or alert interaction.
40+
* - Description: Defines a closure used as a completion handler to process
41+
* the outcome of an update check or alert interaction.
3842
* - Parameters:
39-
* - outcome: The outcome of the operation, encapsulated in a UAOutcome object.
43+
* - outcome: The outcome of the operation, encapsulated in a UAOutcome object.
4044
* - Note: This function does not return a value.
4145
*/
4246
public typealias Complete = (_ outcome: UAOutcome) -> Void
4347
/**
4448
* Default completion handler function.
45-
* This function simply prints the outcome of the operation.
46-
* - Description: This default completion handler logs the outcome of the operation to the console, providing a simple way to observe the results of the update check or alert interaction.
49+
* - Abstract: This function simply prints the outcome of the operation.
50+
* - Description: This default completion handler logs the outcome of the
51+
* operation to the console, providing a simple way to
52+
* observe the results of the update check or alert
53+
* interaction.
4754
*/
4855
public static let defaultComplete: Complete = { (outcome: UAOutcome) in
4956
Swift.print("default complete - outcome: \(String(describing: outcome))")
@@ -55,7 +62,8 @@ extension UpgradeAlert {
5562
extension UpgradeAlert {
5663
/**
5764
* Static property to hold the configuration for UpgradeAlert.
58-
* - Description: Holds the configuration settings for the UpgradeAlert system, which can be customized as needed.
65+
* - Description: Holds the configuration settings for the UpgradeAlert
66+
* system, which can be customized as needed.
5967
* - Note: By default, it uses the default configuration defined in UAConfig.
6068
*/
6169
public static var config: UAConfig = .defaultConfig

Sources/UpgradeAlert/UpgradeAlert.swift

+16-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import UIKit
55
import Cocoa
66
#endif
77
/**
8-
* - Description: The `UpgradeAlert` class is responsible for managing the update notification process within an application. It checks for new versions of the app on the App Store, compares it with the current version, and alerts the user if an update is necessary.
8+
* - Description: The `UpgradeAlert` class manages the update notification
9+
* process within an application. It checks for new versions of
10+
* the app on the App Store, compares it with the current
11+
* version, and alerts the user if an update is necessary.
912
* - Remark: What if a user doesn't want to update and there is no other option than to update?
1013
* - Remark: If the app always show popup when getting focus. Then activate flight-mode. Launch the app again.
1114
* - Remark: Title and message are optional, default values are used if nil etc
@@ -18,13 +21,21 @@ public final class UpgradeAlert {}
1821
extension UpgradeAlert {
1922
/**
2023
* Check for updates
21-
* - Description: Initiates a check for new versions of the app available on the App Store. If a newer version is found, it prompts the user with an update alert.
24+
* - Description: Initiates a check for new versions of the app available
25+
* on the App Store. If a newer version is found, it prompts
26+
* the user with an update alert.
2227
* - Remark: shows alert with one or two btns
23-
* - Parameter: withConfirmation You can force the update by calling, Or the user can choose if they want to update now or later by calling
24-
* - Remark: Version of the app you want to mark for the update. For example, 1.0.0 // This is the version you want the user to force upgrade to a newer version.
28+
* - Remark: Version of the app you want to mark for the update.
29+
* For example, 1.0.0 // This is the version you want the user
30+
* to force upgrade to a newer version.
2531
* - Fixme: ⚠️️ Add onAppStoreOpenComplete -> ability to track how many update etc
2632
* - Fixme: ⚠️️ Use Result instead etc
27-
* - Parameter complete: A closure that is called when the update check is complete. It returns an optional AppInfo object and an optional NSError object. If an error occurs during the update check, the NSError object describes the error. If the update check is successful, the AppInfo object contains information about the app.
33+
* - Parameter complete: A closure that is called when the update check
34+
* is complete. It returns an optional AppInfo object
35+
* and an optional NSError object. If an error occurs
36+
* during the update check, the NSError object describes
37+
* the error. If the update check is successful, the
38+
* AppInfo object contains information about the app.
2839
*/
2940
public static func checkForUpdates(complete: Complete? = defaultComplete) { // complete: (_ appInfo: AppInfo?, error: NSError?)
3041
// Perform network calls on a background thread

Sources/UpgradeAlert/ext/Bundle+Ext.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ extension Bundle {
3030
/**
3131
* Tests if an app is in beta
3232
* - Abstract: determines if beta from receipt
33-
* - Description: Determines if the application is a beta version by checking the app store receipt URL for specific substrings that identify simulator or TestFlight environments.
33+
* - Description: Determines if the application is a beta version by
34+
* checking the app store receipt URL for specific substrings that
35+
* identify simulator or TestFlight environments.
3436
* - Note: From here: https://stackoverflow.com/a/38984554/5389500
3537
* - Note: More complex example: https://stackoverflow.com/a/33830605/5389500
3638
* - Note: Another example: https://stackoverflow.com/a/59047187/5389500

Sources/UpgradeAlert/ext/NSAlert+Ext.swift

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import Cocoa
44
extension NSAlert {
55
/**
66
* Presents a warning alert to the user with customizable text, buttons, and completion handler.
7-
* - Description: Displays a modal alert dialog on macOS with customizable titles for the buttons and a completion handler to capture the user's response.
7+
* - Description: Displays a modal alert dialog on macOS with customizable
8+
* titles for the buttons and a completion handler to capture
9+
* the user's response.
810
* ## Examples:
911
* NSAlert.present(question: "Ok?", text: "Choose your answer.") { answer in
1012
* print(answer)
@@ -15,8 +17,11 @@ extension NSAlert {
1517
* - text: The informative text of the alert.
1618
* - okTitle: The text for the OK button. Defaults to "OK".
1719
* - cancelTitle: The text for the cancel button. Defaults to "Cancel".
18-
* - view: The view to present the alert from. If nil, the alert is presented from the first window of the application.
19-
* - complete: A closure that is called when the user dismisses the alert. The closure takes a single Boolean parameter that is true if the user clicked the OK button and false otherwise.
20+
* - view: The view to present the alert from. If nil, the alert is
21+
* presented from the first window of the application.
22+
* - complete: A closure that is called when the user dismisses the alert.
23+
* The closure takes a single Boolean parameter that is true if
24+
* the user clicked the OK button and false otherwise.
2025
*/
2126
internal static func present(question: String, text: String, okTitle: String? = "OK", cancelTitle: String? = "Cancel", view: NSView? = nil, complete: ((_ answer: Bool) -> Void)?) {
2227
let alert: NSAlert = .init() // Initializes a new NSAlert object.

Sources/UpgradeAlert/ext/UIAlertController+Ext.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import UIKit
44
extension UIAlertController {
55
/**
66
* Present alert
7-
* - Description: Presents the alert controller modally on the currently active view controller or the root view controller if no other controllers are presented.
7+
* - Description: Presents the alert controller modally on the currently
8+
* active view controller or the root view controller if no other
9+
* controllers are presented.
810
* Fix: throw error if vc is not available?
911
*/
1012
internal func present() {
@@ -17,7 +19,9 @@ extension UIAlertController {
1719
extension UIAlertController {
1820
/**
1921
* Presented or root view-controller
20-
* - Description: Retrieves the currently presented view controller or the root view controller if no other view controller is presented.
22+
* - Description: Retrieves the currently presented view controller or the
23+
* root view controller if no other view controller is
24+
* presented.
2125
* - Note: Sometimes there is no vc: https://stackoverflow.com/a/30509569/5389500
2226
*/
2327
fileprivate static var presentedOrRootVC: UIViewController? {

Sources/UpgradeAlert/ext/UIApplication+Ext.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import UIKit
66
extension UIApplication {
77
/**
88
* Key window property.
9-
* - Description: Retrieves the primary window of the application that is currently receiving user events.
9+
* - Description: Retrieves the primary window of the application that is
10+
* currently receiving user events.
1011
* - Remark: The key scene can be found by accessing `keyWin.windowScene`.
1112
* - Returns: The key window if it exists, otherwise nil.
1213
*/

Sources/UpgradeAlert/helper/AppInfo.swift

+18-7
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,38 @@ import Foundation
22

33
/**
44
* This struct represents the basic information about an application.
5-
* It includes the current version of the application and the URL to the application's page on the App Store.
6-
* - Description: This struct encapsulates essential details about the application, such as its current version and the URL to its App Store page, facilitating easy access to its public listing for update and review purposes.
7-
* - Remark: More information such as rating, release date, release notes etc. can be fetched. For more details, see: https://github.com/amebalabs/AppVersion/blob/master/AppVersion/Source/AppStoreVersion.swift
5+
* - Abstract: It includes the current version of the application and the URL
6+
* to the application's page on the App Store.
7+
* - Description: This struct encapsulates essential details about the
8+
* application, such as its current version and the URL to its App Store
9+
* page, facilitating easy access to its public listing for update and
10+
* review purposes.
11+
* - Remark: More information such as rating, release date, release notes etc.
12+
* can be fetched. For more details, see:
13+
* https://github.com/amebalabs/AppVersion/blob/master/AppVersion/Source/AppStoreVersion.swift
814
* - Fixme: ⚠️️ Consider renaming this struct to UAAppInfo for better clarity.
915
* - Fixme: ⚠️️ Add more detailed documentation for this struct and its properties.
1016
*/
1117
public struct AppInfo: Decodable {
1218
/**
1319
* The current version of the application.
14-
* - Description: Specifies the version of the application as a string, which is used to determine if an update is needed.
20+
* - Description: Specifies the version of the application as a string,
21+
* which is used to determine if an update is needed.
1522
*/
1623
public let version: String
1724
/**
1825
* The URL to the application's page on the App Store.
19-
* This might be optional for macOS applications as they might not have an App Store page.
20-
* - Description: Specifies the URL to the application's page on the App Store, which can be used to direct users to update or review the app.
26+
* - Abstract: This might be optional for macOS applications as they might
27+
* not have an App Store page.
28+
* - Description: Specifies the URL to the application's page on the App
29+
* Store, which can be used to direct users to update or
30+
* review the app.
2131
*/
2232
public let trackViewUrl: String
2333
/**
2434
* Initializes a new instance of `AppInfo`.
25-
* - Description: Initializes a new instance of `AppInfo` with the specified version and App Store URL.
35+
* - Description: Initializes a new instance of `AppInfo` with the specified
36+
* version and App Store URL.
2637
* - Parameters:
2738
* - version: The current version of the application.
2839
* - trackViewUrl: The URL to the application's page on the App Store.

Sources/UpgradeAlert/helper/LookupResult.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import Foundation
22
/**
33
* `LookupResult` is a struct that conforms to the `Decodable` protocol.
4-
* - Description: Represents the result of a lookup operation in the Apple App Store API, encapsulating the relevant app information fetched.
5-
* It is used to parse the JSON response from the Apple App Store API.
6-
* The parsed data is stored in the `results` array, which contains instances of `AppInfo`.
4+
* - Description: Represents the result of a lookup operation in the Apple App
5+
* Store API, encapsulating the relevant app information fetched.
6+
* - Note: It is used to parse the JSON response from the Apple App Store API.
7+
* - Note: The parsed data is stored in the `results` array, which contains instances of `AppInfo`.
78
* - Note: This struct is part of the `UpgradeAlert` module, specifically under the `helper` directory.
89
*/
910
struct LookupResult: Decodable {

Sources/UpgradeAlert/helper/UAConfig.swift

+4-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ extension UAConfig {
5555
/**
5656
* Provides a default configuration for the alert.
5757
* This can be used when no specific configuration is provided.
58-
* - Description: Returns a default `UAConfig` instance with predefined values for alert title, message, and button titles, suitable for general use cases where a specific configuration is not necessary.
58+
* - Description: Returns a default `UAConfig` instance with predefined
59+
* values for alert title, message, and button titles,
60+
* suitable for general use cases where a specific
61+
* configuration is not necessary.
5962
*/
6063
public static let defaultConfig: UAConfig = {
6164
.init(

Sources/UpgradeAlert/helper/UAError.swift

+15-5
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,39 @@ import Foundation
22
/**
33
* Error type. So we can track if bundle id etc faults.
44
* This enum is used to handle errors in a more structured way, allowing for better error handling and debugging.
5-
* - Description: Enumerates the various errors that can occur within the UpgradeAlert system, providing specific types for different error scenarios to facilitate precise error handling.
5+
* - Description: Enumerates the various errors that can occur within the
6+
* UpgradeAlert system, providing specific types for different
7+
* error scenarios to facilitate precise error handling.
68
*/
79
public enum UAError: Error {
810
/**
911
* This error is thrown when the URL for the App Store is invalid.
10-
* - Description: Occurs when the URL intended to direct to the App Store is malformed or not properly formatted, preventing navigation to the App Store page.
12+
* - Description: Occurs when the URL intended to direct to the App Store
13+
* is malformed or not properly formatted, preventing
14+
* navigation to the App Store page.
1115
*/
1216
case invalidAppStoreURL
1317
/**
1418
* This error is thrown when a general URL is invalid.
15-
* - Description: Occurs when a general URL that is not specifically for the App Store is malformed or not properly formatted, preventing proper URL navigation or usage.
19+
* - Description: Occurs when a general URL that is not specifically for
20+
* the App Store is malformed or not properly formatted,
21+
* preventing proper URL navigation or usage.
1622
*/
1723
case invalideURL
1824
/**
1925
* This error is thrown when the response from a request is invalid.
2026
* - Parameter description: Provides more details about the error.
21-
* - Description: Provides a detailed explanation of what went wrong with the response, including specifics that can help in debugging the issue.
27+
* - Description: Provides a detailed explanation of what went wrong
28+
* with the response, including specifics that can help
29+
* in debugging the issue.
2230
*/
2331
case invalidResponse(description: String)
2432
/**
2533
* This error is thrown when there is an issue with the bundle.
2634
* The desc parameter provides more details about the error.
27-
* - Description: Indicates an error related to the application's bundle, such as missing required resources or incorrect configuration settings.
35+
* - Description: Indicates an error related to the application's bundle,
36+
* such as missing required resources or incorrect
37+
* configuration settings.
2838
*/
2939
case bundleErr(desc: String)
3040
}

0 commit comments

Comments
 (0)