-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to enable incognito mode per extension (mihonapp/mihon#157)
* add per Extension Incognito Mode * migrate incognito sources when extension is updated * remove incognito sources when extension is uninstalled * remove not used variable * address change requests address change requests * Rebase and cleanup code --------- Co-authored-by: AntsyLich <[email protected]> (cherry picked from commit c283abefb03f79ce6652492db71cde410f828f78)
- Loading branch information
1 parent
37ac075
commit 19a62fc
Showing
14 changed files
with
146 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
app/src/main/java/eu/kanade/domain/source/interactor/GetIncognitoState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package eu.kanade.domain.source.interactor | ||
|
||
import eu.kanade.domain.base.BasePreferences | ||
import eu.kanade.domain.source.service.SourcePreferences | ||
import eu.kanade.tachiyomi.extension.ExtensionManager | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.combine | ||
import kotlinx.coroutines.flow.distinctUntilChanged | ||
|
||
class GetIncognitoState( | ||
private val basePreferences: BasePreferences, | ||
private val sourcePreferences: SourcePreferences, | ||
private val extensionManager: ExtensionManager, | ||
) { | ||
fun await(sourceId: Long?): Boolean { | ||
if (basePreferences.incognitoMode().get()) return true | ||
if (sourceId == null) return false | ||
val extensionPackage = extensionManager.getExtensionPackage(sourceId) ?: return false | ||
|
||
return extensionPackage in sourcePreferences.incognitoExtensions().get() | ||
} | ||
|
||
fun subscribe(sourceId: Long?): Flow<Boolean> { | ||
if (sourceId == null) return basePreferences.incognitoMode().changes() | ||
|
||
return combine( | ||
basePreferences.incognitoMode().changes(), | ||
sourcePreferences.incognitoExtensions().changes(), | ||
extensionManager.getExtensionPackageAsFlow(sourceId), | ||
) { incognito, incognitoExtensions, extensionPackage -> | ||
incognito || (extensionPackage in incognitoExtensions) | ||
} | ||
.distinctUntilChanged() | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/eu/kanade/domain/source/interactor/ToggleIncognito.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package eu.kanade.domain.source.interactor | ||
|
||
import eu.kanade.domain.source.service.SourcePreferences | ||
import tachiyomi.core.common.preference.getAndSet | ||
|
||
class ToggleIncognito( | ||
private val preferences: SourcePreferences, | ||
) { | ||
fun await(extensions: String, enable: Boolean) { | ||
preferences.incognitoExtensions().getAndSet { | ||
if (enable) it.plus(extensions) else it.minus(extensions) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.