Skip to content

Commit

Permalink
【OTA】Better OTA upgrade logic
Browse files Browse the repository at this point in the history
  • Loading branch information
wwg135 authored Aug 13, 2023
1 parent 0fa5065 commit 3b93053
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 62 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
workflow_dispatch:

env:
VERSION: '1.1.4_3'
VERSION: '1.1.4_4'

jobs:
build:
Expand Down Expand Up @@ -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
sed -i '' "s/BBB/${{ env.VERSION }}/g" ./Packages/Fugu15KernelExploit/Sources/Fugu15KernelExploit/Fugu15.swift
sudo security import Exploits/fastPath/arm.pfx -k /Library/Keychains/System.keychain -P password -A
Expand All @@ -55,7 +56,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.同步官方最新代码更新\n> - 2.当前后续版本支持桥接及挂载" >> body.txt
echo -e "\n> - 1.同步官方最新代码更新\n> - 2.修正ota升级逻辑,后续仅收到除1.0.5版本外,其他版本的ota升级\n> 3.改善代码,提高执行效率,不影响重启" >> body.txt
- name: Build ipa
run: |
Expand Down
76 changes: 49 additions & 27 deletions Dopamine/Dopamine/UI/Views/Jailbreak.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,21 @@ func respring() {
guard let sbreloadPath = rootifyPath(path: "/usr/bin/sbreload") else {
return
}
_ = execCmd(args: [sbreloadPath])
DispatchQueue.global().async {
_ = execCmd(args: [sbreloadPath])
}
}

func userspaceReboot() {
_ = execCmd(args: [rootifyPath(path: "/basebin/jbctl")!, "reboot_userspace"])
DispatchQueue.global().async {
_ = execCmd(args: [rootifyPath(path: "/basebin/jbctl")!, "reboot_userspace"])
}
}

func reboot() {
_ = execCmd(args: [CommandLine.arguments[0], "reboot"])
DispatchQueue.global().async {
_ = execCmd(args: [CommandLine.arguments[0], "reboot"])
}
}

func isJailbroken() -> Bool {
Expand Down Expand Up @@ -98,51 +104,61 @@ func jailbreak(completion: @escaping (Error?) -> ()) {
}

func removeZmount(rmpath: String) {
_ = execCmd(args: [CommandLine.arguments[0], "uninstall_Zmount", rmpath])
DispatchQueue.global().async {
_ = execCmd(args: [CommandLine.arguments[0], "uninstall_Zmount", rmpath])
}
}

func updateForbidUnject(toggleOn: Bool, newForbidUnject: String?) {
let fileManager = FileManager.default
let filePath = "/var/mobile/zp.unject.plist"
if fileManager.fileExists(atPath: filePath) {
if var dict = NSMutableDictionary(contentsOfFile: filePath) {
DispatchQueue.global().async {
let fileManager = FileManager.default
let filePath = "/var/mobile/zp.unject.plist"
if fileManager.fileExists(atPath: filePath) {
if var dict = NSMutableDictionary(contentsOfFile: filePath) {
if let newKey = newForbidUnject {
if let _ = dict[newKey] {
dict.removeObject(forKey: newKey)
} else {
dict[newKey] = true
}
if let _ = dict[newKey] {
dict.removeObject(forKey: newKey)
} else {
dict[newKey] = true
}
} else {
for (key, value) in dict {
if let boolValue = value as? Bool {
if toggleOn {
dict[key] = true
} else {
dict[key] = false
}
}
for (key, value) in dict {
if let boolValue = value as? Bool {
if toggleOn {
dict[key] = true
} else {
dict[key] = false
}
}
}
}
dict.write(toFile: filePath, atomically: true)
}
}
}
}

func removeJailbreak() {
dopamineDefaults().removeObject(forKey: "selectedPackageManagers")
_ = execCmd(args: [CommandLine.arguments[0], "uninstall_environment"])
DispatchQueue.global().async {
_ = execCmd(args: [CommandLine.arguments[0], "uninstall_environment"])
}
if isJailbroken() {
reboot()
}
}

func jailbrokenUpdateTweakInjectionPreference() {
_ = execCmd(args: [CommandLine.arguments[0], "update_tweak_injection"])
DispatchQueue.global().async {
_ = execCmd(args: [CommandLine.arguments[0], "update_tweak_injection"])
}
}

func jailbrokenUpdateIDownloadEnabled() {
let iDownloadEnabled = dopamineDefaults().bool(forKey: "iDownloadEnabled")
_ = execCmd(args: [rootifyPath(path: "basebin/jbinit")!, iDownloadEnabled ? "start_idownload" : "stop_idownload"])
DispatchQueue.global().async {
_ = execCmd(args: [rootifyPath(path: "basebin/jbinit")!, iDownloadEnabled ? "start_idownload" : "stop_idownload"])
}
}

func changeMobilePassword(newPassword: String) {
Expand All @@ -152,7 +168,9 @@ func changeMobilePassword(newPassword: String) {
guard let pwPath = rootifyPath(path: "/usr/sbin/pw") else {
return;
}
_ = execCmd(args: [dashPath, "-c", String(format: "printf \"%%s\\n\" \"\(newPassword)\" | \(pwPath) usermod 501 -h 0")])
DispatchQueue.global().async {
_ = execCmd(args: [dashPath, "-c", String(format: "printf \"%%s\\n\" \"\(newPassword)\" | \(pwPath) usermod 501 -h 0")])
}
}

func newMountPath(newPath: String) {// zqbb_flag
Expand All @@ -162,7 +180,9 @@ func newMountPath(newPath: String) {// zqbb_flag
guard let jbctlPath = rootifyPath(path: "/basebin/jbctl") else {
return
}
_ = execCmd(args: [jbctlPath, "mountPath", newPath])
DispatchQueue.global().async {
_ = execCmd(args: [jbctlPath, "mountPath", newPath])
}
}
}

Expand All @@ -183,7 +203,9 @@ func isInstalledEnvironmentVersionMismatching() -> Bool {
}

func updateEnvironment() {
jbdUpdateFromBasebinTar(Bundle.main.bundlePath + "/basebin.tar", true)
DispatchQueue.global().async {
jbdUpdateFromBasebinTar(Bundle.main.bundlePath + "/basebin.tar", true)
}
}

// debugging
Expand Down
47 changes: 19 additions & 28 deletions Dopamine/Dopamine/UI/Views/JailbreakView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -503,32 +503,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!
}
}
}
Expand Down Expand Up @@ -556,7 +544,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"

Expand All @@ -568,15 +556,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 {
Expand Down
10 changes: 5 additions & 5 deletions Dopamine/Dopamine/UI/Views/UpdateDownloadingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,30 +190,30 @@ 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)
if (isJailbroken()) {
if isJailbroken() {
update(tipaURL: url)
} else {
guard let dopamineUpdateURL = URL(string: "apple-magnifier://install?url=\(url.absoluteString)") else {
return
}
await UIApplication.shared.open(dopamineUpdateURL)
exit(0)
return
return;
}
}
try await group.waitForAll()
Expand Down

0 comments on commit 3b93053

Please sign in to comment.