Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
feat: 开机自启
Browse files Browse the repository at this point in the history
  • Loading branch information
jing332 committed Jan 12, 2024
1 parent 7b6912c commit b4b9854
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 13 deletions.
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SYSTEM_EXEMPTED" />
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />


<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down Expand Up @@ -55,6 +57,14 @@
android:usesCleartextTraffic="true"
tools:ignore="UnusedAttribute">

<receiver
android:name=".BootStartReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

<service
android:name=".service.AListService"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.github.jing332.alistandroid

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.github.jing332.alistandroid.config.AppConfig
import com.github.jing332.alistandroid.service.AListService

class BootStartReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent?) {
if (intent?.action == Intent.ACTION_BOOT_COMPLETED && AppConfig.isStartAtBoot.value) {
context.startService(Intent(context, AListService::class.java))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ object AppConfig {
initialValue = ""
)

var isStartAtBoot = mutableDataSaverStateOf(
dataSaverInterface = pref,
key = "isStartAtBoot",
initialValue = false
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,5 @@ object ServerConfig {
DataSaverPreferences(app.getSharedPreferences("server", 0))


var port = mutableDataSaverStateOf(
dataSaverInterface = pref,
key = "port",
initialValue = 2344
)

/**
* 单位 秒
*/
var timeout = mutableDataSaverStateOf(
dataSaverInterface = pref,
key = "timeout",
initialValue = 10
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.material.icons.filled.FilePresent
import androidx.compose.material.icons.filled.HdrAuto
import androidx.compose.material.icons.filled.ScreenLockPortrait
import androidx.compose.material.icons.filled.SupervisorAccount
import androidx.compose.material.icons.filled.SystemSecurityUpdateGood
import androidx.compose.material3.Checkbox
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
Expand Down Expand Up @@ -162,6 +163,15 @@ fun SettingsScreen() {
icon = { Icon(Icons.Default.ScreenLockPortrait, contentDescription = null) }
)

var startAtBoot by remember { AppConfig.isStartAtBoot }
SwitchPreference(
title = { Text(stringResource(R.string.start_at_boot)) },
subTitle = { Text(stringResource(R.string.start_at_boot_desc)) },
checked = startAtBoot,
onCheckedChange = { startAtBoot = it },
icon = { Icon(Icons.Default.SystemSecurityUpdateGood, contentDescription = null) }
)

DividerPreference {
Text(stringResource(id = R.string.web))
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,6 @@
<string name="browser">浏览器</string>
<string name="select_downloader">选择下载器</string>
<string name="last_used">上次使用</string>
<string name="start_at_boot">开机自启动服务</string>
<string name="start_at_boot_desc">在开机时自动开启AList服务。</string>
</resources>

0 comments on commit b4b9854

Please sign in to comment.