v0.9.4: added an opt-in for betas in the update checker

This commit is contained in:
Evan Debenham 2021-07-14 16:16:29 -04:00
parent fd0286b9a1
commit 3c3e22d486
7 changed files with 57 additions and 7 deletions

View File

@ -186,6 +186,7 @@ windows.wndsettings$uitab.key_bindings=Key Bindings
windows.wndsettings$datatab.title=Connectivity Settings
windows.wndsettings$datatab.news=Check for news
windows.wndsettings$datatab.updates=Check for updates
windows.wndsettings$datatab.betas=Include beta updates
windows.wndsettings$datatab.wifi=Only check on WiFi
windows.wndsettings$audiotab.title=Audio Settings
windows.wndsettings$audiotab.music_vol=Music Volume

View File

@ -24,6 +24,7 @@ package com.shatteredpixel.shatteredpixeldungeon;
import com.shatteredpixel.shatteredpixeldungeon.messages.Languages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
import com.shatteredpixel.shatteredpixeldungeon.scenes.PixelScene;
import com.watabou.noosa.Game;
import com.watabou.noosa.audio.Music;
import com.watabou.noosa.audio.Sample;
import com.watabou.utils.GameSettings;
@ -268,6 +269,7 @@ public class SPDSettings extends GameSettings {
public static final String KEY_NEWS = "news";
public static final String KEY_UPDATES = "updates";
public static final String KEY_BETAS = "betas";
public static final String KEY_WIFI = "wifi";
public static final String KEY_NEWS_LAST_READ = "news_last_read";
@ -288,6 +290,14 @@ public class SPDSettings extends GameSettings {
return getBoolean(KEY_UPDATES, true);
}
public static void betas(boolean value){
put(KEY_BETAS, value);
}
public static boolean betas(){
return getBoolean(KEY_BETAS, Game.version.contains("BETA") || Game.version.contains("RC"));
}
public static void WiFi(boolean value){
put(KEY_WIFI, value);
}

View File

@ -41,11 +41,20 @@ public class Updates {
return supportsUpdates() && service.isUpdateable();
}
public static boolean supportsBetaChannel(){
return supportsUpdates() && service.supportsBetaChannel();
}
public static void checkForUpdate(){
if (!isUpdateable()) return;
if (lastCheck != null && (new Date().getTime() - lastCheck.getTime()) < CHECK_DELAY) return;
service.checkForUpdate(!SPDSettings.WiFi(), new UpdateService.UpdateResultCallback() {
//We do this so that automatically enabled beta checking (for users who DLed a beta) persists afterward
if (SPDSettings.betas()){
SPDSettings.betas(true);
}
service.checkForUpdate(!SPDSettings.WiFi(), SPDSettings.betas(), new UpdateService.UpdateResultCallback() {
@Override
public void onUpdateAvailable(AvailableUpdateData update) {
lastCheck = new Date();

View File

@ -528,6 +528,7 @@ public class WndSettings extends WndTabbed {
ColorBlock sep1;
CheckBox chkNews;
CheckBox chkUpdates;
CheckBox chkBetas;
CheckBox chkWifi;
@Override
@ -561,6 +562,19 @@ public class WndSettings extends WndTabbed {
};
chkUpdates.checked(SPDSettings.updates());
add(chkUpdates);
if (Updates.supportsBetaChannel()){
chkBetas = new CheckBox(Messages.get(this, "betas")) {
@Override
protected void onClick() {
super.onClick();
SPDSettings.updates(checked());
Updates.clearUpdate();
}
};
chkBetas.checked(SPDSettings.betas());
add(chkBetas);
}
}
if (!DeviceCompat.isDesktop()){
@ -596,6 +610,11 @@ public class WndSettings extends WndTabbed {
}
}
if (chkBetas != null){
chkBetas.setRect(0, pos + GAP, width, BTN_HEIGHT);
pos = chkBetas.bottom();
}
if (chkWifi != null){
chkWifi.setRect(0, pos + GAP, width, BTN_HEIGHT);
pos = chkWifi.bottom();

View File

@ -34,7 +34,10 @@ public abstract class UpdateService {
//whether the app is updateable via an ingame prompt (e.g. not a demo or an android instant app)
public abstract boolean isUpdateable();
public abstract void checkForUpdate( boolean useMetered, UpdateResultCallback callback );
//whether the service supports an opt-in channel for betas
public abstract boolean supportsBetaChannel();
public abstract void checkForUpdate( boolean useMetered, boolean includeBetas, UpdateResultCallback callback );
public abstract void initializeUpdate( AvailableUpdateData update );

View File

@ -35,7 +35,12 @@ public class DebugUpdates extends UpdateService {
}
@Override
public void checkForUpdate(boolean useMetered, UpdateResultCallback callback) {
public boolean supportsBetaChannel() {
return true;
}
@Override
public void checkForUpdate(boolean useMetered, boolean includeBetas, UpdateResultCallback callback) {
if (!useMetered && !Game.platform.connectedToUnmeteredNetwork()){
callback.onConnectionFailed();

View File

@ -44,7 +44,12 @@ public class GitHubUpdates extends UpdateService {
}
@Override
public void checkForUpdate(boolean useMetered, UpdateResultCallback callback) {
public boolean supportsBetaChannel() {
return true;
}
@Override
public void checkForUpdate(boolean useMetered, boolean includeBetas, UpdateResultCallback callback) {
if (!useMetered && !Game.platform.connectedToUnmeteredNetwork()){
callback.onConnectionFailed();
@ -62,15 +67,13 @@ public class GitHubUpdates extends UpdateService {
Bundle latestRelease = null;
int latestVersionCode = Game.versionCode;
boolean includePrereleases = Game.version.contains("-BETA-") || Game.version.contains("-RC-");
for (Bundle b : Bundle.read( httpResponse.getResultAsStream() ).getBundleArray()){
Matcher m = versionCodePattern.matcher(b.getString("body"));
if (m.find()){
int releaseVersion = Integer.parseInt(m.group(1));
if (releaseVersion > latestVersionCode
&& (includePrereleases || !b.getBoolean("prerelease"))){
&& (includeBetas || !b.getBoolean("prerelease"))){
latestRelease = b;
latestVersionCode = releaseVersion;
}