Skip to content

Commit fc537d6

Browse files
committed
add update version checker
1 parent d8820d7 commit fc537d6

File tree

5 files changed

+82
-4
lines changed

5 files changed

+82
-4
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.wmods.wppenhacer;
2+
3+
import android.app.Activity;
4+
import android.app.AlertDialog;
5+
import android.text.Html;
6+
7+
import com.wmods.wppenhacer.xposed.core.WppCore;
8+
import com.wmods.wppenhacer.xposed.utils.Utils;
9+
10+
import java.util.Objects;
11+
12+
import de.robv.android.xposed.XposedBridge;
13+
import okhttp3.OkHttpClient;
14+
15+
public class UpdateChecker implements Runnable {
16+
17+
private final Activity mActivity;
18+
19+
public UpdateChecker(Activity activity) {
20+
this.mActivity = activity;
21+
}
22+
23+
24+
@Override
25+
public void run() {
26+
try {
27+
var client = new OkHttpClient();
28+
var request = new okhttp3.Request.Builder()
29+
.url("https://t.me/s/waenhancher")
30+
.build();
31+
var response = client.newCall(request).execute();
32+
var body = response.body();
33+
if (body == null) return;
34+
var content = body.string();
35+
var indexHash = content.lastIndexOf("WaEnhancer_debug_");
36+
var lastindexHash = content.indexOf(".apk", indexHash);
37+
var hash = content.substring(indexHash + 17, lastindexHash);
38+
var appInfo = mActivity.getPackageManager().getPackageInfo(BuildConfig.APPLICATION_ID, 0);
39+
XposedBridge.log("hash: " + hash + " version: " + appInfo.versionName);
40+
if (!hash.toLowerCase().contains(appInfo.versionName.toLowerCase()) && !Objects.equals(WppCore.getPrivString("ignored_version", ""), hash)) {
41+
var changelogIndex = content.indexOf("<div class=\"tgme_widget_message_text js-message_text\" dir=\"auto\">", lastindexHash);
42+
var closeTag = content.indexOf("</div>", changelogIndex);
43+
var changelogText = content.substring(changelogIndex, closeTag + 6);
44+
var changelog = Html.fromHtml(changelogText, Html.FROM_HTML_MODE_COMPACT).toString();
45+
mActivity.runOnUiThread(() -> {
46+
AlertDialog.Builder dialog = new AlertDialog.Builder(mActivity);
47+
dialog.setTitle("WAE - New version available!");
48+
dialog.setMessage("Changelog:\n\n" + changelog);
49+
dialog.setNegativeButton("Ignore", (dialog1, which) -> {
50+
WppCore.setPrivString("ignored_version", hash);
51+
dialog1.dismiss();
52+
});
53+
dialog.setPositiveButton("Update", (dialog1, which) -> {
54+
Utils.openLink(mActivity, "https://t.me/waenhancher");
55+
dialog1.dismiss();
56+
});
57+
dialog.show();
58+
});
59+
}
60+
} catch (Exception e) {
61+
XposedBridge.log(e);
62+
}
63+
}
64+
}

app/src/main/java/com/wmods/wppenhacer/xposed/core/FeatureLoader.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import androidx.core.content.ContextCompat;
1919

2020
import com.wmods.wppenhacer.BuildConfig;
21+
import com.wmods.wppenhacer.UpdateChecker;
2122
import com.wmods.wppenhacer.xposed.core.components.AlertDialogWpp;
2223
import com.wmods.wppenhacer.xposed.core.components.FMessageWpp;
2324
import com.wmods.wppenhacer.xposed.core.components.SharedPreferencesWrapper;
@@ -178,6 +179,13 @@ private static void initComponents(ClassLoader loader, XSharedPreferences pref)
178179
AlertDialogWpp.initDialog(loader);
179180
FMessageWpp.init(loader);
180181
Utils.init(loader);
182+
WppCore.addListenerActivity((activity, state) -> {
183+
XposedBridge.log("Activity: " + activity.getClass().getSimpleName() + " " + state);
184+
if (activity.getClass().getSimpleName().equals("HomeActivity") && state == WppCore.ActivityChangeState.ChangeType.START) {
185+
XposedBridge.log("Starting UpdateChecker");
186+
CompletableFuture.runAsync(new UpdateChecker(activity));
187+
}
188+
});
181189
}
182190

183191
private static void registerReceivers() {

app/src/main/java/com/wmods/wppenhacer/xposed/core/WppCore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ public static WaeIIFace getClientBridge() throws Exception {
446446

447447
public interface ActivityChangeState {
448448

449-
void onChange(Object object, ChangeType type);
449+
void onChange(Activity activity, ChangeType type);
450450

451451
enum ChangeType {
452452
START, END, RESUME, PAUSE

app/src/main/java/com/wmods/wppenhacer/xposed/features/privacy/CustomPrivacy.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,11 @@ public void doHook() throws Throwable {
6262
var hooker = new WppCore.ActivityChangeState() {
6363
@SuppressLint("ResourceType")
6464
@Override
65-
public void onChange(Object objActivity, ChangeType type) {
65+
public void onChange(Activity activity, ChangeType type) {
6666
try {
6767
if (type != ChangeType.START) return;
68-
if (!ContactInfoActivityClass.isInstance(objActivity) && !GroupInfoActivityClass.isInstance(objActivity))
68+
if (!ContactInfoActivityClass.isInstance(activity) && !GroupInfoActivityClass.isInstance(activity))
6969
return;
70-
Activity activity = (Activity) objActivity;
7170
if (activity.findViewById(0x7f0a9999) != null) return;
7271
int id = Utils.getID("contact_info_security_card_layout", "id");
7372
ViewGroup infoLayout = activity.getWindow().findViewById(id);

app/src/main/java/com/wmods/wppenhacer/xposed/utils/Utils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.wmods.wppenhacer.xposed.utils;
22

33
import android.annotation.SuppressLint;
4+
import android.app.Activity;
45
import android.app.Application;
56
import android.app.NotificationChannel;
67
import android.app.NotificationManager;
@@ -11,6 +12,7 @@
1112
import android.content.Intent;
1213
import android.content.pm.PackageManager;
1314
import android.media.MediaScannerConnection;
15+
import android.net.Uri;
1416
import android.os.Binder;
1517
import android.os.Handler;
1618
import android.os.Looper;
@@ -254,6 +256,11 @@ public static void showNotification(String title, String content) {
254256
notificationManager.notify(new Random().nextInt(), notification.build());
255257
}
256258

259+
public static void openLink(Activity mActivity, String url) {
260+
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
261+
mActivity.startActivity(browserIntent);
262+
}
263+
257264

258265
@FunctionalInterface
259266
public interface BinderLocalScopeBlock<T> {

0 commit comments

Comments
 (0)