Skip to content

Commit

Permalink
feat: add install options screen (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
rushiiMachine authored Feb 10, 2024
1 parent cd517b8 commit 9d6cdf2
Show file tree
Hide file tree
Showing 64 changed files with 771 additions and 625 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.aliucord.manager.network.service.*
import com.aliucord.manager.ui.screens.about.AboutModel
import com.aliucord.manager.ui.screens.home.HomeModel
import com.aliucord.manager.ui.screens.install.InstallModel
import com.aliucord.manager.ui.screens.installopts.InstallOptionsModel
import com.aliucord.manager.ui.screens.plugins.PluginsModel
import com.aliucord.manager.ui.screens.settings.SettingsModel
import com.aliucord.manager.ui.widgets.updater.UpdaterViewModel
Expand Down Expand Up @@ -54,6 +55,7 @@ class ManagerApplication : Application() {
factoryOf(::AboutModel)
factoryOf(::InstallModel)
factoryOf(::SettingsModel)
factoryOf(::InstallOptionsModel)
viewModelOf(::UpdaterViewModel)
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.aliucord.manager.installer.steps

import com.aliucord.manager.installer.steps.base.Step
import com.aliucord.manager.installer.steps.download.*
import com.aliucord.manager.installer.steps.install.*
import com.aliucord.manager.installer.steps.patch.*
import com.aliucord.manager.installer.steps.prepare.DowngradeCheckStep
import com.aliucord.manager.installer.steps.prepare.FetchInfoStep
import com.aliucord.manager.ui.screens.installopts.InstallOptions
import kotlinx.collections.immutable.persistentListOf

/**
* Used for installing the old Kotlin Discord app.
*/
class KotlinInstallRunner : StepRunner() {
override val steps = persistentListOf<Step>(
class KotlinInstallRunner(options: InstallOptions) : StepRunner() {
override val steps = persistentListOf(
// Prepare
FetchInfoStep(),
DowngradeCheckStep(),
DowngradeCheckStep(options),

// Download
DownloadDiscordStep(),
Expand All @@ -25,8 +25,8 @@ class KotlinInstallRunner : StepRunner() {

// Patch
CopyDependenciesStep(),
ReplaceIconStep(),
PatchManifestStep(),
ReplaceIconStep(options),
PatchManifestStep(options),
AddInjectorStep(),
AddAliuhookStep(),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ import com.aliucord.manager.installer.steps.StepGroup
import com.aliucord.manager.installer.steps.StepRunner
import com.aliucord.manager.installer.steps.base.Step
import com.aliucord.manager.installer.util.ManifestPatcher
import com.aliucord.manager.manager.PreferencesManager
import com.aliucord.manager.ui.screens.installopts.InstallOptions
import com.github.diamondminer88.zip.ZipReader
import com.github.diamondminer88.zip.ZipWriter
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject

/**
* Patch the APK's AndroidManifest.xml
*/
class PatchManifestStep : Step(), KoinComponent {
private val prefs: PreferencesManager by inject()

class PatchManifestStep(private val options: InstallOptions) : Step() {
override val group = StepGroup.Patch
override val localizedName = R.string.install_step_patch_manifests

Expand All @@ -29,9 +25,9 @@ class PatchManifestStep : Step(), KoinComponent {

val patchedManifest = ManifestPatcher.patchManifest(
manifestBytes = manifest,
packageName = prefs.packageName,
appName = prefs.appName,
debuggable = prefs.debuggable,
packageName = options.packageName,
appName = options.appName,
debuggable = options.debuggable,
)

ZipWriter(apk, /* append = */ true).use {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.aliucord.manager.installer.steps.StepGroup
import com.aliucord.manager.installer.steps.StepRunner
import com.aliucord.manager.installer.steps.base.Step
import com.aliucord.manager.installer.steps.base.StepState
import com.aliucord.manager.manager.PreferencesManager
import com.aliucord.manager.ui.screens.installopts.InstallOptions
import com.github.diamondminer88.zip.ZipWriter
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
Expand All @@ -17,15 +17,14 @@ import java.io.InputStream
* Replace icons
*/
@Stable
class ReplaceIconStep : Step(), KoinComponent {
class ReplaceIconStep(private val options: InstallOptions) : Step(), KoinComponent {
private val context: Context by inject()
private val prefs: PreferencesManager by inject()

override val group = StepGroup.Patch
override val localizedName = R.string.setting_replace_icon
override val localizedName = R.string.install_step_patch_icon

override suspend fun execute(container: StepRunner) {
if (!prefs.replaceIcon) {
if (!options.replaceIcon) {
state = StepState.Skipped
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import com.aliucord.manager.installer.steps.StepRunner
import com.aliucord.manager.installer.steps.base.Step
import com.aliucord.manager.installer.steps.base.StepState
import com.aliucord.manager.installer.util.uninstallApk
import com.aliucord.manager.manager.PreferencesManager
import com.aliucord.manager.ui.screens.installopts.InstallOptions
import com.aliucord.manager.util.getPackageVersion
import com.aliucord.manager.util.showToast
import kotlinx.coroutines.Dispatchers
Expand All @@ -19,16 +19,15 @@ import org.koin.core.component.inject
* Prompt the user to uninstall a previous version of Aliucord if it has a larger version code.
* (Prevent conflicts from downgrading)
*/
class DowngradeCheckStep : Step(), KoinComponent {
class DowngradeCheckStep(private val options: InstallOptions) : Step(), KoinComponent {
private val context: Context by inject()
private val prefs: PreferencesManager by inject()

override val group = StepGroup.Prepare
override val localizedName = R.string.install_step_downgrade_check

override suspend fun execute(container: StepRunner) {
val (_, currentVersion) = try {
context.getPackageVersion(prefs.packageName)
context.getPackageVersion(options.packageName)
}
// Package is not installed
catch (_: Throwable) {
Expand All @@ -42,7 +41,7 @@ class DowngradeCheckStep : Step(), KoinComponent {
?: throw IllegalArgumentException("Invalid fetched Aliucord target Discord version")

if (currentVersion > targetVersion) {
context.uninstallApk(prefs.packageName)
context.uninstallApk(options.packageName)

withContext(Dispatchers.Main) {
context.showToast(R.string.installer_uninstall_new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@ import com.aliucord.manager.ui.components.Theme
class PreferencesManager(preferences: SharedPreferences) : BasePreferenceManager(preferences) {
var theme by enumPreference("theme", Theme.SYSTEM)
var dynamicColor by booleanPreference("dynamic_color", true)
var replaceIcon by booleanPreference("replace_icon", true)
var devMode by booleanPreference("dev_mode", false)
var installer by enumPreference("installer", InstallerSetting.PM)
var debuggable by booleanPreference("debuggable", false)
var appName by stringPreference("app_name", "Aliucord")
var packageName by stringPreference("package_name", "com.aliucord")
var version by stringPreference("version", "146108")
var hermesReplaceLibCpp by booleanPreference("hermes_replace_libcpp", false)
var keepPatchedApks by booleanPreference("keep_patched_apks", false)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.aliucord.manager.ui.components

import androidx.compose.animation.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.withStyle
import com.aliucord.manager.R
import com.aliucord.manager.ui.util.DiscordVersion

@Composable
fun AnimatedVersionDisplay(
version: DiscordVersion,
modifier: Modifier = Modifier,
) {
AnimatedVisibility(
enter = fadeIn() + slideInVertically { it * -2 },
exit = fadeOut() + slideOutVertically { it * -2 },
visible = version !is DiscordVersion.None,
modifier = modifier,
) {
VersionDisplay(
version = version,
prefix = {
withStyle(SpanStyle(fontWeight = FontWeight.Bold)) {
append(stringResource(R.string.version_supported))
append(" ")
}
},
modifier = Modifier.alpha(.5f),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.aliucord.manager.ui.components

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import com.aliucord.manager.R
import com.aliucord.manager.ui.util.mirrorVertically

@Composable
fun ResetToDefaultButton(
enabled: Boolean,
onClick: () -> Unit,
modifier: Modifier = Modifier,
) {
AnimatedVisibility(visible = enabled, modifier = modifier) {
IconButton(onClick = onClick) {
Icon(
painter = painterResource(R.drawable.ic_refresh),
tint = MaterialTheme.colorScheme.secondary,
contentDescription = stringResource(R.string.action_reset_default),
modifier = Modifier.mirrorVertically(),
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.aliucord.manager.ui.components

import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp

@Composable
fun TextDivider(
text: String,
modifier: Modifier = Modifier,
) {
Row(
horizontalArrangement = Arrangement.spacedBy(6.dp, Alignment.CenterHorizontally),
verticalAlignment = Alignment.CenterVertically,
modifier = modifier
.fillMaxWidth(),
) {
HorizontalDivider(Modifier.weight(1f))

Text(
text = text,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.outline,
fontWeight = FontWeight.SemiBold,
)

HorizontalDivider(Modifier.weight(1f))
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.aliucord.manager.ui.screens.home.components
package com.aliucord.manager.ui.components

import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
Expand Down

This file was deleted.

Loading

0 comments on commit 9d6cdf2

Please sign in to comment.