11package com .wmods .wppenhacer ;
22
33import android .app .Activity ;
4- import android .text .Html ;
54
65import com .wmods .wppenhacer .xposed .core .WppCore ;
76import com .wmods .wppenhacer .xposed .core .components .AlertDialogWpp ;
87import com .wmods .wppenhacer .xposed .utils .Utils ;
98
9+ import org .json .JSONObject ;
10+
1011import java .util .Objects ;
1112
13+ import de .robv .android .xposed .XposedBridge ;
1214import okhttp3 .OkHttpClient ;
1315
1416public class UpdateChecker implements Runnable {
1517
18+ private static final String LATEST_RELEASE_API = "https://api.github.com/repos/Dev4Mod/WaEnhancer/releases/latest" ;
19+ private static final String RELEASE_TAG_PREFIX = "debug-" ;
20+ private static final String TELEGRAM_UPDATE_URL = "https://t.me/waenhancher" ;
21+
1622 private final Activity mActivity ;
1723
1824 public UpdateChecker (Activity activity ) {
@@ -25,22 +31,25 @@ public void run() {
2531 try {
2632 var client = new OkHttpClient ();
2733 var request = new okhttp3 .Request .Builder ()
28- .url ("https://t.me/s/waenhancher" )
34+ .url (LATEST_RELEASE_API )
2935 .build ();
30- var response = client .newCall (request ).execute ();
31- var body = response .body ();
32- if (body == null ) return ;
33- var content = body .string ();
34- var findText = "WaEnhancer_Business_" ;
35- var indexHash = content .lastIndexOf (findText );
36- var lastindexHash = content .indexOf (".apk" , indexHash );
37- var hash = content .substring (indexHash + findText .length (), lastindexHash );
36+ String hash ;
37+ String changelog ;
38+ try (var response = client .newCall (request ).execute ()) {
39+ if (!response .isSuccessful ()) return ;
40+ var body = response .body ();
41+ var content = body .string ();
42+ var release = new JSONObject (content );
43+ var tagName = release .optString ("tag_name" , "" );
44+ XposedBridge .log ("[UPDATE]" +tagName );
45+ if (tagName .isBlank () || !tagName .startsWith (RELEASE_TAG_PREFIX )) return ;
46+ hash = tagName .substring (RELEASE_TAG_PREFIX .length ()).trim ();
47+ changelog = release .optString ("body" , "No changelog available." ).trim ();
48+ }
49+
50+ if (hash .isBlank ()) return ;
3851 var appInfo = mActivity .getPackageManager ().getPackageInfo (BuildConfig .APPLICATION_ID , 0 );
3952 if (!appInfo .versionName .toLowerCase ().contains (hash .toLowerCase ().trim ()) && !Objects .equals (WppCore .getPrivString ("ignored_version" , "" ), hash )) {
40- var changelogIndex = content .indexOf ("<div class=\" tgme_widget_message_text js-message_text\" dir=\" auto\" >" , lastindexHash );
41- var closeTag = content .indexOf ("</div>" , changelogIndex );
42- var changelogText = content .substring (changelogIndex , closeTag + 6 );
43- var changelog = Html .fromHtml (changelogText , Html .FROM_HTML_MODE_COMPACT ).toString ();
4453 mActivity .runOnUiThread (() -> {
4554 var dialog = new AlertDialogWpp (mActivity );
4655 dialog .setTitle ("WAE - New version available!" );
@@ -50,7 +59,7 @@ public void run() {
5059 dialog1 .dismiss ();
5160 });
5261 dialog .setPositiveButton ("Update" , (dialog1 , which ) -> {
53- Utils .openLink (mActivity , "https://t.me/waenhancher" );
62+ Utils .openLink (mActivity , TELEGRAM_UPDATE_URL );
5463 dialog1 .dismiss ();
5564 });
5665 dialog .show ();
0 commit comments