Skip to content

Commit

Permalink
feat: update always
Browse files Browse the repository at this point in the history
  • Loading branch information
omg-xtao committed Mar 9, 2024
1 parent 9415a2b commit 342627b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
16 changes: 14 additions & 2 deletions TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2765,7 +2765,15 @@ private boolean handleIntent(Intent intent, boolean isNew, boolean restore, bool
FileLog.e(e);
}
} else if (url.startsWith("tg:upgrade") || url.startsWith("tg://upgrade") || url.startsWith("tg:update") || url.startsWith("tg://update")) {
checkAppUpdate(true, null);
boolean updateAlways = false;
try {
url = url.replace("tg:upgrade", "tg://telegram.org").replace("tg://upgrade", "tg://telegram.org").replace("tg:update", "tg://telegram.org").replace("tg://update", "tg://telegram.org");
data = Uri.parse(url);
updateAlways = data.getQueryParameter("always") != null && "true".equals(data.getQueryParameter("always"));
} catch (Exception e) {
FileLog.e(e);
}
checkAppUpdate(true, null, updateAlways);
} else if (url.startsWith("tg:neko") || url.startsWith("tg://neko")) {
url = url.replace("tg:neko", "tg://t.me/nasettings").replace("tg://neko", "tg://t.me/nasettings");
data = Uri.parse(url);
Expand Down Expand Up @@ -5473,6 +5481,10 @@ private List<TLRPC.TL_contact> findContacts(String userName, String userPhone, b
}

public void checkAppUpdate(boolean force, Browser.Progress progress) {
checkAppUpdate(force, progress, false);
}

public void checkAppUpdate(boolean force, Browser.Progress progress, boolean updateAlways) {
// if (BuildVars.isFdroid || BuildVars.isPlay) return;
// if (NekoXConfig.autoUpdateReleaseChannel == 0) return;
// if (!force && System.currentTimeMillis() < NekoConfig.lastUpdateCheckTime.Long() + 48 * 60 * 60 * 1000L) return;
Expand Down Expand Up @@ -5542,7 +5554,7 @@ public void checkAppUpdate(boolean force, Browser.Progress progress) {
progress.end();
}
});
});
}, updateAlways);
if (progress != null) {
progress.init();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public static UpdateHelper getInstance() {
return InstanceHolder.instance;
}

private boolean updateAlways = false;

@Override
protected void onError(String text, Delegate delegate) {
delegate.onTLResponse(null, text);
Expand Down Expand Up @@ -67,7 +69,10 @@ private Update getShouldUpdateVersion(List<JSONObject> responses) {
for (var string : responses) {
try {
int version_code = string.getInt("version_code");
if (version_code > maxVersion) {
if (version_code > maxVersion || updateAlways) {
if (updateAlways) {
updateAlways = false;
}
maxVersion = version_code;
ref = new Update(
string.getBoolean("can_not_skip"),
Expand Down Expand Up @@ -166,10 +171,15 @@ protected void onLoadSuccess(ArrayList<JSONObject> responses, Delegate delegate)
}

public void checkNewVersionAvailable(Delegate delegate) {
checkNewVersionAvailable(delegate, false);
}

public void checkNewVersionAvailable(Delegate delegate, boolean updateAlways_) {
if (NekoXConfig.autoUpdateReleaseChannel == 0) {
delegate.onTLResponse(null, null);
return;
}
updateAlways = updateAlways_;
load(delegate);
}

Expand Down

0 comments on commit 342627b

Please sign in to comment.