From b772d6903d83d4b1cd452bafaa6bf8509accaee6 Mon Sep 17 00:00:00 2001 From: mikooomich Date: Thu, 2 Jan 2025 19:22:57 -0500 Subject: [PATCH] account: Logout now nulls values * Based on https://github.com/z-huang/InnerTune/pull/1694 --- app/src/main/java/com/dd3boh/outertune/App.kt | 3 ++- .../ui/screens/settings/ContentSettings.kt | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/dd3boh/outertune/App.kt b/app/src/main/java/com/dd3boh/outertune/App.kt index 0658b49ce..0e35b9c89 100644 --- a/app/src/main/java/com/dd3boh/outertune/App.kt +++ b/app/src/main/java/com/dd3boh/outertune/App.kt @@ -94,7 +94,8 @@ class App : Application(), ImageLoaderFactory { // we now allow user input now, here be the demons. This serves as a last ditch effort to avoid a crash loop Timber.e("Could not parse cookie. Clearing existing cookie. %s", e.message) dataStore.edit { settings -> - settings[InnerTubeCookieKey] = "" + settings.remove(InnerTubeCookieKey) + settings.remove(VisitorDataKey) } } } diff --git a/app/src/main/java/com/dd3boh/outertune/ui/screens/settings/ContentSettings.kt b/app/src/main/java/com/dd3boh/outertune/ui/screens/settings/ContentSettings.kt index 2e009f5d8..77faa361d 100644 --- a/app/src/main/java/com/dd3boh/outertune/ui/screens/settings/ContentSettings.kt +++ b/app/src/main/java/com/dd3boh/outertune/ui/screens/settings/ContentSettings.kt @@ -26,11 +26,13 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.sp +import androidx.datastore.preferences.core.edit import androidx.navigation.NavController import com.dd3boh.outertune.LocalPlayerAwareWindowInsets import com.dd3boh.outertune.R @@ -48,6 +50,7 @@ import com.dd3boh.outertune.constants.ProxyEnabledKey import com.dd3boh.outertune.constants.ProxyTypeKey import com.dd3boh.outertune.constants.ProxyUrlKey import com.dd3boh.outertune.constants.SYSTEM_DEFAULT +import com.dd3boh.outertune.constants.VisitorDataKey import com.dd3boh.outertune.constants.YtmSyncKey import com.dd3boh.outertune.ui.component.EditTextPreference import com.dd3boh.outertune.ui.component.IconButton @@ -58,9 +61,11 @@ import com.dd3boh.outertune.ui.component.PreferenceGroupTitle import com.dd3boh.outertune.ui.component.SwitchPreference import com.dd3boh.outertune.ui.component.TextFieldDialog import com.dd3boh.outertune.ui.utils.backToMain +import com.dd3boh.outertune.utils.dataStore import com.dd3boh.outertune.utils.rememberEnumPreference import com.dd3boh.outertune.utils.rememberPreference import com.zionhuang.innertube.utils.parseCookieString +import kotlinx.coroutines.runBlocking import java.net.Proxy @OptIn(ExperimentalMaterial3Api::class) @@ -69,6 +74,8 @@ fun ContentSettings( navController: NavController, scrollBehavior: TopAppBarScrollBehavior, ) { + val context = LocalContext.current + val accountName by rememberPreference(AccountNameKey, "") val accountEmail by rememberPreference(AccountEmailKey, "") val accountChannelHandle by rememberPreference(AccountChannelHandleKey, "") @@ -120,6 +127,12 @@ fun ContentSettings( icon = { Icon(Icons.AutoMirrored.Rounded.Logout, null) }, onClick = { onInnerTubeCookieChange("") + runBlocking { + context.dataStore.edit { settings -> + settings.remove(InnerTubeCookieKey) + settings.remove(VisitorDataKey) + } + } } ) }