Skip to content

Commit

Permalink
Wait to hide splashscreen until javascript loads
Browse files Browse the repository at this point in the history
  • Loading branch information
MarmadileManteater committed Feb 28, 2024
1 parent 53ad4cb commit a06c828
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,14 @@ class FreeTubeJavaScriptInterface {
return promise
}

/**
* notifies the context that the js is loaded && ready
*/
@JavascriptInterface
fun notifyReady() {
context.isReady = true
}

/**
* @return the id of a promise on the window
*/
Expand Down
20 changes: 20 additions & 0 deletions android/app/src/main/java/io/freetubeapp/freetube/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import android.content.Intent
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver
import android.webkit.WebChromeClient
import android.webkit.WebResourceRequest
import android.webkit.WebView
Expand Down Expand Up @@ -34,10 +35,29 @@ class MainActivity : AppCompatActivity(), OnRequestPermissionsResultCallback {
lateinit var webView: BackgroundPlayWebView
lateinit var jsInterface: FreeTubeJavaScriptInterface
lateinit var activityResultLauncher: ActivityResultLauncher<Intent>
var isReady: Boolean = false
@Suppress("DEPRECATION")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val content: View = findViewById(android.R.id.content)
content.viewTreeObserver.addOnPreDrawListener(
object : ViewTreeObserver.OnPreDrawListener {
override fun onPreDraw(): Boolean {
// Check whether the initial data is ready.
return if (isReady) {
// The content is ready. Start drawing.
content.viewTreeObserver.removeOnPreDrawListener(this)
true
} else {
// The content isn't ready. Suspend.
false
}
}
}
)


activityResultListeners = mutableListOf()

activityResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { IpcChannels } from '../constants'
import packageDetails from '../../package.json'
import { openExternalLink, openInternalPath, showToast } from './helpers/utils'
import 'core-js'
import android from 'android'

let ipcRenderer = null

Expand Down Expand Up @@ -193,6 +194,8 @@ export default defineComponent({
const uri = decodeURIComponent(intent)
this.handleYoutubeLink(uri)
}
// hides the splash screen
android.notifyReady()
}

this.dataReady = true
Expand Down

0 comments on commit a06c828

Please sign in to comment.