Skip to content

Commit

Permalink
Add: Add version update information
Browse files Browse the repository at this point in the history
  • Loading branch information
whats2000 committed Sep 6, 2024
1 parent e645201 commit b04aba1
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 12 deletions.
7 changes: 6 additions & 1 deletion Localizer/TranslateText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class TranslateText

private static Dictionary<string, string> _displayText = new();
private static Dictionary<string, string> _fallbackDisplayText = new();
private string _currentLanguage = FallbackLanguage;
private static string _currentLanguage = FallbackLanguage;

public static event Action OnLanguageChange;

Expand Down Expand Up @@ -56,6 +56,11 @@ public async Task LoadLanguageAsync(string language)
OnLanguageChange?.Invoke();
}

public static string GetCurrentLanguage()
{
return _currentLanguage;
}

public static string GetTranslateText(string key)
{
return _displayText.TryGetValue(key, out var translateText)
Expand Down
10 changes: 9 additions & 1 deletion Shared/SharedHeader.razor
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,13 @@
OnOk="@HandleOk"
OnCancel="@HandleCancel"
Footer="@ModelFooterTemplate">
<p>@_modalContent</p>
<Title Level="4">@_modalContent</Title>
<Paragraph>
<ul>
@foreach (var item in _updateNotes)
{
<li>@item</li>
}
</ul>
</Paragraph>
</Modal>
32 changes: 27 additions & 5 deletions Shared/SharedHeader.razor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AntDesign;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
Expand All @@ -18,6 +21,7 @@ public partial class SharedHeader
private string _currentVersion = "Loading...";
private string _latestVersion;
private string _modalContent = "";
private string[] _updateNotes = Array.Empty<string>();
private bool _visible = false;
[Inject] private IJSRuntime JsRuntime { get; set; }

Expand Down Expand Up @@ -88,9 +92,12 @@ protected Theme CurrentTheme
}
}

private void ShowVersionModal()
private void ShowVersionModal(string[] updateNotes)
{
_modalContent = TranslateText.GetTranslateText("NewVersionFound").Replace("{_latestVersion}", _latestVersion);
_modalContent = TranslateText.GetTranslateText("NewVersionFound")
.Replace("{_latestVersion}", _latestVersion);
_updateNotes = updateNotes;

_visible = true;
StateHasChanged();
}
Expand Down Expand Up @@ -147,7 +154,11 @@ private async void OnClickChangeLanguage(string language)
private async void CheckForUpdate()
{
_currentVersion = "Loading...";
_latestVersion = await JsRuntime.InvokeAsync<string>("FetchVersionFromServer");

// Fetch version and update notes
var versionData = await JsRuntime.InvokeAsync<VersionData>("FetchVersionFromServer");
_latestVersion = versionData?.Version;
var updateNotes = versionData?.UpdateNotes;
_currentVersion = await JsRuntime.InvokeAsync<string>("localStorage.getItem", "PearlCalculatorBlazor_version");

await Task.Delay(1000);
Expand All @@ -158,7 +169,12 @@ private async void CheckForUpdate()
return;
}

ShowVersionModal();
// Fetch and display the update notes based on the current language
var currentLanguage = TranslateText.GetCurrentLanguage();
if (updateNotes != null && updateNotes.TryGetValue(currentLanguage, out var note))
ShowVersionModal(note);
else
ShowVersionModal(new[] { "No update notes found" });
}

protected override async void OnInitialized()
Expand All @@ -183,4 +199,10 @@ private void RefreshPage()
{
StateHasChanged();
}
}

