refactor: streamline deep link handling and improve sqlite worker initialization
- Simplified `DeepLinkHandler` logic by removing redundant return values and enhancing route parsing with `ifBlank()`. - Refactored `sqlite.worker.js` for better modularity and error handling. - Added helper methods for script imports and initialization error management. Signed-off-by: Stefan Mogeritsch <stefan.mo.co@gmail.com>
This commit is contained in:
+6
-9
@@ -22,10 +22,11 @@ class DeepLinkHandler(
|
||||
|
||||
fun handleDeepLink(url: String): Boolean {
|
||||
val parsed = parseDeepLink(url) ?: return false
|
||||
return processDeepLink(parsed)
|
||||
processDeepLink(parsed)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun processDeepLink(deepLink: DeepLink): Boolean {
|
||||
private fun processDeepLink(deepLink: DeepLink) {
|
||||
val route = cleanRoute(deepLink.route)
|
||||
|
||||
// If the route requires auth and the user is missing → redirect to log in
|
||||
@@ -33,20 +34,19 @@ class DeepLinkHandler(
|
||||
val user = currentUserProvider.getCurrentUser()
|
||||
if (user == null) {
|
||||
navigation.navigateTo(config.loginRoute)
|
||||
return true
|
||||
return
|
||||
}
|
||||
// Admin section guard: requires ADMIN role
|
||||
if (requiresAdmin(route)) {
|
||||
val isAdmin = user.roles.contains(AppRoles.ADMIN)
|
||||
if (!isAdmin) {
|
||||
navigation.navigateTo(Routes.HOME)
|
||||
return true
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
navigation.navigateTo(deepLink.route)
|
||||
return true
|
||||
}
|
||||
|
||||
private fun parseDeepLink(url: String): DeepLink? {
|
||||
@@ -62,7 +62,7 @@ class DeepLinkHandler(
|
||||
val parts = withoutScheme.split("/")
|
||||
if (parts.isEmpty() || parts[0] != config.host) return null
|
||||
val path = "/" + parts.drop(1).joinToString("/")
|
||||
val route = if (path.isBlank()) Routes.HOME else path
|
||||
val route = path.ifBlank { Routes.HOME }
|
||||
return DeepLink(DeepLinkType.CUSTOM_SCHEME, route, url)
|
||||
}
|
||||
|
||||
@@ -86,7 +86,4 @@ class DeepLinkHandler(
|
||||
}
|
||||
|
||||
private fun requiresAdmin(route: String): Boolean = route.startsWith("${Routes.Admin.ROOT}/")
|
||||
|
||||
fun generateDeepLink(route: String, useCustomScheme: Boolean = true): String =
|
||||
if (useCustomScheme) "${config.scheme}://${config.host}$route" else "https://${config.allowedDomains.first()}$route"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user