Rename to NVAppUpdater

This commit is contained in:
2024-05-31 23:15:36 +02:00
parent 9acf308ea6
commit a4f1f0e33d
4 changed files with 39 additions and 28 deletions

View File

@ -9,10 +9,10 @@ open class SelfUpdater: NSObject, NSApplicationDelegate {
// MARK: - Requires Configuration
public init(appName: String, bundleIdentifiers: [String], baseUpdaterPath: String) {
public init(appName: String, bundleIdentifiers: [String], selfUpdaterPath: String) {
self.appName = appName
self.bundleIdentifiers = bundleIdentifiers
self.baseUpdaterPath = baseUpdaterPath
self.selfUpdaterPath = selfUpdaterPath
}
// MARK: - Regular Updater Flow
@ -20,7 +20,7 @@ open class SelfUpdater: NSObject, NSApplicationDelegate {
// Set by the user
private var appName: String
private var bundleIdentifiers: [String]
private var baseUpdaterPath: String
private var selfUpdaterPath: String
// Determined during the flow of the updater
private var updaterPath: String = ""
@ -48,7 +48,7 @@ open class SelfUpdater: NSObject, NSApplicationDelegate {
Log.text("Configured for \(self.appName) bundles: \(self.bundleIdentifiers)")
self.updaterPath = self.baseUpdaterPath
self.updaterPath = self.selfUpdaterPath
.replacingOccurrences(of: "~", with: NSHomeDirectory())
Log.text("Updater directory set to: \(self.updaterPath)")
@ -137,7 +137,7 @@ open class SelfUpdater: NSObject, NSApplicationDelegate {
// Make sure the updater directory exists
var isDirectory: ObjCBool = true
if !FileManager.default.fileExists(atPath: "\(updaterPath)/extracted", isDirectory: &isDirectory) {
await Alert.upgradeFailure(description: "The updater directory is missing. The automatic updater will quit. Make sure that `\(baseUpdaterPath)` is writeable.")
await Alert.upgradeFailure(description: "The updater directory is missing. The automatic updater will quit. Make sure that `\(selfUpdaterPath)` is writeable.")
}
// Unzip the file
@ -151,7 +151,7 @@ open class SelfUpdater: NSObject, NSApplicationDelegate {
// Make sure the file was extracted
if app.isEmpty {
await Alert.upgradeFailure(description: "The downloaded file could not be extracted. The automatic updater will quit. Make sure that `\(baseUpdaterPath)` is writeable.")
await Alert.upgradeFailure(description: "The downloaded file could not be extracted. The automatic updater will quit. Make sure that `\(selfUpdaterPath)` is writeable.")
}
// Remove the original app

View File

@ -11,7 +11,7 @@ open class UpdateCheck
let caskUrl: URL
let promptOnFailure: Bool
let selfUpdaterName: String
let selfUpdaterDirectory: String
let selfUpdaterPath: String
var caskFile: CaskFile!
var newerVersion: AppVersion!
@ -22,8 +22,9 @@ open class UpdateCheck
* - Parameter selfUpdaterName: The name of the self-updater .app file. For example, "App Self-Updater.app".
* This binary should exist as a resource of the current application.
*
* - Parameter selfUpdaterDirectory: The directory that is used by the self-updater. A file `update.json`
* will be placed in this directory and this should be correspond to the `baseUpdaterPath` in `SelfUpdater`.
* - Parameter selfUpdaterPath: The directory that is used by the self-updater.
* A small manifest named `update.json` will be placed in this directory and this
* should be correspond to the `selfUpdaterPath` in `SelfUpdater`.
*
* - Parameter caskUrl: The URL where the Cask file is expected to be located. Redirects will
* be followed when retrieving and validating the Cask file.
@ -34,12 +35,12 @@ open class UpdateCheck
*/
public init(
selfUpdaterName: String,
selfUpdaterDirectory: String,
selfUpdaterPath: String,
caskUrl: URL,
promptOnFailure: Bool
) {
self.selfUpdaterName = selfUpdaterName
self.selfUpdaterDirectory = selfUpdaterDirectory
self.selfUpdaterPath = selfUpdaterPath
self.caskUrl = caskUrl
self.promptOnFailure = promptOnFailure
}
@ -126,9 +127,9 @@ open class UpdateCheck
private func launchSelfUpdater() {
let updater = Bundle.main.resourceURL!.path + "/\(selfUpdaterName)"
system_quiet("mkdir -p \(selfUpdaterDirectory) 2> /dev/null")
system_quiet("mkdir -p \(selfUpdaterPath) 2> /dev/null")
let updaterDirectory = selfUpdaterDirectory
let updaterDirectory = selfUpdaterPath
.replacingOccurrences(of: "~", with: NSHomeDirectory())
system_quiet("cp -R \"\(updater)\" \"\(updaterDirectory)/\(selfUpdaterName)\"")