mirror of
https://github.com/FossifyOrg/Launcher.git
synced 2026-06-12 10:37:28 -04:00
feat: prompt to set as default on startup (#231)
* feat: prompt to set as default on startup To make it more reliable in case of multiple denials, `Long press on home screen ➜ Set as default now` launches the system page for selecting default home app instead of prompting using the RoleManager API. Refs: https://github.com/FossifyOrg/Launcher/issues/230 * docs: update changelog
This commit is contained in:
@@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
### Changed
|
||||
- The app will now prompt to set as default launcher on startup ([#230])
|
||||
|
||||
## [1.2.0] - 2025-07-15
|
||||
### Added
|
||||
@@ -68,6 +70,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
[#106]: https://github.com/FossifyOrg/Launcher/issues/106
|
||||
[#115]: https://github.com/FossifyOrg/Launcher/issues/115
|
||||
[#182]: https://github.com/FossifyOrg/Launcher/issues/182
|
||||
[#230]: https://github.com/FossifyOrg/Launcher/issues/230
|
||||
|
||||
[Unreleased]: https://github.com/FossifyOrg/Launcher/compare/1.2.0...HEAD
|
||||
[1.2.0]: https://github.com/FossifyOrg/Launcher/compare/1.1.4...1.2.0
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.graphics.drawable.Drawable
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.provider.Settings
|
||||
import android.provider.Telephony
|
||||
import android.telecom.TelecomManager
|
||||
import android.view.ContextThemeWrapper
|
||||
@@ -164,6 +165,10 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||
clickedGridItem = it
|
||||
)
|
||||
}
|
||||
|
||||
if (!isDefaultLauncher()) {
|
||||
requestHomeRole()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
@@ -775,7 +780,7 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||
Gravity.TOP or Gravity.END
|
||||
).apply {
|
||||
inflate(R.menu.menu_home_screen)
|
||||
menu.findItem(R.id.set_as_default).isVisible = isQPlus() && !isDefaultLauncher()
|
||||
menu.findItem(R.id.set_as_default).isVisible = !isDefaultLauncher()
|
||||
setOnMenuItemClickListener { item ->
|
||||
when (item.itemId) {
|
||||
R.id.widgets -> showWidgetsFragment()
|
||||
@@ -841,6 +846,18 @@ class MainActivity : SimpleActivity(), FlingListener {
|
||||
}
|
||||
|
||||
private fun launchSetAsDefaultIntent() {
|
||||
val intents = listOf(
|
||||
Intent(Settings.ACTION_HOME_SETTINGS),
|
||||
Intent(Settings.ACTION_MANAGE_DEFAULT_APPS_SETTINGS),
|
||||
Intent(Settings.ACTION_SETTINGS)
|
||||
)
|
||||
val intent = intents.firstOrNull { it.resolveActivity(packageManager) != null }
|
||||
if (intent != null) {
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestHomeRole() {
|
||||
if (isQPlus()) {
|
||||
startActivityForResult(
|
||||
roleManager.createRequestRoleIntent(RoleManager.ROLE_HOME),
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
package org.fossify.home.extensions
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.app.role.RoleManager
|
||||
import android.appwidget.AppWidgetProviderInfo
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.content.pm.LauncherApps
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Build
|
||||
import android.os.Process
|
||||
import android.util.Size
|
||||
import androidx.annotation.RequiresApi
|
||||
import org.fossify.commons.helpers.isQPlus
|
||||
import org.fossify.commons.helpers.isSPlus
|
||||
import org.fossify.home.databases.AppsDatabase
|
||||
import org.fossify.home.helpers.Config
|
||||
@@ -31,7 +35,7 @@ val Context.homeScreenGridItemsDB: HomeScreenGridItemsDao
|
||||
val Context.hiddenIconsDB: HiddenIconsDao
|
||||
get() = AppsDatabase.getInstance(applicationContext).HiddenIconsDao()
|
||||
|
||||
@get:TargetApi(Build.VERSION_CODES.Q)
|
||||
@get:RequiresApi(Build.VERSION_CODES.Q)
|
||||
val Context.roleManager: RoleManager
|
||||
get() = getSystemService(RoleManager::class.java)
|
||||
|
||||
@@ -76,9 +80,20 @@ fun Context.getCellCount(size: Int): Int {
|
||||
return max(tiles, 1)
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.Q)
|
||||
fun Context.isDefaultLauncher(): Boolean {
|
||||
return with(roleManager) {
|
||||
isRoleAvailable(RoleManager.ROLE_HOME) && isRoleHeld(RoleManager.ROLE_HOME)
|
||||
return if (isQPlus()) {
|
||||
with(roleManager) {
|
||||
isRoleAvailable(RoleManager.ROLE_HOME) && isRoleHeld(RoleManager.ROLE_HOME)
|
||||
}
|
||||
} else {
|
||||
val filters = ArrayList<IntentFilter>()
|
||||
val activities = ArrayList<ComponentName>()
|
||||
@Suppress("DEPRECATION")
|
||||
packageManager.getPreferredActivities(filters, activities, null)
|
||||
return activities.indices.any { i ->
|
||||
activities[i].packageName == packageName &&
|
||||
filters[i].hasAction(Intent.ACTION_MAIN) &&
|
||||
filters[i].hasCategory(Intent.CATEGORY_HOME)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user