app: use github api to check updates

This commit is contained in:
vvb2060
2025-05-09 09:22:43 +00:00
committed by John Wu
parent a4b8c5e46b
commit 76962f965e
9 changed files with 88 additions and 66 deletions

View File

@@ -13,24 +13,28 @@ android {
namespace = "com.topjohnwu.magisk"
val canary = !Config.version.contains(".")
val url = if (canary) null
else "https://github.com/topjohnwu/Magisk/releases/download/v${Config.version}/Magisk-v${Config.version}.apk"
val base = "https://github.com/topjohnwu/Magisk/releases/download/"
val url = base + "v${Config.version}/Magisk-v${Config.version}.apk"
val canaryUrl = base + "canary-${Config.versionCode}/"
defaultConfig {
applicationId = "com.topjohnwu.magisk"
versionCode = 1
versionName = "1.0"
buildConfigField("String", "APK_URL", url?.let { "\"$it\"" } ?: "null" )
buildConfigField("String", "APK_URL", "\"$url\"")
buildConfigField("int", "STUB_VERSION", Config.stubVersion)
}
buildTypes {
release {
if (canary) buildConfigField("String", "APK_URL", "\"${canaryUrl}app-release.apk\"")
proguardFiles("proguard-rules.pro")
isMinifyEnabled = true
isShrinkResources = false
}
debug {
if (canary) buildConfigField("String", "APK_URL", "\"${canaryUrl}app-debug.apk\"")
}
}
buildFeatures {

View File

@@ -27,8 +27,6 @@ import com.topjohnwu.magisk.net.Networking;
import com.topjohnwu.magisk.net.Request;
import com.topjohnwu.magisk.utils.APKInstall;
import org.json.JSONException;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
@@ -48,13 +46,8 @@ import javax.crypto.spec.SecretKeySpec;
public class DownloadActivity extends Activity {
private static final String APP_NAME = "Magisk";
private static final String JSON_URL = BuildConfig.DEBUG ?
"https://topjohnwu.github.io/magisk-files/debug.json" :
"https://topjohnwu.github.io/magisk-files/canary.json";
private String apkLink = BuildConfig.APK_URL;
private Context themed;
private ProgressDialog dialog;
private boolean dynLoad;
@Override
@@ -75,11 +68,7 @@ public class DownloadActivity extends Activity {
ProviderInstaller.install(this);
if (Networking.checkNetworkStatus(this)) {
if (BuildConfig.APK_URL == null) {
fetchCanary();
} else {
showDialog();
}
showDialog();
} else {
new AlertDialog.Builder(themed)
.setCancelable(false)
@@ -115,23 +104,10 @@ public class DownloadActivity extends Activity {
.show();
}
private void fetchCanary() {
dialog = ProgressDialog.show(themed, "", "", true);
request(JSON_URL).getAsJSONObject(json -> {
dialog.dismiss();
try {
apkLink = json.getJSONObject("magisk").getString("link");
showDialog();
} catch (JSONException e) {
error(e);
}
});
}
private void dlAPK() {
dialog = ProgressDialog.show(themed, getString(dling), getString(dling) + " " + APP_NAME, true);
ProgressDialog.show(themed, getString(dling), getString(dling) + " " + APP_NAME, true);
// Download and upgrade the app
var request = request(apkLink).setExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
var request = request(BuildConfig.APK_URL).setExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (dynLoad) {
request.getAsFile(StubApk.current(this), file -> StubApk.restartProcess(this));
} else {