mirror of
https://github.com/fankes/TSBattery.git
synced 2025-09-07 19:14:19 +08:00
增加模块自动检查更新功能
This commit is contained in:
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
@@ -4,6 +4,7 @@
|
|||||||
<option name="filePathToZoomLevelMap">
|
<option name="filePathToZoomLevelMap">
|
||||||
<map>
|
<map>
|
||||||
<entry key="app/src/main/res/drawable-v24/dark_round.xml" value="0.4482051282051282" />
|
<entry key="app/src/main/res/drawable-v24/dark_round.xml" value="0.4482051282051282" />
|
||||||
|
<entry key="app/src/main/res/drawable/bg_orange_round.xml" value="0.229" />
|
||||||
<entry key="app/src/main/res/drawable/bg_permotion_round.xml" value="0.2495" />
|
<entry key="app/src/main/res/drawable/bg_permotion_round.xml" value="0.2495" />
|
||||||
<entry key="app/src/main/res/drawable/button_round.xml" value="0.44871794871794873" />
|
<entry key="app/src/main/res/drawable/button_round.xml" value="0.44871794871794873" />
|
||||||
<entry key="app/src/main/res/drawable/dark_round.xml" value="0.4482051282051282" />
|
<entry key="app/src/main/res/drawable/dark_round.xml" value="0.4482051282051282" />
|
||||||
|
@@ -59,6 +59,7 @@ dependencies {
|
|||||||
compileOnly 'de.robv.android.xposed:api:82'
|
compileOnly 'de.robv.android.xposed:api:82'
|
||||||
implementation 'com.highcapable.yukihookapi:api:1.0.6'
|
implementation 'com.highcapable.yukihookapi:api:1.0.6'
|
||||||
ksp 'com.highcapable.yukihookapi:ksp-xposed:1.0.6'
|
ksp 'com.highcapable.yukihookapi:ksp-xposed:1.0.6'
|
||||||
|
implementation 'com.squareup.okhttp3:okhttp:4.9.3'
|
||||||
implementation 'com.geyifeng.immersionbar:immersionbar:3.2.0'
|
implementation 'com.geyifeng.immersionbar:immersionbar:3.2.0'
|
||||||
implementation 'com.geyifeng.immersionbar:immersionbar-ktx:3.2.0'
|
implementation 'com.geyifeng.immersionbar:immersionbar-ktx:3.2.0'
|
||||||
implementation 'androidx.core:core-ktx:1.7.0'
|
implementation 'androidx.core:core-ktx:1.7.0'
|
||||||
|
@@ -3,6 +3,8 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
package="com.fankes.tsbattery">
|
package="com.fankes.tsbattery">
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
<!-- 作用域 APP -->
|
<!-- 作用域 APP -->
|
||||||
<queries>
|
<queries>
|
||||||
<package android:name="com.tencent.mobileqq" />
|
<package android:name="com.tencent.mobileqq" />
|
||||||
|
@@ -24,11 +24,9 @@
|
|||||||
package com.fankes.tsbattery.ui.activity
|
package com.fankes.tsbattery.ui.activity
|
||||||
|
|
||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
import android.content.Intent
|
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.net.Uri
|
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
|
import androidx.core.view.isVisible
|
||||||
import com.fankes.tsbattery.BuildConfig
|
import com.fankes.tsbattery.BuildConfig
|
||||||
import com.fankes.tsbattery.R
|
import com.fankes.tsbattery.R
|
||||||
import com.fankes.tsbattery.databinding.ActivityMainBinding
|
import com.fankes.tsbattery.databinding.ActivityMainBinding
|
||||||
@@ -45,8 +43,10 @@ import com.fankes.tsbattery.hook.HookConst.TIM_PACKAGE_NAME
|
|||||||
import com.fankes.tsbattery.hook.HookConst.WECHAT_PACKAGE_NAME
|
import com.fankes.tsbattery.hook.HookConst.WECHAT_PACKAGE_NAME
|
||||||
import com.fankes.tsbattery.ui.activity.base.BaseActivity
|
import com.fankes.tsbattery.ui.activity.base.BaseActivity
|
||||||
import com.fankes.tsbattery.utils.factory.isInstall
|
import com.fankes.tsbattery.utils.factory.isInstall
|
||||||
|
import com.fankes.tsbattery.utils.factory.openBrowser
|
||||||
import com.fankes.tsbattery.utils.factory.openSelfSetting
|
import com.fankes.tsbattery.utils.factory.openSelfSetting
|
||||||
import com.fankes.tsbattery.utils.factory.showDialog
|
import com.fankes.tsbattery.utils.factory.showDialog
|
||||||
|
import com.fankes.tsbattery.utils.tool.GithubReleaseTool
|
||||||
import com.highcapable.yukihookapi.hook.factory.isModuleActive
|
import com.highcapable.yukihookapi.hook.factory.isModuleActive
|
||||||
import com.highcapable.yukihookapi.hook.factory.isTaiChiModuleActive
|
import com.highcapable.yukihookapi.hook.factory.isTaiChiModuleActive
|
||||||
import com.highcapable.yukihookapi.hook.factory.modulePrefs
|
import com.highcapable.yukihookapi.hook.factory.modulePrefs
|
||||||
@@ -63,6 +63,14 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
|
/** 检查更新 */
|
||||||
|
GithubReleaseTool.checkingForUpdate(context = this, moduleVersion) { version, function ->
|
||||||
|
binding.mainTextReleaseVersion.apply {
|
||||||
|
text = "点击更新 $version"
|
||||||
|
isVisible = true
|
||||||
|
setOnClickListener { function() }
|
||||||
|
}
|
||||||
|
}
|
||||||
/** 判断 Hook 状态 */
|
/** 判断 Hook 状态 */
|
||||||
if (isModuleActive) {
|
if (isModuleActive) {
|
||||||
binding.mainLinStatus.setBackgroundResource(R.drawable.bg_green_round)
|
binding.mainLinStatus.setBackgroundResource(R.drawable.bg_green_round)
|
||||||
@@ -182,28 +190,11 @@ class MainActivity : BaseActivity<ActivityMainBinding>() {
|
|||||||
binding.quickTimButton.setOnClickListener { openSelfSetting(TIM_PACKAGE_NAME) }
|
binding.quickTimButton.setOnClickListener { openSelfSetting(TIM_PACKAGE_NAME) }
|
||||||
/** 快捷操作微信 */
|
/** 快捷操作微信 */
|
||||||
binding.quickWechatButton.setOnClickListener { openSelfSetting(WECHAT_PACKAGE_NAME) }
|
binding.quickWechatButton.setOnClickListener { openSelfSetting(WECHAT_PACKAGE_NAME) }
|
||||||
|
/** 项目地址按钮点击事件 */
|
||||||
|
binding.titleGithubIcon.setOnClickListener { openBrowser(url = "https://github.com/fankes/TSBattery") }
|
||||||
/** 恰饭! */
|
/** 恰饭! */
|
||||||
binding.linkWithFollowMe.setOnClickListener {
|
binding.linkWithFollowMe.setOnClickListener {
|
||||||
runCatching {
|
openBrowser(url = "https://www.coolapk.com/u/876977", packageName = "com.coolapk.market")
|
||||||
startActivity(Intent().apply {
|
|
||||||
setPackage("com.coolapk.market")
|
|
||||||
action = "android.intent.action.VIEW"
|
|
||||||
data = Uri.parse("https://www.coolapk.com/u/876977")
|
|
||||||
/** 防止顶栈一样重叠在自己的 APP 中 */
|
|
||||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
|
||||||
})
|
|
||||||
}.onFailure { Toast.makeText(this, "你可能没有安装酷安", Toast.LENGTH_SHORT).show() }
|
|
||||||
}
|
|
||||||
/** 项目地址按钮点击事件 */
|
|
||||||
binding.titleGithubIcon.setOnClickListener {
|
|
||||||
runCatching {
|
|
||||||
startActivity(Intent().apply {
|
|
||||||
action = "android.intent.action.VIEW"
|
|
||||||
data = Uri.parse("https://github.com/fankes/TSBattery")
|
|
||||||
/** 防止顶栈一样重叠在自己的 APP 中 */
|
|
||||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
|
||||||
})
|
|
||||||
}.onFailure { Toast.makeText(this, "无法启动系统默认浏览器", Toast.LENGTH_SHORT).show() }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -23,15 +23,18 @@
|
|||||||
|
|
||||||
package com.fankes.tsbattery.utils.factory
|
package com.fankes.tsbattery.utils.factory
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageInfo
|
import android.content.pm.PackageInfo
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
|
import android.graphics.Color
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import com.fankes.tsbattery.application.TSApplication.Companion.appContext
|
import com.fankes.tsbattery.application.TSApplication.Companion.appContext
|
||||||
|
import com.google.android.material.snackbar.Snackbar
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统深色模式是否开启
|
* 系统深色模式是否开启
|
||||||
@@ -93,6 +96,26 @@ fun Number.dp(context: Context) = dpFloat(context).toInt()
|
|||||||
*/
|
*/
|
||||||
fun Number.dpFloat(context: Context) = toFloat() * context.resources.displayMetrics.density
|
fun Number.dpFloat(context: Context) = toFloat() * context.resources.displayMetrics.density
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 弹出 [Toast]
|
||||||
|
* @param msg 提示内容
|
||||||
|
*/
|
||||||
|
fun toast(msg: String) = Toast.makeText(appContext, msg, Toast.LENGTH_SHORT).show()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 弹出 [Snackbar]
|
||||||
|
* @param msg 提示内容
|
||||||
|
* @param actionText 按钮文本 - 不写默认取消按钮
|
||||||
|
* @param it 按钮事件回调
|
||||||
|
*/
|
||||||
|
fun Context.snake(msg: String, actionText: String = "", it: () -> Unit = {}) =
|
||||||
|
Snackbar.make((this as Activity).findViewById(android.R.id.content), msg, Snackbar.LENGTH_LONG).apply {
|
||||||
|
if (actionText.isBlank()) return@apply
|
||||||
|
setActionTextColor(Color.WHITE)
|
||||||
|
setAction(actionText) { it() }
|
||||||
|
}.show()
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 跳转 APP 自身设置界面
|
* 跳转 APP 自身设置界面
|
||||||
* @param packageName 包名
|
* @param packageName 包名
|
||||||
@@ -109,3 +132,21 @@ fun Context.openSelfSetting(packageName: String) = runCatching {
|
|||||||
Toast.makeText(this, "启动 $packageName 应用信息失败", Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, "启动 $packageName 应用信息失败", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动系统浏览器
|
||||||
|
* @param url 网址
|
||||||
|
* @param packageName 指定包名 - 可不填
|
||||||
|
*/
|
||||||
|
fun Context.openBrowser(url: String, packageName: String = "") = runCatching {
|
||||||
|
startActivity(Intent().apply {
|
||||||
|
if (packageName.isNotBlank()) setPackage(packageName)
|
||||||
|
action = Intent.ACTION_VIEW
|
||||||
|
data = Uri.parse(url)
|
||||||
|
/** 防止顶栈一样重叠在自己的 APP 中 */
|
||||||
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
})
|
||||||
|
}.onFailure {
|
||||||
|
if (packageName.isNotBlank()) snake(msg = "启动 $packageName 失败")
|
||||||
|
else snake(msg = "启动系统浏览器失败")
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* TSBattery - A new way to save your battery avoid cancer apps hacker it.
|
||||||
|
* Copyright (C) 2019-2022 Fankes Studio(qzmmcn@163.com)
|
||||||
|
* https://github.com/fankes/TSBattery
|
||||||
|
*
|
||||||
|
* This software is non-free but opensource software: you can redistribute it
|
||||||
|
* and/or modify it under the terms of the GNU Affero General Public License
|
||||||
|
* as published by the Free Software Foundation; either
|
||||||
|
* version 3 of the License, or any later version.
|
||||||
|
*
|
||||||
|
* This software is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* and eula along with this software. If not, see
|
||||||
|
* <https://www.gnu.org/licenses/>
|
||||||
|
*
|
||||||
|
* This file is Created by fankes on 2022/3/20.
|
||||||
|
*/
|
||||||
|
package com.fankes.tsbattery.utils.tool
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.content.Context
|
||||||
|
import com.fankes.tsbattery.utils.factory.openBrowser
|
||||||
|
import com.fankes.tsbattery.utils.factory.runInSafe
|
||||||
|
import com.fankes.tsbattery.utils.factory.showDialog
|
||||||
|
import okhttp3.*
|
||||||
|
import org.json.JSONObject
|
||||||
|
import java.io.IOException
|
||||||
|
import java.io.Serializable
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取 Github Release 最新版本工具类
|
||||||
|
*/
|
||||||
|
object GithubReleaseTool {
|
||||||
|
|
||||||
|
/** 仓库作者 */
|
||||||
|
private const val repoAuthor = "fankes"
|
||||||
|
|
||||||
|
/** 仓库名称 */
|
||||||
|
private const val repoName = "TSBattery"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取最新版本信息
|
||||||
|
* @param context 实例
|
||||||
|
* @param version 当前版本
|
||||||
|
* @param it 成功后回调 - ([String] 最新版本,[Function] 更新对话框方法体)
|
||||||
|
*/
|
||||||
|
fun checkingForUpdate(context: Context, version: String, it: (String, () -> Unit) -> Unit) = runInSafe {
|
||||||
|
OkHttpClient().newBuilder().build().newCall(
|
||||||
|
Request.Builder()
|
||||||
|
.url("https://api.github.com/repos/$repoAuthor/$repoName/releases/latest")
|
||||||
|
.get()
|
||||||
|
.build()
|
||||||
|
).enqueue(object : Callback {
|
||||||
|
override fun onFailure(call: Call, e: IOException) {}
|
||||||
|
|
||||||
|
override fun onResponse(call: Call, response: Response) = runInSafe {
|
||||||
|
JSONObject(response.body?.string() ?: "").apply {
|
||||||
|
GithubReleaseBean(
|
||||||
|
name = getString("name"),
|
||||||
|
htmlUrl = getString("html_url"),
|
||||||
|
content = getString("body"),
|
||||||
|
date = getString("published_at").replace(oldValue = "T", newValue = " ").replace(oldValue = "Z", newValue = "")
|
||||||
|
).apply {
|
||||||
|
fun showUpdate() = context.showDialog {
|
||||||
|
title = "最新版本 $name"
|
||||||
|
msg = "发布于 $date\n\n" +
|
||||||
|
"更新日志\n\n" + content
|
||||||
|
confirmButton(text = "更新") { context.openBrowser(htmlUrl) }
|
||||||
|
cancelButton()
|
||||||
|
}
|
||||||
|
if (name != version) (context as? Activity?)?.runOnUiThread {
|
||||||
|
showUpdate()
|
||||||
|
it(name) { showUpdate() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Github Release bean
|
||||||
|
* @param name 版本名称
|
||||||
|
* @param htmlUrl 网页地址
|
||||||
|
* @param content 更新日志
|
||||||
|
* @param date 发布时间
|
||||||
|
*/
|
||||||
|
private data class GithubReleaseBean(
|
||||||
|
var name: String,
|
||||||
|
var htmlUrl: String,
|
||||||
|
var content: String,
|
||||||
|
var date: String
|
||||||
|
) : Serializable
|
||||||
|
}
|
6
app/src/main/res/drawable/bg_orange_round.xml
Executable file
6
app/src/main/res/drawable/bg_orange_round.xml
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle">
|
||||||
|
<solid android:color="#FF7043" />
|
||||||
|
<corners android:radius="15dp" />
|
||||||
|
</shape>
|
@@ -79,16 +79,38 @@
|
|||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="18sp" />
|
android:textSize="18sp" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:gravity="center|start"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/main_text_version"
|
android:id="@+id/main_text_version"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="10dp"
|
|
||||||
android:alpha="0.8"
|
android:alpha="0.8"
|
||||||
android:text="模块版本:%1"
|
android:text="模块版本:%1"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="13sp" />
|
android:textSize="13sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/main_text_release_version"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="5dp"
|
||||||
|
android:background="@drawable/bg_orange_round"
|
||||||
|
android:paddingLeft="5dp"
|
||||||
|
android:paddingTop="2dp"
|
||||||
|
android:paddingRight="5dp"
|
||||||
|
android:paddingBottom="2dp"
|
||||||
|
android:text="点击更新 %1"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="11sp"
|
||||||
|
android:visibility="gone" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
Reference in New Issue
Block a user