diff --git a/app/src/main/java/com/deniscerri/ytdl/App.kt b/app/src/main/java/com/deniscerri/ytdl/App.kt index 787b5bf9..9535dda3 100644 --- a/app/src/main/java/com/deniscerri/ytdl/App.kt +++ b/app/src/main/java/com/deniscerri/ytdl/App.kt @@ -38,6 +38,14 @@ class App : Application() { val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this@App) setDefaultValues() + ThemeUtil.init(this) + + val processName = getProcessNameImpl() + if (processName.endsWith(":incognito_process") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + WebView.setDataDirectorySuffix("incognito_store") + return + } + applicationScope = CoroutineScope(SupervisorJob()) applicationScope.launch((Dispatchers.IO)) { try { @@ -63,16 +71,6 @@ class App : Application() { if (requiresServer) { BgUtilsPoTokenGeneratorUtil.acquireServer(this@App) } - - val processName = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - getProcessName() - } else { - packageName - } - if (processName.endsWith(":incognito_process") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - WebView.setDataDirectorySuffix("incognito_store") - } - }catch (e: Exception){ Looper.prepare().runCatching { Toast.makeText(this@App, e.message, Toast.LENGTH_SHORT).show() @@ -80,7 +78,6 @@ class App : Application() { e.printStackTrace() } } - ThemeUtil.init(this) } @Throws(ExecuteException::class) private fun initLibraries() { @@ -108,6 +105,14 @@ class App : Application() { notificationUtil.createNotificationChannel() } + private fun getProcessNameImpl() : String { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + getProcessName() + } else { + packageName + } + } + companion object { private const val TAG = "App" private lateinit var applicationScope: CoroutineScope diff --git a/app/src/main/java/com/deniscerri/ytdl/services/BgUtilsPoTokenGeneratorService.kt b/app/src/main/java/com/deniscerri/ytdl/services/BgUtilsPoTokenGeneratorService.kt index ff988643..68c22263 100644 --- a/app/src/main/java/com/deniscerri/ytdl/services/BgUtilsPoTokenGeneratorService.kt +++ b/app/src/main/java/com/deniscerri/ytdl/services/BgUtilsPoTokenGeneratorService.kt @@ -65,6 +65,7 @@ class BgUtilsPoTokenGeneratorService : Service() { val runtimeManager = RuntimeManager.getInstance() if (intent?.action == "ACTION_EXIT") { + BgUtilsPoTokenGeneratorUtil.resetState() runtimeManager.destroyProcessById(currentRunningProcess) stopForeground(STOP_FOREGROUND_REMOVE) stopSelf() diff --git a/app/src/main/java/com/deniscerri/ytdl/util/BgUtilsPoTokenGeneratorUtil.kt b/app/src/main/java/com/deniscerri/ytdl/util/BgUtilsPoTokenGeneratorUtil.kt index 97717d14..e1feac0c 100644 --- a/app/src/main/java/com/deniscerri/ytdl/util/BgUtilsPoTokenGeneratorUtil.kt +++ b/app/src/main/java/com/deniscerri/ytdl/util/BgUtilsPoTokenGeneratorUtil.kt @@ -172,6 +172,11 @@ object BgUtilsPoTokenGeneratorUtil { } } + fun resetState() { + activeJobCount.set(0) + shutdownJob = null + } + fun releaseServer(context: Context, idleDelayMs: Long = 5000) { if (activeJobCount.decrementAndGet() <= 0) { activeJobCount.set(0)