Skip to content

Commit

Permalink
The settings UI is now loading (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed Mar 21, 2021
1 parent e9f6152 commit df832cc
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 6 deletions.
75 changes: 69 additions & 6 deletions InternetTest/InternetTest/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ MIT License
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
using InternetTest.Classes;
using LeoCorpLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -49,33 +51,94 @@ public partial class SettingsPage : Page
public SettingsPage()
{
InitializeComponent();
InitUI();
}

private async void InitUI()
{
try
{
// Load RadioButtons
DarkRadioBtn.IsChecked = Global.Settings.IsDarkTheme; // Change IsChecked property
LightRadioBtn.IsChecked = !Global.Settings.IsDarkTheme; // Change IsChecked property

// Load LangComboBox
LangComboBox.Items.Add(Properties.Resources.Default); // Add "default"

for (int i = 0; i < Global.LanguageList.Count; i++)
{
LangComboBox.Items.Add(Global.LanguageList[i]);
}

LangComboBox.SelectedIndex = (Global.Settings.Language == "_default") ? 0 : Global.LanguageCodeList.IndexOf(Global.Settings.Language) + 1;

LangApplyBtn.Visibility = Visibility.Hidden; // Hide
ThemeApplyBtn.Visibility = Visibility.Hidden; // Hide

// Update the UpdateStatusTxt
isAvailable = Update.IsAvailable(Global.Version, await Update.GetLastVersionAsync(Global.LastVersionLink));

UpdateStatusTxt.Text = isAvailable ? Properties.Resources.AvailableUpdates : Properties.Resources.UpToDate; // Set the text
InstallIconTxt.Text = isAvailable ? "\uF152" : "\uF191"; // Set text
InstallMsgTxt.Text = isAvailable ? Properties.Resources.Install : Properties.Resources.CheckUpdate; // Set text
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.StackTrace, MessageBoxButton.OK, MessageBoxImage.Error); // Show error
}
}

private void RefreshInstallBtn_Click(object sender, RoutedEventArgs e)
private async void RefreshInstallBtn_Click(object sender, RoutedEventArgs e)
{
if (isAvailable) // If there is updates
{
string lastVersion = await Update.GetLastVersionAsync(Global.LastVersionLink); // Get last version
if (MessageBox.Show(Properties.Resources.InstallConfirmMsg, $"{Properties.Resources.InstallVersion} {lastVersion}", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
{
Env.ExecuteAsAdmin(Directory.GetCurrentDirectory() + @"\Xalyus Updater.exe"); // Start the updater
Environment.Exit(0); // Close
}
}
else
{
// Update the UpdateStatusTxt
isAvailable = Update.IsAvailable(Global.Version, await Update.GetLastVersionAsync(Global.LastVersionLink));

UpdateStatusTxt.Text = isAvailable ? Properties.Resources.AvailableUpdates : Properties.Resources.UpToDate; // Set the text
InstallIconTxt.Text = isAvailable ? "\uF152" : "\uF191"; // Set text
InstallMsgTxt.Text = isAvailable ? Properties.Resources.Install : Properties.Resources.CheckUpdate; // Set text
}
}

private void ThemeApplyBtn_Click(object sender, RoutedEventArgs e)
{

Global.Settings.IsDarkTheme = DarkRadioBtn.IsChecked.Value; // Set the settings
SettingsManager.Save(); // Save the changes
ThemeApplyBtn.Visibility = Visibility.Hidden; // Hide
DisplayRestartMessage();
}

private void LangComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{

LangApplyBtn.Visibility = Visibility.Visible; // Show the LangApplyBtn button
}

private void LangApplyBtn_Click(object sender, RoutedEventArgs e)
{

Global.Settings.Language = LangComboBox.Text switch
{
"English (United States)" => Global.LanguageCodeList[0], // Set the settings value
"Français (France)" => Global.LanguageCodeList[1], // Set the settings value
_ => "_default" // Set the settings value
};
SettingsManager.Save(); // Save the changes
LangApplyBtn.Visibility = Visibility.Hidden; // Hide
DisplayRestartMessage();
}

private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{

//TODO: Add licenses
}

private void LightRadioBtn_Checked(object sender, RoutedEventArgs e)
Expand All @@ -95,7 +158,7 @@ private void DisplayRestartMessage()
{
if (MessageBox.Show(Properties.Resources.NeedRestartToApplyChanges, Properties.Resources.InternetTest, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
Process.Start(Directory.GetCurrentDirectory() + @"\Gerayis.exe"); // Start
Process.Start(Directory.GetCurrentDirectory() + @"\InternetTest.exe"); // Start
Environment.Exit(0); // Close
}
}
Expand Down
63 changes: 63 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.Designer.cs

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

21 changes: 21 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.en-US.resx
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,25 @@
<data name="NeedRestartToApplyChanges" xml:space="preserve">
<value>InternetTest needs to restart to apply the changes. Do you want to restart now?</value>
</data>
<data name="Default" xml:space="preserve">
<value>Default</value>
</data>
<data name="UpToDate" xml:space="preserve">
<value>InternetTest is up to date.</value>
</data>
<data name="AvailableUpdates" xml:space="preserve">
<value>Updates are available.</value>
</data>
<data name="CheckUpdate" xml:space="preserve">
<value>Check updates</value>
</data>
<data name="InstallConfirmMsg" xml:space="preserve">
<value>To install updates, InternetTest needs to restarts. Do you want to continue?</value>
</data>
<data name="InstallVersion" xml:space="preserve">
<value>Install version</value>
</data>
<data name="Version" xml:space="preserve">
<value>Version</value>
</data>
</root>
21 changes: 21 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.fr-FR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,25 @@
<data name="NeedRestartToApplyChanges" xml:space="preserve">
<value>InternetTest doit redémarrer pour appliquer les changements. Voulez-vous redémarrer maintenant ?</value>
</data>
<data name="Default" xml:space="preserve">
<value>Par défaut</value>
</data>
<data name="UpToDate" xml:space="preserve">
<value>InternetTest est à jour.</value>
</data>
<data name="AvailableUpdates" xml:space="preserve">
<value>Des mises à jour sont disponibles.</value>
</data>
<data name="CheckUpdate" xml:space="preserve">
<value>Rechercher des mises à jour</value>
</data>
<data name="InstallConfirmMsg" xml:space="preserve">
<value>Pour installer les mises à jour, InternetTest doit redémarrer. Voulez-vous continuer ?</value>
</data>
<data name="InstallVersion" xml:space="preserve">
<value>Installer la version</value>
</data>
<data name="Version" xml:space="preserve">
<value>Version</value>
</data>
</root>
21 changes: 21 additions & 0 deletions InternetTest/InternetTest/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,25 @@
<data name="NeedRestartToApplyChanges" xml:space="preserve">
<value>InternetTest needs to restart to apply the changes. Do you want to restart now?</value>
</data>
<data name="Default" xml:space="preserve">
<value>Default</value>
</data>
<data name="UpToDate" xml:space="preserve">
<value>InternetTest is up to date.</value>
</data>
<data name="AvailableUpdates" xml:space="preserve">
<value>Updates are available.</value>
</data>
<data name="CheckUpdate" xml:space="preserve">
<value>Check updates</value>
</data>
<data name="InstallConfirmMsg" xml:space="preserve">
<value>To install updates, InternetTest needs to restarts. Do you want to continue?</value>
</data>
<data name="InstallVersion" xml:space="preserve">
<value>Install version</value>
</data>
<data name="Version" xml:space="preserve">
<value>Version</value>
</data>
</root>

0 comments on commit df832cc

Please sign in to comment.