feat: add PWA 1-click install, Apple iOS Add-to-Home-Screen guide modal, manifest, and service worker

This commit is contained in:
2026-10-23 00:23:16 +06:00
parent e8ee5e8ac2
commit 5a79667bf7
11 changed files with 412 additions and 4 deletions
+43 -3
View File
@@ -1,9 +1,27 @@
import "./globals.css";
import type { Metadata } from "next";
import type { Metadata, Viewport } from "next";
export const viewport: Viewport = {
themeColor: "#030712",
width: "device-width",
initialScale: 1,
maximumScale: 1,
userScalable: false,
};
export const metadata: Metadata = {
title: "AuraTrade // Institutional Quant Terminal",
description: "High-Frequency Trading Terminal & Sentinel Risk Firewall for Exness MT5",
description: "High-Frequency Quantitative Trading Terminal & Sentinel Risk Firewall for Exness MT5",
manifest: "/manifest.json",
appleWebApp: {
capable: true,
statusBarStyle: "black-translucent",
title: "AuraTrade",
},
icons: {
icon: "/icons/icon-192x192.png",
apple: "/icons/apple-touch-icon.png",
},
};
export default function RootLayout({
@@ -13,8 +31,30 @@ export default function RootLayout({
}) {
return (
<html lang="en" className="dark">
<body className="bg-darkBg text-gray-100 min-h-screen antialiased">
<head>
<link rel="manifest" href="/manifest.json" />
<link rel="apple-touch-icon" href="/icons/apple-touch-icon.png" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="apple-mobile-web-app-title" content="AuraTrade" />
<meta name="mobile-web-app-capable" content="yes" />
</head>
<body className="bg-darkBg text-gray-100 min-h-screen antialiased selection:bg-cyan-500/20">
{children}
<script
dangerouslySetInnerHTML={{
__html: `
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/sw.js').then(
function(reg) { console.log('AuraTrade PWA ServiceWorker registered'); },
function(err) { console.log('AuraTrade PWA ServiceWorker registration failed: ', err); }
);
});
}
`,
}}
/>
</body>
</html>
);
+97 -1
View File
@@ -12,10 +12,13 @@ import {
Flame,
Clock,
Activity,
Layers
Layers,
Download,
CheckCircle2
} from "lucide-react";
import { LiveTelemetry } from "@/hooks/useExnessWebSocket";
import { soundFX } from "@/lib/soundEffects";
import { InstallAppModal } from "@/components/pwa/InstallAppModal";
interface TitanHeaderProps {
telemetry: LiveTelemetry | null;
@@ -37,6 +40,70 @@ export const TitanHeader: React.FC<TitanHeaderProps> = ({
const [audioEnabled, setAudioEnabled] = useState(true);
const [nowUtc, setNowUtc] = useState<Date>(new Date());
// PWA & iOS State
const [deferredPrompt, setDeferredPrompt] = useState<any>(null);
const [isInstalled, setIsInstalled] = useState(false);
const [isIOS, setIsIOS] = useState(false);
const [showInstallModal, setShowInstallModal] = useState(false);
useEffect(() => {
if (typeof window === "undefined") return;
// Detect iOS
const ua = window.navigator.userAgent.toLowerCase();
const isApple = /iphone|ipad|ipod/.test(ua) || (navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1);
setIsIOS(isApple);
// Detect if already installed as standalone
const isStandalone = window.matchMedia("(display-mode: standalone)").matches || (window.navigator as any).standalone === true;
setIsInstalled(isStandalone);
// Capture beforeinstallprompt for Chrome/Edge/Android
const handleBeforeInstall = (e: Event) => {
e.preventDefault();
setDeferredPrompt(e);
};
window.addEventListener("beforeinstallprompt", handleBeforeInstall);
window.addEventListener("appinstalled", () => {
setIsInstalled(true);
setDeferredPrompt(null);
});
return () => {
window.removeEventListener("beforeinstallprompt", handleBeforeInstall);
};
}, []);
const handleInstallClick = () => {
soundFX.playClick();
if (isIOS) {
setShowInstallModal(true);
} else if (deferredPrompt) {
deferredPrompt.prompt();
deferredPrompt.userChoice.then((choiceResult: any) => {
if (choiceResult.outcome === "accepted") {
setIsInstalled(true);
}
setDeferredPrompt(null);
});
} else {
setShowInstallModal(true);
}
};
const handleNativeInstallTrigger = () => {
if (deferredPrompt) {
deferredPrompt.prompt();
deferredPrompt.userChoice.then((choiceResult: any) => {
if (choiceResult.outcome === "accepted") {
setIsInstalled(true);
}
setDeferredPrompt(null);
});
}
};
useEffect(() => {
const timer = setInterval(() => setNowUtc(new Date()), 1000);
return () => clearInterval(timer);
@@ -174,6 +241,26 @@ export const TitanHeader: React.FC<TitanHeaderProps> = ({
{/* 4. Controls & Emergency Actions */}
<div className="flex items-center gap-2">
{/* PWA / iOS Install Button */}
{isInstalled ? (
<div
title="AuraTrade Running in Native Desktop/Mobile App Mode"
className="hidden sm:flex items-center gap-1 px-2.5 py-1.5 rounded-lg bg-emerald-950/40 border border-emerald-500/30 text-emerald-400 text-[11px] font-bold shadow-sm"
>
<CheckCircle2 className="w-3.5 h-3.5 text-emerald-400 stroke-[2.5]" />
<span className="hidden md:inline">APP ACTIVE</span>
</div>
) : (
<button
onClick={handleInstallClick}
title={isIOS ? "Install AuraTrade on Apple iOS Home Screen" : "1-Click Install AuraTrade Standalone App"}
className="bg-gradient-to-r from-cyan-500/20 to-blue-500/20 hover:from-cyan-500/30 hover:to-blue-500/30 active:scale-95 text-cyan-300 font-bold text-[11px] px-2.5 py-1.5 rounded-lg flex items-center gap-1.5 border border-cyan-500/40 shadow-sm shadow-cyan-500/20 transition group"
>
<Download className="w-3.5 h-3.5 text-cyan-400 stroke-[2.5] group-hover:translate-y-0.5 transition-transform" />
<span>{isIOS ? "APPLE APP" : "INSTALL"}</span>
</button>
)}
{/* Audio FX Toggle */}
<button
onClick={toggleAudio}
@@ -204,6 +291,15 @@ export const TitanHeader: React.FC<TitanHeaderProps> = ({
<Zap className="w-3.5 h-3.5 fill-current" /> KILL ALL
</button>
</div>
{/* PWA & Apple iOS Install Modal */}
<InstallAppModal
isOpen={showInstallModal}
onClose={() => setShowInstallModal(false)}
isIOS={isIOS}
onNativeInstall={handleNativeInstallTrigger}
canNativeInstall={!!deferredPrompt}
/>
</header>
);
};
@@ -0,0 +1,168 @@
"use client";
import React from "react";
import {
X,
Share2,
PlusSquare,
CheckCircle2,
Download,
Smartphone,
Laptop,
Sparkles,
ArrowRight
} from "lucide-react";
interface InstallAppModalProps {
isOpen: boolean;
onClose: () => void;
isIOS: boolean;
onNativeInstall?: () => void;
canNativeInstall: boolean;
}
export const InstallAppModal: React.FC<InstallAppModalProps> = ({
isOpen,
onClose,
isIOS,
onNativeInstall,
canNativeInstall,
}) => {
if (!isOpen) return null;
return (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/80 backdrop-blur-md animate-in fade-in duration-200">
<div
className="relative w-full max-w-md p-6 rounded-2xl bg-[#081224] border border-cyan-500/30 shadow-2xl shadow-cyan-950/50 text-gray-100 overflow-hidden"
onClick={(e) => e.stopPropagation()}
>
{/* Luminous Top Accent Glow */}
<div className="absolute top-0 left-0 right-0 h-1 bg-gradient-to-r from-cyan-500 via-amber-400 to-emerald-400" />
{/* Close Button */}
<button
onClick={onClose}
className="absolute top-4 right-4 p-1.5 rounded-lg bg-[#0c182e] hover:bg-[#14233d] text-gray-400 hover:text-white transition"
>
<X className="w-4 h-4" />
</button>
{/* Modal Header */}
<div className="flex items-center gap-3 mb-5">
<div className="w-12 h-12 rounded-xl bg-gradient-to-br from-cyan-500/20 to-amber-500/20 border border-cyan-500/40 flex items-center justify-center shadow-lg shadow-cyan-500/10">
<Smartphone className="w-6 h-6 text-cyan-400" />
</div>
<div>
<div className="flex items-center gap-2">
<h3 className="text-base font-black tracking-wide text-white">
INSTALL AURATRADE
</h3>
<span className="text-[10px] font-bold px-1.5 py-0.5 rounded bg-cyan-950/80 border border-cyan-500/40 text-cyan-400">
PWA APP
</span>
</div>
<p className="text-xs text-gray-400 mt-0.5">
{isIOS
? "Apple iPhone / iPad হোম স্ক্রিনে ইনস্টল করুন"
: "পিসি বা মোবাইলে ১-ক্লিকে ইনস্টল করুন"}
</p>
</div>
</div>
{/* Content Mode: iOS vs Desktop/Android */}
{isIOS ? (
/* Apple iOS Visual Instructions */
<div className="space-y-3.5 my-4">
<div className="p-3 rounded-xl bg-[#0c182e] border border-[#182b4a] flex items-start gap-3">
<div className="w-7 h-7 rounded-lg bg-cyan-950/60 border border-cyan-500/30 flex items-center justify-center shrink-0 mt-0.5">
<span className="text-xs font-black text-cyan-400">১</span>
</div>
<div className="text-xs">
<p className="text-gray-200 font-semibold flex items-center gap-1.5">
Safari-এর নিচে <Share2 className="w-3.5 h-3.5 text-cyan-400" /> <strong>Share</strong> বাটনে চাপ দিন
</p>
<p className="text-gray-400 text-[11px] mt-0.5">
আইফোনের সাফারি ব্রাউজারের নিচে শেয়ার আইকনে ট্যাপ করুন।
</p>
</div>
</div>
<div className="p-3 rounded-xl bg-[#0c182e] border border-[#182b4a] flex items-start gap-3">
<div className="w-7 h-7 rounded-lg bg-cyan-950/60 border border-cyan-500/30 flex items-center justify-center shrink-0 mt-0.5">
<span className="text-xs font-black text-cyan-400">২</span>
</div>
<div className="text-xs">
<p className="text-gray-200 font-semibold flex items-center gap-1.5">
স্ক্রোল করে <PlusSquare className="w-3.5 h-3.5 text-amber-400" /> <strong>Add to Home Screen</strong> চাপুন
</p>
<p className="text-gray-400 text-[11px] mt-0.5">
মেনুটি একটু নিচে স্ক্রোল করে এই অপশনটি নির্বাচন করুন।
</p>
</div>
</div>
<div className="p-3 rounded-xl bg-[#0c182e] border border-[#182b4a] flex items-start gap-3">
<div className="w-7 h-7 rounded-lg bg-cyan-950/60 border border-cyan-500/30 flex items-center justify-center shrink-0 mt-0.5">
<span className="text-xs font-black text-cyan-400">৩</span>
</div>
<div className="text-xs">
<p className="text-gray-200 font-semibold flex items-center gap-1.5">
উপরে ডানে <CheckCircle2 className="w-3.5 h-3.5 text-emerald-400" /> <strong>Add</strong> বাটনে ট্যাপ করুন
</p>
<p className="text-gray-400 text-[11px] mt-0.5">
অ্যাপল ডিভাইসের হোম স্ক্রিনে AuraTrade অ্যাপ আইকন তৈরি হয়ে যাবে।
</p>
</div>
</div>
</div>
) : (
/* Desktop / Android Direct Native 1-Click Trigger */
<div className="space-y-4 my-4">
<div className="p-4 rounded-xl bg-gradient-to-br from-[#0c182e] to-[#081224] border border-cyan-500/30 text-xs">
<div className="flex items-center gap-2 text-cyan-300 font-bold mb-1">
<Sparkles className="w-4 h-4 text-cyan-400" />
<span>নেটিভ উইন্ডো ও ইনস্ট্যান্ট স্পিড</span>
</div>
<p className="text-gray-300 leading-relaxed text-[11px]">
ব্রাউজারের কোনো অ্যাড্রেস বার বা ট্যাব ছাড়াই আলাদা সফটওয়্যারের মতো ফুলস্ক্রিনে চলবে। এক্সনেস লাইভ টিক ও চার্ট ০% ল্যাগিংয়ে লোড হবে।
</p>
</div>
{canNativeInstall ? (
<button
onClick={() => {
if (onNativeInstall) onNativeInstall();
onClose();
}}
className="w-full py-3 px-4 rounded-xl bg-gradient-to-r from-cyan-500 to-blue-600 hover:from-cyan-400 hover:to-blue-500 active:scale-98 text-black font-black text-sm tracking-wider uppercase flex items-center justify-center gap-2 shadow-lg shadow-cyan-500/25 transition"
>
<Download className="w-4 h-4 text-black stroke-[2.5]" />
এখনই ইনস্টল করুন (1-Click Install)
</button>
) : (
<div className="p-3 rounded-xl bg-[#0c182e] border border-[#14233d] text-center text-xs text-gray-300">
<p className="font-semibold text-amber-400">ব্রাউজার মেনু থেকে ইনস্টল করুন:</p>
<p className="text-gray-400 text-[11px] mt-1">
ব্রাউজারের অ্যাড্রেস বারের ডানপাশে থাকা <Download className="w-3.5 h-3.5 inline mx-1 text-cyan-400" /> <strong>ইনস্টল আইকন</strong> অথবা ব্রাউজার সেটিংস মেনু থেকে &apos;Install AuraTrade&apos; নির্বাচন করুন।
</p>
</div>
)}
</div>
)}
{/* Benefits Footer */}
<div className="pt-3 border-t border-[#14233d] flex items-center justify-between text-[11px] text-gray-400">
<span className="flex items-center gap-1 text-emerald-400">
<CheckCircle2 className="w-3.5 h-3.5" /> অফলাইন ও ব্যাকগ্রাউন্ড সিঙ্ক
</span>
<button
onClick={onClose}
className="text-gray-400 hover:text-white transition font-medium"
>
বুঝেছি (Close)
</button>
</div>
</div>
</div>
);
};