Skip to content
Snippets Groups Projects
Commit 27dc5395 authored by Kr328's avatar Kr328
Browse files

Improve: migrate to latest dependencies

parent 4f05ba1a
No related branches found
No related tags found
No related merge requests found
Showing
with 62 additions and 52 deletions
...@@ -114,7 +114,7 @@ abstract class BaseActivity<D : Design<*>> : ...@@ -114,7 +114,7 @@ abstract class BaseActivity<D : Design<*>> :
Remote.broadcasts.addObserver(this) Remote.broadcasts.addObserver(this)
events.offer(Event.ActivityStart) events.trySend(Event.ActivityStart)
} }
override fun onStop() { override fun onStop() {
...@@ -124,7 +124,7 @@ abstract class BaseActivity<D : Design<*>> : ...@@ -124,7 +124,7 @@ abstract class BaseActivity<D : Design<*>> :
Remote.broadcasts.removeObserver(this) Remote.broadcasts.removeObserver(this)
events.offer(Event.ActivityStop) events.trySend(Event.ActivityStop)
} }
override fun onDestroy() { override fun onDestroy() {
...@@ -174,23 +174,23 @@ abstract class BaseActivity<D : Design<*>> : ...@@ -174,23 +174,23 @@ abstract class BaseActivity<D : Design<*>> :
} }
override fun onProfileChanged() { override fun onProfileChanged() {
events.offer(Event.ProfileChanged) events.trySend(Event.ProfileChanged)
} }
override fun onProfileLoaded() { override fun onProfileLoaded() {
events.offer(Event.ProfileLoaded) events.trySend(Event.ProfileLoaded)
} }
override fun onServiceRecreated() { override fun onServiceRecreated() {
events.offer(Event.ServiceRecreated) events.trySend(Event.ServiceRecreated)
} }
override fun onStarted() { override fun onStarted() {
events.offer(Event.ClashStart) events.trySend(Event.ClashStart)
} }
override fun onStopped(cause: String?) { override fun onStopped(cause: String?) {
events.offer(Event.ClashStop) events.trySend(Event.ClashStop)
if (cause != null && activityStarted) { if (cause != null && activityStarted) {
launch { launch {
......
...@@ -141,7 +141,7 @@ class FilesActivity : BaseActivity<FilesDesign>() { ...@@ -141,7 +141,7 @@ class FilesActivity : BaseActivity<FilesDesign>() {
} }
override fun onBackPressed() { override fun onBackPressed() {
design?.requests?.offer(FilesDesign.Request.PopStack) design?.requests?.trySend(FilesDesign.Request.PopStack)
} }
private suspend fun FilesDesign.fetch(client: FilesClient, stack: Stack<String>, root: String) { private suspend fun FilesDesign.fetch(client: FilesClient, stack: Stack<String>, root: String) {
......
...@@ -97,7 +97,7 @@ class LogcatService : Service(), CoroutineScope by CoroutineScope(Dispatchers.De ...@@ -97,7 +97,7 @@ class LogcatService : Service(), CoroutineScope by CoroutineScope(Dispatchers.De
LogcatWriter(this@LogcatService).use { LogcatWriter(this@LogcatService).use {
val observer = object : ILogObserver { val observer = object : ILogObserver {
override fun newItem(log: LogMessage) { override fun newItem(log: LogMessage) {
channel.offer(log) channel.trySend(log)
} }
} }
......
...@@ -47,7 +47,7 @@ class LogsActivity : BaseActivity<LogsDesign>() { ...@@ -47,7 +47,7 @@ class LogsActivity : BaseActivity<LogsDesign>() {
deleteAllLogs() deleteAllLogs()
} }
events.offer(Event.ActivityStart) events.trySend(Event.ActivityStart)
} }
} }
is LogsDesign.Request.OpenFile -> { is LogsDesign.Request.OpenFile -> {
......
...@@ -32,4 +32,8 @@ class MainApplication : Application() { ...@@ -32,4 +32,8 @@ class MainApplication : Application() {
sendServiceRecreated() sendServiceRecreated()
} }
} }
fun finalize() {
Global.destroy()
}
} }
\ No newline at end of file
...@@ -73,7 +73,7 @@ class ProxyActivity : BaseActivity<ProxyDesign>() { ...@@ -73,7 +73,7 @@ class ProxyActivity : BaseActivity<ProxyDesign>() {
} }
ProxyDesign.Request.ReloadAll -> { ProxyDesign.Request.ReloadAll -> {
names.indices.forEach { idx -> names.indices.forEach { idx ->
design.requests.offer(ProxyDesign.Request.Reload(idx)) design.requests.trySend(ProxyDesign.Request.Reload(idx))
} }
} }
is ProxyDesign.Request.Reload -> { is ProxyDesign.Request.Reload -> {
......
...@@ -10,7 +10,6 @@ import com.github.kr328.clash.store.AppStore ...@@ -10,7 +10,6 @@ import com.github.kr328.clash.store.AppStore
import com.github.kr328.clash.util.ApplicationObserver import com.github.kr328.clash.util.ApplicationObserver
import com.github.kr328.clash.util.verifyApk import com.github.kr328.clash.util.verifyApk
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
...@@ -30,9 +29,9 @@ object Remote { ...@@ -30,9 +29,9 @@ object Remote {
fun launch() { fun launch() {
ApplicationObserver.attach(Global.application) ApplicationObserver.attach(Global.application)
ApplicationObserver.onVisibleChanged(visible::offer) ApplicationObserver.onVisibleChanged { visible.trySend(it) }
GlobalScope.launch(Dispatchers.IO) { Global.launch(Dispatchers.IO) {
run() run()
} }
} }
......
package com.github.kr328.clash.common package com.github.kr328.clash.common
import android.app.Application import android.app.Application
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
object Global { object Global : CoroutineScope by CoroutineScope(Dispatchers.IO) {
val application: Application val application: Application
get() = application_ get() = application_
...@@ -11,4 +14,8 @@ object Global { ...@@ -11,4 +14,8 @@ object Global {
fun init(application: Application) { fun init(application: Application) {
this.application_ = application this.application_ = application
} }
fun destroy() {
cancel()
}
} }
\ No newline at end of file
...@@ -218,7 +218,7 @@ object Clash { ...@@ -218,7 +218,7 @@ object Clash {
return Channel<LogMessage>(32).apply { return Channel<LogMessage>(32).apply {
Bridge.nativeSubscribeLogcat(object : LogcatInterface { Bridge.nativeSubscribeLogcat(object : LogcatInterface {
override fun received(jsonPayload: String) { override fun received(jsonPayload: String) {
offer(Json.decodeFromString(LogMessage.serializer(), jsonPayload)) trySend(Json.decodeFromString(LogMessage.serializer(), jsonPayload))
} }
}) })
} }
......
...@@ -236,7 +236,7 @@ class OverrideSettingsDesign( ...@@ -236,7 +236,7 @@ class OverrideSettingsDesign(
summary = R.string.sideload_geoip_summary summary = R.string.sideload_geoip_summary
) { ) {
clicked { clicked {
requests.offer(Request.EditSideloadGeoip) requests.trySend(Request.EditSideloadGeoip)
} }
} }
...@@ -394,6 +394,6 @@ class OverrideSettingsDesign( ...@@ -394,6 +394,6 @@ class OverrideSettingsDesign(
} }
fun requestClear() { fun requestClear() {
requests.offer(Request.ResetOverride) requests.trySend(Request.ResetOverride)
} }
} }
\ No newline at end of file
...@@ -32,48 +32,48 @@ class ProxyMenu( ...@@ -32,48 +32,48 @@ class ProxyMenu(
R.id.not_selectable -> { R.id.not_selectable -> {
uiStore.proxyExcludeNotSelectable = item.isChecked uiStore.proxyExcludeNotSelectable = item.isChecked
requests.offer(ProxyDesign.Request.ReLaunch) requests.trySend(ProxyDesign.Request.ReLaunch)
} }
R.id.single -> { R.id.single -> {
uiStore.proxySingleLine = true uiStore.proxySingleLine = true
updateConfig() updateConfig()
requests.offer(ProxyDesign.Request.ReloadAll) requests.trySend(ProxyDesign.Request.ReloadAll)
} }
R.id.multiple -> { R.id.multiple -> {
uiStore.proxySingleLine = false uiStore.proxySingleLine = false
updateConfig() updateConfig()
requests.offer(ProxyDesign.Request.ReloadAll) requests.trySend(ProxyDesign.Request.ReloadAll)
} }
R.id.default_ -> { R.id.default_ -> {
uiStore.proxySort = ProxySort.Default uiStore.proxySort = ProxySort.Default
requests.offer(ProxyDesign.Request.ReloadAll) requests.trySend(ProxyDesign.Request.ReloadAll)
} }
R.id.name -> { R.id.name -> {
uiStore.proxySort = ProxySort.Title uiStore.proxySort = ProxySort.Title
requests.offer(ProxyDesign.Request.ReloadAll) requests.trySend(ProxyDesign.Request.ReloadAll)
} }
R.id.delay -> { R.id.delay -> {
uiStore.proxySort = ProxySort.Delay uiStore.proxySort = ProxySort.Delay
requests.offer(ProxyDesign.Request.ReloadAll) requests.trySend(ProxyDesign.Request.ReloadAll)
} }
R.id.dont_modify -> { R.id.dont_modify -> {
requests.offer(ProxyDesign.Request.PatchMode(null)) requests.trySend(ProxyDesign.Request.PatchMode(null))
} }
R.id.direct_mode -> { R.id.direct_mode -> {
requests.offer(ProxyDesign.Request.PatchMode(TunnelState.Mode.Direct)) requests.trySend(ProxyDesign.Request.PatchMode(TunnelState.Mode.Direct))
} }
R.id.global_mode -> { R.id.global_mode -> {
requests.offer(ProxyDesign.Request.PatchMode(TunnelState.Mode.Global)) requests.trySend(ProxyDesign.Request.PatchMode(TunnelState.Mode.Global))
} }
R.id.rule_mode -> { R.id.rule_mode -> {
requests.offer(ProxyDesign.Request.PatchMode(TunnelState.Mode.Rule)) requests.trySend(ProxyDesign.Request.PatchMode(TunnelState.Mode.Rule))
} }
else -> return false else -> return false
} }
......
...@@ -93,7 +93,7 @@ class AccessControlDesign( ...@@ -93,7 +93,7 @@ class AccessControlDesign(
binding.surface = dialog.surface binding.surface = dialog.surface
binding.mainList.applyLinearAdapter(context, adapter) binding.mainList.applyLinearAdapter(context, adapter)
binding.keywordView.addTextChangedListener { binding.keywordView.addTextChangedListener {
filter.offer(Unit) filter.trySend(Unit)
} }
binding.closeView.setOnClickListener { binding.closeView.setOnClickListener {
dialog.dismiss() dialog.dismiss()
......
...@@ -38,7 +38,7 @@ class ApkBrokenDesign(context: Context) : Design<ApkBrokenDesign.Request>(contex ...@@ -38,7 +38,7 @@ class ApkBrokenDesign(context: Context) : Design<ApkBrokenDesign.Request>(contex
summary = R.string.google_play_url summary = R.string.google_play_url
) { ) {
clicked { clicked {
requests.offer(Request(context.getString(R.string.google_play_url))) requests.trySend(Request(context.getString(R.string.google_play_url)))
} }
} }
...@@ -47,7 +47,7 @@ class ApkBrokenDesign(context: Context) : Design<ApkBrokenDesign.Request>(contex ...@@ -47,7 +47,7 @@ class ApkBrokenDesign(context: Context) : Design<ApkBrokenDesign.Request>(contex
summary = R.string.github_releases_url summary = R.string.github_releases_url
) { ) {
clicked { clicked {
requests.offer(Request(context.getString(R.string.github_releases_url))) requests.trySend(Request(context.getString(R.string.github_releases_url)))
} }
} }
} }
......
...@@ -61,7 +61,7 @@ class AppSettingsDesign( ...@@ -61,7 +61,7 @@ class AppSettingsDesign(
title = R.string.dark_mode title = R.string.dark_mode
) { ) {
listener = OnChangedListener { listener = OnChangedListener {
requests.offer(Request.ReCreateAllActivities) requests.trySend(Request.ReCreateAllActivities)
} }
} }
......
...@@ -72,38 +72,38 @@ class FilesDesign(context: Context) : Design<FilesDesign.Request>(context) { ...@@ -72,38 +72,38 @@ class FilesDesign(context: Context) : Design<FilesDesign.Request>(context) {
private fun requestOpen(file: File) { private fun requestOpen(file: File) {
if (file.isDirectory) { if (file.isDirectory) {
requests.offer(Request.OpenDirectory(file)) requests.trySend(Request.OpenDirectory(file))
} else { } else {
requests.offer(Request.OpenFile(file)) requests.trySend(Request.OpenFile(file))
} }
} }
fun requestRename(dialog: Dialog, file: File) { fun requestRename(dialog: Dialog, file: File) {
requests.offer(Request.RenameFile(file)) requests.trySend(Request.RenameFile(file))
dialog.dismiss() dialog.dismiss()
} }
fun requestImport(dialog: Dialog, file: File) { fun requestImport(dialog: Dialog, file: File) {
requests.offer(Request.ImportFile(file)) requests.trySend(Request.ImportFile(file))
dialog.dismiss() dialog.dismiss()
} }
fun requestExport(dialog: Dialog, file: File) { fun requestExport(dialog: Dialog, file: File) {
requests.offer(Request.ExportFile(file)) requests.trySend(Request.ExportFile(file))
dialog.dismiss() dialog.dismiss()
} }
fun requestDelete(dialog: Dialog, file: File) { fun requestDelete(dialog: Dialog, file: File) {
requests.offer(Request.DeleteFile(file)) requests.trySend(Request.DeleteFile(file))
dialog.dismiss() dialog.dismiss()
} }
fun requestNew() { fun requestNew() {
requests.offer(Request.ImportFile(null)) requests.trySend(Request.ImportFile(null))
} }
private fun requestMore(file: File) { private fun requestMore(file: File) {
......
...@@ -23,7 +23,7 @@ class LogsDesign(context: Context) : Design<LogsDesign.Request>(context) { ...@@ -23,7 +23,7 @@ class LogsDesign(context: Context) : Design<LogsDesign.Request>(context) {
private val binding = DesignLogsBinding private val binding = DesignLogsBinding
.inflate(context.layoutInflater, context.root, false) .inflate(context.layoutInflater, context.root, false)
private val adapter = LogFileAdapter(context) { private val adapter = LogFileAdapter(context) {
requests.offer(Request.OpenFile(it)) requests.trySend(Request.OpenFile(it))
} }
override val root: View override val root: View
......
...@@ -97,6 +97,6 @@ class MainDesign(context: Context) : Design<MainDesign.Request>(context) { ...@@ -97,6 +97,6 @@ class MainDesign(context: Context) : Design<MainDesign.Request>(context) {
} }
fun request(request: Request) { fun request(request: Request) {
requests.offer(request) requests.trySend(request)
} }
} }
\ No newline at end of file
...@@ -96,7 +96,7 @@ class NetworkSettingsDesign( ...@@ -96,7 +96,7 @@ class NetworkSettingsDesign(
summary = R.string.access_control_packages_summary, summary = R.string.access_control_packages_summary,
) { ) {
clicked { clicked {
requests.offer(Request.StartAccessControlList) requests.trySend(Request.StartAccessControlList)
} }
vpnDependencies.add(this) vpnDependencies.add(this)
......
...@@ -38,13 +38,13 @@ class NewProfileDesign(context: Context) : Design<NewProfileDesign.Request>(cont ...@@ -38,13 +38,13 @@ class NewProfileDesign(context: Context) : Design<NewProfileDesign.Request>(cont
} }
private fun requestCreate(provider: ProfileProvider) { private fun requestCreate(provider: ProfileProvider) {
requests.offer(Request.Create(provider)) requests.trySend(Request.Create(provider))
} }
private fun requestDetail(provider: ProfileProvider): Boolean { private fun requestDetail(provider: ProfileProvider): Boolean {
if (provider !is ProfileProvider.External) return false if (provider !is ProfileProvider.External) return false
requests.offer(Request.OpenDetail(provider)) requests.trySend(Request.OpenDetail(provider))
return true return true
} }
......
...@@ -49,7 +49,7 @@ class ProfilesDesign(context: Context) : Design<ProfilesDesign.Request>(context) ...@@ -49,7 +49,7 @@ class ProfilesDesign(context: Context) : Design<ProfilesDesign.Request>(context)
suspend fun requestSave(profile: Profile) { suspend fun requestSave(profile: Profile) {
showToast(R.string.active_unsaved_tips, ToastDuration.Long) { showToast(R.string.active_unsaved_tips, ToastDuration.Long) {
setAction(R.string.edit) { setAction(R.string.edit) {
requests.offer(Request.Edit(profile)) requests.trySend(Request.Edit(profile))
} }
} }
} }
...@@ -84,37 +84,37 @@ class ProfilesDesign(context: Context) : Design<ProfilesDesign.Request>(context) ...@@ -84,37 +84,37 @@ class ProfilesDesign(context: Context) : Design<ProfilesDesign.Request>(context)
} }
fun requestUpdateAll() { fun requestUpdateAll() {
requests.offer(Request.UpdateAll) requests.trySend(Request.UpdateAll)
} }
fun requestCreate() { fun requestCreate() {
requests.offer(Request.Create) requests.trySend(Request.Create)
} }
private fun requestActive(profile: Profile) { private fun requestActive(profile: Profile) {
requests.offer(Request.Active(profile)) requests.trySend(Request.Active(profile))
} }
fun requestUpdate(dialog: Dialog, profile: Profile) { fun requestUpdate(dialog: Dialog, profile: Profile) {
requests.offer(Request.Update(profile)) requests.trySend(Request.Update(profile))
dialog.dismiss() dialog.dismiss()
} }
fun requestEdit(dialog: Dialog, profile: Profile) { fun requestEdit(dialog: Dialog, profile: Profile) {
requests.offer(Request.Edit(profile)) requests.trySend(Request.Edit(profile))
dialog.dismiss() dialog.dismiss()
} }
fun requestDuplicate(dialog: Dialog, profile: Profile) { fun requestDuplicate(dialog: Dialog, profile: Profile) {
requests.offer(Request.Duplicate(profile)) requests.trySend(Request.Duplicate(profile))
dialog.dismiss() dialog.dismiss()
} }
fun requestDelete(dialog: Dialog, profile: Profile) { fun requestDelete(dialog: Dialog, profile: Profile) {
requests.offer(Request.Delete(profile)) requests.trySend(Request.Delete(profile))
dialog.dismiss() dialog.dismiss()
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment