Skip to content

Commit

Permalink
Make a few things static
Browse files Browse the repository at this point in the history
  • Loading branch information
ScrubN committed Aug 1, 2023
1 parent 672ec43 commit add6d55
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 39 deletions.
23 changes: 8 additions & 15 deletions TwitchDownloaderWPF/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Windows.Threading;
using TwitchDownloaderWPF.Properties;
using TwitchDownloaderWPF.Services;
using TwitchDownloaderWPF.Translations;

namespace TwitchDownloaderWPF
{
Expand All @@ -15,12 +14,6 @@ public partial class App : Application
{
public static ThemeService ThemeServiceSingleton { get; private set; }
public static CultureService CultureServiceSingleton { get; private set; }
public static App AppSingleton { get; private set; }

public App()
{
AppSingleton = this;
}

protected override void OnStartup(StartupEventArgs e)
{
Expand All @@ -42,29 +35,29 @@ protected override void OnStartup(StartupEventArgs e)
MainWindow.Show();
}

private void Current_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
private static void Current_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
var ex = e.Exception;
MessageBox.Show(ex.ToString(), Strings.FatalError, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(ex.ToString(), Translations.Strings.FatalError, MessageBoxButton.OK, MessageBoxImage.Error);

Current?.Shutdown();
}

private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var ex = (Exception)e.ExceptionObject;
MessageBox.Show(ex.ToString(), Strings.FatalError, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(ex.ToString(), Translations.Strings.FatalError, MessageBoxButton.OK, MessageBoxImage.Error);

Current?.Shutdown();
}

public void RequestAppThemeChange()
public static void RequestAppThemeChange()
=> ThemeServiceSingleton.ChangeAppTheme();

public void RequestTitleBarChange()
=> ThemeServiceSingleton.SetTitleBarTheme(Windows);
public static void RequestTitleBarChange()
=> ThemeServiceSingleton.SetTitleBarTheme(Current.Windows);

public void RequestCultureChange()
public static void RequestCultureChange()
=> CultureServiceSingleton.SetApplicationCulture(Settings.Default.GuiCulture);
}
}
3 changes: 1 addition & 2 deletions TwitchDownloaderWPF/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Windows;
using TwitchDownloaderWPF.Properties;
using Xabe.FFmpeg.Downloader;
using static TwitchDownloaderWPF.App;

