Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.kr328.clash

import com.github.kr328.clash.common.compat.versionCodeCompat
import com.github.kr328.clash.common.log.Log
import com.github.kr328.clash.design.AppCrashedDesign
import com.github.kr328.clash.log.SystemLogcat
Expand All @@ -18,7 +17,7 @@ class AppCrashedActivity : BaseActivity<AppCrashedDesign>() {
withContext(Dispatchers.IO) { packageManager.getPackageInfo(packageName, 0) }

Log.i(
"App version: versionName = ${packageInfo.versionName} versionCode = ${packageInfo.versionCodeCompat}"
"App version: versionName = ${packageInfo.versionName} versionCode = ${packageInfo.longVersionCode}"
)

val logs = withContext(Dispatchers.IO) { SystemLogcat.dumpCrash() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AppSettingsActivity : BaseActivity<AppSettingsDesign>(), Behavior {
setContentDesign(design)

while (isActive) {
select<Unit> {
select {
events.onReceive {
when (it) {
Event.ClashStart,
Expand Down
23 changes: 6 additions & 17 deletions app/src/main/java/com/github/kr328/clash/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.github.kr328.clash

import android.app.ActivityManager
import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import android.view.View
import androidx.activity.result.contract.ActivityResultContract
Expand All @@ -28,14 +27,14 @@ import com.github.kr328.clash.util.ApplicationObserver
import java.util.UUID
import java.util.concurrent.atomic.AtomicInteger
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.NonCancellable
import kotlinx.coroutines.cancel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext

abstract class BaseActivity<D : Design<*>> :
Expand Down Expand Up @@ -76,7 +75,7 @@ abstract class BaseActivity<D : Design<*>> :
val requestKey = nextRequestKey.getAndIncrement().toString()

ActivityResultLifecycle().use { lifecycle, start ->
suspendCoroutine { c ->
suspendCancellableCoroutine { c ->
activityResultRegistry
.register(requestKey, lifecycle, contracts) { c.resume(it) }
.apply { start() }
Expand All @@ -86,7 +85,7 @@ abstract class BaseActivity<D : Design<*>> :
}

suspend fun setContentDesign(design: D) {
suspendCoroutine<Unit> {
suspendCancellableCoroutine {
window.decorView.post {
this.design = design
it.resume(Unit)
Expand Down Expand Up @@ -147,10 +146,6 @@ abstract class BaseActivity<D : Design<*>> :
}
}

open fun shouldDisplayHomeAsUpEnabled(): Boolean {
return true
}

override fun onSupportNavigateUp(): Boolean {
this.onBackPressed()
return true
Expand Down Expand Up @@ -215,15 +210,9 @@ abstract class BaseActivity<D : Design<*>> :
window.statusBarColor = resolveThemedColor(android.R.attr.statusBarColor)
window.navigationBarColor = resolveThemedColor(android.R.attr.navigationBarColor)

if (Build.VERSION.SDK_INT >= 23) {
window.isLightStatusBarsCompat =
resolveThemedBoolean(android.R.attr.windowLightStatusBar)
}

if (Build.VERSION.SDK_INT >= 27) {
window.isLightNavigationBarCompat =
resolveThemedBoolean(android.R.attr.windowLightNavigationBar)
}
window.isLightStatusBarsCompat = resolveThemedBoolean(android.R.attr.windowLightStatusBar)
window.isLightNavigationBarCompat =
resolveThemedBoolean(android.R.attr.windowLightNavigationBar)

this.dayNight = dayNight
}
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/com/github/kr328/clash/FilesActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("BlockingMethodInNonBlockingContext")

package com.github.kr328.clash

import android.content.Intent
Expand Down Expand Up @@ -37,7 +35,7 @@ class FilesActivity : BaseActivity<FilesDesign>() {
val ticker = ticker(TimeUnit.MINUTES.toMillis(1))

while (isActive) {
select<Unit> {
select {
events.onReceive {
when (it) {
Event.ActivityStart,
Expand Down
13 changes: 5 additions & 8 deletions app/src/main/java/com/github/kr328/clash/LogcatActivity.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.github.kr328.clash

import android.content.ComponentName
import android.content.Context
import android.content.ServiceConnection
import android.net.Uri
import android.os.IBinder
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import com.github.kr328.clash.common.compat.startForegroundServiceCompat
import com.github.kr328.clash.common.log.Log
import com.github.kr328.clash.common.util.fileName
import com.github.kr328.clash.common.util.intent
Expand All @@ -24,10 +22,10 @@ import com.github.kr328.clash.log.LogcatReader
import com.github.kr328.clash.util.logsDir
import java.io.OutputStreamWriter
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.isActive
import kotlinx.coroutines.selects.select
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext

class LogcatActivity : BaseActivity<LogcatDesign>() {
Expand Down Expand Up @@ -94,15 +92,15 @@ class LogcatActivity : BaseActivity<LogcatDesign>() {

setContentDesign(design)

startForegroundServiceCompat(LogcatService::class.intent)
startForegroundService(LogcatService::class.intent)

val logcat = bindLogcatService()
val ticker = ticker(500)

var initial = true

while (isActive) {
select<Unit> {
select {
events.onReceive {}

design.requests.onReceive {
Expand Down Expand Up @@ -135,7 +133,7 @@ class LogcatActivity : BaseActivity<LogcatDesign>() {
}

private suspend fun bindLogcatService(): LogcatService {
return suspendCoroutine { ctx ->
return suspendCancellableCoroutine { ctx ->
bindService(
LogcatService::class.intent,
object : ServiceConnection {
Expand All @@ -151,12 +149,11 @@ class LogcatActivity : BaseActivity<LogcatDesign>() {
conn = null
}
},
Context.BIND_AUTO_CREATE,
BIND_AUTO_CREATE,
)
Comment thread
Goooler marked this conversation as resolved.
}
}

@Suppress("BlockingMethodInNonBlockingContext")
private suspend fun writeLogTo(messages: List<LogMessage>, file: LogFile, uri: Uri) {
LogcatFilter(OutputStreamWriter(contentResolver.openOutputStream(uri)), this).use {
withContext(Dispatchers.Main) {
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/com/github/kr328/clash/LogcatService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.github.kr328.clash
import android.app.PendingIntent
import android.app.Service
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.ServiceConnection
import android.os.Binder
Expand Down Expand Up @@ -58,7 +57,7 @@ class LogcatService : Service(), CoroutineScope by CoroutineScope(Dispatchers.De

showNotification()

bindService(RemoteService::class.intent, connection, Context.BIND_AUTO_CREATE)
bindService(RemoteService::class.intent, connection, BIND_AUTO_CREATE)
Comment thread
Goooler marked this conversation as resolved.
}

override fun onDestroy() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/github/kr328/clash/LogsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class LogsActivity : BaseActivity<LogsDesign>() {
setContentDesign(design)

while (isActive) {
select<Unit> {
select {
events.onReceive {
when (it) {
Event.ActivityStart -> {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/github/kr328/clash/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MainActivity : BaseActivity<MainDesign>() {
val ticker = ticker(TimeUnit.SECONDS.toMillis(1))

while (isActive) {
select<Unit> {
select {
events.onReceive {
when (it) {
Event.ActivityStart,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import com.github.kr328.clash.util.clashDir
import java.io.File
import java.io.FileOutputStream

@Suppress("unused")
class MainApplication : Application() {
private val uiStore by lazy(LazyThreadSafetyMode.NONE) { UiStore(this) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MetaFeatureSettingsActivity : BaseActivity<MetaFeatureSettingsDesign>() {
setContentDesign(design)

while (isActive) {
select<Unit> {
select {
events.onReceive {}

design.requests.onReceive {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class NetworkSettingsActivity : BaseActivity<NetworkSettingsDesign>() {
setContentDesign(design)

while (isActive) {
select<Unit> {
select {
events.onReceive {
when (it) {
Event.ClashStart,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.kr328.clash

import android.app.Activity
import android.content.ComponentName
import android.content.Intent
import android.net.Uri
Expand Down Expand Up @@ -43,7 +42,7 @@ class NewProfileActivity : BaseActivity<NewProfileDesign>() {
setContentDesign(design)

while (isActive) {
select<Unit> {
select {
events.onReceive {}

design.requests.onReceive {
Expand Down Expand Up @@ -109,7 +108,7 @@ class NewProfileActivity : BaseActivity<NewProfileDesign>() {
PropertiesActivity::class.intent.setUUID(uuid),
)

if (r.resultCode == Activity.RESULT_OK) finish()
if (r.resultCode == RESULT_OK) finish()
}

private suspend fun ProfileProvider.External.get(): Pair<Uri, String?>? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package com.github.kr328.clash

import com.github.kr328.clash.core.Clash
import com.github.kr328.clash.design.OverrideSettingsDesign
import com.github.kr328.clash.service.store.ServiceStore
import com.github.kr328.clash.util.withClash
import kotlinx.coroutines.isActive
import kotlinx.coroutines.selects.select

class OverrideSettingsActivity : BaseActivity<OverrideSettingsDesign>() {
override suspend fun main() {
val configuration = withClash { queryOverride(Clash.OverrideSlot.Persist) }
val service = ServiceStore(this)

Comment thread
Goooler marked this conversation as resolved.
defer { withClash { patchOverride(Clash.OverrideSlot.Persist, configuration) } }

Expand All @@ -19,7 +17,7 @@ class OverrideSettingsActivity : BaseActivity<OverrideSettingsDesign>() {
setContentDesign(design)

while (isActive) {
select<Unit> {
select {
events.onReceive {}

design.requests.onReceive {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ProfilesActivity : BaseActivity<ProfilesDesign>() {
val ticker = ticker(TimeUnit.MINUTES.toMillis(1))

while (isActive) {
select<Unit> {
select {
events.onReceive {
when (it) {
Event.ActivityStart,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PropertiesActivity : BaseActivity<PropertiesDesign>() {
}

while (isActive) {
select<Unit> {
select {
events.onReceive {
when (it) {
Event.ActivityStop -> {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/github/kr328/clash/ProxyActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ProxyActivity : BaseActivity<ProxyDesign>() {
val mode = withClash { queryOverride(Clash.OverrideSlot.Session).mode }
val names = withClash { queryProxyGroupNames(uiStore.proxyExcludeNotSelectable) }
val states = List(names.size) { ProxyState("?") }
val unorderedStates = names.indices.map { names[it] to states[it] }.toMap()
val unorderedStates = names.indices.associate { names[it] to states[it] }
val reloadLock = Semaphore(10)

val design = ProxyDesign(this, mode, names, uiStore)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SettingsActivity : BaseActivity<SettingsDesign>() {
setContentDesign(design)

while (isActive) {
select<Unit> {
select {
events.onReceive {}

design.requests.onReceive {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/github/kr328/clash/TileService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class TileService : TileService() {

tile.state = if (clashRunning) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE

tile.label = if (currentProfile.isEmpty()) getText(R.string.launch_name) else currentProfile
tile.label = currentProfile.ifEmpty { getText(R.string.launch_name) }

tile.icon =
Icon.createWithResource(this, com.github.kr328.clash.service.R.drawable.ic_logo_service)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class LogcatReader(context: Context, file: LogFile) : AutoCloseable {
.filter { !it.startsWith("#") }
.map { it.split(":", limit = 3) }
.map {
val time = it[0].toLongOrNull()?.let { Date(it) } ?: lastTime
val time = it[0].toLongOrNull()?.let { date -> Date(date) } ?: lastTime
val logMessage =
if (it[0].toLongOrNull() != null) {
LogMessage(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
@file:Suppress("BlockingMethodInNonBlockingContext")

package com.github.kr328.clash.remote

import android.content.Context
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/java/com/github/kr328/clash/remote/Remote.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.github.kr328.clash.store.AppStore
import com.github.kr328.clash.util.ApplicationObserver
import com.github.kr328.clash.util.verifyApk
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch

object Remote {
Expand All @@ -25,8 +24,6 @@ object Remote {
Global.application.startActivity(intent)
}

private val visible = Channel<Boolean>(Channel.CONFLATED)

fun launch() {
ApplicationObserver.attach(Global.application)

Expand All @@ -45,7 +42,7 @@ object Remote {
Global.launch(Dispatchers.IO) { verifyApp() }
}

private suspend fun verifyApp() {
private fun verifyApp() {
val context = Global.application
val store = AppStore(context)
val updatedAt = getLastUpdated(context)
Expand Down
20 changes: 0 additions & 20 deletions app/src/main/java/com/github/kr328/clash/store/TipsStore.kt

This file was deleted.

Loading