From f2e15a2e1ff59ae7780cfbd366e5165f4e2b191d Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Wed, 10 Apr 2024 00:59:23 +0400 Subject: [PATCH] fix(YouTube - Settings): Do not show a toast if migrating old unknown settings --- .../app/revanced/integrations/shared/settings/Setting.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/java/app/revanced/integrations/shared/settings/Setting.java b/app/src/main/java/app/revanced/integrations/shared/settings/Setting.java index f5f7b890e9..499e4d0bf2 100644 --- a/app/src/main/java/app/revanced/integrations/shared/settings/Setting.java +++ b/app/src/main/java/app/revanced/integrations/shared/settings/Setting.java @@ -224,6 +224,7 @@ public static void migrateFromOldPreferences(@NonNull SharedPrefCategory oldPref if (!oldPrefs.preferences.contains(settingKey)) { return; // Nothing to do. } + Object newValue = setting.get(); final Object migratedValue; if (setting instanceof BooleanSetting) { @@ -238,13 +239,17 @@ public static void migrateFromOldPreferences(@NonNull SharedPrefCategory oldPref migratedValue = oldPrefs.getString(settingKey, (String) newValue); } else { Logger.printException(() -> "Unknown setting: " + setting); + // Remove otherwise it'll show a toast on every launch + oldPrefs.preferences.edit().remove(settingKey).apply(); return; } + oldPrefs.preferences.edit().remove(settingKey).apply(); // Remove the old setting. if (migratedValue.equals(newValue)) { Logger.printDebug(() -> "Value does not need migrating: " + settingKey); return; // Old value is already equal to the new setting value. } + Logger.printDebug(() -> "Migrating old preference value into current preference: " + settingKey); //noinspection unchecked setting.save(migratedValue);