Skip to content

Commit

Permalink
Add setting to disable showing refresh stream dialog errors
Browse files Browse the repository at this point in the history
  • Loading branch information
laurencee committed Aug 31, 2019
1 parent e53b9b8 commit c0beb1b
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 69 deletions.
21 changes: 14 additions & 7 deletions Livestream.Monitor/Core/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,10 @@ public class Settings : PropertyChangedBase

private MetroThemeBaseColour? metroThemeBaseColour;
private MetroThemeAccentColour? metroThemeAccentColour;
private string livestreamerFullPath;
private string chatCommandLine;
private int minimumEventViewers = DEFAULT_MINIMUM_EVENT_VIEWERS;
private bool disableNotifications, passthroughClientId;
private bool hideStreamOutputMessageBoxOnLoad;
private string twitchAuthToken;
private bool twitchAuthTokenInLivestreamerConfig;
private string livestreamerFullPath, chatCommandLine, twitchAuthToken;
private bool disableNotifications, passthroughClientId, hideStreamOutputMessageBoxOnLoad, checkForNewVersions, disableRefreshErrorDialogs, twitchAuthTokenInLivestreamerConfig;
private int settingsVersion;
private bool checkForNewVersions;

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public int SettingsVersion
Expand All @@ -63,6 +58,18 @@ public bool CheckForNewVersions
}
}

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public bool DisableRefreshErrorDialogs
{
get => disableRefreshErrorDialogs;
set
{
if (value == disableRefreshErrorDialogs) return;
disableRefreshErrorDialogs = value;
NotifyOfPropertyChange(() => DisableRefreshErrorDialogs);
}
}

