Skip to content

Commit e2010f2

Browse files
committed
feat: fetch automatically the newest version of edpu for firefox
1 parent cd4bb86 commit e2010f2

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

src/components/EdpUnblock/EdpUnblock.jsx

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const browserLogosInfos = {
2121
Firefox: {
2222
logo: <FirefoxLogo />,
2323
available: true,
24-
url: "https://unblock.ecole-directe.plus/ecole_directe_plus_unblock-0.2.1.xpi",
24+
url: undefined,
2525
},
2626
Chrome: {
2727
logo: <ChromeLogo />,
@@ -50,6 +50,16 @@ const browserLogosInfos = {
5050
},
5151
}
5252

53+
async function getFirefoxUrl() {
54+
return fetch("https://unblock.ecole-directe.plus/update.json")
55+
.then((response) => response.json())
56+
.then((response) => {
57+
const updates = response.addons["{edpu-firefox-self-host@ecole-directe.plus}"].updates;
58+
const url = updates[updates.length - 1].update_link;
59+
return url;
60+
})
61+
}
62+
5363
const userOS = getOS();
5464
const userBrowser = getBrowser();
5565
// const userOS = "iOS";
@@ -63,6 +73,7 @@ const compatibilityCondition = ((userOS === "iOS" && nonCompatibleIOSBrowsers.in
6373
export default function EdpUnblock({ isEDPUnblockActuallyInstalled }) {
6474
const location = useLocation();
6575

76+
const [url, setUrl] = useState(browserLogosInfos?.[userBrowser].url);
6677
const aboutRef = useRef(null);
6778
const aboutButtonRef = useRef(null);
6879
const heroBannerRef = useRef(null);
@@ -99,6 +110,12 @@ export default function EdpUnblock({ isEDPUnblockActuallyInstalled }) {
99110
scrollToAbout();
100111
}, [location.hash])
101112

113+
useEffect(() => {
114+
getFirefoxUrl().then((url) => {
115+
setUrl(url);
116+
})
117+
}, []);
118+
102119
return (<>
103120
<div id="edpu-background-image"></div>
104121
<span className="edpu-back-arrow">
@@ -121,17 +138,21 @@ export default function EdpUnblock({ isEDPUnblockActuallyInstalled }) {
121138
<h2>Ecole Directe Plus Unblock</h2>
122139
</div>
123140
</div>
124-
<p>Ecole Directe Plus a besoin de cette extension de navigateur pour <span style={{ fontWeight: "800"}}>fonctionner correctement</span> et accéder à l’API d’EcoleDirecte.</p>
125-
{compatibilityCondition && (userOS !== "iOS" ? <><p>Malheureusement, l'extension Ecole Directe Plus Unblock n'est pas disponible sur votre navigateur. 😥</p><p>S'il vous plaît considérez l'usage d'un navigateur compatible comme le <a href={userOS === "iOS" ? "https://apps.apple.com/app/id1484498200" : "https://play.google.com/store/apps/details?id=org.mozilla.firefox"} className="suggested-browser" target="_blank">{userOS === "iOS" ? "navigateur Orion" : "navigateur Firefox"}</a>.</p></> : <p>Malheureusement, l'extension Ecole Directe Plus Unblock n'est pas compatible avec les navigateurs sur iOS et iPadOS. S'il vous plaît, considérez l'usage d'un autre appareil avec un système d'exploitation compatible comme un ordinateur sous Windows ou Linux, ou un appareil mobile sous Android.</p>) }
126-
<a href={browserLogosInfos[userBrowser] && browserLogosInfos[userBrowser].url} target={userBrowser === "Firefox" ? "_self" : "_blank"} className={`edpu-download-link ${compatibilityCondition ? "disabled" : ""} ${browserLogosInfos[userBrowser] && browserLogosInfos[userBrowser].available ? "available" : "unavailable"}`}>
141+
<p>Ecole Directe Plus a besoin de cette extension de navigateur pour <span style={{ fontWeight: "800" }}>fonctionner correctement</span> et accéder à l’API d’EcoleDirecte.</p>
142+
{compatibilityCondition && (userOS !== "iOS" ? <><p>Malheureusement, l'extension Ecole Directe Plus Unblock n'est pas disponible sur votre navigateur. 😥</p><p>S'il vous plaît considérez l'usage d'un navigateur compatible comme le <a href={userOS === "iOS" ? "https://apps.apple.com/app/id1484498200" : "https://play.google.com/store/apps/details?id=org.mozilla.firefox"} className="suggested-browser" target="_blank">{userOS === "iOS" ? "navigateur Orion" : "navigateur Firefox"}</a>.</p></> : <p>Malheureusement, l'extension Ecole Directe Plus Unblock n'est pas compatible avec les navigateurs sur iOS et iPadOS. S'il vous plaît, considérez l'usage d'un autre appareil avec un système d'exploitation compatible comme un ordinateur sous Windows ou Linux, ou un appareil mobile sous Android.</p>)}
143+
<a
144+
href={url}
145+
target={userBrowser === "Firefox" ? "_self" : "_blank"}
146+
className={`edpu-download-link ${(compatibilityCondition && url === undefined) ? "disabled" : ""} ${browserLogosInfos?.[userBrowser].available ? "available" : "unavailable"}`}
147+
>
127148
{browserLogosInfos[userBrowser] && browserLogosInfos[userBrowser].logo}
128149
{isEDPUnblockActuallyInstalled
129-
? <span>Extension installée</span>
130-
: (compatibilityCondition ? <span>Navigateur incompatible</span> : <span>Ajouter l’extension</span>)
150+
? <span>Extension installée</span>
151+
: (compatibilityCondition ? <span>Navigateur incompatible</span> : <span>Ajouter l’extension</span>)
131152
}
132153
{isEDPUnblockActuallyInstalled
133-
? <BadgeCheck />
134-
: (compatibilityCondition ? <div className="download-unavailable"></div> : <DownloadIcon />)
154+
? <BadgeCheck />
155+
: (compatibilityCondition ? <div className="download-unavailable"></div> : <DownloadIcon />)
135156
}
136157
</a>
137158
</div>

0 commit comments

Comments
 (0)