package com.gh.download

object DownloadWorkManager {

    private const val TAG_DOWNLOAD = "tag_download"

    @JvmStatic
    fun addWorker() {
//        cancelWorker()
//
//        // 可用存储空间少于 5G ，不使用 WorkManager，避免各种因为存储空间造成的问题
//        if (FileUtils.isMounted() && FileUtils.getFreeSpaceByPath(Environment.getExternalStorageDirectory().absolutePath) < 1024F * 5) return
//
//        // 每 15 分钟检查一下是否需要重试下载
//        val builder = PeriodicWorkRequest.Builder(
//                DownloadWorker::class.java,
//                PeriodicWorkRequest.MIN_PERIODIC_INTERVAL_MILLIS,
//                TimeUnit.MILLISECONDS)
//
//        val workerRequest = builder
//                .addTag(TAG_DOWNLOAD)
//                .build()
//
//        tryWithDefaultCatch { WorkManager.getInstance(HaloApp.getInstance().applicationContext).enqueue(workerRequest) }
    }

    @JvmStatic
    fun cancelWorker() {
//        tryWithDefaultCatch { WorkManager.getInstance(HaloApp.getInstance().applicationContext).cancelAllWorkByTag(TAG_DOWNLOAD) }
    }

}