Add missing items in pop-up menu, if there are any

- Add feature flag to toggle legacy options migration
- Move migration logic to be at launcher start
- Add feature flag to manually edit popup items list
This commit is contained in:
SuperDragonXD
2025-01-15 11:39:29 +08:00
parent 65954e0498
commit 05f4dbbbef
3 changed files with 27 additions and 5 deletions

View File

@@ -45,6 +45,7 @@ import app.lawnchair.preferences2.PreferenceManager2
import app.lawnchair.root.RootHelperManager
import app.lawnchair.root.RootNotAvailableException
import app.lawnchair.theme.ThemeProvider
import app.lawnchair.ui.popup.LauncherOptionsPopup
import app.lawnchair.ui.popup.LawnchairShortcut
import app.lawnchair.util.getThemedIconPacksInstalled
import app.lawnchair.util.unsafeLazy
@@ -221,6 +222,9 @@ class LawnchairLauncher : QuickstepLauncher() {
hasBackGesture = handler !is GestureHandlerConfig.NoOp
}
LauncherOptionsPopup.restoreMissingPopupOptions(launcher)
LauncherOptionsPopup.migrateLegacyPreferences(launcher)
// Handle update from version 12 Alpha 4 to version 12 Alpha 5.
if (
prefs.themedIcons.get() &&

View File

@@ -34,6 +34,26 @@ object LauncherOptionsPopup {
)
}
fun restoreMissingPopupOptions(
launcher: Launcher,
) {
val prefs2 = getInstance(launcher)
val currentOrder = prefs2.launcherPopupOrder.firstBlocking()
val defaultOptions = DEFAULT_ORDER.toLauncherOptions()
val currentOptions = currentOrder.toLauncherOptions()
// check for missing items in current options; if so, add them
val missingItems = defaultOptions.filter { defaultItem ->
defaultItem.identifier !in currentOptions.map { it.identifier }
}
prefs2.launcherPopupOrder.setBlocking(
(missingItems + currentOptions).toOptionOrderString(),
)
}
/**
* Returns the list of supported actions
*/
@@ -50,8 +70,6 @@ object LauncherOptionsPopup {
val lockHomeScreen = prefs2.lockHomeScreen.firstBlocking()
val optionOrder = prefs2.launcherPopupOrder.firstBlocking()
migrateLegacyPreferences(launcher)
val wallpaperResString =
if (Utilities.existsStyleWallpapers(launcher)) R.string.styles_wallpaper_button_text else R.string.wallpapers
val wallpaperResDrawable =
@@ -154,7 +172,7 @@ object LauncherOptionsPopup {
}
}
private fun migrateLegacyPreferences(
fun migrateLegacyPreferences(
launcher: Launcher,
) {
val prefs2 = getInstance(launcher)

View File

@@ -100,10 +100,10 @@ fun DebugMenuPreferences(
}
private val PreferenceManager2.debugFlags: List<Preference<Boolean, Boolean, Preferences.Key<Boolean>>>
get() = listOf(showComponentNames)
get() = listOf(showComponentNames, legacyPopupOptionsMigrated)
private val PreferenceManager2.textFlags: List<Preference<String, String, Preferences.Key<String>>>
get() = listOf(additionalFonts)
get() = listOf(additionalFonts, launcherPopupOrder)
private val PreferenceManager.debugFlags
get() = listOf(ignoreFeedWhitelist)