public class VersionData
{
public string Version { get; init; }
public Dictionary<string, string[]> UpdateNotes { get; init; }
}
1 change: 1 addition & 0 deletions wwwroot/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"CalculateTNTAmount": "Calculate TNT Amount",
"CheckForUpdate": "Check for Update",
"Coordinate": "Coordinate",
"CopyGeneralDataToManuallyData": "Copy General Data",
"DefaultBlueTNTPos": "Default Blue TNT Position",
"DefaultBlueTNTPosDesc": "Preset the position of the TNT duped from the blue array relative to the pearl without being changed by the slime block",
"DefaultRedTNTPos": "Default Red TNT Position",
Expand Down
1 change: 1 addition & 0 deletions wwwroot/assets/i18n/es_ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"CalculateTNTAmount": "Calcular Cantidades de TNT",
"CheckForUpdate": "Buscar Actualizaciones",
"Coordinate": "Coordenada",
"CopyGeneralDataToManuallyData": "Copiar Datos Generales",
"DefaultBlueTNTPos": "Posición Predet. TNT Azul",
"DefaultBlueTNTPosDesc": "La Posición de la TNT Azul (Respecto a la perla) si el Slime Block no la mueve",
"DefaultRedTNTPos": "Posición Predet. TNT Roja",
Expand Down
1 change: 1 addition & 0 deletions wwwroot/assets/i18n/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"CheckForUpdate": "检查更新",
"ConsoleHeader": "控制台",
"Coordinate": "坐标",
"CopyGeneralDataToManuallyData": "复制一般数据",
"DefaultBlueTNTPos": "预设蓝色TNT方位",
"DefaultBlueTNTPosDesc": "预设从蓝色阵列复制的TNT\n在不被粘液块改位置下相对于珍珠的方位",
"DefaultRedTNTPos": "预设红色TNT方位",
Expand Down
1 change: 1 addition & 0 deletions wwwroot/assets/i18n/zh_tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"CheckForUpdate": "檢查更新",
"ConsoleHeader": "控制台",
"Coordinate": "座標",
"CopyGeneralDataToManuallyData": "複製一般設定",
"DefaultBlueTNTPos": "預設藍色TNT方位",
"DefaultBlueTNTPosDesc": "預設從藍色陣列複製的TNT\n在不被史萊姆方塊改位置下相對於珍珠的方位",
"DefaultRedTNTPos": "預設紅色TNT方位",
Expand Down
2 changes: 1 addition & 1 deletion wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<script src="scripts/fileInputProxy.js?v=20240905"></script>
<script src="scripts/theme.js?v=20240905"></script>
<script src="scripts/tntWeightSlider.js?v=20240905"></script>
<script src="scripts/version.js?v=20240905"></script>
<script src="scripts/version.js?v=20240906"></script>
<script>navigator.serviceWorker.register('service-worker.js');</script>
<script src="_content/AntDesign/js/ant-design-blazor.js"></script>
<script src="_content/AntDesign.Charts/g2plot.min.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions wwwroot/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
"theme_color": "#03173d",
"icons": [
{
"src": "icon-512.png",
"src": "Logo.png",
"type": "image/png",
"sizes": "512x512"
"sizes": "308x308"
}
]
}
5 changes: 4 additions & 1 deletion wwwroot/scripts/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
const timestamp = new Date().getTime();
const response = await fetch(`${basePath}/version.json?t=${timestamp}`);
const data = await response.json();
return data.version;
return {
version: data.version,
updateNotes: data.updateNotes
};
} catch (error) {
console.error('Error fetching version:', error);
return null;
Expand Down
24 changes: 23 additions & 1 deletion wwwroot/version.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
{
"version": "2.71.2"
"version": "2.71.3",
"updateNotes": {
"en": [
"Added manual mode to copy data from general mode.",
"Fixed issue where previous calculation results were displayed if no direction angle was found in the updated calculation.",
"Added update log feature."
],
"es_ES": [
"Se añadió el modo manual para copiar datos del modo general.",
"Se corrigió un problema donde se mostraban los resultados de cálculos anteriores si no se encontraba un ángulo de dirección en el cálculo actualizado.",
"Se añadió la función de registro de actualizaciones."
],
"zh_tw": [
"新增手動模式複製一般模式資料。",
"修正更新計算後若不存在方向角則仍維持顯示前一計算結果。",
"新增更新日誌功能。"
],
"zh_cn": [
"新增手动模式复制一般模式资料。",
"修正更新计算后若不存在方向角则仍维持显示前一计算结果。",
"新增更新日志功能。"
]
}
}

0 comments on commit b04aba1

Please sign in to comment.