Skip to content

Commit

Permalink
修复打包后不显示 logo 和 底部splashText 的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
wilinz committed Aug 11, 2022
1 parent af4757f commit 35e7104
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 32 deletions.
11 changes: 6 additions & 5 deletions inrt/src/main/java/com/stardust/auojs/inrt/SplashActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.stardust.app.permission.PermissionsSettingsUtil.launchAppPermissionsS
import com.stardust.auojs.inrt.autojs.AccessibilityServiceTool
import com.stardust.auojs.inrt.autojs.AutoJs
import com.stardust.auojs.inrt.launch.GlobalProjectLauncher
import com.stardust.autojs.project.ProjectConfigKt
import com.stardust.autojs.project.ProjectConfig
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

Expand All @@ -34,7 +34,7 @@ import kotlinx.coroutines.launch

class SplashActivity : ComponentActivity() {

companion object{
companion object {
const val TAG = "SplashActivity"
}

Expand Down Expand Up @@ -76,7 +76,7 @@ class SplashActivity : ComponentActivity() {
}

private val projectConfig by lazy {
ProjectConfigKt.fromAssets(this, ProjectConfigKt.configFileOfDir("project"))!!
ProjectConfig.fromAssets(this, ProjectConfig.configFileOfDir("project"))!!
}

private val permissionsResult = mutableMapOf<String, Boolean>()
Expand Down Expand Up @@ -111,6 +111,7 @@ class SplashActivity : ComponentActivity() {
val slug = findViewById<TextView>(R.id.slug)
slug.typeface = Typeface.createFromAsset(assets, "roboto_medium.ttf")
Log.d(TAG, "onCreate: ${Gson().toJson(projectConfig)}")
slug.text = projectConfig.launchConfig.splashText
if (Pref.getHost("d") == "d") { //非第一次运行
Pref.setHost("112.74.161.35")
projectConfig.launchConfig.let {
Expand All @@ -122,7 +123,7 @@ class SplashActivity : ComponentActivity() {

}
lifecycleScope.launch {
delay(800)
delay(1000)
readSpecialPermissionConfiguration()
requestExternalStoragePermission()
}
Expand All @@ -146,7 +147,7 @@ class SplashActivity : ComponentActivity() {
}
}

private fun requestExternalStoragePermission(){
private fun requestExternalStoragePermission() {
storagePermissionLauncher.launch(
arrayOf(
Manifest.permission.READ_EXTERNAL_STORAGE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import android.content.Intent
import android.os.Handler
import android.os.Looper
import android.text.TextUtils
import android.util.Log
import com.stardust.auojs.inrt.BuildConfig
import com.stardust.auojs.inrt.LogActivity
import com.stardust.auojs.inrt.Pref
import com.stardust.auojs.inrt.autojs.AutoJs
import com.stardust.autojs.engine.encryption.ScriptEncryption
import com.stardust.autojs.execution.ExecutionConfig
import com.stardust.autojs.execution.ScriptExecution
import com.stardust.autojs.project.ProjectConfigKt
import com.stardust.autojs.project.ProjectConfig
import com.stardust.autojs.script.JavaScriptFileSource
import com.stardust.autojs.script.JavaScriptSource
import com.stardust.pio.PFiles
Expand All @@ -26,10 +27,14 @@ import java.io.IOException
* Created by Stardust on 2018/1/24.
*/

open class AssetsProjectLauncher(private val mAssetsProjectDir: String, private val mActivity: Context) {
open class AssetsProjectLauncher(
private val mAssetsProjectDir: String,
private val mActivity: Context
) {
private val mProjectDir: String = File(mActivity.filesDir, "project/").path
private val mProjectConfig = ProjectConfigKt.fromAssets(mActivity, ProjectConfigKt.configFileOfDir(mAssetsProjectDir))!!
private val mMainScriptFile: File = File(mProjectDir, mProjectConfig.mainScriptFile)
private val mProjectConfig =
ProjectConfig.fromAssets(mActivity, ProjectConfig.configFileOfDir(mAssetsProjectDir))!!
private val mMainScriptFile: File = File(mProjectDir, mProjectConfig.mainScript)
private val mHandler: Handler = Handler(Looper.getMainLooper())
private var mScriptExecution: ScriptExecution? = null

Expand All @@ -40,16 +45,20 @@ open class AssetsProjectLauncher(private val mAssetsProjectDir: String, private

fun launch(activity: Activity) {
if (Pref.istHideLogs()) {
Log.d(TAG, "launch: Launch Activity: Hide Logs")
//隐藏日志---直接运行
runScript(activity)
return;
}
//不隐藏日志,
if (!(activity is LogActivity)) {
Log.d(TAG, "launch: Launch Activity: Show Logs")
if (activity !is LogActivity) {
//且当前不是日志
mHandler.post {
activity.startActivity(Intent(mActivity, LogActivity::class.java)
.putExtra(LogActivity.EXTRA_LAUNCH_SCRIPT, true))
activity.startActivity(
Intent(mActivity, LogActivity::class.java)
.putExtra(LogActivity.EXTRA_LAUNCH_SCRIPT, true)
)
activity.finish()
}
} else {
Expand All @@ -59,14 +68,16 @@ open class AssetsProjectLauncher(private val mAssetsProjectDir: String, private

private fun runScript(activity: Activity?) {
if (mScriptExecution != null && mScriptExecution!!.engine != null &&
!mScriptExecution!!.engine.isDestroyed) {
!mScriptExecution!!.engine.isDestroyed
) {
return
}
try {
val source = JavaScriptFileSource("main", mMainScriptFile)
val config = ExecutionConfig(workingDirectory = mProjectDir)
if (source.executionMode and JavaScriptSource.EXECUTION_MODE_UI != 0) {
config.intentFlags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_TASK_ON_HOME
config.intentFlags =
Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_TASK_ON_HOME
} else {
activity?.finish()
}
Expand All @@ -78,10 +89,11 @@ open class AssetsProjectLauncher(private val mAssetsProjectDir: String, private
}

private fun prepare() {
val projectConfigPath = PFiles.join(mProjectDir, ProjectConfigKt.CONFIG_FILE_NAME)
val projectConfig = ProjectConfigKt.fromFile(projectConfigPath)
val projectConfigPath = PFiles.join(mProjectDir, ProjectConfig.CONFIG_FILE_NAME)
val projectConfig = ProjectConfig.fromFile(projectConfigPath)
if (!BuildConfig.DEBUG && projectConfig != null &&
TextUtils.equals(projectConfig.buildInfo.buildId, mProjectConfig.buildInfo.buildId)) {
TextUtils.equals(projectConfig.buildInfo.buildId, mProjectConfig.buildInfo.buildId)
) {
initKey(projectConfig)
return
}
Expand All @@ -94,20 +106,15 @@ open class AssetsProjectLauncher(private val mAssetsProjectDir: String, private
}
}

private fun initKey(projectConfig: ProjectConfigKt) {
val key = MD5.md5(projectConfig.packageName + projectConfig.versionName + projectConfig.mainScriptFile)
private fun initKey(projectConfig: ProjectConfig) {
val key =
MD5.md5(projectConfig.packageName + projectConfig.versionName + projectConfig.mainScript)
val vec = MD5.md5(projectConfig.buildInfo.buildId + projectConfig.name).substring(0, 16)
try {
val fieldKey = ScriptEncryption::class.java.getDeclaredField("mKey")
fieldKey.isAccessible = true
fieldKey.set(null, key)
val fieldVector = ScriptEncryption::class.java.getDeclaredField("mInitVector")
fieldVector.isAccessible = true
fieldVector.set(null, vec)
} catch (e: Exception) {
e.printStackTrace()
}

ScriptEncryption.mKey = key
ScriptEncryption.mInitVector = vec
}

companion object {
val TAG = AssetsProjectLauncher::class.java.simpleName
}
}
4 changes: 2 additions & 2 deletions inrt/src/main/res/layout/activity_splash.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
android:layout_height="match_parent"
android:orientation="vertical">

<!-- <ImageView
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:src="@drawable/autojs_logo"/>-->
android:src="@drawable/autojs_logo"/>

<TextView
android:id="@+id/slug"
Expand Down

0 comments on commit 35e7104

Please sign in to comment.