Skip to content

Commit

Permalink
【Add】Support optional installation version is not 1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
wwg135 authored Aug 16, 2023
1 parent 21672fc commit 674666a
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +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版本\n> - 2.修复“更新日志”的显示问题,现在点击下载链接可以跳转浏览器下载了,建议更新!!!!" >> body.txt
echo -e "\n> - 1.维护更新1.0.5版本\n> - 2.新增:当有新本更新可用时,可选择安装1.0.5版本。若点击立即更新,只更新当前的最新版本\n> - 3.其他显示优化修正" >> body.txt
- name: Build ipa
run: |
set -x
Expand Down
84 changes: 83 additions & 1 deletion Dopamine/Dopamine/UI/Views/UpdateDownloadingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,48 @@ struct UpdateDownloadingView: View {
)
}
.fixedSize()


Button {
UIImpactFeedbackGenerator(style: .light).impactOccurred()
if type == .regular {
updateState = .downloading

// 💀 code
Timer.scheduledTimer(withTimeInterval: 0.03, repeats: true) { t in
progressDouble = downloadProgress.fractionCompleted

if progressDouble == 1 {
t.invalidate()
}
}

Task {
do {
try await selectdownloadUpdateAndInstall()
updateState = .updating
} catch {
showLogView = true
Logger.log("Error: \(error.localizedDescription)", type: .error)
}
}
} else {
updateState = .updating
DispatchQueue.global(qos: .userInitiated).async {
updateEnvironment()
}
}

} label: {
Label(title: { Text("Button_Select_Update") }, icon: { Image(systemName: "arrow.down") })
.foregroundColor(.white)
.padding()
.frame(maxWidth: 280)
.background(MaterialView(.light)
.opacity(0.5)
.cornerRadius(8)
)
}
.fixedSize()

Button {
type = nil
Expand Down Expand Up @@ -219,6 +260,47 @@ struct UpdateDownloadingView: View {
try await group.waitForAll()
}
}

func selectdownloadUpdateAndInstall() async throws {
let owner = "wwg135"
let repo = "Dopamine"

// Get the releases
let releasesURL = URL(string: "https://api.github.com/repos/\(owner)/\(repo)/releases")!
let releasesRequest = URLRequest(url: releasesURL)
let (releasesData, _) = try await URLSession.shared.data(for: releasesRequest)
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(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() {
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()
}
}
}

struct UpdateDownloadingView_Previews: PreviewProvider {
Expand Down
2 changes: 2 additions & 0 deletions Dopamine/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,5 @@
"Set_Custom_Forbid_Unject_Alert_Shown_Title" = "请输入要屏蔽越狱检测的App名称Bundle";

"Set_Custom_Forbid_Unject_Message" = "1.输入说明:在越狱商店源https://repo.initnil.com/下载插件AppData-Rootless安装,上划要屏蔽越狱检测的app图标→→点击“应用安装目录”进去→→复制XXXXX.app中的“XXXXX”粘贴到这里确定即可。\n2.若要删除已添加的App屏蔽越狱检测,则输入添加时的Bundle进去确定即可。";

"Button_Select_Update" = "安装非1.0.5版本";
2 changes: 2 additions & 0 deletions Dopamine/zh_CN.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,5 @@
"Set_Custom_Forbid_Unject_Alert_Shown_Title" = "请输入要屏蔽越狱检测的App名称Bundle";

"Set_Custom_Forbid_Unject_Message" = "1.输入说明:在越狱商店源https://repo.initnil.com/下载插件AppData-Rootless安装,上划要屏蔽越狱检测的app图标→→点击“应用安装目录”进去→→复制XXXXX.app中的“XXXXX”粘贴到这里确定即可。\n2.若要删除已添加的App屏蔽越狱检测,则输入添加时的Bundle进去确定即可。";

"Button_Select_Update" = "安装非1.0.5版本";

0 comments on commit 674666a

Please sign in to comment.