diff --git a/Trdo/Pages/SettingsPage.xaml b/Trdo/Pages/SettingsPage.xaml
index d1a31c0..edc234b 100644
--- a/Trdo/Pages/SettingsPage.xaml
+++ b/Trdo/Pages/SettingsPage.xaml
@@ -43,9 +43,52 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /// Gets or sets whether the app should automatically start playing the last selected station on startup.
+ /// Defaults to false when no saved value exists.
+ ///
+ public static bool AutoPlayOnStartup
+ {
+ get
+ {
+ try
+ {
+ if (ApplicationData.Current.LocalSettings.Values.TryGetValue(AutoPlayOnStartupKey, out object? value))
+ {
+ return value switch
+ {
+ bool b => b,
+ string s when bool.TryParse(s, out bool b2) => b2,
+ _ => false
+ };
+ }
+ return false;
+ }
+ catch
+ {
+ return false;
+ }
+ }
+ set
+ {
+ try
+ {
+ ApplicationData.Current.LocalSettings.Values[AutoPlayOnStartupKey] = value;
+ }
+ catch
+ {
+ // Silently fail if unable to save
+ }
+ }
+ }
///
/// Gets or sets whether the volume slider is visible on the playing page.
diff --git a/Trdo/Services/WindowPlacementService.cs b/Trdo/Services/WindowPlacementService.cs
index 2c47938..10e7576 100644
--- a/Trdo/Services/WindowPlacementService.cs
+++ b/Trdo/Services/WindowPlacementService.cs
@@ -29,8 +29,11 @@ public static void PositionWindowNearAnchor(Window window, int width, int height
int x = placeLeft ? anchor.X - width - WindowMargin : anchor.X + WindowMargin;
int y = placeAbove ? anchor.Y - height - WindowMargin : anchor.Y + WindowMargin;
- x = System.Math.Clamp(x, workArea.X, workArea.X + workArea.Width - width);
- y = System.Math.Clamp(y, workArea.Y, workArea.Y + workArea.Height - height);
+ int maxX = System.Math.Max(workArea.X, workArea.X + workArea.Width - width);
+ int maxY = System.Math.Max(workArea.Y, workArea.Y + workArea.Height - height);
+
+ x = System.Math.Clamp(x, workArea.X, maxX);
+ y = System.Math.Clamp(y, workArea.Y, maxY);
window.MoveAndResize(x, y, width, height);
}
diff --git a/Trdo/ViewModels/PlayerViewModel.cs b/Trdo/ViewModels/PlayerViewModel.cs
index 53f21ff..614d335 100644
--- a/Trdo/ViewModels/PlayerViewModel.cs
+++ b/Trdo/ViewModels/PlayerViewModel.cs
@@ -108,6 +108,13 @@ public PlayerViewModel()
{
Debug.WriteLine($"[PlayerViewModel] Initializing stream with URL: {_selectedStation.StreamUrl}");
InitializeStream(_selectedStation.StreamUrl);
+
+ // Auto-play on startup if the setting is enabled
+ if (SettingsService.AutoPlayOnStartup)
+ {
+ Debug.WriteLine("[PlayerViewModel] AutoPlayOnStartup is enabled, starting playback...");
+ _player.Play();
+ }
}
else
{
diff --git a/Trdo/ViewModels/SettingsViewModel.cs b/Trdo/ViewModels/SettingsViewModel.cs
index 213852c..ac1ddb2 100644
--- a/Trdo/ViewModels/SettingsViewModel.cs
+++ b/Trdo/ViewModels/SettingsViewModel.cs
@@ -20,6 +20,7 @@ public partial class SettingsViewModel : INotifyPropertyChanged
private string _startupToggleText = "Off";
private string _watchdogToggleText = "Off";
private string _autoBufferToggleText = "Off";
+ private string _autoPlayOnStartupToggleText = "Off";
private StartupTask? _startupTask;
private bool _initDone;
@@ -27,7 +28,7 @@ public partial class SettingsViewModel : INotifyPropertyChanged
public SettingsViewModel()
{
- _playerViewModel = new PlayerViewModel();
+ _playerViewModel = PlayerViewModel.Shared;
// Subscribe to PlayerViewModel property changes
_playerViewModel.PropertyChanged += (_, args) =>
@@ -57,6 +58,7 @@ public SettingsViewModel()
// Initialize toggle text
WatchdogToggleText = GetToggleText(_playerViewModel.WatchdogEnabled);
AutoBufferToggleText = GetToggleText(_playerViewModel.AutoBufferIncreaseEnabled);
+ AutoPlayOnStartupToggleText = GetToggleText(SettingsService.AutoPlayOnStartup);
// Initialize startup task
_ = InitializeStartupTaskAsync();
@@ -101,6 +103,32 @@ public string StartupToggleText
}
}
+ ///
+ /// Gets or sets whether the app should automatically start playing the last selected station on startup.
+ ///
+ public bool IsAutoPlayOnStartupEnabled
+ {
+ get => SettingsService.AutoPlayOnStartup;
+ set
+ {
+ if (value == SettingsService.AutoPlayOnStartup) return;
+ SettingsService.AutoPlayOnStartup = value;
+ OnPropertyChanged();
+ AutoPlayOnStartupToggleText = GetToggleText(value);
+ }
+ }
+
+ public string AutoPlayOnStartupToggleText
+ {
+ get => _autoPlayOnStartupToggleText;
+ set
+ {
+ if (value == _autoPlayOnStartupToggleText) return;
+ _autoPlayOnStartupToggleText = value;
+ OnPropertyChanged();
+ }
+ }
+
public bool IsWatchdogEnabled
{
get => _playerViewModel.WatchdogEnabled;