From 2e77fa06080c265236d778bfb684bf5d389d77ff Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Thu, 30 May 2024 17:20:39 +0200 Subject: [PATCH] Cleanup --- README.md | 2 +- ...AppSelfUpdater.swift => SelfUpdater.swift} | 14 +++++++-- Sources/AppUpdater/Support/Executable.swift | 30 +++++++++++++++++++ .../AppUpdater/Support/ReleaseManifest.swift | 9 ------ 4 files changed, 42 insertions(+), 13 deletions(-) rename Sources/AppUpdater/{AppSelfUpdater.swift => SelfUpdater.swift} (94%) create mode 100644 Sources/AppUpdater/Support/Executable.swift delete mode 100644 Sources/AppUpdater/Support/ReleaseManifest.swift diff --git a/README.md b/README.md index c9137f9..6bc6a98 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ As a separate target (for a macOS app), you need to add the following file: import Cocoa import AppUpdater -let delegate = AppSelfUpdater( +let delegate = SelfUpdater( appName: "My App", bundleIdentifiers: ["com.example.my-app"], baseUpdaterPath: "~/.config/com.example.my-app/updater" diff --git a/Sources/AppUpdater/AppSelfUpdater.swift b/Sources/AppUpdater/SelfUpdater.swift similarity index 94% rename from Sources/AppUpdater/AppSelfUpdater.swift rename to Sources/AppUpdater/SelfUpdater.swift index 4073635..e37d097 100644 --- a/Sources/AppUpdater/AppSelfUpdater.swift +++ b/Sources/AppUpdater/SelfUpdater.swift @@ -5,7 +5,7 @@ import Cocoa -open class AppSelfUpdater: NSObject, NSApplicationDelegate { +open class SelfUpdater: NSObject, NSApplicationDelegate { // MARK: - Requires Configuration @@ -41,9 +41,12 @@ open class AppSelfUpdater: NSObject, NSApplicationDelegate { } func installUpdate() async { - print("APP SELF-UPDATER by Nico Verbruggen") - print("Configured for \(self.appName)\n\(self.bundleIdentifiers)") print("===========================================") + print("\(Executable.name), version \(Executable.fullVersion)") + print("Using AppUpdater by Nico Verbruggen") + print("===========================================") + + print("Configured for \(self.appName) bundles: \(self.bundleIdentifiers)") self.updaterPath = self.baseUpdaterPath .replacingOccurrences(of: "~", with: NSHomeDirectory()) @@ -171,3 +174,8 @@ open class AppSelfUpdater: NSObject, NSApplicationDelegate { return "/Applications/\(app)" } } + +struct ReleaseManifest: Codable { + let url: String + let sha256: String +} diff --git a/Sources/AppUpdater/Support/Executable.swift b/Sources/AppUpdater/Support/Executable.swift new file mode 100644 index 0000000..2651b33 --- /dev/null +++ b/Sources/AppUpdater/Support/Executable.swift @@ -0,0 +1,30 @@ +// +// Created by Nico Verbruggen on 30/05/2024. +// Copyright © 2024 Nico Verbruggen. All rights reserved. +// + +import Foundation + +class Executable { + static var name: String { + Bundle.main.infoDictionary?["CFBundleName"] as! String + } + + static var identifier: String { + Bundle.main.infoDictionary?["CFBundleIdentifier"] as! String + } + + static var fullVersion: String { + let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String + let build = Bundle.main.infoDictionary?["CFBundleVersion"] as! String + return "\(version) (\(build))" + } + + static var bundleVersion: String { + return Bundle.main.infoDictionary?["CFBundleVersion"] as! String + } + + static var shortVersion: String { + return Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String + } +} diff --git a/Sources/AppUpdater/Support/ReleaseManifest.swift b/Sources/AppUpdater/Support/ReleaseManifest.swift deleted file mode 100644 index c61b8ce..0000000 --- a/Sources/AppUpdater/Support/ReleaseManifest.swift +++ /dev/null @@ -1,9 +0,0 @@ -// -// Created by Nico Verbruggen on 26/05/2024. -// Copyright © 2024 Nico Verbruggen. All rights reserved. -// - -struct ReleaseManifest: Codable { - let url: String - let sha256: String -}