Skip to content

Commit cfe7d6d

Browse files
committed
Listen to UserMessage only if caller requires it. This should reduce issues when switching users with different skins. Currently MP2 still crashes
1 parent f9c8009 commit cfe7d6d

9 files changed

Lines changed: 32 additions & 10 deletions

File tree

MediaPortal/Source/Core/MediaPortal.Common/Services/Settings/SettingsChangeWatcher.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ You should have received a copy of the GNU General Public License
2323
#endregion
2424

2525
using System;
26+
using System.Collections.Generic;
27+
using System.Threading.Tasks;
2628
using MediaPortal.Common.Messaging;
2729
using MediaPortal.Common.Settings;
2830
using MediaPortal.Common.UserManagement;
@@ -45,8 +47,14 @@ public class SettingsChangeWatcher<T> : IDisposable
4547
#endregion
4648

4749
public SettingsChangeWatcher()
50+
: this(false) { }
51+
52+
public SettingsChangeWatcher(bool updateOnUserChange)
4853
{
49-
_messageQueue = new AsynchronousMessageQueue(this, new string[] { SettingsManagerMessaging.CHANNEL, UserMessaging.CHANNEL });
54+
List<string> channels = new List<string> { SettingsManagerMessaging.CHANNEL };
55+
if (updateOnUserChange)
56+
channels.Add(UserMessaging.CHANNEL);
57+
_messageQueue = new AsynchronousMessageQueue(this, channels);
5058
_messageQueue.MessageReceived += OnMessageReceived;
5159
_messageQueue.Start();
5260
}
@@ -67,6 +75,14 @@ public T Settings
6775
}
6876
}
6977

78+
/// <summary>
79+
/// Refreshes the settings asynchronously.
80+
/// </summary>
81+
public void RefreshAsync()
82+
{
83+
Task.Run(() => Refresh());
84+
}
85+
7086
/// <summary>
7187
/// Forces the refresh of the settings.
7288
/// </summary>
@@ -88,7 +104,7 @@ protected void OnMessageReceived(AsynchronousMessageQueue queue, SystemMessage m
88104
{
89105
// If the user has been changed, refresh the settings in every case.
90106
case UserMessaging.MessageType.UserChanged:
91-
Refresh();
107+
RefreshAsync();
92108
break;
93109
}
94110
}

MediaPortal/Source/UI/Players/RefreshRateChanger/VideoFpsWatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class VideoFpsWatcher : IPluginStateTracker, IDisposable
4444
protected Timer _timer;
4545
protected object _syncObj = new object();
4646
protected bool _isEnabled;
47-
protected SettingsChangeWatcher<RefreshRateChangerSettings> _settings = new SettingsChangeWatcher<RefreshRateChangerSettings>();
47+
protected SettingsChangeWatcher<RefreshRateChangerSettings> _settings = new SettingsChangeWatcher<RefreshRateChangerSettings>(true);
4848

4949
public VideoFpsWatcher()
5050
{

MediaPortal/Source/UI/Players/VideoEffectChanger/VideoEffectChanger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class VideoEffectChanger
3939
private double DEFAULT_CHECK_INTERVAL = 1000;
4040

4141
private AsynchronousMessageQueue _messageQueue;
42-
private readonly SettingsChangeWatcher<VideoEffectChangerSettings> _settings = new SettingsChangeWatcher<VideoEffectChangerSettings>();
42+
private readonly SettingsChangeWatcher<VideoEffectChangerSettings> _settings = new SettingsChangeWatcher<VideoEffectChangerSettings>(true);
4343
private Timer _timer;
4444

4545
public VideoEffectChanger()

MediaPortal/Source/UI/SkinEngine/Controls/Visuals/Triggers/SoundPlayerAction.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,13 @@ public override void Execute(UIElement element)
102102
.Any(player => player is IAudioPlayer || player is IVideoPlayer))
103103
return;
104104
}
105-
using (SoundPlayer simpleSound = new SoundPlayer(SkinContext.SkinResources.GetResourceFilePath(SkinResources.SOUNDS_DIRECTORY + "\\" + source)))
105+
106+
// The path can only be null during skin switching
107+
var resourceFilePath = SkinContext.SkinResources.GetResourceFilePath(SkinResources.SOUNDS_DIRECTORY + "\\" + source);
108+
if (resourceFilePath == null)
109+
return;
110+
111+
using (SoundPlayer simpleSound = new SoundPlayer(resourceFilePath))
106112
simpleSound.Play();
107113
}
108114
}

MediaPortal/Source/UI/TV/SlimTvClient/Models/SlimTvGuideModelBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ void InitSettingsWatcher()
422422
{
423423
if (_settings != null)
424424
return;
425-
_settings = new SettingsChangeWatcher<SlimTvClientSettings>();
425+
_settings = new SettingsChangeWatcher<SlimTvClientSettings>(true);
426426
UpdatePropertiesFromSettings(_settings.Settings);
427427
_settings.SettingsChanged = OnSettingsChanged;
428428
}

MediaPortal/Source/UI/UiComponents/News/Models/NewsModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public void Deactivate(NavigationContext oldContext, NavigationContext newContex
175175

176176
public void Reactivate(NavigationContext oldContext, NavigationContext newContext)
177177
{
178-
GetFeeds();
178+
// Nothing to do here
179179
}
180180

181181
public void UpdateMenuActions(NavigationContext context, IDictionary<Guid, WorkflowAction> actions)

MediaPortal/Source/UI/UiComponents/News/NewsCollector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class NewsCollector : INewsCollector
4545
protected NewsItem _lastRandomNewsItem = null;
4646
protected List<NewsFeed> _feeds = new List<NewsFeed>();
4747
protected bool _refeshInProgress = false;
48-
protected SettingsChangeWatcher<NewsSettings> _settings = new SettingsChangeWatcher<NewsSettings>();
48+
protected SettingsChangeWatcher<NewsSettings> _settings = new SettingsChangeWatcher<NewsSettings>(true);
4949
IntervalWork _work = null;
5050

5151
public NewsCollector()

MediaPortal/Source/UI/UiComponents/Weather/Grabbers/OpenWeatherMap.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class OpenWeatherMapCatcher : IWeatherCatcher, IApiToken, IDisposable
5858
private SemaphoreSlim _lock = new SemaphoreSlim(1, 1);
5959
private Dictionary<int, Tuple<City, DateTime>> _cache = new Dictionary<int, Tuple<City, DateTime>>();
6060
private TimeSpan MAX_CACHE_DURATION = TimeSpan.FromMinutes(30);
61-
private SettingsChangeWatcher<WeatherSettings> _settings = new SettingsChangeWatcher<WeatherSettings>();
61+
private SettingsChangeWatcher<WeatherSettings> _settings = new SettingsChangeWatcher<WeatherSettings>(true);
6262

6363
public OpenWeatherMapCatcher()
6464
{

MediaPortal/Source/UI/UiComponents/Weather/Models/CurrentWeatherModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class CurrentWeatherModel : BaseTimerControlledModel
4545
/// </summary>
4646
private const int WEATHER_UPDATE_INTERVAL = 30 * 60 * 1000;
4747

48-
protected readonly SettingsChangeWatcher<WeatherSettings> _settings = new SettingsChangeWatcher<WeatherSettings>();
48+
protected readonly SettingsChangeWatcher<WeatherSettings> _settings = new SettingsChangeWatcher<WeatherSettings>(true);
4949

5050
protected readonly AbstractProperty _currentLocationProperty = new WProperty(typeof(City), City.NoData);
5151

0 commit comments

Comments
 (0)