Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新功能:使用sparkle框架增加检查更新功能 #17

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions ChuanhuWallpaper.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -62,13 +64,17 @@
38E0F9322987FB4D00E0A309 /* WallpaperPlaceholderCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WallpaperPlaceholderCell.swift; sourceTree = "<group>"; };
38E0F9342987FB5400E0A309 /* WallpaperDropDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WallpaperDropDelegate.swift; sourceTree = "<group>"; };
38FF038E298E306200A1834C /* AppearanceCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppearanceCell.swift; sourceTree = "<group>"; };
E31757B8299E771B006CC4FE /* appcast.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = appcast.xml; sourceTree = "<group>"; };
E37B62DB2996939C0063562C /* AutoUpdater.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoUpdater.swift; sourceTree = "<group>"; };
E37B62E429969C5D0063562C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
1207B476296EF60200B5D36D /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
E37B62DA2996919A0063562C /* Sparkle in Frameworks */,
38273E842982C993002433F9 /* WallpapperLib in Frameworks */,
1207B49E296FAE6E00B5D36D /* FilePicker in Frameworks */,
);
Expand Down Expand Up @@ -97,13 +103,15 @@
1207B47B296EF60200B5D36D /* ChuanhuWallpaper */ = {
isa = PBXGroup;
children = (
E37B62E429969C5D0063562C /* Info.plist */,
1207B47C296EF60200B5D36D /* ChuanhuWallpaperApp.swift */,
12BF6A5729704133001F0EB4 /* AppDelegate.swift */,
1207B47E296EF60200B5D36D /* ContentView.swift */,
38E0F9362987FCC600E0A309 /* View */,
38E0F9372987FCDA00E0A309 /* Utilities */,
38E0F9382987FCF100E0A309 /* Components */,
38E0F9392987FD0900E0A309 /* Models */,
E37B62E12996977A0063562C /* Updater */,
1207B4AB2970055000B5D36D /* Localizable.strings */,
1207B482296EF60300B5D36D /* Preview Content */,
1207B49F296FC77700B5D36D /* noimage.jpg */,
Expand Down Expand Up @@ -181,6 +189,15 @@
path = Models;
sourceTree = "<group>";
};
E37B62E12996977A0063562C /* Updater */ = {
isa = PBXGroup;
children = (
E37B62DB2996939C0063562C /* AutoUpdater.swift */,
E31757B8299E771B006CC4FE /* appcast.xml */,
);
path = Updater;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand All @@ -200,6 +217,7 @@
packageProductDependencies = (
1207B49D296FAE6E00B5D36D /* FilePicker */,
38273E832982C993002433F9 /* WallpapperLib */,
E37B62D92996919A0063562C /* Sparkle */,
);
productName = ChuanhuWallpaper;
productReference = 1207B479296EF60200B5D36D /* ChuanhuWallpaper.app */;
Expand Down Expand Up @@ -232,6 +250,7 @@
mainGroup = 1207B470296EF60200B5D36D;
packageReferences = (
1207B49C296FAE6E00B5D36D /* XCRemoteSwiftPackageReference "FilePicker" */,
E37B62D82996919A0063562C /* XCRemoteSwiftPackageReference "Sparkle" */,
);
productRefGroup = 1207B47A296EF60200B5D36D /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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 = (
Expand Down Expand Up @@ -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 */
Expand All @@ -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 */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
]
},
Expand Down
12 changes: 12 additions & 0 deletions ChuanhuWallpaper/ChuanhuWallpaperApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -36,6 +45,9 @@ struct ChuanhuWallpaperApp: App {
)
}
}
CommandGroup(after: .appInfo) {
CheckForUpdatesView(updater: updaterController.updater)
}
}
}
}
14 changes: 14 additions & 0 deletions ChuanhuWallpaper/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SUEnableDownloaderService</key>
<true/>
<key>SUEnableInstallerLauncherService</key>
<true/>
<key>SUFeedURL</key>
<string>! 最好能放在另一个服务器上发布,实在不方便再用https://raw.githubusercontent.com/GaiZhenbiao/ChuanhuWallpaper/main/ChuanhuWallpaper/Updater/appcast.xml</string>
<key>SUPublicEDKey</key>
<string>! 运行 ./bin/generate_keys tool (from the Sparkle distribution root).</string>
</dict>
</plist>
39 changes: 39 additions & 0 deletions ChuanhuWallpaper/Updater/AutoUpdater.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
38 changes: 38 additions & 0 deletions ChuanhuWallpaper/Updater/appcast.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle" xmlns:dc="http://purl.org/dc/elements/1.1/">
<!-- 请查看此处的文档 https://sparkle-project.org/documentation/publishing/#publishing-an-update -->
<channel>
<title>Chuanhu Wallpaper</title>

<item>
<title>2.1.2</title>
<pubDate>Sat, 11 Feb 2023 02:10:31 +0800</pubDate>
<sparkle:version>17</sparkle:version>
<sparkle:shortVersionString>2.1.2</sparkle:shortVersionString>
<description><![CDATA[
<h2>2.1.2</h2>
<h3>New Feature</h3>
<li>增加自动检测更新功能</li>
]]>
</description>
<link>https://github.com/GaiZhenbiao/ChuanhuWallpaper</link>
<sparkle:minimumSystemVersion>11.0</sparkle:minimumSystemVersion>
<enclosure url="https://github.com/GaiZhenbiao/ChuanhuWallpaper/releases/download/v2.1.2/ChuanhuWallpaper.app.zip" length="!LENTH" type="application/octet-stream" sparkle:edSignature="!PLEASE ENTER YOUR SUPublicEDKey HERE"/>
<!-- 请使用 generate_appcast tool 来生成上面的签名和大小信息,见 https://sparkle-project.org/documentation/ -->
</item>

<item>
<title>2.1.1</title>
<link>https://github.com/GaiZhenbiao/ChuanhuWallpaper</link>
<sparkle:version>16</sparkle:version>
<description><![CDATA[
<li>修复了某些情况下,亮暗色壁纸失效的问题</li>
]]>
</description>
<pubDate>Thur, 9 Feb 2023 12:00:00 +0800</pubDate>
<enclosure url="https://github.com/GaiZhenbiao/ChuanhuWallpaper/releases/download/v2.1.1/ChuanhuWallpaper.app.zip" lengh="1178091" type="application/octet-stream" />
<sparkle:minimumSystemVersion>11.0</sparkle:minimumSystemVersion>
</item>

</channel>
</rss>
1 change: 1 addition & 0 deletions ChuanhuWallpaper/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@
"OR" = "或者";
"Choose Photo(s)..." = "选取图像...";
"Remove All" = "清空图像";
"Check for Updates…" = "检查更新…";