namespace TwitchDownloaderWPF
{
Expand Down Expand Up @@ -60,7 +59,7 @@ private void btnQueue_Click(object sender, RoutedEventArgs e)

private async void Window_Loaded(object sender, RoutedEventArgs e)
{
AppSingleton.RequestAppThemeChange();
App.RequestAppThemeChange();

Main.Content = pageVodDownload;
if (Settings.Default.UpgradeRequired)
Expand Down
2 changes: 1 addition & 1 deletion TwitchDownloaderWPF/Services/DefaultThemeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace TwitchDownloaderWPF.Services
{
public class DefaultThemeService
public static class DefaultThemeService
{
public static bool WriteIncludedThemes()
{
Expand Down
3 changes: 2 additions & 1 deletion TwitchDownloaderWPF/Services/WindowsThemeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Management;
using System.Security.Principal;
using System.Windows;

namespace TwitchDownloaderWPF.Services
{
Expand Down Expand Up @@ -32,7 +33,7 @@ public WindowsThemeService()
private void WindowsThemeService_EventArrived(object sender, EventArrivedEventArgs e)
{
var newWindowsTheme = GetWindowsTheme();
App.AppSingleton.Dispatcher.BeginInvoke(() => ThemeChanged?.Invoke(this, newWindowsTheme));
Application.Current.Dispatcher.BeginInvoke(() => ThemeChanged?.Invoke(this, newWindowsTheme));
}

public static string GetWindowsTheme()
Expand Down
3 changes: 1 addition & 2 deletions TwitchDownloaderWPF/WindowMassDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using TwitchDownloaderCore.TwitchObjects.Gql;
using TwitchDownloaderWPF.Properties;
using TwitchDownloaderWPF.TwitchTasks;
using static TwitchDownloaderWPF.App;

namespace TwitchDownloaderWPF
{
Expand Down Expand Up @@ -246,7 +245,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
Title = downloaderType == DownloadType.Video
? Translations.Strings.TitleVideoMassDownloader
: Translations.Strings.TitleClipMassDownloader;
AppSingleton.RequestTitleBarChange();
App.RequestTitleBarChange();
}

private async void TextChannel_OnKeyDown(object sender, KeyEventArgs e)
Expand Down
16 changes: 7 additions & 9 deletions TwitchDownloaderWPF/WindowQueueOptions.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
using TwitchDownloaderCore.Options;
using TwitchDownloaderWPF.Properties;
using TwitchDownloaderWPF.Services;
using TwitchDownloaderWPF.Translations;
using TwitchDownloaderWPF.TwitchTasks;
using static TwitchDownloaderWPF.App;

namespace TwitchDownloaderWPF
{
Expand Down Expand Up @@ -110,7 +108,7 @@ private async void btnQueue_Click(object sender, RoutedEventArgs e)
string folderPath = textFolder.Text;
if (!Directory.Exists(folderPath))
{
MessageBox.Show(Strings.InvaliFolderPathMessage, Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Translations.Strings.InvaliFolderPathMessage, Translations.Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

Expand Down Expand Up @@ -194,7 +192,7 @@ private async void btnQueue_Click(object sender, RoutedEventArgs e)
string folderPath = textFolder.Text;
if (!Directory.Exists(folderPath))
{
MessageBox.Show(Strings.InvaliFolderPathMessage, Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Translations.Strings.InvaliFolderPathMessage, Translations.Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

Expand Down Expand Up @@ -273,7 +271,7 @@ private async void btnQueue_Click(object sender, RoutedEventArgs e)
string folderPath = textFolder.Text;
if (!Directory.Exists(folderPath))
{
MessageBox.Show(Strings.InvaliFolderPathMessage, Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Translations.Strings.InvaliFolderPathMessage, Translations.Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

Expand Down Expand Up @@ -320,7 +318,7 @@ private async void btnQueue_Click(object sender, RoutedEventArgs e)
string folderPath = textFolder.Text;
if (!Directory.Exists(folderPath))
{
MessageBox.Show(Strings.InvaliFolderPathMessage, Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Translations.Strings.InvaliFolderPathMessage, Translations.Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

Expand Down Expand Up @@ -352,7 +350,7 @@ private async void btnQueue_Click(object sender, RoutedEventArgs e)
{
if (!Directory.Exists(folderPath))
{
MessageBox.Show(Strings.InvaliFolderPathMessage, Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Translations.Strings.InvaliFolderPathMessage, Translations.Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

Expand Down Expand Up @@ -386,7 +384,7 @@ private async void btnQueue_Click(object sender, RoutedEventArgs e)
string folderPath = textFolder.Text;
if (!Directory.Exists(folderPath))
{
MessageBox.Show(Strings.InvaliFolderPathMessage, Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
MessageBox.Show(Translations.Strings.InvaliFolderPathMessage, Translations.Strings.InvalidFolderPath, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

Expand Down Expand Up @@ -585,7 +583,7 @@ private void radioHTML_Checked(object sender, RoutedEventArgs e)
private void Window_loaded(object sender, RoutedEventArgs e)
{
Title = Translations.Strings.TitleEnqueueOptions;
AppSingleton.RequestTitleBarChange();
App.RequestTitleBarChange();
}
}
}
4 changes: 1 addition & 3 deletions TwitchDownloaderWPF/WindowRangeSelect.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using TwitchDownloaderCore;
using static TwitchDownloaderWPF.App;

namespace TwitchDownloaderWPF
{
Expand Down Expand Up @@ -87,7 +85,7 @@ private void numEnd_TextChanged(object sender, TextChangedEventArgs e)
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Title = Translations.Strings.TitleRenderRange;
AppSingleton.RequestTitleBarChange();
App.RequestTitleBarChange();
}
}
}
7 changes: 3 additions & 4 deletions TwitchDownloaderWPF/WindowSettings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Windows.Controls;
using TwitchDownloaderWPF.Properties;
using TwitchDownloaderWPF.Services;
using static TwitchDownloaderWPF.App;
using MessageBox = System.Windows.MessageBox;

namespace TwitchDownloaderWPF
Expand Down Expand Up @@ -108,7 +107,7 @@ private void btnClearCache_Click(object sender, RoutedEventArgs e)
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Title = Translations.Strings.TitleGlobalSettings;
AppSingleton.RequestTitleBarChange();
App.RequestTitleBarChange();
}

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
Expand Down Expand Up @@ -143,7 +142,7 @@ private void comboTheme_SelectionChanged(object sender, SelectionChangedEventArg
if (!((string)comboTheme.SelectedItem).Equals(Settings.Default.GuiTheme, StringComparison.OrdinalIgnoreCase))
{
Settings.Default.GuiTheme = (string)comboTheme.SelectedItem;
AppSingleton.RequestAppThemeChange();
App.RequestAppThemeChange();
}
}

Expand All @@ -158,7 +157,7 @@ private void comboLocale_SelectionChanged(object sender, SelectionChangedEventAr
if (selectedCulture != Settings.Default.GuiCulture)
{
Settings.Default.GuiCulture = selectedCulture;
AppSingleton.RequestCultureChange();
App.RequestCultureChange();
Title = Translations.Strings.TitleGlobalSettings;
}
}
Expand Down
3 changes: 1 addition & 2 deletions TwitchDownloaderWPF/WindowUrlList.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using TwitchDownloaderCore.TwitchObjects.Gql;
using TwitchDownloaderWPF.Properties;
using TwitchDownloaderWPF.TwitchTasks;
using static TwitchDownloaderWPF.App;

namespace TwitchDownloaderWPF
{
Expand Down Expand Up @@ -165,7 +164,7 @@ private async void btnQueue_Click(object sender, RoutedEventArgs e)
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Title = Translations.Strings.TitleUrlList;
AppSingleton.RequestTitleBarChange();
App.RequestTitleBarChange();
}
}
}

0 comments on commit add6d55

Please sign in to comment.