Skip to content

Commit

Permalink
Fix incorrect culture after reboot
Browse files Browse the repository at this point in the history
  • Loading branch information
reagcz committed Oct 14, 2024
1 parent 4a4650a commit fc65b40
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 deletions.
22 changes: 17 additions & 5 deletions IdeapadToolkit/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Serilog.Core;
using System.Globalization;
using System.Threading;
using IdeapadToolkit.Localization;

namespace IdeapadToolkit
{
Expand Down Expand Up @@ -57,9 +58,10 @@ protected override void OnStartup(StartupEventArgs e)
ConfigureServices(container);
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
bool exists = Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Environment.ProcessPath)).Length > 1;
TrySetCulture();
if (exists && !e.Args.Contains("ignoreRunning"))
{
MessageBox.Show("Already running!", "", MessageBoxButton.OK, MessageBoxImage.Asterisk);
MessageBox.Show(Strings.ALREADY_RUNNING, "", MessageBoxButton.OK, MessageBoxImage.Asterisk);
Application.Current.Shutdown();
return;
}
Expand All @@ -70,7 +72,7 @@ protected override void OnStartup(StartupEventArgs e)

if (!File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PowerBattery.dll")))
{
MessageBox.Show("PowerBattery.dll has to be present in the same folder as IdeapadToolkit.exe", "", MessageBoxButton.OK, MessageBoxImage.Asterisk);
MessageBox.Show(Strings.DLL_MISSING_ERROR, "", MessageBoxButton.OK, MessageBoxImage.Asterisk);
Application.Current.Shutdown();
}
if (!e.Args.Contains("nogui"))
Expand All @@ -91,6 +93,16 @@ private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionE
public void ShowMainWindow(object? sender, EventArgs? e)
{
if (App.Current.MainWindow == null)
{
TrySetCulture();
App.Current.MainWindow = _container.GetInstance<MainWindow>();
}
App.Current.MainWindow.Show();
}

private void TrySetCulture()
{
try
{
var culture = Settings.Default.Language;
if (!String.IsNullOrWhiteSpace(culture))
Expand All @@ -104,10 +116,10 @@ public void ShowMainWindow(object? sender, EventArgs? e)
});
}
}

App.Current.MainWindow = _container.GetInstance<MainWindow>();
}
App.Current.MainWindow.Show();
catch (Exception ex)

Check warning on line 120 in IdeapadToolkit/App.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'ex' is declared but never used
{
}
}

private void MenuItemExit_Click(object sender, RoutedEventArgs e)
Expand Down
18 changes: 18 additions & 0 deletions IdeapadToolkit/Localization/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions IdeapadToolkit/Localization/Strings.cs-CZ.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ALREADY_RUNNING" xml:space="preserve">
<value>Aplikace je již spuštěná</value>
</data>
<data name="ALWAYS_ON_USB" xml:space="preserve">
<value>USB vždy zapnuté</value>
</data>
Expand All @@ -132,6 +135,9 @@
<data name="CONSERVATION" xml:space="preserve">
<value>Šetrný</value>
</data>
<data name="DLL_MISSING_ERROR" xml:space="preserve">
<value>Soubor PowerBattery.dll musí být přítomen ve stejné složce jako IdeapadToolkit.exe</value>
</data>
<data name="EXTREME_PERFORMANCE" xml:space="preserve">
<value>Extrémní výkon</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions IdeapadToolkit/Localization/Strings.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ALREADY_RUNNING" xml:space="preserve">
<value>L'application est déjà en cours d'exécution</value>
</data>
<data name="ALWAYS_ON_USB" xml:space="preserve">
<value>USB toujours activé</value>
</data>
Expand All @@ -132,6 +135,9 @@
<data name="CONSERVATION" xml:space="preserve">
<value>Conservation</value>
</data>
<data name="DLL_MISSING_ERROR" xml:space="preserve">
<value>PowerBattery.dll doit être présent dans le même dossier que IdeapadToolkit.exe</value>
</data>
<data name="EXTREME_PERFORMANCE" xml:space="preserve">
<value>Performances maximales</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions IdeapadToolkit/Localization/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="ALREADY_RUNNING" xml:space="preserve">
<value>The app is already running</value>
</data>
<data name="ALWAYS_ON_USB" xml:space="preserve">
<value>Always on USB</value>
</data>
Expand All @@ -132,6 +135,9 @@
<data name="CONSERVATION" xml:space="preserve">
<value>Conservation</value>
</data>
<data name="DLL_MISSING_ERROR" xml:space="preserve">
<value>PowerBattery.dll has to be present in the same folder as IdeapadToolkit.exe</value>
</data>
<data name="EXTREME_PERFORMANCE" xml:space="preserve">
<value>Extreme Performance</value>
</data>
Expand Down

0 comments on commit fc65b40

Please sign in to comment.