Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.

Commit 007a1a5

Browse files
committed
3.1.2-dev
1 parent f97a26e commit 007a1a5

File tree

9 files changed

+99
-57
lines changed

9 files changed

+99
-57
lines changed

app/build.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ apply plugin: 'kotlin-kapt'
55
apply plugin: 'kotlinx-serialization'
66

77

8-
def CORE_VERSION = "2.5.1"
9-
def CONSOLE_VERSION = "2.5.1"
8+
def CORE_VERSION = "2.6-M2"
9+
def CONSOLE_VERSION = "2.6-M2"
1010
def LUAMIRAI_VERSION = "2.0.8"
1111

1212
android {
@@ -17,8 +17,8 @@ android {
1717
applicationId "io.github.mzdluo123.mirai.android"
1818
minSdkVersion 26
1919
targetSdkVersion 30
20-
versionCode 44
21-
versionName "3.1.1"
20+
versionCode 45
21+
versionName "3.1.2-dev"
2222
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2323
buildConfigField("String", "COREVERSION", "\"$CORE_VERSION\"")
2424
buildConfigField("String", "CONSOLEVERSION", "\"$CONSOLE_VERSION\"")
@@ -165,6 +165,8 @@ dependencies {
165165
//test
166166
implementation 'androidx.test.espresso:espresso-idling-resource:3.3.0'
167167

168+
implementation 'com.fanjun:keeplive:1.1.22'
169+
168170
// fuck!! 他不能在Android平台工作
169171
// implementation 'org.codehaus.groovy:groovy:2.4.6:grooid'
170172

app/src/main/java/io/github/mzdluo123/mirai/android/AppSettings.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ object AppSettings : Preferences("setting") {
2222
var refreshPerMinute by IntPrefSaveAsStr("status_refresh_count", 15)
2323
var startOnBoot by BoolPref("start_on_boot_preference", false)
2424
var waitingDebugger by BoolPref("waiting_debugger_preference", false)
25+
26+
var keepLive by BoolPref("keeplive_preference", false)
2527
}

app/src/main/java/io/github/mzdluo123/mirai/android/BotApplication.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import android.content.Context
66
import android.content.Intent
77
import android.os.Build
88
import android.os.Process
9+
import com.fanjun.keeplive.KeepLive
10+
import com.fanjun.keeplive.config.ForegroundNotification
11+
import com.fanjun.keeplive.config.KeepLiveService
912
import io.github.mzdluo123.mirai.android.NotificationFactory.initNotification
1013
import io.github.mzdluo123.mirai.android.activity.CrashReportActivity
1114
import io.github.mzdluo123.mirai.android.crash.MiraiAndroidReportSenderFactory
@@ -73,7 +76,22 @@ class BotApplication : Application() {
7376
return null
7477
}
7578

79+
internal fun keepLive() {
80+
val notification = ForegroundNotification("MiraiAndroid", "保活服务已启动", R.mipmap.ic_launcher)
81+
KeepLive.startWork(this, KeepLive.RunMode.ROGUE, notification, object : KeepLiveService {
82+
override fun onWorking() {
83+
startBotService()
84+
}
85+
86+
override fun onStop() {
87+
stopBotService()
88+
}
89+
90+
})
91+
}
92+
7693
internal fun startBotService() {
94+
7795
val account = getSharedPreferences("account", Context.MODE_PRIVATE)
7896
this.startService(Intent(this, BotService::class.java).apply {
7997
putExtra("action", BotService.START_SERVICE)

app/src/main/java/io/github/mzdluo123/mirai/android/activity/MainActivity.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ import androidx.navigation.ui.AppBarConfiguration
1212
import androidx.navigation.ui.navigateUp
1313
import androidx.navigation.ui.setupActionBarWithNavController
1414
import androidx.navigation.ui.setupWithNavController
15-
import io.github.mzdluo123.mirai.android.BotApplication
16-
import io.github.mzdluo123.mirai.android.BuildConfig
17-
import io.github.mzdluo123.mirai.android.NotificationFactory
18-
import io.github.mzdluo123.mirai.android.R
15+
import io.github.mzdluo123.mirai.android.*
1916
import io.github.mzdluo123.mirai.android.utils.RequestUtil
2017
import io.github.mzdluo123.mirai.android.utils.SafeDns
2118
import io.github.mzdluo123.mirai.android.utils.shareText
@@ -69,6 +66,9 @@ class MainActivity : AppCompatActivity() {
6966
(application as BotApplication).startBotService()
7067
setupListeners()
7168
crashCheck()
69+
if (AppSettings.keepLive) {
70+
BotApplication.context.keepLive()
71+
}
7272
// if (BuildConfig.DEBUG) toast("跳过更新检查")
7373
// else updateCheck()
7474
updateCheck()

app/src/main/java/io/github/mzdluo123/mirai/android/miraiconsole/MiraiAndroidLogger.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,19 @@ fun logException(err: Throwable?) {
3232
MiraiAndroidLogger.error(stringWriter.toString())
3333
}
3434

35+
internal fun processHTMLLog(log: String): String =
36+
log.replace("\n", "<br>")
37+
.replace("<", "&lt;")
38+
.replace(">", "&gt")
39+
.replace("&", "&amp;")
40+
.replace("\"", "&quot")
41+
3542
object MiraiAndroidLogger :
3643
SimpleLogger(LOGGER_IDENTITY, { priority: LogPriority, message: String?, e: Throwable? ->
3744
val log = "[${priority.name}] ${message ?: e}"
3845
val colorLog =
3946
"<font color=\"${LogColor.valueOf(priority.name).color}\">[${priority.name}]</font> ${
40-
message?.replace(
41-
"\n",
42-
"<br>"
43-
) ?: "发生错误"
47+
processHTMLLog(message ?: "")
4448
}"
4549

4650
synchronized(this) {

app/src/main/java/io/github/mzdluo123/mirai/android/ui/tools/ToolsFragment.kt

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.github.mzdluo123.mirai.android.ui.tools
22

33
import android.annotation.SuppressLint
4-
import android.content.ComponentName
54
import android.content.Intent
65
import android.os.Bundle
76
import android.view.LayoutInflater
@@ -60,18 +59,18 @@ class ToolsFragment : Fragment() {
6059
getDeviceFile()?.delete() ?: return@setOnClickListener
6160
toast("成功")
6261
}
63-
btn_open_data_folder.setOnClickListener {
64-
val intent = Intent()
65-
66-
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK;
67-
intent.component = ComponentName(
68-
"com.android.documentsui",
69-
"com.android.documentsui.files.FilesActivity"
70-
)
71-
72-
requireContext().startActivity(intent)
73-
74-
}
62+
// btn_open_data_folder.setOnClickListener {
63+
// val intent = Intent()
64+
//
65+
// intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK;
66+
// intent.component = ComponentName(
67+
// "com.android.documentsui",
68+
// "com.android.documentsui.files.FilesActivity"
69+
// )
70+
//
71+
// requireContext().startActivity(intent)
72+
//
73+
// }
7574
}
7675

7776
private fun getDeviceFile(): File? {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24"
6+
android:tint="?attr/colorControlNormal">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M23,12l-2.44,-2.78 0.34,-3.68 -3.61,-0.82 -1.89,-3.18L12,3 8.6,1.54 6.71,4.72l-3.61,0.81 0.34,3.68L1,12l2.44,2.78 -0.34,3.69 3.61,0.82 1.89,3.18L12,21l3.4,1.46 1.89,-3.18 3.61,-0.82 -0.34,-3.68L23,12zM13,17h-2v-2h2v2zM13,13h-2L11,7h2v6z" />
10+
</vector>

app/src/main/res/layout/fragment_tools.xml

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,38 @@
3030

3131
</androidx.cardview.widget.CardView>
3232

33-
<androidx.cardview.widget.CardView
34-
android:layout_width="match_parent"
35-
android:layout_height="wrap_content"
36-
android:layout_marginStart="8dp"
37-
android:layout_marginTop="8dp"
38-
android:layout_marginEnd="8dp">
39-
40-
<LinearLayout
41-
android:layout_width="match_parent"
42-
android:layout_height="wrap_content"
43-
android:orientation="vertical">
44-
45-
<TextView
46-
android:layout_width="match_parent"
47-
android:layout_height="wrap_content"
48-
android:layout_margin="10dp"
49-
android:text="数据工具"
50-
android:textSize="18sp"
51-
android:textStyle="bold" />
52-
53-
54-
<Button
55-
android:id="@+id/btn_open_data_folder"
56-
android:layout_width="match_parent"
57-
android:layout_height="wrap_content"
58-
android:layout_marginHorizontal="8dp"
59-
android:text="打开系统文件管理器" />
60-
61-
62-
</LinearLayout>
63-
64-
</androidx.cardview.widget.CardView>
33+
<!-- <androidx.cardview.widget.CardView-->
34+
<!-- android:layout_width="match_parent"-->
35+
<!-- android:layout_height="wrap_content"-->
36+
<!-- android:layout_marginStart="8dp"-->
37+
<!-- android:layout_marginTop="8dp"-->
38+
<!-- android:layout_marginEnd="8dp">-->
39+
40+
<!-- <LinearLayout-->
41+
<!-- android:layout_width="match_parent"-->
42+
<!-- android:layout_height="wrap_content"-->
43+
<!-- android:orientation="vertical">-->
44+
45+
<!-- <TextView-->
46+
<!-- android:layout_width="match_parent"-->
47+
<!-- android:layout_height="wrap_content"-->
48+
<!-- android:layout_margin="10dp"-->
49+
<!-- android:text="数据工具"-->
50+
<!-- android:textSize="18sp"-->
51+
<!-- android:textStyle="bold" />-->
52+
53+
54+
<!-- <Button-->
55+
<!-- android:id="@+id/btn_open_data_folder"-->
56+
<!-- android:layout_width="match_parent"-->
57+
<!-- android:layout_height="wrap_content"-->
58+
<!-- android:layout_marginHorizontal="8dp"-->
59+
<!-- android:text="打开系统文件管理器" />-->
60+
61+
62+
<!-- </LinearLayout>-->
63+
64+
<!-- </androidx.cardview.widget.CardView>-->
6565

6666
<androidx.cardview.widget.CardView
6767
android:layout_width="match_parent"

app/src/main/res/xml/setting_screen.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@
3030
android:key="start_on_boot_preference"
3131
android:summary="请加入开机自启白名单以确保能够正常开机启动"
3232
android:title="开机启动" />
33+
34+
<SwitchPreference
35+
android:defaultValue="false"
36+
android:icon="@drawable/ic_baseline_new_releases_24"
37+
android:key="keeplive_preference"
38+
android:summary="降低MiraiAndroid被系统杀死的可能性,不保证效果"
39+
android:title="启用保活服务" />
3340
<!-- <SwitchPreference-->
3441
<!-- android:defaultValue="false"-->
3542
<!-- android:icon="@drawable/ic_battery_alert_24"-->

0 commit comments

Comments
 (0)