Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions HTTPShortcuts/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,27 @@ android {
}
}

val shellApkTemplateAssetDir = layout.buildDirectory.dir("generated/assets/shell-apk-template").get().asFile

val copyShellApkTemplate by tasks.registering(Copy::class) {
dependsOn(":shell_apk_template:assembleRelease")
from(project(":shell_apk_template").layout.buildDirectory.file("outputs/apk/release/shell_apk_template-release-unsigned.apk")) {
rename { "shell-apk-template.apk" }
}
into(shellApkTemplateAssetDir)
}

android.sourceSets.getByName("main").assets.srcDir(shellApkTemplateAssetDir)

tasks.configureEach {
if (name.startsWith("merge") && name.endsWith("Assets")) {
dependsOn(copyShellApkTemplate)
}
if (name.contains("Lint", ignoreCase = true)) {
dependsOn(copyShellApkTemplate)
}
}

composeCompiler {
includeSourceInformation = true
stabilityConfigurationFiles.add(rootProject.layout.projectDirectory.file("stability_config.conf"))
Expand Down Expand Up @@ -359,6 +380,9 @@ dependencies {
/* Reading & writing zip files for Import & Export */
implementation(libs.zip4j)

/* Signing generated shell APKs */
implementation(libs.apksig)

/* Google Assistant integration */
"releaseFullImplementation"(libs.androidx.googleShortcuts)

Expand Down
8 changes: 8 additions & 0 deletions HTTPShortcuts/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />

<!-- Needed for checking the current wi-fi SSID, and for the `getLocation()` scripting function -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Expand Down Expand Up @@ -235,6 +236,13 @@
android:showWhenLocked="true"
android:theme="@style/Theme.Transparent" />

<activity
android:name=".shell_apk.ShellApkInstallerActivity"
android:excludeFromRecents="true"
android:exported="false"
android:noHistory="true"
android:theme="@style/Theme.Transparent" />

<service
android:name=".tiles.QuickTileService"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ fun MainContent(
activeCategoryId: CategoryId,
onActiveCategoryIdChanged: (CategoryId) -> Unit,
onPlaceShortcutOnHomeScreen: (ShortcutPlaceholder) -> Unit,
onInstallShortcutAsApp: (ShortcutPlaceholder) -> Unit,
onRemoveShortcutFromHomeScreen: (ShortcutPlaceholder) -> Unit,
onSelectShortcut: (ShortcutId) -> Unit,
onLongPress: () -> Unit,
Expand Down Expand Up @@ -103,6 +104,7 @@ fun MainContent(
isActive = index == pagerState.currentPage,
highlightedShortcutId = highlightedShortcutId,
onPlaceShortcutOnHomeScreen = onPlaceShortcutOnHomeScreen,
onInstallShortcutAsApp = onInstallShortcutAsApp,
onRemoveShortcutFromHomeScreen = onRemoveShortcutFromHomeScreen,
onSelectShortcut = onSelectShortcut,
onLongPress = onLongPress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ fun MainScreen(
highlightedShortcutId = viewState.highlightedShortcutId,
onActiveCategoryIdChanged = viewModel::onActiveCategoryChanged,
onPlaceShortcutOnHomeScreen = viewModel::onPlaceShortcutOnHomeScreen,
onInstallShortcutAsApp = viewModel::onInstallShortcutAsApp,
onRemoveShortcutFromHomeScreen = viewModel::onRemoveShortcutFromHomeScreen,
onSelectShortcut = viewModel::onSelectShortcut,
onLongPress = viewModel::onLongPress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import ch.rmy.android.http_shortcuts.icons.ShortcutIcon
import ch.rmy.android.http_shortcuts.navigation.NavigationArgStore
import ch.rmy.android.http_shortcuts.navigation.NavigationDestination
import ch.rmy.android.http_shortcuts.scheduling.ExecutionScheduler
import ch.rmy.android.http_shortcuts.shell_apk.InvalidShellApkException
import ch.rmy.android.http_shortcuts.shell_apk.ShellApkInstaller
import ch.rmy.android.http_shortcuts.sync.ObserveSyncReplaceUseCase
import ch.rmy.android.http_shortcuts.utils.ActivityCloser
import ch.rmy.android.http_shortcuts.utils.AppOverlayUtil
Expand Down Expand Up @@ -98,6 +100,7 @@ constructor(
private val navigationArgStore: NavigationArgStore,
private val observeSyncReplace: ObserveSyncReplaceUseCase,
private val shortcutUpdateWorkerStarter: ShortcutUpdateWorker.Starter,
private val shellApkInstaller: ShellApkInstaller,
) : BaseViewModel<MainViewModel.InitData, MainViewState>(application) {

private lateinit var categories: List<Category>
Expand Down Expand Up @@ -636,6 +639,32 @@ constructor(
placeShortcutOnHomeScreen(shortcut)
}

fun onInstallShortcutAsApp(shortcut: ShortcutPlaceholder) = runAction {
withProgressTracking {
try {
val result = shellApkInstaller.prepareInstall(
shortcutId = shortcut.id,
shortcutName = shortcut.name,
shortcutIcon = shortcut.icon,
allShortcutIds = shortcutRepository.getShortcuts().map { it.id },
)
when (result) {
is ShellApkInstaller.Result.PermissionRequired -> {
showSnackbar(R.string.message_shell_apk_unknown_sources_permission_required, long = true)
sendIntent(result.intent)
}
is ShellApkInstaller.Result.ReadyToInstall -> {
sendIntent(result.intent)
}
}
} catch (e: InvalidShellApkException) {
showSnackbar(R.string.error_shell_apk_invalid, long = true)
} catch (e: Exception) {
handleUnexpectedError(e)
}
}
}

fun onRemoveShortcutFromHomeScreen(shortcut: ShortcutPlaceholder) = runAction {
removeShortcutFromHomeScreen(shortcut)
shortcutUpdateWorkerStarter.invoke()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fun ShortcutListContent(
isActive: Boolean,
highlightedShortcutId: ShortcutId?,
onPlaceShortcutOnHomeScreen: (ShortcutPlaceholder) -> Unit,
onInstallShortcutAsApp: (ShortcutPlaceholder) -> Unit,
onRemoveShortcutFromHomeScreen: (ShortcutPlaceholder) -> Unit,
onSelectShortcut: (ShortcutId) -> Unit,
onLongPress: () -> Unit,
Expand Down Expand Up @@ -77,6 +78,9 @@ fun ShortcutListContent(
is ShortcutListEvent.PlaceShortcutOnHomeScreen -> consume {
onPlaceShortcutOnHomeScreen(event.shortcut)
}
is ShortcutListEvent.InstallShortcutAsApp -> consume {
onInstallShortcutAsApp(event.shortcut)
}
is ShortcutListEvent.RemoveShortcutFromHomeScreen -> consume {
onRemoveShortcutFromHomeScreen(event.shortcut)
}
Expand Down Expand Up @@ -126,6 +130,7 @@ fun ShortcutListContent(
dialogState = state.dialogState,
isInSyncReplaceMode = isInSyncReplaceMode,
onPlaceOnHomeScreenOptionSelected = viewModel::onPlaceOnHomeScreenOptionSelected,
onInstallAsAppOptionSelected = viewModel::onInstallAsAppOptionSelected,
onExecuteOptionSelected = viewModel::onExecuteOptionSelected,
onCancelPendingExecutionOptionSelected = viewModel::onCancelPendingExecutionOptionSelected,
onEditOptionSelected = viewModel::onEditOptionSelected,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fun ShortcutListDialogs(
dialogState: ShortcutListDialogState?,
isInSyncReplaceMode: Boolean,
onPlaceOnHomeScreenOptionSelected: () -> Unit,
onInstallAsAppOptionSelected: () -> Unit,
onExecuteOptionSelected: () -> Unit,
onCancelPendingExecutionOptionSelected: () -> Unit,
onEditOptionSelected: () -> Unit,
Expand Down Expand Up @@ -95,6 +96,7 @@ fun ShortcutListDialogs(
isPending = dialogState.isPending,
isHidden = dialogState.isHidden,
onPlaceOnHomeScreenOptionSelected = onPlaceOnHomeScreenOptionSelected,
onInstallAsAppOptionSelected = onInstallAsAppOptionSelected,
onExecuteOptionSelected = onExecuteOptionSelected,
onCancelPendingExecutionOptionSelected = onCancelPendingExecutionOptionSelected,
onEditOptionSelected = onEditOptionSelected,
Expand Down Expand Up @@ -293,6 +295,7 @@ private fun ContextMenuDialog(
isPending: Boolean,
isHidden: Boolean,
onPlaceOnHomeScreenOptionSelected: () -> Unit,
onInstallAsAppOptionSelected: () -> Unit,
onExecuteOptionSelected: () -> Unit,
onCancelPendingExecutionOptionSelected: () -> Unit,
onEditOptionSelected: () -> Unit,
Expand All @@ -315,6 +318,12 @@ private fun ContextMenuDialog(
icon = painterResource(R.drawable.outline_menu_24),
onClick = onPlaceOnHomeScreenOptionSelected,
)
SelectDialogEntry(
horizontalPadding = horizontalPadding,
label = stringResource(R.string.action_install_as_app),
icon = painterResource(R.drawable.outline_touch_app_24),
onClick = onInstallAsAppOptionSelected,
)
SelectDialogEntry(
horizontalPadding = horizontalPadding,
label = stringResource(R.string.action_run),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ abstract class ShortcutListEvent : ViewModelEvent() {

data class PlaceShortcutOnHomeScreen(val shortcut: ShortcutPlaceholder) : ShortcutListEvent()

data class InstallShortcutAsApp(val shortcut: ShortcutPlaceholder) : ShortcutListEvent()

data class RemoveShortcutFromHomeScreen(val shortcut: ShortcutPlaceholder) : ShortcutListEvent()

data class SelectShortcut(val shortcutId: ShortcutId) : ShortcutListEvent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,13 @@ constructor(
emitEvent(ShortcutListEvent.PlaceShortcutOnHomeScreen(shortcut.toShortcutPlaceholder()))
}

fun onInstallAsAppOptionSelected() = runAction {
updateDialogState(null)
val shortcutId = activeShortcutId ?: skipAction()
val shortcut = getShortcutById(shortcutId) ?: skipAction()
emitEvent(ShortcutListEvent.InstallShortcutAsApp(shortcut.toShortcutPlaceholder()))
}

fun onExecuteOptionSelected() = runAction {
updateDialogState(null)
val shortcutId = activeShortcutId ?: skipAction()
Expand Down
Loading