feat(settings): choose German or English for the interface
A language card on the settings page switches all texts right after saving, without a restart; German is the default and the choice is kept in settings.json. The laut.fm station ID and token fields are gone with the library provider, and the device labels now read Für die Hörer and Für dich. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d906222a39
commit
4c8740774d
4 files changed
+110
-88
No files matched your search
@@ -4,6 +4,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Radiosender.Controllers;
|
||||
using Radiosender.Services.Audio;
|
||||
using Radiosender.Services.Library;
|
||||
using Radiosender.Services.Localization;
|
||||
using Radiosender.Services.Providers;
|
||||
using Radiosender.Services.Scheduling;
|
||||
using Radiosender.Services.Settings;
|
||||
@@ -67,8 +68,8 @@ public partial class App : Application
|
||||
{
|
||||
base.OnStartup(e);
|
||||
_services = BuildServices();
|
||||
// Eager: applies settings to generator and audio output before first plan.
|
||||
_services.GetRequiredService<SettingsStore>();
|
||||
// Eager: applies settings to generator and audio output before first plan, language before first window.
|
||||
Loc.SetLanguage(_services.GetRequiredService<SettingsStore>().Current.Language);
|
||||
Wpf.Ui.Appearance.ApplicationThemeManager.ApplySystemTheme();
|
||||
_services.GetRequiredService<MainWindow>().Show();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Radiosender.Services.Localization;
|
||||
using Radiosender.Services.Scheduling;
|
||||
|
||||
namespace Radiosender.Services.Settings;
|
||||
@@ -14,6 +15,8 @@ public record AppSettings
|
||||
|
||||
private static readonly JsonSerializerOptions WriteOptions = new() { WriteIndented = true };
|
||||
|
||||
public string Language { get; init; } = Loc.German;
|
||||
|
||||
public bool NewsAlert { get; init; } = true;
|
||||
|
||||
public int NewsAlertSeconds { get; init; } = 30;
|
||||
@@ -37,8 +40,6 @@ public record AppSettings
|
||||
|
||||
public bool LautFmEnabled { get; init; }
|
||||
|
||||
public string LautFmStationId { get; init; } = "";
|
||||
|
||||
public string LautFmHost { get; init; } = "";
|
||||
|
||||
public int LautFmPort { get; init; } = 8080;
|
||||
@@ -47,20 +48,14 @@ public record AppSettings
|
||||
|
||||
public string LautFmUser { get; init; } = "source";
|
||||
|
||||
// Secrets: plain in memory, DPAPI-encrypted in the file via the Protected* properties.
|
||||
// Secret: plain in memory, DPAPI-encrypted in the file via ProtectedLautFmPassword.
|
||||
[JsonIgnore]
|
||||
public string LautFmPassword { get; init; } = "";
|
||||
|
||||
[JsonIgnore]
|
||||
public string LautFmToken { get; init; } = "";
|
||||
|
||||
[JsonInclude, JsonPropertyName("LautFmPassword")]
|
||||
private string? ProtectedLautFmPassword { get => Protect(LautFmPassword); init => LautFmPassword = Unprotect(value); }
|
||||
|
||||
[JsonInclude, JsonPropertyName("LautFmToken")]
|
||||
private string? ProtectedLautFmToken { get => Protect(LautFmToken); init => LautFmToken = Unprotect(value); }
|
||||
|
||||
// Record ToString would leak secrets into logs/debugger.
|
||||
// Record ToString would leak the password into logs/debugger.
|
||||
public override string ToString() => nameof(AppSettings);
|
||||
|
||||
public static string DefaultPath { get; } = Path.Combine(
|
||||
@@ -68,24 +63,24 @@ public record AppSettings
|
||||
|
||||
public string? Validate()
|
||||
{
|
||||
if (!Loc.IsSupported(Language))
|
||||
return Loc.T("Settings_LanguageUnsupported");
|
||||
if (NewsAlertSeconds is < MinAlertSeconds or > MaxAlertSeconds || ModeratorAlertSeconds is < MinAlertSeconds or > MaxAlertSeconds)
|
||||
return $"Die Hinweiszeit muss zwischen {MinAlertSeconds} und {MaxAlertSeconds} Sekunden liegen.";
|
||||
return Loc.F("Settings_AlertSecondsRange", MinAlertSeconds, MaxAlertSeconds);
|
||||
if (NewsMinutesPerHour < 2)
|
||||
return "Nachrichten brauchen mindestens 2 Minuten pro Stunde.";
|
||||
return Loc.T("Settings_NewsMinMinutes");
|
||||
if (ModeratorMinutesPerHour < 0 || AdMinutesPerHour < 0)
|
||||
return "Minuten pro Stunde dürfen nicht negativ sein.";
|
||||
return Loc.T("Settings_MinutesNegative");
|
||||
if (NewsMinutesPerHour + ModeratorMinutesPerHour + AdMinutesPerHour > 60)
|
||||
return "Nachrichten, Moderation und Werbung dürfen zusammen höchstens 60 Minuten pro Stunde dauern.";
|
||||
return Loc.T("Settings_MinutesTotal");
|
||||
if (LautFmEnabled)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(LautFmHost) || Uri.CheckHostName(LautFmHost.Trim()) == UriHostNameType.Unknown)
|
||||
return "Für laut.fm fehlt ein gültiger Server.";
|
||||
return Loc.T("Settings_LautFmHostMissing");
|
||||
if (LautFmPort is < 1 or > 65535)
|
||||
return "Der laut.fm-Port muss zwischen 1 und 65535 liegen.";
|
||||
return Loc.T("Settings_LautFmPortRange");
|
||||
if (string.IsNullOrWhiteSpace(LautFmMount))
|
||||
return "Für laut.fm fehlt der Mountpoint.";
|
||||
if (LautFmToken.Length > 0 && string.IsNullOrWhiteSpace(LautFmStationId))
|
||||
return "Für die laut.fm-Bibliothek fehlt die Stations-ID.";
|
||||
return Loc.T("Settings_LautFmMountMissing");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
|
||||
Title="Einstellungen"
|
||||
xmlns:l="clr-namespace:Radiosender.Views"
|
||||
Title="{l:Tr Settings_Title}"
|
||||
Foreground="{DynamicResource TextFillColorPrimaryBrush}"
|
||||
Loaded="OnLoaded">
|
||||
Loaded="OnLoaded"
|
||||
Unloaded="OnUnloaded">
|
||||
<Page.Resources>
|
||||
<Style x:Key="Card" TargetType="Border">
|
||||
<Setter Property="Margin" Value="0,0,0,12" />
|
||||
@@ -37,6 +39,22 @@
|
||||
<StackPanel MaxWidth="640" Margin="24" HorizontalAlignment="Left">
|
||||
<ui:InfoBar x:Name="Message" Margin="0,0,0,12" IsClosable="True" IsOpen="False" />
|
||||
|
||||
<!-- Language: names stay in their own language so everyone finds theirs -->
|
||||
<Border Style="{StaticResource Card}">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="220" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Label VerticalAlignment="Center" Content="{l:Tr Settings_Language}" Target="{Binding ElementName=LanguageBox}" />
|
||||
<ComboBox x:Name="LanguageBox" Grid.Column="1" Width="200" HorizontalAlignment="Left"
|
||||
AutomationProperties.Name="{l:Tr Settings_Language}">
|
||||
<ComboBoxItem Content="Deutsch" Tag="de" />
|
||||
<ComboBoxItem Content="English" Tag="en" />
|
||||
</ComboBox>
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- Speaking alerts: one block per kind -->
|
||||
<Border Style="{StaticResource Card}">
|
||||
<Grid>
|
||||
@@ -49,17 +67,17 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ui:ToggleSwitch x:Name="NewsAlertSwitch" Grid.ColumnSpan="2" Content="Hinweis vor Nachrichten" />
|
||||
<ui:ToggleSwitch x:Name="NewsAlertSwitch" Grid.ColumnSpan="2" Content="{l:Tr Settings_NewsAlert}" />
|
||||
<Label Grid.Row="1" Margin="0,12,0,0" VerticalAlignment="Center"
|
||||
Content="Sekunden vor dem Start"
|
||||
Content="{l:Tr Settings_SecondsBefore}"
|
||||
Target="{Binding ElementName=NewsSecondsBox}"
|
||||
IsEnabled="{Binding IsChecked, ElementName=NewsAlertSwitch}" />
|
||||
<ui:NumberBox x:Name="NewsSecondsBox" Grid.Row="1" Grid.Column="1" Margin="0,12,0,0"
|
||||
Style="{StaticResource Seconds}"
|
||||
AutomationProperties.Name="Sekunden vor Nachrichten"
|
||||
AutomationProperties.Name="{l:Tr Settings_NewsSecondsName}"
|
||||
IsEnabled="{Binding IsChecked, ElementName=NewsAlertSwitch}" />
|
||||
<CheckBox x:Name="NewsSoundBox" Grid.Row="2" Grid.ColumnSpan="2" Margin="0,8,0,0"
|
||||
Content="Bing-Ton abspielen"
|
||||
Content="{l:Tr Settings_PlayChime}"
|
||||
IsEnabled="{Binding IsChecked, ElementName=NewsAlertSwitch}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
@@ -75,17 +93,17 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ui:ToggleSwitch x:Name="ModeratorAlertSwitch" Grid.ColumnSpan="2" Content="Hinweis vor Moderation" />
|
||||
<ui:ToggleSwitch x:Name="ModeratorAlertSwitch" Grid.ColumnSpan="2" Content="{l:Tr Settings_ModeratorAlert}" />
|
||||
<Label Grid.Row="1" Margin="0,12,0,0" VerticalAlignment="Center"
|
||||
Content="Sekunden vor dem Start"
|
||||
Content="{l:Tr Settings_SecondsBefore}"
|
||||
Target="{Binding ElementName=ModeratorSecondsBox}"
|
||||
IsEnabled="{Binding IsChecked, ElementName=ModeratorAlertSwitch}" />
|
||||
<ui:NumberBox x:Name="ModeratorSecondsBox" Grid.Row="1" Grid.Column="1" Margin="0,12,0,0"
|
||||
Style="{StaticResource Seconds}"
|
||||
AutomationProperties.Name="Sekunden vor Moderation"
|
||||
AutomationProperties.Name="{l:Tr Settings_ModeratorSecondsName}"
|
||||
IsEnabled="{Binding IsChecked, ElementName=ModeratorAlertSwitch}" />
|
||||
<CheckBox x:Name="ModeratorSoundBox" Grid.Row="2" Grid.ColumnSpan="2" Margin="0,8,0,0"
|
||||
Content="Bing-Ton abspielen"
|
||||
Content="{l:Tr Settings_PlayChime}"
|
||||
IsEnabled="{Binding IsChecked, ElementName=ModeratorAlertSwitch}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
@@ -103,18 +121,18 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ui:TextBlock Grid.ColumnSpan="2" FontTypography="BodyStrong" Text="Audio-Ausgabe" />
|
||||
<ui:TextBlock Grid.ColumnSpan="2" FontTypography="BodyStrong" Text="{l:Tr Settings_AudioOutput}" />
|
||||
<Label Grid.Row="1" Margin="0,12,0,0" VerticalAlignment="Center"
|
||||
Content="Sendung (für andere)" Target="{Binding ElementName=BroadcastDeviceBox}" />
|
||||
Content="{l:Tr Settings_ForListeners}" Target="{Binding ElementName=BroadcastDeviceBox}" />
|
||||
<ComboBox x:Name="BroadcastDeviceBox" Grid.Row="1" Grid.Column="1" Margin="0,12,0,0"
|
||||
AutomationProperties.Name="Ausgabegerät für die Sendung" />
|
||||
AutomationProperties.Name="{l:Tr Settings_BroadcastDeviceName}" />
|
||||
<Label Grid.Row="2" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Für mich (Kopfhörer)" Target="{Binding ElementName=MonitorDeviceBox}" />
|
||||
Content="{l:Tr Settings_ForYou}" Target="{Binding ElementName=MonitorDeviceBox}" />
|
||||
<ComboBox x:Name="MonitorDeviceBox" Grid.Row="2" Grid.Column="1" Margin="0,8,0,0"
|
||||
AutomationProperties.Name="Ausgabegerät für mich" />
|
||||
AutomationProperties.Name="{l:Tr Settings_MonitorDeviceName}" />
|
||||
<ui:TextBlock Grid.Row="3" Grid.ColumnSpan="2" Margin="0,12,0,0" TextWrapping="Wrap"
|
||||
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
|
||||
Text="Getrennte Lautstärken für dich und für andere brauchen zwei verschiedene Geräte. Mit nur einem Gerät hörst du deinen eigenen Mix." />
|
||||
Text="{l:Tr Settings_DevicesHint}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
@@ -132,36 +150,36 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ui:TextBlock Grid.ColumnSpan="2" FontTypography="BodyStrong" Text="Minuten pro Stunde" />
|
||||
<ui:TextBlock Grid.ColumnSpan="2" FontTypography="BodyStrong" Text="{l:Tr Settings_MinutesPerHour}" />
|
||||
<Label Grid.Row="1" Margin="0,12,0,0" VerticalAlignment="Center"
|
||||
Content="Nachrichten" Target="{Binding ElementName=NewsMinutesBox}" />
|
||||
Content="{l:Tr Settings_News}" Target="{Binding ElementName=NewsMinutesBox}" />
|
||||
<ui:NumberBox x:Name="NewsMinutesBox" Grid.Row="1" Grid.Column="1" Margin="0,12,0,0"
|
||||
Style="{StaticResource Minutes}" Minimum="2"
|
||||
AutomationProperties.Name="Nachrichten-Minuten pro Stunde" />
|
||||
AutomationProperties.Name="{l:Tr Settings_NewsMinutesName}" />
|
||||
<Label Grid.Row="2" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Moderation" Target="{Binding ElementName=ModeratorMinutesBox}" />
|
||||
Content="{l:Tr Settings_Moderation}" Target="{Binding ElementName=ModeratorMinutesBox}" />
|
||||
<ui:NumberBox x:Name="ModeratorMinutesBox" Grid.Row="2" Grid.Column="1" Margin="0,8,0,0"
|
||||
Style="{StaticResource Minutes}"
|
||||
AutomationProperties.Name="Moderations-Minuten pro Stunde" />
|
||||
AutomationProperties.Name="{l:Tr Settings_ModeratorMinutesName}" />
|
||||
<Label Grid.Row="3" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Werbung" Target="{Binding ElementName=AdMinutesBox}" />
|
||||
Content="{l:Tr Settings_Ads}" Target="{Binding ElementName=AdMinutesBox}" />
|
||||
<ui:NumberBox x:Name="AdMinutesBox" Grid.Row="3" Grid.Column="1" Margin="0,8,0,0"
|
||||
Style="{StaticResource Minutes}"
|
||||
AutomationProperties.Name="Werbe-Minuten pro Stunde" />
|
||||
AutomationProperties.Name="{l:Tr Settings_AdMinutesName}" />
|
||||
<ui:TextBlock Grid.Row="4" Grid.ColumnSpan="2" Margin="0,12,0,0" TextWrapping="Wrap"
|
||||
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
|
||||
Text="Sollwerte, zusammen höchstens 60 Minuten. Gilt für den nächsten Plan." />
|
||||
Text="{l:Tr Settings_MinutesHint}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
<!-- laut.fm: live streaming and the station's library -->
|
||||
<!-- laut.fm: live streaming -->
|
||||
<Border Style="{StaticResource Card}">
|
||||
<StackPanel>
|
||||
<ui:ToggleSwitch x:Name="LautFmSwitch" Content="laut.fm"
|
||||
Checked="OnLautFmChanged" Unchecked="OnLautFmChanged" />
|
||||
<ui:TextBlock Margin="0,8,0,0" TextWrapping="Wrap"
|
||||
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
|
||||
Text="Sendet live auf deine laut.fm-Station und bietet ihre Musik beim Import an. Im Plan erscheint dann der Button „Live“." />
|
||||
Text="{l:Tr Settings_LautFmInfo}" />
|
||||
<Grid x:Name="LautFmFields" Margin="0,4,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="220" />
|
||||
@@ -175,57 +193,44 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<ui:TextBlock Margin="0,12,0,0" Grid.ColumnSpan="2" FontTypography="BodyStrong" Text="Live senden" />
|
||||
<ui:TextBlock Margin="0,12,0,0" Grid.ColumnSpan="2" FontTypography="BodyStrong" Text="{l:Tr Settings_LiveHeader}" />
|
||||
<Label Grid.Row="1" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Server" Target="{Binding ElementName=LautFmHostBox}" />
|
||||
<ui:TextBox x:Name="LautFmHostBox" Grid.Row="1" Grid.Column="1" Margin="0,8,0,0"
|
||||
AutomationProperties.Name="laut.fm-Server" />
|
||||
AutomationProperties.Name="{l:Tr Settings_LautFmHostName}" />
|
||||
<Label Grid.Row="2" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Port" Target="{Binding ElementName=LautFmPortBox}" />
|
||||
<ui:NumberBox x:Name="LautFmPortBox" Grid.Row="2" Grid.Column="1" Margin="0,8,0,0"
|
||||
Width="130" HorizontalAlignment="Left" Minimum="1" Maximum="65535"
|
||||
MaxDecimalPlaces="0" SmallChange="1" ClearButtonEnabled="False"
|
||||
AutomationProperties.Name="laut.fm-Port" />
|
||||
AutomationProperties.Name="{l:Tr Settings_LautFmPortName}" />
|
||||
<Label Grid.Row="3" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Mountpoint" Target="{Binding ElementName=LautFmMountBox}" />
|
||||
<ui:TextBox x:Name="LautFmMountBox" Grid.Row="3" Grid.Column="1" Margin="0,8,0,0"
|
||||
AutomationProperties.Name="laut.fm-Mountpoint" />
|
||||
AutomationProperties.Name="{l:Tr Settings_LautFmMountName}" />
|
||||
<Label Grid.Row="4" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Benutzer" Target="{Binding ElementName=LautFmUserBox}" />
|
||||
Content="{l:Tr Settings_User}" Target="{Binding ElementName=LautFmUserBox}" />
|
||||
<ui:TextBox x:Name="LautFmUserBox" Grid.Row="4" Grid.Column="1" Margin="0,8,0,0"
|
||||
AutomationProperties.Name="laut.fm-Benutzer" />
|
||||
AutomationProperties.Name="{l:Tr Settings_LautFmUserName}" />
|
||||
<Label Grid.Row="5" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Passwort" Target="{Binding ElementName=LautFmPasswordBox}" />
|
||||
Content="{l:Tr Settings_Password}" Target="{Binding ElementName=LautFmPasswordBox}" />
|
||||
<ui:PasswordBox x:Name="LautFmPasswordBox" Grid.Row="5" Grid.Column="1" Margin="0,8,0,0"
|
||||
AutomationProperties.Name="laut.fm-Passwort" />
|
||||
AutomationProperties.Name="{l:Tr Settings_LautFmPasswordName}" />
|
||||
<ui:TextBlock Grid.Row="6" Grid.ColumnSpan="2" Margin="0,8,0,0" TextWrapping="Wrap"
|
||||
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
|
||||
Text="Diese Werte stehen in Radioadmin unter „Live senden“." />
|
||||
<ui:TextBlock Grid.Row="7" Margin="0,16,0,0" Grid.ColumnSpan="2" FontTypography="BodyStrong" Text="Bibliothek" />
|
||||
<Label Grid.Row="8" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Stations-ID" Target="{Binding ElementName=LautFmStationBox}" />
|
||||
<ui:TextBox x:Name="LautFmStationBox" Grid.Row="8" Grid.Column="1" Margin="0,8,0,0"
|
||||
AutomationProperties.Name="laut.fm-Stations-ID" />
|
||||
<Label Grid.Row="9" Margin="0,8,0,0" VerticalAlignment="Center"
|
||||
Content="Radioadmin-Token" Target="{Binding ElementName=LautFmTokenBox}" />
|
||||
<ui:PasswordBox x:Name="LautFmTokenBox" Grid.Row="9" Grid.Column="1" Margin="0,8,0,0"
|
||||
AutomationProperties.Name="Radioadmin-Token"
|
||||
ToolTip="Nach dem Login in Radioadmin in den Entwicklertools des Browsers: Lokaler Speicher, Schlüssel laut.fm.api.token." />
|
||||
Text="{l:Tr Settings_LautFmValuesHint}" />
|
||||
</Grid>
|
||||
<ui:TextBlock x:Name="LautFmHint" Margin="0,12,0,0" TextWrapping="Wrap"
|
||||
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
|
||||
Text="Passwort und Token werden verschlüsselt für deinen Windows-Benutzer gespeichert. Die Bibliothek nutzt eine nicht offizielle laut.fm-Schnittstelle und kann ohne Vorwarnung ausfallen." />
|
||||
Text="{l:Tr Settings_LautFmPasswordHint}" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<StackPanel Margin="0,4,0,0" Orientation="Horizontal">
|
||||
<ui:Button Appearance="Primary" MinWidth="110" Content="Speichern" Icon="{ui:SymbolIcon Save24}" Click="OnSave" />
|
||||
<ui:Button Margin="8,0,0,0" MinWidth="110" Content="Zurücksetzen" Icon="{ui:SymbolIcon ArrowReset24}"
|
||||
ToolTip="Setzt die Standardwerte ins Formular. Mit Speichern übernehmen."
|
||||
<ui:Button Appearance="Primary" MinWidth="110" Content="{l:Tr Settings_Save}" Icon="{ui:SymbolIcon Save24}" Click="OnSave" />
|
||||
<ui:Button Margin="8,0,0,0" MinWidth="110" Content="{l:Tr Settings_Reset}" Icon="{ui:SymbolIcon ArrowReset24}"
|
||||
ToolTip="{l:Tr Settings_ResetTooltip}"
|
||||
Click="OnReset" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using Radiosender.Services.Audio;
|
||||
using Radiosender.Services.Localization;
|
||||
using Radiosender.Services.Settings;
|
||||
using Wpf.Ui.Controls;
|
||||
|
||||
@@ -17,19 +18,41 @@ public partial class SettingsPage : Page
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void OnLoaded(object sender, RoutedEventArgs e) => Show(_store.Current);
|
||||
private void OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Loc.Changed -= OnLanguageChanged;
|
||||
Loc.Changed += OnLanguageChanged;
|
||||
Show(_store.Current);
|
||||
}
|
||||
|
||||
private void OnUnloaded(object sender, RoutedEventArgs e) => Loc.Changed -= OnLanguageChanged;
|
||||
|
||||
// Re-fill the code-set first entries, keep the selection.
|
||||
private void OnLanguageChanged(object? sender, EventArgs e)
|
||||
{
|
||||
var (broadcast, monitor) = (BroadcastDeviceBox.SelectedIndex, MonitorDeviceBox.SelectedIndex);
|
||||
FillDevices();
|
||||
BroadcastDeviceBox.SelectedIndex = broadcast;
|
||||
MonitorDeviceBox.SelectedIndex = monitor;
|
||||
}
|
||||
|
||||
private List<string> _devices = [];
|
||||
|
||||
// Index 0 of each list = no device name (null).
|
||||
private const string DefaultDevice = "Windows-Standardgerät";
|
||||
private const string NoDevice = "Kein eigenes Gerät";
|
||||
private void FillDevices()
|
||||
{
|
||||
BroadcastDeviceBox.ItemsSource = _devices.Prepend(Loc.T("Settings_DefaultDevice")).ToList();
|
||||
MonitorDeviceBox.ItemsSource = _devices.Prepend(Loc.T("Settings_NoDevice")).ToList();
|
||||
}
|
||||
|
||||
private void Show(AppSettings settings)
|
||||
{
|
||||
var devices = ProgramOutput.DeviceNames().ToList();
|
||||
BroadcastDeviceBox.ItemsSource = devices.Prepend(DefaultDevice).ToList();
|
||||
MonitorDeviceBox.ItemsSource = devices.Prepend(NoDevice).ToList();
|
||||
_devices = ProgramOutput.DeviceNames().ToList();
|
||||
var devices = _devices;
|
||||
FillDevices();
|
||||
BroadcastDeviceBox.SelectedIndex = devices.IndexOf(settings.BroadcastDevice ?? "") + 1;
|
||||
MonitorDeviceBox.SelectedIndex = devices.IndexOf(settings.MonitorDevice ?? "") + 1;
|
||||
LanguageBox.SelectedIndex = settings.Language == Loc.English ? 1 : 0;
|
||||
NewsAlertSwitch.IsChecked = settings.NewsAlert;
|
||||
NewsSecondsBox.Value = settings.NewsAlertSeconds;
|
||||
NewsSoundBox.IsChecked = settings.NewsAlertSound;
|
||||
@@ -45,8 +68,6 @@ public partial class SettingsPage : Page
|
||||
LautFmMountBox.Text = settings.LautFmMount;
|
||||
LautFmUserBox.Text = settings.LautFmUser;
|
||||
LautFmPasswordBox.Password = settings.LautFmPassword;
|
||||
LautFmStationBox.Text = settings.LautFmStationId;
|
||||
LautFmTokenBox.Password = settings.LautFmToken;
|
||||
OnLautFmChanged(this, new RoutedEventArgs());
|
||||
}
|
||||
|
||||
@@ -58,6 +79,7 @@ public partial class SettingsPage : Page
|
||||
|
||||
private AppSettings Read() => new()
|
||||
{
|
||||
Language = (LanguageBox.SelectedItem as ComboBoxItem)?.Tag as string ?? Loc.German,
|
||||
NewsAlert = NewsAlertSwitch.IsChecked == true,
|
||||
NewsAlertSeconds = (int)(NewsSecondsBox.Value ?? Defaults.NewsAlertSeconds),
|
||||
NewsAlertSound = NewsSoundBox.IsChecked == true,
|
||||
@@ -75,8 +97,6 @@ public partial class SettingsPage : Page
|
||||
LautFmMount = LautFmMountBox.Text.Trim(),
|
||||
LautFmUser = LautFmUserBox.Text.Trim(),
|
||||
LautFmPassword = LautFmPasswordBox.Password,
|
||||
LautFmStationId = LautFmStationBox.Text.Trim(),
|
||||
LautFmToken = LautFmTokenBox.Password.Trim(),
|
||||
};
|
||||
|
||||
private void OnSave(object sender, RoutedEventArgs e)
|
||||
@@ -84,29 +104,30 @@ public partial class SettingsPage : Page
|
||||
var settings = Read();
|
||||
if (settings.Validate() is { } problem)
|
||||
{
|
||||
ShowMessage(InfoBarSeverity.Error, "Nicht gespeichert", problem);
|
||||
ShowMessage(InfoBarSeverity.Error, Loc.T("Settings_NotSaved"), problem);
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_store.Save(settings);
|
||||
ShowMessage(InfoBarSeverity.Success, "Gespeichert", "Minuten pro Stunde gelten für den nächsten Plan.");
|
||||
Loc.SetLanguage(settings.Language);
|
||||
ShowMessage(InfoBarSeverity.Success, Loc.T("Settings_Saved"), Loc.T("Settings_SavedDetail"));
|
||||
}
|
||||
catch (NAudio.MmException)
|
||||
{
|
||||
ShowMessage(InfoBarSeverity.Error, "Nicht gespeichert", "Ein gewähltes Audiogerät konnte nicht geöffnet werden. Die bisherigen Geräte bleiben aktiv.");
|
||||
ShowMessage(InfoBarSeverity.Error, Loc.T("Settings_NotSaved"), Loc.T("Settings_AudioDeviceFailed"));
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
|
||||
{
|
||||
ShowMessage(InfoBarSeverity.Error, "Nicht gespeichert", ex.Message);
|
||||
ShowMessage(InfoBarSeverity.Error, Loc.T("Settings_NotSaved"), ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnReset(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Show(Defaults);
|
||||
ShowMessage(InfoBarSeverity.Informational, "Standardwerte eingesetzt", "Mit Speichern übernehmen.");
|
||||
ShowMessage(InfoBarSeverity.Informational, Loc.T("Settings_DefaultsApplied"), Loc.T("Settings_DefaultsApplyHint"));
|
||||
}
|
||||
|
||||
private void ShowMessage(InfoBarSeverity severity, string title, string text)
|
||||
|
||||
Reference in new issue
Block a user