mirror of
https://github.com/MetaCubeX/ClashMetaForAndroid.git
synced 2024-11-22 13:26:09 +03:00
Fix: crash with app icon (#1260)
This commit is contained in:
parent
7006cb516c
commit
c173114368
@ -2,6 +2,8 @@ package com.github.kr328.clash.common.compat
|
|||||||
|
|
||||||
import android.app.ActivityThread
|
import android.app.ActivityThread
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
|
import android.graphics.drawable.AdaptiveIconDrawable
|
||||||
|
import android.graphics.drawable.Drawable
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import com.github.kr328.clash.common.log.Log
|
import com.github.kr328.clash.common.log.Log
|
||||||
|
|
||||||
@ -18,3 +20,12 @@ val Application.currentProcessName: String
|
|||||||
packageName
|
packageName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Drawable.foreground(): Drawable {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
|
||||||
|
this is AdaptiveIconDrawable && this.background == null
|
||||||
|
) {
|
||||||
|
return this.foreground
|
||||||
|
}
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
@ -2,12 +2,13 @@ package com.github.kr328.clash.design.util
|
|||||||
|
|
||||||
import android.content.pm.PackageInfo
|
import android.content.pm.PackageInfo
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
|
import com.github.kr328.clash.common.compat.foreground
|
||||||
import com.github.kr328.clash.design.model.AppInfo
|
import com.github.kr328.clash.design.model.AppInfo
|
||||||
|
|
||||||
fun PackageInfo.toAppInfo(pm: PackageManager): AppInfo {
|
fun PackageInfo.toAppInfo(pm: PackageManager): AppInfo {
|
||||||
return AppInfo(
|
return AppInfo(
|
||||||
packageName = packageName,
|
packageName = packageName,
|
||||||
icon = applicationInfo.loadIcon(pm),
|
icon = applicationInfo.loadIcon(pm).foreground(),
|
||||||
label = applicationInfo.loadLabel(pm).toString(),
|
label = applicationInfo.loadLabel(pm).toString(),
|
||||||
installTime = firstInstallTime,
|
installTime = firstInstallTime,
|
||||||
updateDate = lastUpdateTime,
|
updateDate = lastUpdateTime,
|
||||||
|
Loading…
Reference in New Issue
Block a user