Files
FocusBox/src/main/java/com/focusbox/app/App.kt

34 lines
1.0 KiB
Kotlin
Raw Normal View History

package com.focusbox.app
import android.app.Application
import androidx.appcompat.app.AppCompatDelegate
import com.focusbox.app.data.Store
import com.focusbox.app.service.Notif
import com.focusbox.app.service.TimerCore
import com.focusbox.app.util.Prefs
class App : Application() {
override fun onCreate() {
super.onCreate()
Prefs.init(this)
Store.init(this)
// 重复任务按间隔滚到当前周期:冷启动就补齐,避免过期后不再出现在清单里
runCatching { Store.rollRepeatingTasks() }
Notif.createChannels(this)
applyTheme()
TimerCore.init(this)
}
/** 深色模式在 Activity 创建前定好,避免首帧闪一下浅色再跳深色 */
fun applyTheme() {
AppCompatDelegate.setDefaultNightMode(
when (Prefs.themeMode) {
1 -> AppCompatDelegate.MODE_NIGHT_NO
2 -> AppCompatDelegate.MODE_NIGHT_YES
else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
}
)
}
}