Skip to content

Commit

Permalink
https://github.com/Hi-Windom/Sillot-android/issues/71
Browse files Browse the repository at this point in the history
  • Loading branch information
Soltus committed Jun 20, 2024
1 parent ac150f2 commit 79afed4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/org/b3log/siyuan/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class App : Application() {

val isMainThread: Boolean
get() = Looper.getMainLooper().thread.id == Thread.currentThread().id

var KernelService: BootService? = null
}

override fun onCreate() {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/org/b3log/siyuan/services/BootService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import mobile.Mobile
import org.apache.commons.io.FileUtils
import org.apache.commons.io.filefilter.DirectoryFileFilter
import org.apache.commons.io.filefilter.TrueFileFilter
import org.b3log.siyuan.App
import org.b3log.siyuan.Utils
import org.b3log.siyuan.workers.CheckHttpServerWorker
import org.b3log.siyuan.workers.SyncDataWorker
Expand Down Expand Up @@ -93,6 +94,7 @@ class BootService : Service() {
private val binder = LocalBinder()

override fun onBind(intent: Intent): IBinder {
App.KernelService = this
webViewKey = intent.getStringExtra(S.INTENT.EXTRA_WEB_VIEW_KEY)
return binder
}
Expand Down Expand Up @@ -485,6 +487,7 @@ class BootService : Service() {

/**
* 这种方法并不是官方推荐的,因为它可能会导致任务之间的延迟,并且在高频率下可能会对系统资源造成压力。
* 实际上如果不显示前台WIFI悬浮窗的话这个很快就会失效。
*/
private fun scheduleCheckHttpServerWork() {
val constraints = Constraints.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package org.b3log.siyuan.workers
import android.content.Context
import androidx.work.Worker
import androidx.work.WorkerParameters
import com.blankj.utilcode.util.ServiceUtils.stopService
import com.tencent.bugly.crashreport.BuglyLog
import mobile.Mobile
import org.b3log.siyuan.App

class CheckHttpServerWorker(context: Context, params: WorkerParameters) : Worker(context, params) {
private val TAG = "workers/CheckHttpServerWorker.kt"
override fun doWork(): Result {
if (!Mobile.isHttpServing()) {
// 如果没有运行,重启
stopService("org.b3log.siyuan.services.BootService")
val s = App.KernelService
if (s != null) {
BuglyLog.i(TAG, "check: Mobile.isHttpServing(): ${Mobile.isHttpServing()} || s.isHttpServerRunning(): ${s.isHttpServerRunning()}")
}
// 返回Result.success()表示任务成功完成
return Result.success()
Expand Down

0 comments on commit 79afed4

Please sign in to comment.