Fix modules json self update mechanism! (Fix #49)

pull/55/head
Fox2Code 2 years ago
parent 44472aaadb
commit b112330c9a

@ -15,9 +15,14 @@ import com.fox2code.mmm.installer.InstallerInitializer;
import com.fox2code.mmm.manager.LocalModuleInfo;
import com.fox2code.mmm.manager.ModuleInfo;
import com.fox2code.mmm.manager.ModuleManager;
import com.fox2code.mmm.utils.Http;
import com.fox2code.mmm.utils.IntentHelper;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import java.nio.charset.StandardCharsets;
import io.noties.markwon.Markwon;
public enum ActionButtonType {
INFO(R.drawable.ic_baseline_info_24) {
@Override
@ -71,28 +76,23 @@ public enum ActionButtonType {
new MaterialAlertDialogBuilder(button.getContext());
builder.setTitle(moduleInfo.name).setCancelable(true)
.setIcon(R.drawable.ic_baseline_extension_24);
String desc;
CharSequence desc = moduleInfo.description;
final boolean noPatch;
if (moduleInfo instanceof LocalModuleInfo) {
LocalModuleInfo localModuleInfo = (LocalModuleInfo) moduleInfo;
desc = localModuleInfo.updateChangeLog.isEmpty() ?
moduleInfo.description : localModuleInfo.updateChangeLog;
if (!localModuleInfo.updateChangeLog.isEmpty()) {
Markwon markwon = MainApplication.getINSTANCE().getMarkwon();
// Re-render each time in cse of config changes
desc = markwon.render(markwon.parse(localModuleInfo.updateChangeLog));
}
noPatch = true;
} else {
desc = moduleInfo.description;
noPatch = false;
}
if (desc == null || desc.isEmpty()) {
if (desc == null || desc.length() == 0) {
builder.setMessage(R.string.no_desc_found);
} else {
if (desc.length() == 1000) {
int lastDot = desc.lastIndexOf('.');
if (lastDot == -1) {
int lastSpace = desc.lastIndexOf(' ');
if (lastSpace == -1)
desc = desc.substring(0, lastSpace);
} else {
desc = desc.substring(0, lastDot + 1);
}
}
builder.setMessage(desc);
}
Log.d("Test", "URL: " + updateZipUrl);
@ -103,7 +103,7 @@ public enum ActionButtonType {
R.string.update_module : R.string.install_module, (x, y) -> {
String updateZipChecksum = moduleHolder.getUpdateZipChecksum();
IntentHelper.openInstaller(button.getContext(), updateZipUrl,
moduleInfo.name, moduleInfo.config, updateZipChecksum);
moduleInfo.name, moduleInfo.config, updateZipChecksum, noPatch);
});
}
int dim5dp = CompatDisplay.dpToPixel(5);

@ -86,8 +86,9 @@ public class AndroidacyWebAPI {
Uri uri = Uri.parse(moduleUrl);
if (uri.getScheme().equals("https") && uri.getHost().endsWith(".androidacy.com")) {
this.activity.backOnResume = true;
IntentHelper.openInstaller(this.activity,
moduleUrl, installTitle, null, checksum);
IntentHelper.openInstaller(
this.activity, moduleUrl, installTitle,
null, checksum, true);
} else {
this.activity.forceBackPressed();
}

@ -8,12 +8,16 @@ import com.fox2code.mmm.utils.PropUtils;
import org.json.JSONObject;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import io.noties.markwon.Markwon;
public class LocalModuleInfo extends ModuleInfo {
public String updateVersion;
public long updateVersionCode = Long.MIN_VALUE;
public String updateZipUrl;
public String updateChangeLogUrl;
public String updateChangeLog = "";
public String updateChecksum;
@ -25,11 +29,21 @@ public class LocalModuleInfo extends ModuleInfo {
if (this.updateJson != null) {
try {
JSONObject jsonUpdate = new JSONObject(new String(Http.doHttpGet(
this.updateJson, false), StandardCharsets.UTF_8));
this.updateJson, true), StandardCharsets.UTF_8));
this.updateVersion = jsonUpdate.optString("version");
this.updateVersionCode = jsonUpdate.getLong("versionCode");
this.updateZipUrl = jsonUpdate.getString("zipUrl");
this.updateChangeLog = jsonUpdate.optString("changelog");
this.updateChangeLogUrl = jsonUpdate.optString("changelog");
try {
String desc = new String(Http.doHttpGet(
this.updateChangeLogUrl, true), StandardCharsets.UTF_8);
if (desc.length() > 1000) {
desc = desc.substring(0, 1000);
}
this.updateChangeLog = desc;
} catch (IOException ioe) {
this.updateChangeLog = "";
}
this.updateChecksum = jsonUpdate.optString("checksum");
if (this.updateZipUrl.isEmpty()) throw FastException.INSTANCE;
this.updateVersion = PropUtils.shortenVersionName(

@ -125,6 +125,11 @@ public class IntentHelper {
openInstaller(context, url, title, config, checksum, false, false);
}
public static void openInstaller(Context context, String url, String title, String config,
String checksum, boolean noPatch) {
openInstaller(context, url, title, config, checksum, noPatch, false);
}
public static void openInstaller(Context context, String url, String title, String config,
String checksum, boolean noPatch,boolean testDebug) {
try {

Loading…
Cancel
Save