@@ -3,6 +3,7 @@ package com.klyx.activities
33import android.annotation.SuppressLint
44import android.app.ActivityManager
55import android.content.Intent
6+ import android.net.Uri
67import android.os.Build
78import android.os.Bundle
89import android.view.KeyEvent
@@ -31,11 +32,13 @@ import com.klyx.core.file.openFile
3132import com.klyx.core.file.toKxFile
3233import com.klyx.core.theme.LocalIsDarkMode
3334import com.klyx.filetree.FileTreeViewModel
35+ import com.klyx.project.toWorktree
3436import com.klyx.terminal.SessionBinder
3537import com.klyx.terminal.event.TerminateAllSessionEvent
3638import com.klyx.terminal.service.SessionService
3739import com.klyx.ui.event.TerminalNotificationTapEvent
3840import com.klyx.viewmodel.EditorViewModel
41+ import com.klyx.viewmodel.KlyxViewModel
3942import io.github.vinceglb.filekit.FileKit
4043import io.github.vinceglb.filekit.dialogs.init
4144import kotlinx.coroutines.launch
@@ -48,6 +51,7 @@ class MainActivity : KlyxActivity(), Subscriber<CrashEvent> {
4851
4952 private val editorViewModel by viewModel<EditorViewModel >()
5053 private val fileTreeViewModel by viewModel<FileTreeViewModel >()
54+ private val klyxVm by viewModel<KlyxViewModel >()
5155
5256 @OptIn(UnsafeGlobalAccess ::class )
5357 private val app by lazy { GlobalApp }
@@ -108,9 +112,39 @@ class MainActivity : KlyxActivity(), Subscriber<CrashEvent> {
108112 }
109113
110114 private fun handleIntent (intent : Intent ) {
115+ val uri = intent.data
116+
117+ if (uri != null && uri.scheme == " klyx" ) {
118+ when (uri.host) {
119+ " open" -> {
120+ val path = uri.getQueryParameter(" project" )?.let { Uri .decode(it) }
121+ ? : uri.getQueryParameter(" file" )?.let { Uri .decode(it) }
122+
123+ if (! path.isNullOrEmpty()) {
124+ val file = path.toKxFile()
125+ if (file.exists) {
126+ if (file.isDirectory) {
127+ klyxVm.openProject(file.toWorktree())
128+ } else if (file.isFile) {
129+ editorViewModel.openFile(file)
130+ }
131+ } else {
132+ notifier.error(
133+ title = " Invalid path" ,
134+ message = " ${file.absolutePath} does not exist"
135+ )
136+ }
137+ }
138+ }
139+ }
140+ setIntent(Intent ())
141+ return
142+ }
143+
111144 if (intent.action == Intent .ACTION_VIEW || intent.action == Intent .ACTION_EDIT ) {
112- val uri = intent.data!!
113- editorViewModel.openFile(uri.toKxFile())
145+ if (uri != null ) {
146+ editorViewModel.openFile(uri.toKxFile())
147+ }
114148 setIntent(Intent ())
115149 } else if (intent.action == SessionService .ACTION_NOTIFICATION_TAP ) {
116150 EventBus .INSTANCE .tryPost(TerminalNotificationTapEvent )
@@ -120,6 +154,7 @@ class MainActivity : KlyxActivity(), Subscriber<CrashEvent> {
120154 override fun onNewIntent (intent : Intent ) {
121155 super .onNewIntent(intent)
122156 setIntent(intent)
157+ handleIntent(intent)
123158 }
124159
125160 @SuppressLint(" RestrictedApi" )
@@ -141,20 +176,6 @@ class MainActivity : KlyxActivity(), Subscriber<CrashEvent> {
141176 }
142177 }
143178
144- private fun getSystemSpecs () = buildString {
145- appendLine(" Klyx: ${KlyxBuildConfig .VERSION_NAME } (${KlyxBuildConfig .VERSION_CODE } )" )
146- appendLine(" Android Version: ${Build .VERSION .RELEASE } " )
147- appendLine(" Android SDK: ${Build .VERSION .SDK_INT } " )
148- appendLine(" Architecture: ${Build .SUPPORTED_ABIS .first()} " )
149-
150- val activityManager = getSystemService(ActivityManager ::class .java)
151- val memoryInfo = ActivityManager .MemoryInfo ()
152- activityManager.getMemoryInfo(memoryInfo)
153-
154- appendLine(" Memory: ${memoryInfo.totalMem.humanBytes()} " )
155- append(" CPU Count: ${Runtime .getRuntime().availableProcessors()} " )
156- }
157-
158179 override suspend fun onEvent (event : CrashEvent ) {
159180 val isLogFileSaved = event.logFile != null
160181
0 commit comments