@@ -26,6 +26,7 @@ object OpacityCore {
2626 private lateinit var _url : String
2727 private var headers: Bundle = Bundle ()
2828 private lateinit var sRuntime: GeckoRuntime
29+ private var isBrowserActive = false
2930
3031 init {
3132 System .loadLibrary(" OpacityCore" )
@@ -73,40 +74,49 @@ object OpacityCore {
7374 }
7475
7576 fun presentBrowser () {
76- val intent = Intent ()
77- intent.setClassName(
78- appContext.packageName,
79- " com.opacitylabs.opacitycore.InAppBrowserActivity"
80- )
77+ val intent = Intent (appContext, InAppBrowserActivity ::class .java)
8178 intent.putExtra(" url" , _url )
8279 intent.putExtra(" headers" , headers)
8380 appContext.startActivity(intent)
81+ isBrowserActive = true
8482 }
8583
86- fun getBrowserCookiesForCurrentUrl (): String {
84+ fun getBrowserCookiesForCurrentUrl (): String? {
85+ if (! isBrowserActive) {
86+ return null
87+ }
88+
8789 val cookiesIntent = Intent (" com.opacitylabs.opacitycore.GET_COOKIES_FOR_CURRENT_URL" )
8890 val resultReceiver = CookieResultReceiver ()
8991 cookiesIntent.putExtra(" receiver" , resultReceiver)
9092 LocalBroadcastManager .getInstance(appContext).sendBroadcast(cookiesIntent)
9193 val json = resultReceiver.waitForResult(1000 ) // Wait up to 1 second for the result
92- return json.toString()
94+ return json? .toString()
9395 }
9496
95- fun getBrowserCookiesForDomain (domain : String ): String {
97+ fun getBrowserCookiesForDomain (domain : String ): String? {
98+ if (! isBrowserActive) {
99+ return null
100+ }
101+
96102 val cookiesIntent = Intent (" com.opacitylabs.opacitycore.GET_COOKIES_FOR_DOMAIN" )
97103 val resultsReceiver = CookieResultReceiver ()
98104 cookiesIntent.putExtra(" receiver" , resultsReceiver)
99105 cookiesIntent.putExtra(" domain" , domain)
100106 LocalBroadcastManager .getInstance(appContext).sendBroadcast(cookiesIntent)
101107 val json = resultsReceiver.waitForResult(1000 )
102- return json.toString()
108+ return json? .toString()
103109 }
104110
105111 fun closeBrowser () {
106112 val closeIntent = Intent (" com.opacitylabs.opacitycore.CLOSE_BROWSER" )
107113 LocalBroadcastManager .getInstance(appContext).sendBroadcast(closeIntent)
108114 }
109115
116+ fun onBrowserDestroyed () {
117+ isBrowserActive = false
118+ }
119+
110120 private fun parseOpacityError (error : String? ): OpacityError {
111121 if (error == null ) {
112122 return OpacityError (" UnknownError" , " No Message" )
0 commit comments