### Default Asset Selection Logic (Swift) Source: https://github.com/michaeljberk/basicupdater/blob/main/Sources/BasicUpdater/BasicUpdater.docc/Creating the Updater.md Demonstrates the default behavior for selecting an asset to use for an update. This example explicitly shows how to use the `assetToUse` closure to select the first asset from the list of available assets in a GitHub release. ```swift let updater = Updater(projectURL: ..., shouldUpdateTo: { release in //... }, assetToUse: { assets in return assets.first! }) ``` -------------------------------- ### Custom Update Eligibility Logic (Swift) Source: https://github.com/michaeljberk/basicupdater/blob/main/Sources/BasicUpdater/BasicUpdater.docc/Creating the Updater.md Provides an example of how to implement custom logic for determining if a user should be prompted to update to a new release. This uses a closure passed to the `Updater` initializer, comparing build numbers extracted from the release tag and the current application's bundle version. ```swift let updater = Updater(projectURL: ..., shouldUpdateTo: { release in //Example: `release.tagName` is "5.0.3-307" let regexStr = #"\d*$"# let tag = release.tagName let range = tag.range(of: regexStr, options: .regularExpression)! let newBuildStr = String(tag[range]) let newBuildNum = Int(newBuildStr)! let currentBuildStr = Bundle.main.infoDictionary?["CFBundleVersion"] as! String let currentBuildNum = Int(currentBuildStr)! return newBuildNum > currentBuildNum }) ``` -------------------------------- ### Initialize Updater in SwiftUI App Struct Source: https://github.com/michaeljberk/basicupdater/blob/main/Sources/BasicUpdater/BasicUpdater.docc/Creating the Updater.md Illustrates the initialization of the Updater object as a static constant within the `App` struct in a SwiftUI application. This method is suitable for SwiftUI-based applications, providing global access to the updater instance. ```swift struct MyCoolApp: App { //... static let updater = Updater(...) //... } ``` -------------------------------- ### Define Base URL for BasicUpdater Source: https://github.com/michaeljberk/basicupdater/blob/main/docs/documentation/basicupdater/githubasset/assetstate/rawrepresentable-implementations/index.html This JavaScript snippet defines the base URL for the BasicUpdater application. It is likely used to construct relative paths for resources or API endpoints. No external dependencies are noted. ```javascript var baseUrl = "/BasicUpdater/" ``` -------------------------------- ### Initialize Updater in AppKit AppDelegate Source: https://github.com/michaeljberk/basicupdater/blob/main/Sources/BasicUpdater/BasicUpdater.docc/Creating the Updater.md Demonstrates how to initialize the Updater object as a static constant within the `AppDelegate` class in an AppKit application. This approach ensures the updater is accessible throughout the application's lifecycle. ```swift class AppDelegate: NSObject, NSApplicationDelegate { //... static let updater = Updater(...) //... } ``` -------------------------------- ### CSS for NoScript Fallback Message Source: https://github.com/michaeljberk/basicupdater/blob/main/docs/documentation/basicupdater/githubrelease/assets/index.html Provides styling for a 'noscript' message that is displayed when JavaScript is disabled. This CSS ensures the fallback message is readable and appropriately sized across different screen resolutions. ```css .noscript{font-family:"SF Pro Display","SF Pro Icons","Helvetica Neue",Helvetica,Arial,sans-serif;margin:92px auto 140px auto;text-align:center;width:980px}.noscript-title{color:#111;font-size:48px;font-weight:600;letter-spacing:-.003em;line-height:1.08365;margin:0 auto 54px auto;width:502px}@media only screen and (max-width:1068px){.noscript{margin:90px auto 120px auto;width:692px}.noscript-title{font-size:40px;letter-spacing:0;line-height:1.1;margin:0 auto 45px auto;width:420px}}@media only screen and (max-width:735px){.noscript{margin:45px auto 60px auto;width:87.5%}.noscript-title{font-size:32px;letter-spacing:.004em;line-height:1.125;margin:0 auto 35px auto;max-width:330px;width:auto}}#loading-placeholder{display:none} ``` -------------------------------- ### Configure Base URL for BasicUpdater Source: https://github.com/michaeljberk/basicupdater/blob/main/docs/documentation/basicupdater/githubasset/assetstate/!=(_:_:)/index.html Sets the base URL for the BasicUpdater application. This variable is typically used in client-side scripts to construct correct paths for API requests or resource loading. No external dependencies are required. ```javascript var baseUrl = "/BasicUpdater/" ``` -------------------------------- ### JavaScript Requirement Message (CSS) Source: https://github.com/michaeljberk/basicupdater/blob/main/docs/documentation/basicupdater/githubrelease/name/index.html This CSS defines styles for a message displayed when JavaScript is not enabled. It includes different styles for various screen sizes. The 'noscript' class targets the container, and 'noscript-title' targets the heading. ```css .noscript { font-family: "SF Pro Display", "SF Pro Icons", "Helvetica Neue", Helvetica, Arial, sans-serif; margin: 92px auto 140px auto; text-align: center; width: 980px; } .noscript-title { color: #111; font-size: 48px; font-weight: 600; letter-spacing: -.003em; line-height: 1.08365; margin: 0 auto 54px auto; width: 502px; } @media only screen and (max-width: 1068px) { .noscript { margin: 90px auto 120px auto; width: 692px; } .noscript-title { font-size: 40px; letter-spacing: 0; line-height: 1.1; margin: 0 auto 45px auto; width: 420px; } } @media only screen and (max-width: 735px) { .noscript { margin: 45px auto 60px auto; width: 87.5%; } .noscript-title { font-size: 32px; letter-spacing: .004em; line-height: 1.125; margin: 0 auto 35px auto; max-width: 330px; width: auto; } } #loading-placeholder { display: none; } ``` -------------------------------- ### Styling for NoScript Message (CSS) Source: https://github.com/michaeljberk/basicupdater/blob/main/docs/documentation/basicupdater/updater/autocheckforupdateskey/index.html This CSS code defines styles for the `.noscript` and `.noscript-title` classes. These styles are applied to display a message when JavaScript is disabled in the browser, ensuring a consistent user experience across different screen sizes. ```css .noscript{font-family:"SF Pro Display","SF Pro Icons",Helvetica Neue,Helvetica,Arial,sans-serif;margin:92px auto 140px auto;text-align:center;width:980px}.noscript-title{color:#111;font-size:48px;font-weight:600;letter-spacing:-.003em;line-height:1.08365;margin:0 auto 54px auto;width:502px}@media only screen and (max-width:1068px){.noscript{margin:90px auto 120px auto;width:692px}.noscript-title{font-size:40px;letter-spacing:0;line-height:1.1;margin:0 auto 45px auto;width:420px}}@media only screen and (max-width:735px){.noscript{margin:45px auto 60px auto;width:87.5%}.noscript-title{font-size:32px;letter-spacing:.004em;line-height:1.125;margin:0 auto 35px auto;max-width:330px;width:auto}}#loading-placeholder{display:none} ``` -------------------------------- ### Manually Check for Updates with Swift UI Source: https://github.com/michaeljberk/basicupdater/blob/main/Sources/BasicUpdater/BasicUpdater.docc/Checking for Updates.md This code snippet demonstrates how to manually trigger an update check using the `checkForUpdates()` method from the `Updater` environment object within a Swift UI View. It provides a button that, when tapped, invokes the update check. If an update is available, it prompts the user; otherwise, it notifies them they are on the latest version. ```swift struct MyView: View { @EnvironmentObject var updater: Updater var body: some View { Button("Check for Updates") { updater.checkForUpdates() } } } ``` -------------------------------- ### Accessing Skipped Versions in UserDefaults - Swift Source: https://github.com/michaeljberk/basicupdater/blob/main/Sources/BasicUpdater/BasicUpdater.docc/Skipping Versions.md This snippet demonstrates how to access and modify the array of skipped version tag names stored in UserDefaults. It highlights the default storage location and the possibility of customizing the UserDefaults suite. ```swift let skippedVersionsKey = "Updater/skippedVersionsKey" // Accessing the array from standard UserDefaults suite var skippedVersions = UserDefaults.standard.stringArray(forKey: skippedVersionsKey) ?? [] // To manually add a version: if let newVersion = githubRelease.tagName { skippedVersions.append(newVersion) UserDefaults.standard.set(skippedVersions, forKey: skippedVersionsKey) } // To manually remove a version: if let versionToRemove = githubRelease.tagName { skippedVersions.removeAll { $0 == versionToRemove } UserDefaults.standard.set(skippedVersions, forKey: skippedVersionsKey) } // Example of initializing Updater with a custom UserDefaults suite: let customUpdater = Updater(projectURL: URL(string: "https://api.github.com/repos/michaeljberk/basicupdater")!, userDefaultsSuite: "com.mycompany.app.updaterSettings") ``` -------------------------------- ### JavaScript Check for Web Applications Source: https://github.com/michaeljberk/basicupdater/blob/main/docs/documentation/basicupdater/githubrelease/htmlurl/index.html This snippet demonstrates a common pattern for checking if JavaScript is enabled in a user's browser. If JavaScript is disabled, it displays a fallback message. This is crucial for web applications that rely heavily on JavaScript for their core functionality. ```html