Fix RadioBrowser crashes if no internet connection
This commit is contained in:
		@@ -117,7 +117,7 @@
 | 
				
			|||||||
                        <TextBlock x:Name="SnapcastText" Text="{x:Static properties:Resources.StartSnapcast}" Margin="5, 0, 0, 0"/>
 | 
					                        <TextBlock x:Name="SnapcastText" Text="{x:Static properties:Resources.StartSnapcast}" Margin="5, 0, 0, 0"/>
 | 
				
			||||||
                    </StackPanel>
 | 
					                    </StackPanel>
 | 
				
			||||||
                </Button>
 | 
					                </Button>
 | 
				
			||||||
                <Button x:Name="Radio" Padding="5, 2" HorizontalAlignment="Left" Click="Radios_Clicked"  Margin="5,0,10,0" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" FocusVisualStyle="{x:Null}">
 | 
					                <Button x:Name="Radio" Padding="5, 2" HorizontalAlignment="Left" Click="Radios_Clicked"  Margin="5,0,10,0" Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" FocusVisualStyle="{x:Null}" IsEnabled="False">
 | 
				
			||||||
                    <StackPanel Orientation="Horizontal">
 | 
					                    <StackPanel Orientation="Horizontal">
 | 
				
			||||||
                        <emoji:TextBlock Text="📻" Padding="0,0,0,2"/>
 | 
					                        <emoji:TextBlock Text="📻" Padding="0,0,0,2"/>
 | 
				
			||||||
                        <TextBlock Text="{x:Static properties:Resources.Radios}" Margin="5, 0, 0, 0"/>
 | 
					                        <TextBlock Text="{x:Static properties:Resources.Radios}" Margin="5, 0, 0, 0"/>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -188,6 +188,11 @@ namespace unison
 | 
				
			|||||||
                SnapcastText.Text = unison.Resources.Resources.StartSnapcast;
 | 
					                SnapcastText.Text = unison.Resources.Resources.StartSnapcast;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public void OnRadioBrowserConnected()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            Radio.IsEnabled = true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void UpdateButton(ref Border border, bool b)
 | 
					        public void UpdateButton(ref Border border, bool b)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            border.Style = b ? (Style)Resources["SelectedButton"] : (Style)Resources["UnselectedButton"];
 | 
					            border.Style = b ? (Style)Resources["SelectedButton"] : (Style)Resources["UnselectedButton"];
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -59,9 +59,22 @@ namespace unison
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            InitializeComponent();
 | 
					            InitializeComponent();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            try
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
                _radioBrowser = new RadioBrowserClient();
 | 
					                _radioBrowser = new RadioBrowserClient();
 | 
				
			||||||
                Initialize();
 | 
					                Initialize();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            catch (Exception e)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                Debug.WriteLine("Exception while connecting to RadioBrowser: " + e.Message);
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            Application.Current.Dispatcher.Invoke(() =>
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                MainWindow MainWin = (MainWindow)Application.Current.MainWindow;
 | 
				
			||||||
 | 
					                MainWin.OnRadioBrowserConnected();
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public async void Initialize()
 | 
					        public async void Initialize()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
@@ -84,6 +97,8 @@ namespace unison
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public async Task SearchAdvanced(string name, string country, string tags)
 | 
					        public async Task SearchAdvanced(string name, string country, string tags)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            try
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                SearchStatus.Text = unison.Resources.Resources.Radio_Loading;
 | 
					                SearchStatus.Text = unison.Resources.Resources.Radio_Loading;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -115,6 +130,11 @@ namespace unison
 | 
				
			|||||||
                else
 | 
					                else
 | 
				
			||||||
                    SearchStatus.Text = unison.Resources.Resources.Radio_NotFound;
 | 
					                    SearchStatus.Text = unison.Resources.Resources.Radio_NotFound;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            catch (Exception except)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                Debug.WriteLine("Error on RadioBrowser search advanced: " + except.Message);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void FitToContent()
 | 
					        private void FitToContent()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
@@ -147,10 +167,17 @@ namespace unison
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private async void Search_Clicked(object sender, RoutedEventArgs e)
 | 
					        private async void Search_Clicked(object sender, RoutedEventArgs e)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            try
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                CountryListItem a = (CountryListItem)CountryList.SelectedItem;
 | 
					                CountryListItem a = (CountryListItem)CountryList.SelectedItem;
 | 
				
			||||||
                await SearchAdvanced(NameSearch.Text, a?.Name, TagSearch.Text);
 | 
					                await SearchAdvanced(NameSearch.Text, a?.Name, TagSearch.Text);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            catch (Exception except)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                Debug.WriteLine("Error on RadioBrowser search: " + except.Message);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void Reset_Clicked(object sender, RoutedEventArgs e)
 | 
					        private void Reset_Clicked(object sender, RoutedEventArgs e)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user