[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public MetroThemeBaseColour? MetroThemeBaseColour
{
Expand Down
30 changes: 18 additions & 12 deletions Livestream.Monitor/ViewModels/LivestreamListViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class LivestreamListViewModel : Screen, IHandleWithTask<ExceptionDispatch
{
private readonly StreamLauncher streamLauncher;
private readonly INavigationService navigationService;
private readonly ISettingsHandler settingsHandler;
private readonly DispatcherTimer refreshTimer;

private bool loading;
Expand All @@ -41,10 +42,12 @@ public LivestreamListViewModel()
IMonitorStreamsModel monitorStreamsModel,
FilterModel filterModel,
StreamLauncher streamLauncher,
INavigationService navigationService)
INavigationService navigationService,
ISettingsHandler settingsHandler)
{
this.streamLauncher = streamLauncher ?? throw new ArgumentNullException(nameof(streamLauncher));
this.navigationService = navigationService ?? throw new ArgumentNullException(nameof(navigationService));
this.settingsHandler = settingsHandler ?? throw new ArgumentNullException(nameof(settingsHandler));
this.StreamsModel = monitorStreamsModel ?? throw new ArgumentNullException(nameof(monitorStreamsModel));
FilterModel = filterModel;
refreshTimer = new DispatcherTimer { Interval = Constants.RefreshPollingTime };
Expand Down Expand Up @@ -95,18 +98,21 @@ public async Task RefreshLivestreams()
// keep trying to refresh until we hit too many consecutive errors unless it's our first query
if (refreshCount == 0 || refreshErrorCount >= 3)
{
foreach (var ex in aggregateException.InnerExceptions)
if (!settingsHandler.Settings.DisableRefreshErrorDialogs)
{
var messageDialogResult = await this.ShowMessageAsync(
"Error refreshing livestreams", ex.ExtractErrorMessage(),
MessageDialogStyle.AffirmativeAndNegative,
new MetroDialogSettings()
{
NegativeButtonText = "Ignore"
});

if (messageDialogResult == MessageDialogResult.Negative)
StreamsModel.IgnoreQueryFailure(ex.Message);
foreach (var ex in aggregateException.InnerExceptions)
{
var messageDialogResult = await this.ShowMessageAsync(
"Error refreshing livestreams", ex.ExtractErrorMessage(),
MessageDialogStyle.AffirmativeAndNegative,
new MetroDialogSettings()
{
NegativeButtonText = "Ignore"
});

if (messageDialogResult == MessageDialogResult.Negative)
StreamsModel.IgnoreQueryFailure(ex.Message);
}
}

refreshTimer.Start();
Expand Down
20 changes: 18 additions & 2 deletions Livestream.Monitor/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class SettingsViewModel : Screen, INotifyDataErrorInfo
private readonly ISettingsHandler settingsHandler;
private string livestreamerFullPath, chatCommandLine;
private int minimumEventViewers;
private bool disableNotifications, hideStreamOutputOnLoad, passthroughClientId, checkForNewVersions;
private bool disableNotifications, hideStreamOutputOnLoad, passthroughClientId, checkForNewVersions, disableRefreshErrorDialogs;

public SettingsViewModel()
{
Expand Down Expand Up @@ -141,6 +141,18 @@ public bool CheckForNewVersions
}
}

public bool DisableRefreshErrorDialogs
{
get => disableRefreshErrorDialogs;
set
{
if (value == disableRefreshErrorDialogs) return;
disableRefreshErrorDialogs = value;
NotifyOfPropertyChange(() => DisableRefreshErrorDialogs);
NotifyOfPropertyChange(() => CanSave);
}
}

public bool CanSave
{
get
Expand All @@ -156,7 +168,8 @@ public bool CanSave
DisableNotifications != settingsHandler.Settings.DisableNotifications ||
HideStreamOutputOnLoad != settingsHandler.Settings.HideStreamOutputMessageBoxOnLoad ||
PassthroughClientId != settingsHandler.Settings.PassthroughClientId ||
CheckForNewVersions != settingsHandler.Settings.CheckForNewVersions;
CheckForNewVersions != settingsHandler.Settings.CheckForNewVersions ||
DisableRefreshErrorDialogs != settingsHandler.Settings.DisableRefreshErrorDialogs;
}
}

Expand Down Expand Up @@ -185,6 +198,8 @@ public void Save()
settingsHandler.Settings.DisableNotifications = DisableNotifications;
settingsHandler.Settings.HideStreamOutputMessageBoxOnLoad = HideStreamOutputOnLoad;
settingsHandler.Settings.PassthroughClientId = PassthroughClientId;
settingsHandler.Settings.CheckForNewVersions = CheckForNewVersions;
settingsHandler.Settings.DisableRefreshErrorDialogs = DisableRefreshErrorDialogs;
settingsHandler.SaveSettings();

settingsHandler.Settings.PropertyChanged += SettingsOnPropertyChanged;
Expand Down Expand Up @@ -270,6 +285,7 @@ protected override void OnActivate()
HideStreamOutputOnLoad = settingsHandler.Settings.HideStreamOutputMessageBoxOnLoad;
PassthroughClientId = settingsHandler.Settings.PassthroughClientId;
CheckForNewVersions = settingsHandler.Settings.CheckForNewVersions;
DisableRefreshErrorDialogs = settingsHandler.Settings.DisableRefreshErrorDialogs;

settingsHandler.Settings.PropertyChanged += SettingsOnPropertyChanged;
base.OnActivate();
Expand Down
98 changes: 51 additions & 47 deletions Livestream.Monitor/Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,68 +16,72 @@
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<StackPanel Orientation="Vertical" Grid.Row="0">
<StackPanel.Resources>
<ResourceDictionary>
<Style TargetType="TextBlock" BasedOn="{StaticResource MetroTextBlock}">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Margin" Value="0,5" />
</Style>
<Style TargetType="TextBox" BasedOn="{StaticResource MetroTextBox}">
<Setter Property="Margin" Value="0,5" />
</Style>
</ResourceDictionary>
</StackPanel.Resources>

<ContentControl x:Name="ThemeSelector" cal:View.Model="{Binding ThemeSelector}" Margin="0,5,5,5" HorizontalAlignment="Left" />
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" >
<StackPanel Orientation="Vertical" Grid.Row="0">
<StackPanel.Resources>
<ResourceDictionary>
<Style TargetType="TextBlock" BasedOn="{StaticResource MetroTextBlock}">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Margin" Value="0,5" />
</Style>
<Style TargetType="TextBox" BasedOn="{StaticResource MetroTextBox}">
<Setter Property="Margin" Value="0,5" />
</Style>
</ResourceDictionary>
</StackPanel.Resources>

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<TextBlock Grid.Row="0" Grid.Column="0" Text="Livestreamer/Streamlink Path" />
<TextBox Grid.Row="1" Grid.Column="0" x:Name="LivestreamerFullPath" />
<Button Grid.Row="1" Grid.Column="1" x:Name="SetLivestreamerFilePath" Content="..." Padding="5" Margin="5,0" Height="10" />
<ContentControl x:Name="ThemeSelector" cal:View.Model="{Binding ThemeSelector}" Margin="0,5,5,5" HorizontalAlignment="Left" />

<TextBlock Grid.Row="2" Grid.Column="0" Text="Predefined Chat Commands (Optional)" />
<StackPanel Grid.Row="3" Grid.Column="0" Orientation="Horizontal" >
<Button x:Name="Chrome" Content="Chrome" Margin="5,0" />
<Button x:Name="Edge" Content="Edge" Margin="5,0" />
<Button x:Name="Firefox" Content="Firefox" Margin="5,0" />
</StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<TextBlock Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2"
<TextBlock Grid.Row="0" Grid.Column="0" Text="Livestreamer/Streamlink Path" />
<TextBox Grid.Row="1" Grid.Column="0" x:Name="LivestreamerFullPath" />
<Button Grid.Row="1" Grid.Column="1" x:Name="SetLivestreamerFilePath" Content="..." Padding="5" Margin="5,0" Height="10" />

<TextBlock Grid.Row="2" Grid.Column="0" Text="Predefined Chat Commands (Optional)" />
<StackPanel Grid.Row="3" Grid.Column="0" Orientation="Horizontal" >
<Button x:Name="Chrome" Content="Chrome" Margin="5,0" />
<Button x:Name="Edge" Content="Edge" Margin="5,0" />
<Button x:Name="Firefox" Content="Firefox" Margin="5,0" />
</StackPanel>

<TextBlock Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2"
Text="Chat Command (Optional) - variable {url}"
ToolTip="Command line argument to pass in a chat {url} - e.g. microsoft-edge:{url}" />
<TextBox Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2"
<TextBox Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2"
x:Name="ChatCommandLine"
ToolTip="Command line argument to pass in a chat {url} - e.g. microsoft-edge:{url}" />
</Grid>
</Grid>

<TextBlock Text="Popular stream minimum viewers (0 for off)" Margin="0,20,0,0"
<TextBlock Text="Popular stream minimum viewers (0 for off)" Margin="0,20,0,0"
ToolTip="Minimum nuber of viewers for a stream to be shown in a notification as a popular/event stream.&#10;This helps you not miss out on special events/popular streams." />
<TextBox x:Name="MinimumEventViewers" MaxLength="7"
<TextBox x:Name="MinimumEventViewers" MaxLength="7"
ui:BindableBehaviors.Behaviors="{StaticResource NumericRestriction}"
ToolTip="Minimum nuber of viewers for a stream to be shown in a notification as a popular/event stream.&#10;This helps you not miss out on special events/popular streams." />
<CheckBox x:Name="CheckForNewVersions" Content="Check for new app versions"
<CheckBox x:Name="CheckForNewVersions" Content="Check for new app versions"
ToolTip="When unchecked, will disable checking for new versions on app startup" />
<CheckBox x:Name="DisableNotifications" Content="Disable Notifications"
<CheckBox x:Name="DisableNotifications" Content="Disable Notifications"
ToolTip="When unchecked, will disable all notifications (including online notifications) from displaying" />
<CheckBox x:Name="HideStreamOutputOnLoad" Content="Hide Stream Output On Load"
<CheckBox x:Name="DisableRefreshErrorDialogs" Content="Disable refresh error dialogs"
ToolTip="When checked, will disable error dialogs from being displayed due to stream refresh failures" />
<CheckBox x:Name="HideStreamOutputOnLoad" Content="Hide Stream Output On Load"
ToolTip="When checked, the stream output box will be hidden upon successful stream load" />
<CheckBox x:Name="PassthroughClientId" Content="Bypass OAuth to twitch"
<CheckBox x:Name="PassthroughClientId" Content="Bypass OAuth to twitch"
ToolTip="When checked, a client id for Livestream Monitor will provided to twitch so an OAuth token is not required to launch streams." />
</StackPanel>
</StackPanel>
</ScrollViewer>

<Button Grid.Row="1" x:Name="Save" Content="Save" Margin="20,5,20,20" />
</Grid>
Expand Down
2 changes: 1 addition & 1 deletion Livestream.Monitor/Views/ShellView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
xmlns:tb="http://www.hardcodet.net/taskbar"
d:DataContext="{d:DesignInstance Type=viewModels:ShellViewModel, IsDesignTimeCreatable=True}"
cal:Bind.AtDesignTime="True" WindowState="{Binding WindowState}" AllowsTransparency="True"
Height="500" Width="810">
Height="477" Width="810">
<mah:MetroWindow.RightWindowCommands>
<mah:WindowCommands>
<!--<ContentControl x:Name="ThemeSelector" cal:View.Model="{Binding ThemeSelector}" />-->
Expand Down

0 comments on commit c0beb1b

Please sign in to comment.