Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
feat(YouTube - Spoof app version): Show the dialog when the app is fi…
Browse files Browse the repository at this point in the history
…rst installed
  • Loading branch information
anddea committed Oct 23, 2024
1 parent 469a716 commit 7287672
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@
import static app.revanced.integrations.shared.utils.Utils.runOnMainThreadDelayed;

import android.app.Activity;
import android.app.AlertDialog;

import androidx.annotation.NonNull;

import app.revanced.integrations.shared.settings.BaseSettings;
import app.revanced.integrations.shared.settings.BooleanSetting;
import app.revanced.integrations.shared.utils.Utils;
import app.revanced.integrations.youtube.settings.Settings;
import app.revanced.integrations.youtube.utils.ExtendedUtils;

@SuppressWarnings("unused")
public class InitializationPatch {
private static final BooleanSetting SETTINGS_INITIALIZED = BaseSettings.SETTINGS_INITIALIZED;
private static final BooleanSetting SPOOF_APP_VERSION = Settings.SPOOF_APP_VERSION;
private static final boolean hasRollingNumberIssue = Settings.SPOOF_APP_VERSION_TARGET.defaultValue.startsWith("19");

/**
* Some layouts that depend on litho do not load when the app is first installed.
Expand All @@ -21,10 +28,18 @@ public class InitializationPatch {
* To fix this, show the restart dialog when the app is installed for the first time.
*/
public static void onCreate(@NonNull Activity mActivity) {
if (BaseSettings.SETTINGS_INITIALIZED.get())
if (SETTINGS_INITIALIZED.get()) {
return;
runOnMainThreadDelayed(() -> showRestartDialog(mActivity, str("revanced_extended_restart_first_run"), 3500), 500);
runOnMainThreadDelayed(() -> BaseSettings.SETTINGS_INITIALIZED.save(true), 1000);
}
showSpoofAppVersionDialog(mActivity);
runOnMainThreadDelayed(() -> {
if (hasRollingNumberIssue) {
showSpoofAppVersionDialog(mActivity);
} else {
showRestartDialog(mActivity, str("revanced_extended_restart_first_run"), 3500);
}
}, 500);
runOnMainThreadDelayed(() -> SETTINGS_INITIALIZED.save(true), 1000);
}

public static void setExtendedUtils(@NonNull Activity mActivity) {
Expand All @@ -33,4 +48,18 @@ public static void setExtendedUtils(@NonNull Activity mActivity) {
ExtendedUtils.setVersionName();
ExtendedUtils.setPlayerFlyoutMenuAdditionalSettings();
}

private static void showSpoofAppVersionDialog(@NonNull Activity mActivity) {
new AlertDialog.Builder(mActivity)
.setMessage(str("revanced_extended_restart_first_run_rolling_number"))
.setPositiveButton(android.R.string.ok, (dialog, id)
-> Utils.runOnMainThreadDelayed(() -> {
SPOOF_APP_VERSION.save(true);
Utils.restartApp(mActivity);
}, 3500))
.setNegativeButton(android.R.string.cancel, (dialog, id)
-> Utils.runOnMainThreadDelayed(() -> Utils.restartApp(mActivity), 3500))
.setCancelable(false)
.show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ public static String RVXMusicPackageName() {
return "com.google.android.apps.youtube.music";
}

// Modified by a patch. Do not touch.
public static String SpoofAppVersionDefaultString() {
return "18.17.43";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ public class Settings extends BaseSettings {
public static final BooleanSetting REMOVE_VIEWER_DISCRETION_DIALOG = new BooleanSetting("revanced_remove_viewer_discretion_dialog", FALSE);

public static final EnumSetting<FormFactor> CHANGE_LAYOUT = new EnumSetting<>("revanced_change_layout", FormFactor.ORIGINAL, true);
public static final BooleanSetting SPOOF_APP_VERSION = new BooleanSetting("revanced_spoof_app_version", FALSE, true, "revanced_spoof_app_version_user_dialog_message");
public static final StringSetting SPOOF_APP_VERSION_TARGET = new StringSetting("revanced_spoof_app_version_target", "18.17.43", true, parent(SPOOF_APP_VERSION));
public static final BooleanSetting SPOOF_APP_VERSION = new BooleanSetting("revanced_spoof_app_version", false, true, "revanced_spoof_app_version_user_dialog_message");
public static final StringSetting SPOOF_APP_VERSION_TARGET = new StringSetting("revanced_spoof_app_version_target",
PatchStatus.SpoofAppVersionDefaultString(), true, parent(SPOOF_APP_VERSION));

// PreferenceScreen: General - Account menu
public static final BooleanSetting HIDE_ACCOUNT_MENU = new BooleanSetting("revanced_hide_account_menu", FALSE);
Expand Down

0 comments on commit 7287672

Please sign in to comment.