mirror of
https://github.com/readest/readest.git
synced 2026-04-29 12:00:49 +00:00
parent
7ccf3d0632
commit
6131180a31
18 changed files with 161 additions and 46 deletions
|
|
@ -3,7 +3,4 @@ package com.readest.native_bridge
|
|||
import android.util.Log
|
||||
|
||||
class NativeBridge {
|
||||
fun auth_with_safari(value: String): String {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
package com.readest.native_bridge
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.util.Log
|
||||
import androidx.browser.customtabs.CustomTabsIntent
|
||||
import app.tauri.annotation.Command
|
||||
import app.tauri.annotation.InvokeArg
|
||||
import app.tauri.annotation.TauriPlugin
|
||||
|
|
@ -11,7 +14,7 @@ import app.tauri.plugin.Invoke
|
|||
import java.io.*
|
||||
|
||||
@InvokeArg
|
||||
class SafariAuthRequestArgs {
|
||||
class AuthRequestArgs {
|
||||
var authUrl: String? = null
|
||||
}
|
||||
|
||||
|
|
@ -24,14 +27,25 @@ class CopyURIRequestArgs {
|
|||
@TauriPlugin
|
||||
class NativeBridgePlugin(private val activity: Activity): Plugin(activity) {
|
||||
private val implementation = NativeBridge()
|
||||
private var redirectScheme = "readest"
|
||||
private var redirectHost = "auth-callback"
|
||||
|
||||
companion object {
|
||||
var pendingInvoke: Invoke? = null
|
||||
}
|
||||
|
||||
@Command
|
||||
fun auth_with_safari(invoke: Invoke) {
|
||||
val args = invoke.parseArgs(SafariAuthRequestArgs::class.java)
|
||||
fun auth_with_custom_tab(invoke: Invoke) {
|
||||
val args = invoke.parseArgs(AuthRequestArgs::class.java)
|
||||
val uri = Uri.parse(args.authUrl)
|
||||
|
||||
val ret = JSObject()
|
||||
ret.put("redirectUrl", implementation.auth_with_safari(args.authUrl ?: ""))
|
||||
invoke.resolve(ret)
|
||||
val customTabsIntent = CustomTabsIntent.Builder().build()
|
||||
customTabsIntent.intent.flags = Intent.FLAG_ACTIVITY_NO_HISTORY
|
||||
|
||||
Log.d("NativeBridgePlugin", "Launching OAuth URL: ${args.authUrl}")
|
||||
customTabsIntent.launchUrl(activity, uri)
|
||||
|
||||
pendingInvoke = invoke
|
||||
}
|
||||
|
||||
@Command
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue