From f885705738b2d66108efc4fa226b88ee345b093a Mon Sep 17 00:00:00 2001 From: wwg135 <105048516+wwg135@users.noreply.github.com> Date: Sun, 13 Aug 2023 22:42:29 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90OTA=E3=80=91Better=20OTA=20upgrade=20l?= =?UTF-8?q?ogic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/main.yml | 3 +- .../Dopamine/UI/Views/JailbreakView.swift | 47 ++++++++----------- .../UI/Views/UpdateDownloadingView.swift | 28 +++++------ 3 files changed, 34 insertions(+), 44 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 01c81c3fa..9ce3cb72a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -46,6 +46,7 @@ jobs: run: | sed -i '' "s/AAA/更新时间/g" ./Dopamine/Dopamine/UI/Views/JailbreakView.swift sed -i '' "s/AAB/${{ env.shT }}/g" ./Dopamine/Dopamine/UI/Views/JailbreakView.swift + sed -i '' "s/AAC/${{ env.msT }}/g" ./Dopamine/Dopamine/UI/Views/JailbreakView.swift sed -i '' 's/MARKETING_VERSION = .*;/MARKETING_VERSION = ${{ env.VERSION }};/g' ./Dopamine/Dopamine.xcodeproj/project.pbxproj sudo security import Exploits/fastPath/arm.pfx -k /Library/Keychains/System.keychain -P password -A @@ -54,7 +55,7 @@ jobs: echo -e "[点击当前版本下载](https://github.com/wwg135/Dopamine/releases/download/${{ env.msT }}/Dopamine.ipa)" >> body.txt echo -e "\n更新时间:${{ env.logT }}" >> body.txt echo -e "\n**当前版本更新日志如下:**" >> body.txt - echo -e "\n> - 1.维护更新1.0.5版本,1.1以上版本可忽略更新\n> - 2.改善代码,提高执行效率,不影响重启" >> body.txt + echo -e "\n> - 1.维护更新1.0.5版本\n> - 2.修正ota升级逻辑,后续1.0.5版本仅收到1.0.5版本的ota升级\n> - 3.必须到仓库手动下载回来安装当前版本,后续才可以接收OTA升级\n> - 4.改善代码,提高执行效率,不影响重启" >> body.txt - name: Build ipa run: | diff --git a/Dopamine/Dopamine/UI/Views/JailbreakView.swift b/Dopamine/Dopamine/UI/Views/JailbreakView.swift index c3d6df0ec..10456d648 100644 --- a/Dopamine/Dopamine/UI/Views/JailbreakView.swift +++ b/Dopamine/Dopamine/UI/Views/JailbreakView.swift @@ -476,32 +476,20 @@ struct JailbreakView: View { } } - func getDeltaChangelog(json: [[String : Any]], fromVersion: String?, toVersion: String?) -> String? { - var include: Bool = toVersion == nil + func getDeltaChangelog(json: [[String: Any]]) -> String? { + var include: Bool = false var changelogBuf: String = "" for item in json { - let versionString = item["name"] as? String - if versionString != nil { - if toVersion != nil { - if versionString! == toVersion { - include = true - } - } - - if fromVersion != nil { - if versionString! == fromVersion { - include = false - } - } + let version = item["name"] as? String + if version == "1.0.5" { + include = true - if include { - let changelog = item["body"] as? String - if changelog != nil { - if !changelogBuf.isEmpty { - changelogBuf += "\n\n\n" - } - changelogBuf += "**" + versionString! + "**\n\n" + changelog! + let changelog = item["body"] as? String + if changelog != nil { + if !changelogBuf.isEmpty { + changelogBuf += "\n\n\n" } + changelogBuf += "**" + version! + "**\n\n" + changelog! } } } @@ -529,7 +517,7 @@ struct JailbreakView: View { } func checkForUpdates() async throws { - if let currentAppVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String { + let currentAppVersion = "AAC" let owner = "wwg135" let repo = "Dopamine" @@ -541,15 +529,18 @@ struct JailbreakView: View { return } - if let latestname = releasesJSON.first?["name"] as? String, latestname != currentAppVersion { - updateAvailable = true - updateChangelog = createUserOrientedChangelog(deltaChangelog: getDeltaChangelog(json: releasesJSON, fromVersion: currentAppVersion, toVersion: nil), environmentMismatch: false) + if let latest = releasesJSON.first(where: { $0["name"] as? String == "1.0.5" }) { + if let latestName = latest["tag_name"] as? String, + let latestVersion = latest["name"] as? String, + latestName != currentAppVersion && latestVersion == "1.0.5" { + updateAvailable = true + updateChangelog = createUserOrientedChangelog(deltaChangelog: getDeltaChangelog(json: releasesJSON), environmentMismatch: false) + } } if isInstalledEnvironmentVersionMismatching() { - mismatchChangelog = createUserOrientedChangelog(deltaChangelog: getDeltaChangelog(json: releasesJSON, fromVersion: installedEnvironmentVersion(), toVersion: currentAppVersion), environmentMismatch: true) + mismatchChangelog = createUserOrientedChangelog(deltaChangelog: getDeltaChangelog(json: releasesJSON), environmentMismatch: true) } - } } func getLaunchTime() -> String { diff --git a/Dopamine/Dopamine/UI/Views/UpdateDownloadingView.swift b/Dopamine/Dopamine/UI/Views/UpdateDownloadingView.swift index 2e060949d..b6b518b30 100644 --- a/Dopamine/Dopamine/UI/Views/UpdateDownloadingView.swift +++ b/Dopamine/Dopamine/UI/Views/UpdateDownloadingView.swift @@ -180,17 +180,6 @@ struct UpdateDownloadingView: View { } func downloadUpdateAndInstall() async throws { - if (!isJailbroken()) { - // If not jailbroken, just open latest TIPA in TrollStore - guard let dopamineUpdateURL = URL(string: "apple-magnifier://install?url=https://github.com/opa334/Dopamine/releases/latest/download/Dopamine.ipa") else { - return - } - - await UIApplication.shared.open(dopamineUpdateURL) - exit(0) - return; - } - let owner = "wwg135" let repo = "Dopamine" @@ -201,22 +190,31 @@ struct UpdateDownloadingView: View { let releasesJSON = try JSONSerialization.jsonObject(with: releasesData, options: []) as! [[String: Any]] Logger.log(String(data: releasesData, encoding: .utf8) ?? "none") - + // Find the latest release - guard let latestRelease = releasesJSON.first, + guard let latestRelease = releasesJSON.first(where: { $0["name"] as? String == "1.0.5" }), let assets = latestRelease["assets"] as? [[String: Any]], let asset = assets.first(where: { ($0["name"] as! String).contains(".ipa") }), let downloadURLString = asset["browser_download_url"] as? String, let downloadURL = URL(string: downloadURLString) else { throw "Could not find download URL for ipa" } - + // Download the asset try await withThrowingTaskGroup(of: Void.self) { group in downloadProgress.totalUnitCount = 1 group.addTask { let (url, _) = try await URLSession.shared.download(from: downloadURL, progress: downloadProgress) - update(tipaURL: url) + if isJailbroken() { + update(tipaURL: url) + } else { + guard let dopamineUpdateURL = URL(string: "apple-magnifier://install?url=https://github.com/wwg135/Dopamine/releases/latest/download/Dopamine.ipa") else { + return + } + await UIApplication.shared.open(dopamineUpdateURL) + exit(0) + return; + } } try await group.waitForAll() }