From c686d413f28e1169104691eda51dc603a365edd9 Mon Sep 17 00:00:00 2001 From: Keldos Date: Sat, 11 Feb 2023 16:02:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=8A=9F=E8=83=BD=EF=BC=9A=E4=BD=BF?= =?UTF-8?q?=E7=94=A8sparkle=E6=A1=86=E6=9E=B6=E5=A2=9E=E5=8A=A0=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E6=9B=B4=E6=96=B0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 需要最终执行分发的开发者签名,本次提交不能直接合并入主分支。 该commit曾被rebase追加两个补充的提交: 1. update Sparkle package 2.3.1 -> 2.3.2 2. 修正 appcast.xml 位置 --- ChuanhuWallpaper.xcodeproj/project.pbxproj | 35 +++++++++++++++++ .../xcshareddata/swiftpm/Package.resolved | 9 +++++ ChuanhuWallpaper/ChuanhuWallpaperApp.swift | 12 ++++++ ChuanhuWallpaper/Info.plist | 14 +++++++ ChuanhuWallpaper/Updater/AutoUpdater.swift | 39 +++++++++++++++++++ ChuanhuWallpaper/Updater/appcast.xml | 38 ++++++++++++++++++ .../zh-Hans.lproj/Localizable.strings | 1 + 7 files changed, 148 insertions(+) create mode 100644 ChuanhuWallpaper/Info.plist create mode 100644 ChuanhuWallpaper/Updater/AutoUpdater.swift create mode 100644 ChuanhuWallpaper/Updater/appcast.xml diff --git a/ChuanhuWallpaper.xcodeproj/project.pbxproj b/ChuanhuWallpaper.xcodeproj/project.pbxproj index 46c9c5c..876d5bd 100644 --- a/ChuanhuWallpaper.xcodeproj/project.pbxproj +++ b/ChuanhuWallpaper.xcodeproj/project.pbxproj @@ -32,6 +32,8 @@ 38E0F9332987FB4D00E0A309 /* WallpaperPlaceholderCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38E0F9322987FB4D00E0A309 /* WallpaperPlaceholderCell.swift */; }; 38E0F9352987FB5400E0A309 /* WallpaperDropDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38E0F9342987FB5400E0A309 /* WallpaperDropDelegate.swift */; }; 38FF038F298E306200A1834C /* AppearanceCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 38FF038E298E306200A1834C /* AppearanceCell.swift */; }; + E37B62DA2996919A0063562C /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = E37B62D92996919A0063562C /* Sparkle */; }; + E37B62DC2996939C0063562C /* AutoUpdater.swift in Sources */ = {isa = PBXBuildFile; fileRef = E37B62DB2996939C0063562C /* AutoUpdater.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -62,6 +64,9 @@ 38E0F9322987FB4D00E0A309 /* WallpaperPlaceholderCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WallpaperPlaceholderCell.swift; sourceTree = ""; }; 38E0F9342987FB5400E0A309 /* WallpaperDropDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WallpaperDropDelegate.swift; sourceTree = ""; }; 38FF038E298E306200A1834C /* AppearanceCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppearanceCell.swift; sourceTree = ""; }; + E31757B8299E771B006CC4FE /* appcast.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = appcast.xml; sourceTree = ""; }; + E37B62DB2996939C0063562C /* AutoUpdater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoUpdater.swift; sourceTree = ""; }; + E37B62E429969C5D0063562C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -69,6 +74,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + E37B62DA2996919A0063562C /* Sparkle in Frameworks */, 38273E842982C993002433F9 /* WallpapperLib in Frameworks */, 1207B49E296FAE6E00B5D36D /* FilePicker in Frameworks */, ); @@ -97,6 +103,7 @@ 1207B47B296EF60200B5D36D /* ChuanhuWallpaper */ = { isa = PBXGroup; children = ( + E37B62E429969C5D0063562C /* Info.plist */, 1207B47C296EF60200B5D36D /* ChuanhuWallpaperApp.swift */, 12BF6A5729704133001F0EB4 /* AppDelegate.swift */, 1207B47E296EF60200B5D36D /* ContentView.swift */, @@ -104,6 +111,7 @@ 38E0F9372987FCDA00E0A309 /* Utilities */, 38E0F9382987FCF100E0A309 /* Components */, 38E0F9392987FD0900E0A309 /* Models */, + E37B62E12996977A0063562C /* Updater */, 1207B4AB2970055000B5D36D /* Localizable.strings */, 1207B482296EF60300B5D36D /* Preview Content */, 1207B49F296FC77700B5D36D /* noimage.jpg */, @@ -181,6 +189,15 @@ path = Models; sourceTree = ""; }; + E37B62E12996977A0063562C /* Updater */ = { + isa = PBXGroup; + children = ( + E37B62DB2996939C0063562C /* AutoUpdater.swift */, + E31757B8299E771B006CC4FE /* appcast.xml */, + ); + path = Updater; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -200,6 +217,7 @@ packageProductDependencies = ( 1207B49D296FAE6E00B5D36D /* FilePicker */, 38273E832982C993002433F9 /* WallpapperLib */, + E37B62D92996919A0063562C /* Sparkle */, ); productName = ChuanhuWallpaper; productReference = 1207B479296EF60200B5D36D /* ChuanhuWallpaper.app */; @@ -232,6 +250,7 @@ mainGroup = 1207B470296EF60200B5D36D; packageReferences = ( 1207B49C296FAE6E00B5D36D /* XCRemoteSwiftPackageReference "FilePicker" */, + E37B62D82996919A0063562C /* XCRemoteSwiftPackageReference "Sparkle" */, ); productRefGroup = 1207B47A296EF60200B5D36D /* Products */; projectDirPath = ""; @@ -279,6 +298,7 @@ 38E0F92E2987FAC400E0A309 /* ImageModel.swift in Sources */, 1207B495296EF74B00B5D36D /* SolarWallpaperView.swift in Sources */, 38E0F91E2985443B00E0A309 /* Color.swift in Sources */, + E37B62DC2996939C0063562C /* AutoUpdater.swift in Sources */, 38E0F92529865D6E00E0A309 /* ModePicker.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -428,6 +448,7 @@ ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = ChuanhuWallpaper/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = "川虎壁纸"; INFOPLIST_KEY_NSHumanReadableCopyright = ""; LD_RUNPATH_SEARCH_PATHS = ( @@ -458,6 +479,7 @@ ENABLE_HARDENED_RUNTIME = YES; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = ChuanhuWallpaper/Info.plist; INFOPLIST_KEY_CFBundleDisplayName = "川虎壁纸"; INFOPLIST_KEY_NSHumanReadableCopyright = ""; LD_RUNPATH_SEARCH_PATHS = ( @@ -505,6 +527,14 @@ minimumVersion = 1.0.0; }; }; + E37B62D82996919A0063562C /* XCRemoteSwiftPackageReference "Sparkle" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/sparkle-project/Sparkle"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 2.0.0; + }; + }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ @@ -517,6 +547,11 @@ isa = XCSwiftPackageProductDependency; productName = WallpapperLib; }; + E37B62D92996919A0063562C /* Sparkle */ = { + isa = XCSwiftPackageProductDependency; + package = E37B62D82996919A0063562C /* XCRemoteSwiftPackageReference "Sparkle" */; + productName = Sparkle; + }; /* End XCSwiftPackageProductDependency section */ }; rootObject = 1207B471296EF60200B5D36D /* Project object */; diff --git a/ChuanhuWallpaper.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ChuanhuWallpaper.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index c6a246a..4952d84 100644 --- a/ChuanhuWallpaper.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ChuanhuWallpaper.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -9,6 +9,15 @@ "revision": "720f8cb5ca0c0efc982ed381afc84ba3e8b3214e", "version": "1.0.1" } + }, + { + "package": "Sparkle", + "repositoryURL": "https://github.com/sparkle-project/Sparkle", + "state": { + "branch": null, + "revision": "dda155c7d3ef38c53d29f8584cb2aad2a1a54dba", + "version": "2.3.2" + } } ] }, diff --git a/ChuanhuWallpaper/ChuanhuWallpaperApp.swift b/ChuanhuWallpaper/ChuanhuWallpaperApp.swift index b480882..bd41f8d 100644 --- a/ChuanhuWallpaper/ChuanhuWallpaperApp.swift +++ b/ChuanhuWallpaper/ChuanhuWallpaperApp.swift @@ -6,11 +6,20 @@ // import SwiftUI +import Sparkle @main struct ChuanhuWallpaperApp: App { @NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate + private let updaterController: SPUStandardUpdaterController + + init() { + // If you want to start the updater manually, pass false to startingUpdater and call .startUpdater() later + // This is where you can also pass an updater delegate if you need one + updaterController = SPUStandardUpdaterController(startingUpdater: true, updaterDelegate: nil, userDriverDelegate: nil) + } + var body: some Scene { WindowGroup { ContentView() @@ -36,6 +45,9 @@ struct ChuanhuWallpaperApp: App { ) } } + CommandGroup(after: .appInfo) { + CheckForUpdatesView(updater: updaterController.updater) + } } } } diff --git a/ChuanhuWallpaper/Info.plist b/ChuanhuWallpaper/Info.plist new file mode 100644 index 0000000..8511e5a --- /dev/null +++ b/ChuanhuWallpaper/Info.plist @@ -0,0 +1,14 @@ + + + + + SUEnableDownloaderService + + SUEnableInstallerLauncherService + + SUFeedURL + ! 最好能放在另一个服务器上发布,实在不方便再用https://raw.githubusercontent.com/GaiZhenbiao/ChuanhuWallpaper/main/ChuanhuWallpaper/Updater/appcast.xml + SUPublicEDKey + ! 运行 ./bin/generate_keys tool (from the Sparkle distribution root). + + diff --git a/ChuanhuWallpaper/Updater/AutoUpdater.swift b/ChuanhuWallpaper/Updater/AutoUpdater.swift new file mode 100644 index 0000000..658b2a6 --- /dev/null +++ b/ChuanhuWallpaper/Updater/AutoUpdater.swift @@ -0,0 +1,39 @@ +// +// AutoUpdater.swift +// ChuanhuWallpaper +// +// Created by Keldos on 2023/2/10. +// + +import SwiftUI +import Sparkle + +// This view model class publishes when new updates can be checked by the user +final class CheckForUpdatesViewModel: ObservableObject { + @Published var canCheckForUpdates = false + + init(updater: SPUUpdater) { + updater.publisher(for: \.canCheckForUpdates) + .assign(to: &$canCheckForUpdates) + } +} + +// This is the view for the Check for Updates menu item +// Note this intermediate view is necessary for the disabled state on the menu item to work properly before Monterey. +// See https://stackoverflow.com/questions/68553092/menu-not-updating-swiftui-bug for more info +struct CheckForUpdatesView: View { + @ObservedObject private var checkForUpdatesViewModel: CheckForUpdatesViewModel + private let updater: SPUUpdater + + init(updater: SPUUpdater) { + self.updater = updater + + // Create our view model for our CheckForUpdatesView + self.checkForUpdatesViewModel = CheckForUpdatesViewModel(updater: updater) + } + + var body: some View { + Button("Check for Updates…", action: updater.checkForUpdates) + .disabled(!checkForUpdatesViewModel.canCheckForUpdates) + } +} diff --git a/ChuanhuWallpaper/Updater/appcast.xml b/ChuanhuWallpaper/Updater/appcast.xml new file mode 100644 index 0000000..d76c42b --- /dev/null +++ b/ChuanhuWallpaper/Updater/appcast.xml @@ -0,0 +1,38 @@ + + + + + Chuanhu Wallpaper + + + 2.1.2 + Sat, 11 Feb 2023 02:10:31 +0800 + 17 + 2.1.2 + 2.1.2 +

New Feature

+
  • 增加自动检测更新功能
  • + ]]> +
    + https://github.com/GaiZhenbiao/ChuanhuWallpaper + 11.0 + + +
    + + + 2.1.1 + https://github.com/GaiZhenbiao/ChuanhuWallpaper + 16 + 修复了某些情况下,亮暗色壁纸失效的问题 + ]]> + + Thur, 9 Feb 2023 12:00:00 +0800 + + 11.0 + + +
    +
    diff --git a/ChuanhuWallpaper/zh-Hans.lproj/Localizable.strings b/ChuanhuWallpaper/zh-Hans.lproj/Localizable.strings index a4b2e3d..9f119d3 100644 --- a/ChuanhuWallpaper/zh-Hans.lproj/Localizable.strings +++ b/ChuanhuWallpaper/zh-Hans.lproj/Localizable.strings @@ -45,3 +45,4 @@ "OR" = "或者"; "Choose Photo(s)..." = "选取图像..."; "Remove All" = "清空图像"; +"Check for Updates…" = "检查更新…";