22import { Icon } from " astro-icon/components" ;
33import { fromPairs , map , mapValues , toPairs } from " lodash-es" ;
44
5+
6+
57const BROWSERS = {
68 windows64: {
79 label: " Windows" ,
@@ -77,7 +79,11 @@ const DOWNLOAD_LINKS = await getDownloadLinks();
7779
7880---
7981
80- <div class =" d-flex flex-column align-items-start" >
82+ <download-gephi-desktop
83+ class =" d-flex flex-column align-items-start"
84+ data-browsers ={ JSON .stringify (BROWSERS )}
85+ data-links ={ JSON .stringify (DOWNLOAD_LINKS )}
86+ >
8187 <a href =" https://github.com/gephi/gephi/releases"
8288 id =" download-gephi"
8389 class ={ buttonClass || " btn btn-white fs-4 fw-bold mb-2" }
@@ -97,30 +103,39 @@ const DOWNLOAD_LINKS = await getDownloadLinks();
97103 <a class = " text-light" href = " https://github.com/gephi/gephi/releases" >
98104 <Icon name = " ph:clock-counter-clockwise" /> Download Older Versions
99105 </a >}
100- </div >
101- <script define:vars ={ { DOWNLOAD_LINKS , BROWSERS }} >
106+ </download-gephi-desktop>
107+ <script >
108+ import { UAParser } from 'ua-parser-js';
109+ class DownloadGephiDesktop extends HTMLElement {
110+ connectedCallback() {
111+ // Read the message from the data attribute.
112+ const BROWSERS = JSON.parse(this.dataset.browsers||'{}');
113+ const DOWNLOAD_LINKS = JSON.parse(this.dataset.links||'{}');
114+ const { os, cpu } = UAParser(navigator.userAgent);
115+
102116 let currentBrowser = "windows64";
103-
104- if (navigator.appVersion.indexOf("Win") !== -1) {
105- currentBrowser = "windows64";
106- } else if (navigator.appVersion.indexOf("Mac") !== -1) {
107- if (navigator.userAgent.indexOf("Intel") !== -1)
108- currentBrowser = "macIntel"
109- else
110- currentBrowser = "macSilicon";
111- } else if (navigator.userAgent.indexOf("Ubuntu") !== -1) {
112- currentBrowser = "linux";
113- } else if (navigator.appVersion.indexOf("X11") !== -1) {
114- currentBrowser = "linux";
117+ switch(os.name){
118+ case "Windows": currentBrowser = cpu.architecture?.includes("32") ? "windows32": "windows64" ; break;
119+ case "macOS": currentBrowser = cpu.architecture?.includes("arm") ? "macSilicon" : "macIntel"; break;
120+ // default to linux for all variety of linux OS + all variety of mobile...
121+ // TODO: for mobile/tablet/console (detected in the device) we could advertize gephi-lite
122+ default: currentBrowser = "linux";
115123 }
116124
117- const link = document.getElementById("download-gephi");
118- const linkText = link.querySelector(".text");
119- if (DOWNLOAD_LINKS.links[currentBrowser]) {
125+ const link = document.getElementById("download-gephi") as HTMLAnchorElement|null;
126+ const linkText = link?.querySelector(".text");
127+
128+ if (link && DOWNLOAD_LINKS.links[currentBrowser]) {
120129 link.href = DOWNLOAD_LINKS.links[currentBrowser];
121- linkText.innerHTML = `Download Gephi for ${BROWSERS[currentBrowser].label}`;
130+ if(linkText)
131+ linkText.innerHTML = `Download Gephi for ${BROWSERS[currentBrowser].label}`;
122132 }
123133
124134 const smallLink = document.querySelector(`a[data-browser='${currentBrowser}']`);
125135 if (smallLink) smallLink.remove();
136+ }
137+ }
138+
139+ customElements.define('download-gephi-desktop', DownloadGephiDesktop);
140+
126141</script >
0 commit comments