Skip to content

Commit b524b4f

Browse files
committed
Small tweaks to the download page
1 parent ddbf1d7 commit b524b4f

8 files changed

Lines changed: 101 additions & 35 deletions

File tree

pages/desktop-app.tsx

Lines changed: 71 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,86 @@ export default DesktopAppPage;
88

99
export const getServerSideProps: GetServerSideProps<any> = async ({ res, locale = "en" }) => {
1010
const octokit = new Octokit();
11-
const response = await octokit.request("GET /repos/{owner}/{repo}/releases/latest", {
12-
owner: "cohstats",
13-
repo: "coh3-stats-desktop-app",
14-
headers: {
15-
"X-GitHub-Api-Version": "2022-11-28",
16-
},
17-
});
1811

1912
console.log(`SSR - /desktop-app`);
2013

2114
let downloadURL = "https://github.com/cohstats/coh3-stats-desktop-app/releases/latest"; // fallback in case request fails
2215
let downloadCount = 0;
2316
let version = "";
24-
if (response.status === 200) {
25-
const assets = response.data.assets.filter((asset: { browser_download_url: string }) => {
26-
if (asset.browser_download_url.split(".").at(-1) === "sig") {
27-
return false;
28-
} else if (asset.browser_download_url.includes("full")) {
29-
return false;
30-
}
17+
let totalDownloadCount = 0;
3118

32-
return true;
19+
try {
20+
// Fetch last 20 releases - this includes the latest release
21+
const response = await octokit.request("GET /repos/{owner}/{repo}/releases", {
22+
owner: "cohstats",
23+
repo: "coh3-stats-desktop-app",
24+
per_page: 100,
25+
headers: {
26+
"X-GitHub-Api-Version": "2022-11-28",
27+
},
3328
});
34-
if (assets.length > 0) {
35-
downloadCount = assets
36-
.map((asset: { download_count: any }) => asset.download_count)
37-
.reduce((a: any, b: any) => a + b);
38-
}
3929

40-
version = "v" + response.data.tag_name;
41-
const msiAsset = assets.find(
42-
(asset: { browser_download_url: string }) =>
43-
asset.browser_download_url.split(".").at(-1) === "msi",
44-
);
45-
if (msiAsset) {
46-
downloadURL = msiAsset.browser_download_url;
30+
if (response.status === 200 && response.data.length > 0) {
31+
// Filter out draft releases
32+
const releases = response.data.filter((release: { draft: boolean }) => !release.draft);
33+
34+
if (releases.length > 0) {
35+
// First release is the latest
36+
const latestRelease = releases[0];
37+
38+
// Get latest release info
39+
const latestAssets = latestRelease.assets.filter(
40+
(asset: { browser_download_url: string }) => {
41+
if (asset.browser_download_url.split(".").at(-1) === "sig") {
42+
return false;
43+
} else if (asset.browser_download_url.includes("full")) {
44+
return false;
45+
}
46+
return true;
47+
},
48+
);
49+
50+
if (latestAssets.length > 0) {
51+
downloadCount = latestAssets
52+
.map((asset: { download_count: number }) => asset.download_count)
53+
.reduce((a: number, b: number) => a + b);
54+
}
55+
56+
version = "v" + latestRelease.tag_name;
57+
const msiAsset = latestAssets.find(
58+
(asset: { browser_download_url: string }) =>
59+
asset.browser_download_url.split(".").at(-1) === "msi",
60+
);
61+
if (msiAsset) {
62+
downloadURL = msiAsset.browser_download_url;
63+
}
64+
65+
// Calculate total downloads across all releases
66+
totalDownloadCount = releases.reduce((total: number, release: any) => {
67+
const releaseAssets = release.assets.filter(
68+
(asset: { browser_download_url: string }) => {
69+
if (asset.browser_download_url.split(".").at(-1) === "sig") {
70+
return false;
71+
} else if (asset.browser_download_url.includes("full")) {
72+
return false;
73+
}
74+
return true;
75+
},
76+
);
77+
78+
const releaseDownloads = releaseAssets.reduce(
79+
(sum: number, asset: { download_count: number }) => sum + asset.download_count,
80+
0,
81+
);
82+
83+
return total + releaseDownloads;
84+
}, 0);
85+
}
4786
}
87+
} catch (error) {
88+
console.error("Failed to fetch releases:", error);
89+
// If fetching releases fails, use fallback values
90+
totalDownloadCount = 0;
4891
}
4992

5093
res.setHeader(
@@ -56,6 +99,7 @@ export const getServerSideProps: GetServerSideProps<any> = async ({ res, locale
5699
props: {
57100
downloadURL,
58101
downloadCount,
102+
totalDownloadCount,
59103
version,
60104
...(await serverSideTranslations(locale, ["common", "desktopapp"])),
61105
},

public/locales/cs/desktopapp.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"button": "Stáhnout zdarma {{version}}",
2020
"buttonAriaLabel": "Stáhnout instalátor Grenadier - COH3 Stats Desktop App {{version}} pro Windows",
2121
"downloads": "{{count}} stažení",
22+
"totalDownloads": "{{count}} stažení celkem",
2223
"releaseNotes": "Poznámky k vydání",
2324
"microsoftStore": "Získat v Microsoft Store",
2425
"microsoftStoreAriaLabel": "Získat Grenadier - COH3 Companion v Microsoft Store",
@@ -54,6 +55,7 @@
5455
"recentGames": "Zobrazit vaše nedávné hry přímo v aplikaci",
5556
"notifications": "Získejte volitelná zvuková upozornění při připojení ke hře",
5657
"replays": "Automatické nahrávání záznamů do cloudu pro další analýzu",
58+
"muteOnFocusLoss": "Možnost ztlumit hru, když okno není v popředí",
5759
"streaming": {
5860
"before": "Překrytí pro streamery pro",
5961
"and": "a",

public/locales/de/desktopapp.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"button": "Kostenloser Download {{version}}",
2020
"buttonAriaLabel": "Grenadier - COH3 Stats Desktop App {{version}} Installer für Windows herunterladen",
2121
"downloads": "{{count}} Downloads",
22+
"totalDownloads": "{{count}} Downloads insgesamt",
2223
"releaseNotes": "Versionshinweise",
2324
"microsoftStore": "Im Microsoft Store herunterladen",
2425
"microsoftStoreAriaLabel": "Grenadier - COH3 Companion im Microsoft Store herunterladen",
@@ -54,6 +55,7 @@
5455
"recentGames": "Sieh deine letzten Spiele direkt in der App",
5556
"notifications": "Erhalte optionale Soundbenachrichtigungen beim Beitritt zu einem Spiel",
5657
"replays": "Automatischer Upload von Replays in die Cloud für zusätzliche Analysen",
58+
"muteOnFocusLoss": "Möglichkeit, das Spiel stummzuschalten, wenn das Fenster nicht im Fokus ist",
5759
"streaming": {
5860
"before": "Streamer-Overlay für",
5961
"and": "und",

public/locales/en/desktopapp.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"button": "Free Download {{version}}",
2020
"buttonAriaLabel": "Download Grenadier - COH3 Stats Desktop App {{version}} installer for Windows",
2121
"downloads": "{{count}} downloads",
22+
"totalDownloads": "{{count}} total downloads",
2223
"releaseNotes": "Release Notes",
2324
"microsoftStore": "Get on Microsoft Store",
2425
"microsoftStoreAriaLabel": "Get Grenadier - COH3 Companion on Microsoft Store",
@@ -34,14 +35,14 @@
3435
"Certified App by Microsoft",
3536
"Updates and patches handled by Microsoft",
3637
"Lifetime license",
37-
"Support the app with the purchase! Thank you"
38+
"Support the app with the purchase! "
3839
]
3940
},
4041
"freeDownload": {
4142
"title": "Free Download",
4243
"benefits": [
4344
"Direct download, not certified app",
44-
"Same features as the Microsoft Store App"
45+
"Same features as the Microsoft Store App *"
4546
]
4647
}
4748
},
@@ -54,6 +55,7 @@
5455
"recentGames": "See your recent games directly in the app",
5556
"notifications": "Receive optional sound notifications upon joining a game",
5657
"replays": "Auto upload replays to the cloud for additional analysis",
58+
"muteOnFocusLoss": "Ability to mute the game when the window is not in focus",
5759
"streaming": {
5860
"before": "Streamer overlay for",
5961
"and": "and",

public/locales/es/desktopapp.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"button": "Descarga Gratuita {{version}}",
2020
"buttonAriaLabel": "Descargar instalador de Grenadier - COH3 Stats Desktop App {{version}} para Windows",
2121
"downloads": "{{count}} Descargas",
22+
"totalDownloads": "{{count}} descargas totales",
2223
"releaseNotes": "Notas de la versión",
2324
"microsoftStore": "Obtener en Microsoft Store",
2425
"microsoftStoreAriaLabel": "Obtener Grenadier - COH3 Companion en Microsoft Store",
@@ -54,6 +55,7 @@
5455
"recentGames": "Ve tus juegos recientes directamente en la app",
5556
"notifications": "Recibe notificaciones de sonido opcionales al entrar a un juego",
5657
"replays": "Sube repeticiones automaticamente a la nube para análisis adicional",
58+
"muteOnFocusLoss": "Capacidad de silenciar el juego cuando la ventana no está en foco",
5759
"streaming": {
5860
"before": "Overlay para transmisiones",
5961
"and": "y",

public/locales/ru/desktopapp.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"button": "Бесплатная загрузка {{version}}",
2020
"buttonAriaLabel": "Скачать установщик Grenadier - COH3 Stats Desktop App {{version}} для Windows",
2121
"downloads": "{{count}} загрузок",
22+
"totalDownloads": "{{count}} загрузок всего",
2223
"releaseNotes": "Список изменений",
2324
"microsoftStore": "Получить в Microsoft Store",
2425
"microsoftStoreAriaLabel": "Получить Grenadier - COH3 Companion в Microsoft Store",
@@ -54,6 +55,7 @@
5455
"recentGames": "Просматривайте ваши недавние игры прямо в приложении",
5556
"notifications": "Получайте дополнительные звуковые уведомления при нахлждении игры",
5657
"replays": "Автоматическая загрузка повторов в облако для дополнительного анализа",
58+
"muteOnFocusLoss": "Возможность отключить звук игры, когда окно не в фокусе",
5759
"streaming": {
5860
"before": "Стрим-оверлей для",
5961
"and": "и",

public/locales/zh-Hans/desktopapp.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"button": "免费下载 {{version}}",
2020
"buttonAriaLabel": "下载 Windows 版 Grenadier - COH3 Stats 桌面应用 {{version}} 安装程序",
2121
"downloads": "{{count}} 次下载",
22+
"totalDownloads": "总计 {{count}} 次下载",
2223
"releaseNotes": "发布说明",
2324
"microsoftStore": "在 Microsoft Store 获取",
2425
"microsoftStoreAriaLabel": "在 Microsoft Store 获取 Grenadier - COH3 Companion",
@@ -51,6 +52,7 @@
5152
"recentGames": "直接在应用中查看最近的游戏",
5253
"notifications": "加入游戏时接收可选的声音通知",
5354
"replays": "自动上传录像到云端进行额外分析",
55+
"muteOnFocusLoss": "当窗口失去焦点时可以静音游戏",
5456
"streaming": {
5557
"before": "适用于",
5658
"and": "",

screens/desktop-app/index.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ import Autoplay from "embla-carousel-autoplay";
2525
import classes from "./desktop-app.module.css";
2626
import { createPageSEO } from "../../src/seo-utils";
2727

28-
const DesktopAppPage: NextPage = ({ downloadURL, downloadCount, version }: any) => {
28+
const DesktopAppPage: NextPage = ({
29+
downloadURL,
30+
downloadCount,
31+
totalDownloadCount,
32+
version,
33+
}: any) => {
2934
const { t } = useTranslation("desktopapp");
3035
const autoplay = useRef(Autoplay({ delay: 4000, stopOnMouseEnter: true }));
3136

@@ -110,7 +115,7 @@ const DesktopAppPage: NextPage = ({ downloadURL, downloadCount, version }: any)
110115
<Grid gutter="xl" align="center">
111116
{/* Left Column - Download Buttons */}
112117
<Grid.Col span={{ base: 12, md: 6 }}>
113-
<Stack align="center" gap="md" justify="center" style={{ height: "100%" }}>
118+
<Stack align="center" gap="sm" justify="center" style={{ height: "100%" }}>
114119
{/* Microsoft Store Button */}
115120
<Anchor
116121
href="https://apps.microsoft.com/detail/9PBKK60PKDQS"
@@ -142,11 +147,15 @@ const DesktopAppPage: NextPage = ({ downloadURL, downloadCount, version }: any)
142147
{t("download.button", { version })}
143148
</Button>
144149
</Anchor>
145-
<Text size="sm" c="dimmed">
146-
{t("download.downloads", { count: downloadCount })}
147-
</Text>
150+
<Stack align="center" gap="0">
151+
<Text size="sm" c="dimmed">
152+
{t("download.downloads", { count: downloadCount })}
153+
</Text>
154+
<Text size="xs" c="dimmed">
155+
{t("download.totalDownloads", { count: totalDownloadCount })}
156+
</Text>
157+
</Stack>
148158
</Stack>
149-
150159
<Anchor
151160
href="https://github.com/cohstats/coh3-stats-desktop-app/releases/latest"
152161
target="_blank"
@@ -228,6 +237,7 @@ const DesktopAppPage: NextPage = ({ downloadURL, downloadCount, version }: any)
228237
<List.Item>{t("features.list.recentGames")}</List.Item>
229238
<List.Item>{t("features.list.notifications")}</List.Item>
230239
<List.Item>{t("features.list.replays")}</List.Item>
240+
<List.Item>{t("features.list.muteOnFocusLoss")}</List.Item>
231241
<List.Item>
232242
{t("features.list.streaming.before")}{" "}
233243
<Anchor href="https://obsproject.com/" target="_blank" rel="noopener">

0 commit comments

Comments
 (0)