Merge branch 'main' of https://github.com/ATLAS-PJK-GM007/ZeaVis-Edu into selly/frontend
This commit is contained in:
+25
-10
@@ -64,23 +64,38 @@ function decodeGoogleIdToken(idToken: string): GoogleIdPayload {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render a page for the Android system browser that redirects back to the
|
* Render a page for the Android system browser that uses Chrome's native
|
||||||
* Tauri app via a custom scheme (zeavisedu://). The app's AndroidManifest
|
* `intent://` protocol to open the Tauri app with the session URL.
|
||||||
* must register an intent filter for this scheme.
|
* Falls back to a clickable button if the intent is blocked.
|
||||||
*/
|
*/
|
||||||
function renderTauriDeepLinkPage(targetUrl: string): Response {
|
function renderTauriDeepLinkPage(targetUrl: string): Response {
|
||||||
// Rewrite https://... to zeavisedu://... for the custom scheme
|
// Extract the path + query from the full URL for the intent
|
||||||
const deepLink = targetUrl.replace(/^https?:\/\//, 'zeavisedu://');
|
let pathAndQuery = '/login';
|
||||||
|
try {
|
||||||
|
const u = new URL(targetUrl);
|
||||||
|
pathAndQuery = u.pathname + u.search + u.hash;
|
||||||
|
} catch { /* use default */ }
|
||||||
|
|
||||||
|
const displayUrl = targetUrl.replace(/"/g, '"');
|
||||||
|
const escapedPath = pathAndQuery.replace(/"/g, '"');
|
||||||
|
// intent:// scheme: Chrome on Android opens the target app by package name
|
||||||
|
// browser_fallback_url: shown if the app isn't installed
|
||||||
|
const intentUrl = `intent:${escapedPath}#Intent;scheme=zeavisedu;package=com.zeavis.edu;S.browser_fallback_url=${encodeURIComponent(targetUrl)};end`;
|
||||||
|
|
||||||
const html = `<!DOCTYPE html>
|
const html = `<!DOCTYPE html>
|
||||||
<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
<title>Kembali ke ZeaVis Edu</title></head>
|
<title>Kembali ke ZeaVis Edu</title></head>
|
||||||
<body style="font-family:sans-serif;display:flex;align-items:center;justify-content:center;min-height:100vh;margin:0;background:#f0fdf4">
|
<body style="font-family:sans-serif;display:flex;align-items:center;justify-content:center;min-height:100vh;margin:0;background:#f0fdf4">
|
||||||
<div style="text-align:center;padding:2rem">
|
<div style="text-align:center;padding:2rem;max-width:360px">
|
||||||
<p style="color:#166534;font-size:1.1rem;margin-bottom:1.5rem">Login berhasil!<br>Kembali ke aplikasi...</p>
|
<p style="color:#166534;font-size:1.1rem;margin-bottom:1.5rem">Login Google berhasil!<br>Kembali ke aplikasi...</p>
|
||||||
<a href="${deepLink.replace(/"/g, '"')}" style="display:inline-block;background:#16a34a;color:white;padding:0.75rem 2rem;border-radius:0.5rem;text-decoration:none;font-weight:600;font-size:1rem">Buka ZeaVis Edu</a>
|
<a href="${intentUrl.replace(/"/g, '"')}" id="open-app" style="display:inline-block;background:#16a34a;color:white;padding:0.75rem 2rem;border-radius:0.5rem;text-decoration:none;font-weight:600;font-size:1rem;margin-bottom:1rem">Buka ZeaVis Edu</a>
|
||||||
<p style="color:#6b7280;font-size:0.8rem;margin-top:1rem">Jika tombol tidak berfungsi, salin URL ini:<br><code style="word-break:break-all;font-size:0.75rem">${deepLink.replace(/</g, '<')}</code></p>
|
<p style="color:#6b7280;font-size:0.8rem">Jika tombol di atas tidak berfungsi, salin dan buka URL ini di aplikasi ZeaVis Edu:</p>
|
||||||
|
<code style="display:block;word-break:break-all;font-size:0.7rem;color:#4b5563;background:#e5e7eb;padding:0.5rem;border-radius:0.25rem;margin-top:0.5rem">${displayUrl.replace(/</g, '<').replace(/>/g, '>')}</code>
|
||||||
</div>
|
</div>
|
||||||
<script>window.location.href=${JSON.stringify(deepLink)};</script>
|
<script>
|
||||||
|
// Auto-open the intent
|
||||||
|
window.location.href = ${JSON.stringify(intentUrl)};
|
||||||
|
</script>
|
||||||
</body></html>`;
|
</body></html>`;
|
||||||
return new Response(html, {
|
return new Response(html, {
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -3,6 +3,18 @@ pub fn run() {
|
|||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.plugin(tauri_plugin_opener::init())
|
.plugin(tauri_plugin_opener::init())
|
||||||
.plugin(tauri_plugin_deep_link::init())
|
.plugin(tauri_plugin_deep_link::init())
|
||||||
|
.setup(|app| {
|
||||||
|
// On Android, always load from the live web URL so the APK
|
||||||
|
// never needs to be rebuilt when web changes. The APK is a
|
||||||
|
// thin shell — the web app is always up to date.
|
||||||
|
#[cfg(target_os = "android")]
|
||||||
|
{
|
||||||
|
if let Some(window) = app.get_webview_window("main") {
|
||||||
|
let _ = window.navigate("https://zeavisedu.asepharyana.my.id");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user