TF-2565: Update iOS store link

This commit is contained in:
HuyNguyen
2024-02-05 09:23:46 +07:00
committed by Dat PHAM HOANG
parent 8a2ccf0822
commit f0ac4ef80a
2 changed files with 125 additions and 122 deletions
+17 -17
View File
@@ -1,26 +1,26 @@
.bottom-sheet { .bottom-sheet {
display: none; display: none;
position: fixed; position: fixed;
bottom: 0; bottom: 0;
left: 0; left: 0;
width: 100%; width: 100%;
background-color: #fff; background-color: #fff;
border-top-left-radius: 20px; border-top-left-radius: 20px;
border-top-right-radius: 20px; border-top-right-radius: 20px;
box-shadow: 0px -3px 10px rgba(0, 0, 0, 0.2); box-shadow: 0px -3px 10px rgba(0, 0, 0, 0.2);
overflow: hidden; overflow: hidden;
} }
.sheet-header { .sheet-header {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
padding: 10px 20px; padding: 10px 20px;
color: #fff; color: #fff;
} }
.sheet-content { .sheet-content {
padding: 20px; padding: 20px;
} }
.open_on_mobile_title { .open_on_mobile_title {
+108 -105
View File
@@ -1,8 +1,9 @@
const androidStore = 'https://play.google.com/store/apps/details?id=com.linagora.android.teammail'; const androidStore = 'https://play.google.com/store/apps/details?id=com.linagora.android.teammail';
const iosStore = 'https://apps.apple.com/vn/app/twake-mail/id1587086189'; const iosStore = 'https://apps.apple.com/app/twake-mail/id1587086189';
const iosPlatform = 'iOS'; const iosPlatform = 'iOS';
const androidPlatform = 'android'; const androidPlatform = 'android';
const otherPlatform = 'other'; const otherPlatform = 'other';
const timeoutDuration = 4000;
var serviceWorkerVersion = null; var serviceWorkerVersion = null;
var scriptLoaded = false; var scriptLoaded = false;
@@ -18,119 +19,121 @@ function loadMainDartJs() {
} }
function fetchServiceWorker() { function fetchServiceWorker() {
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
// Service workers are supported. Use them. // Service workers are supported. Use them.
// Wait for registration to finish before dropping the <script>tag. // Wait for registration to finish before dropping the <script>tag.
// Otherwise, the browser will load the script multiple times, // Otherwise, the browser will load the script multiple times,
// potentially different versions. // potentially different versions.
navigator.serviceWorker.register('firebase-messaging-sw.js').then(serviceWorkerRegistration => { navigator.serviceWorker.register('firebase-messaging-sw.js').then(serviceWorkerRegistration => {
console.info('[TwakeMail] fetchServiceWorker(): Service worker firebase-messaging was registered.'); console.info('[TwakeMail] fetchServiceWorker(): Service worker firebase-messaging was registered.');
}).catch(error => { }).catch(error => {
console.error( console.error(
'[TwakeMail] fetchServiceWorker(): An error occurred while registering the service worker firebase-messaging.' '[TwakeMail] fetchServiceWorker(): An error occurred while registering the service worker firebase-messaging.'
); );
console.error(error); console.error(error);
}); });
var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion; var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
navigator.serviceWorker.register(serviceWorkerUrl) navigator.serviceWorker.register(serviceWorkerUrl)
.then((reg) => { .then((reg) => {
function waitForActivation(serviceWorker) { function waitForActivation(serviceWorker) {
serviceWorker.addEventListener('statechange', () => { serviceWorker.addEventListener('statechange', () => {
if (serviceWorker.state == 'activated') { if (serviceWorker.state == 'activated') {
console.log('[TwakeMail] fetchServiceWorker(): Installed new service worker.'); console.log('[TwakeMail] fetchServiceWorker(): Installed new service worker.');
loadMainDartJs(); loadMainDartJs();
} }
}); });
} }
if (!reg.active && (reg.installing || reg.waiting)) { if (!reg.active && (reg.installing || reg.waiting)) {
// No active web worker and we have installed or are installing // No active web worker and we have installed or are installing
// one for the first time. Simply wait for it to activate. // one for the first time. Simply wait for it to activate.
waitForActivation(reg.installing || reg.waiting); waitForActivation(reg.installing || reg.waiting);
} else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) { } else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
// When the app updates the serviceWorkerVersion changes, so we // When the app updates the serviceWorkerVersion changes, so we
// need to ask the service worker to update. // need to ask the service worker to update.
console.log('[TwakeMail] fetchServiceWorker(): New service worker available.'); console.log('[TwakeMail] fetchServiceWorker(): New service worker available.');
reg.update(); reg.update();
waitForActivation(reg.installing); waitForActivation(reg.installing);
} else { } else {
// Existing service worker is still good. // Existing service worker is still good.
console.log('[TwakeMail] fetchServiceWorker(): Loading app from service worker.'); console.log('[TwakeMail] fetchServiceWorker(): Loading app from service worker.');
loadMainDartJs();
}
});
// If service worker doesn't succeed in a reasonable amount of time,
// fallback to plaint <script> tag.
setTimeout(() => {
if (!scriptLoaded) {
console.warn(
'[TwakeMail] fetchServiceWorker(): Failed to load app from service worker. Falling back to plain <script> tag.',
);
loadMainDartJs(); loadMainDartJs();
} }
}); }, timeoutDuration);
// If service worker doesn't succeed in a reasonable amount of time, } else {
// fallback to plaint <script> tag.
setTimeout(() => {
if (!scriptLoaded) {
console.warn(
'[TwakeMail] fetchServiceWorker(): Failed to load app from service worker. Falling back to plain <script> tag.',
);
loadMainDartJs();
}
}, 4000);
}
else {
// Service workers not supported. Just drop the <script> tag. // Service workers not supported. Just drop the <script> tag.
loadMainDartJs(); loadMainDartJs();
} }
} }
function handleContinueTwakeMailOnWeb() { function handleContinueTwakeMailOnWeb() {
console.info('[TwakeMail] handleContinueTwakeMailOnWeb(): Continue on web.'); console.info('[TwakeMail] handleContinueTwakeMailOnWeb(): Continue on web.');
closeBottomSheet(); closeBottomSheet();
fetchServiceWorker();
}
function getPlatform() {
console.info('[TwakeMail] getPlatform(): ', navigator.userAgent);
if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) {
return iosPlatform;
}
if (/Android/i.test(navigator.userAgent)) {
return androidPlatform;
}
return otherPlatform;
}
function handleOpenTwakeMailApp() {
const os = getPlatform();
console.info('[TwakeMail] handleOpenTwakeMailApp() - OS:', os);
if (os === androidPlatform) {
document.location.replace(androidStore);
} else if (os === iosPlatform) {
document.location.replace(iosStore);
}
}
function initialWorkerService() {
const os = getPlatform();
const originInUrl = window.location;
console.info('[TwakeMail] initialWorkerService(): OriginInUrl:', originInUrl);
// For desktop, we don't show the open on app popup
if (os === otherPlatform || typeof window === 'undefined') {
fetchServiceWorker(); fetchServiceWorker();
return;
} }
function getPlatform() { if (window.location.pathname.includes('/login')) {
console.info('[TwakeMail] getPlatform(): ', navigator.userAgent); console.info('[TwakeMail] initialWorkerService(): Login callback');
if (/iPhone|iPad|iPod/i.test(navigator.userAgent)) { handleContinueTwakeMailOnWeb();
return iosPlatform; } else {
} openBottomSheet();
if (/Android/i.test(navigator.userAgent)) {
return androidPlatform;
}
return otherPlatform;
} }
}
function hanldeOpenTwakeMailApp() { function openBottomSheet() {
const os = getPlatform(); console.info('[TwakeMail] openBottomSheet(): Open the bottom sheet.');
console.info('[TwakeMail] hanldeOpenTwakeMailApp() - OS:', os); const bottomSheet = document.querySelector(".bottom-sheet");
if (os === androidPlatform) { bottomSheet.style.display = "block";
document.location.replace(androidStore); document.body.style.overflow = "hidden";
} else if (os === iosPlatform) { bottomSheet.style.bottom = "0";
document.location.replace(iosStore); }
}
}
function initialWorkerService() { function closeBottomSheet() {
const os = getPlatform(); console.info('[TwakeMail] closeBottomSheet(): Closing the bottom sheet.');
const searchParams = Object.fromEntries( const bottomSheet = document.querySelector(".bottom-sheet");
new URLSearchParams(window.location.search), bottomSheet.style.display = "none";
); document.body.style.overflow = "auto";
const originInUrl = searchParams.origin; bottomSheet.style.bottom = "-100%";
// For desktop, we don't show the open on app popup }
if (os === otherPlatform || typeof window === 'undefined') {
if (os !== otherPlatform) {
console.log('[TwakeMail] initialWorkerService(): Keep on browser because:', {
os,
originInUrl,
windowUndefined: typeof window === 'undefined',
});
}
fetchServiceWorker();
return;
}
console.log('[TwakeMail] initialWorkerService(): Open the bottom sheet.');
const bottomSheet = document.querySelector(".bottom-sheet");
bottomSheet.style.display = "block";
document.body.style.overflow = "hidden";
bottomSheet.style.bottom = "0";
}
function closeBottomSheet() {
console.info('[TwakeMail] closeBottomSheet(): Closing the bottom sheet.');
const bottomSheet = document.querySelector(".bottom-sheet");
bottomSheet.style.display = "none";
document.body.style.overflow = "auto";
bottomSheet.style.bottom = "-100%";
}