Skip to content

Commit 7857376

Browse files
authored
Merge pull request #8 from OpacityLabs/hrvdm/window-close
Add location event when single page app changes location.
2 parents cbe58d5 + 03413db commit 7857376

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

OpacityCore/src/main/assets/extension/background.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ browser.webNavigation.onDOMContentLoaded.addListener(function (details) {
7070
});
7171
});
7272
}
73-
});
73+
});

OpacityCore/src/main/kotlin/com/opacitylabs/opacitycore/InAppBrowserActivity.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ class InAppBrowserActivity : AppCompatActivity() {
180180
hasUserGesture: Boolean
181181
) {
182182
if (url != null) {
183-
currentUrl = url
184183
addToVisitedUrls(url)
184+
emitLocationEvent(url)
185185
}
186186
}
187187
}
@@ -195,6 +195,16 @@ class InAppBrowserActivity : AppCompatActivity() {
195195
}
196196
}
197197

198+
private fun emitLocationEvent(url: String) {
199+
val event: Map<String, Any?> =
200+
mapOf(
201+
"event" to "location_changed",
202+
"url" to url,
203+
"id" to System.currentTimeMillis().toString()
204+
)
205+
OpacityCore.emitWebviewEvent(JSONObject(event).toString())
206+
}
207+
198208
private fun emitNavigationEvent() {
199209
val domain = java.net.URL(currentUrl).host
200210
val event: Map<String, Any?> =

app/src/main/java/com/opacitylabs/opacitycoreexample/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,4 @@ class MainActivity : ComponentActivity() {
129129
OpacityCore.setContext(this)
130130
OpacityCore.initialize(opacityApiKey, false, OpacityCore.Environment.PRODUCTION, true)
131131
}
132-
}
132+
}

0 commit comments

Comments
 (0)