Skip to content

Commit

Permalink
UI: Rename App to RyujinxApp
Browse files Browse the repository at this point in the history
Add more NotificationHelper methods
Simplify ID copy logic
  • Loading branch information
GreemDev committed Dec 24, 2024
1 parent 4d7350f commit 16a60fd
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 40 deletions.
9 changes: 4 additions & 5 deletions src/Ryujinx/Common/ApplicationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public static void ExtractSection(string destination, NcaSectionType ncaSectionT
var cancellationToken = new CancellationTokenSource();

UpdateWaitWindow waitingDialog = new(
App.FormatTitle(LocaleKeys.DialogNcaExtractionTitle),
RyujinxApp.FormatTitle(LocaleKeys.DialogNcaExtractionTitle),
LocaleManager.Instance.UpdateAndGetDynamicValue(LocaleKeys.DialogNcaExtractionMessage, ncaSectionType, Path.GetFileName(titleFilePath)),
cancellationToken);

Expand Down Expand Up @@ -268,10 +268,9 @@ public static void ExtractSection(string destination, NcaSectionType ncaSectionT
{
Dispatcher.UIThread.Post(waitingDialog.Close);

NotificationHelper.Show(
App.FormatTitle(LocaleKeys.DialogNcaExtractionTitle),
$"{titleName}\n\n{LocaleManager.Instance[LocaleKeys.DialogNcaExtractionSuccessMessage]}",
NotificationType.Information);
NotificationHelper.ShowInformation(
RyujinxApp.FormatTitle(LocaleKeys.DialogNcaExtractionTitle),
$"{titleName}\n\n{LocaleManager.Instance[LocaleKeys.DialogNcaExtractionSuccessMessage]}");
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Ryujinx/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static int Main(string[] args)
}

public static AppBuilder BuildAvaloniaApp() =>
AppBuilder.Configure<App>()
AppBuilder.Configure<RyujinxApp>()
.UsePlatformDetect()
.With(new X11PlatformOptions
{
Expand Down Expand Up @@ -100,7 +100,7 @@ private static void Initialize(string[] args)
// Delete backup files after updating.
Task.Run(Updater.CleanupUpdate);

Console.Title = $"{App.FullAppName} Console {Version}";
Console.Title = $"{RyujinxApp.FullAppName} Console {Version}";

// Hook unhandled exception and process exit events.
AppDomain.CurrentDomain.UnhandledException += (sender, e)
Expand Down Expand Up @@ -225,7 +225,7 @@ public static void ReloadConfig()

private static void PrintSystemInfo()
{
Logger.Notice.Print(LogClass.Application, $"{App.FullAppName} Version: {Version}");
Logger.Notice.Print(LogClass.Application, $"{RyujinxApp.FullAppName} Version: {Version}");
SystemInfo.Gather().Print();

var enabledLogLevels = Logger.GetEnabledLevels().ToArray();
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx/App.axaml → src/Ryujinx/RyujinxApp.axaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Application
x:Class="Ryujinx.Ava.App"
x:Class="Ryujinx.Ava.RyujinxApp"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sty="using:FluentAvalonia.Styling">
Expand Down
12 changes: 8 additions & 4 deletions src/Ryujinx/App.axaml.cs → src/Ryujinx/RyujinxApp.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Input.Platform;
using Avalonia.Markup.Xaml;
using Avalonia.Platform;
using Avalonia.Styling;
Expand All @@ -19,7 +20,7 @@

namespace Ryujinx.Ava
{
public class App : Application
public class RyujinxApp : Application
{
internal static string FormatTitle(LocaleKeys? windowTitleKey = null)
=> windowTitleKey is null
Expand All @@ -32,8 +33,11 @@ internal static string FormatTitle(LocaleKeys? windowTitleKey = null)
.ApplicationLifetime.Cast<IClassicDesktopStyleApplicationLifetime>()
.MainWindow.Cast<MainWindow>();

public static IClassicDesktopStyleApplicationLifetime DesktopLifetime => Current!
.ApplicationLifetime.Cast<IClassicDesktopStyleApplicationLifetime>();
public static bool IsClipboardAvailable(out IClipboard clipboard)
{
clipboard = MainWindow.Clipboard;
return clipboard != null;
}

public static void SetTaskbarProgress(TaskBarProgressBarState state) => MainWindow.PlatformFeatures.SetTaskBarProgressBarState(state);
public static void SetTaskbarProgressValue(ulong current, ulong total) => MainWindow.PlatformFeatures.SetTaskBarProgressBarValue(current, total);
Expand Down Expand Up @@ -135,7 +139,7 @@ public static ThemeVariant ConvertThemeVariant(PlatformThemeVariant platformThem
};

public static ThemeVariant DetectSystemTheme() =>
Current is App { PlatformSettings: not null } app
Current is RyujinxApp { PlatformSettings: not null } app
? ConvertThemeVariant(app.PlatformSettings.GetColorValues().ThemeVariant)
: ThemeVariant.Default;
}
Expand Down
20 changes: 11 additions & 9 deletions src/Ryujinx/UI/Controls/ApplicationListView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,19 @@ private async void IdString_OnClick(object sender, RoutedEventArgs e)

if (sender is not Button { Content: TextBlock idText })
return;

if (!RyujinxApp.IsClipboardAvailable(out var clipboard))
return;

if (App.MainWindow.Clipboard is { } clipboard)
{
var appData = mwvm.Applications.FirstOrDefault(it => it.IdString == idText.Text);
if (appData is null)
return;

await clipboard.SetTextAsync(appData.IdString);
var appData = mwvm.Applications.FirstOrDefault(it => it.IdString == idText.Text);
if (appData is null)
return;

await clipboard.SetTextAsync(appData.IdString);

NotificationHelper.Show("Copied Title ID", $"{appData.Name} ({appData.IdString})", NotificationType.Information);
}
NotificationHelper.ShowInformation(
"Copied Title ID",
$"{appData.Name} ({appData.IdString})");
}
}
}
45 changes: 41 additions & 4 deletions src/Ryujinx/UI/Helpers/NotificationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,46 @@ public static void Show(string title, string text, NotificationType type, bool w
_notifications.Add(new Notification(title, text, type, delay, onClick, onClose));
}

public static void ShowError(string message)
{
Show(LocaleManager.Instance[LocaleKeys.DialogErrorTitle], $"{LocaleManager.Instance[LocaleKeys.DialogErrorMessage]}\n\n{message}", NotificationType.Error);
}
public static void ShowError(string message) =>
ShowError(
LocaleManager.Instance[LocaleKeys.DialogErrorTitle],
$"{LocaleManager.Instance[LocaleKeys.DialogErrorMessage]}\n\n{message}"
);

public static void ShowInformation(string title, string text, bool waitingExit = false, Action onClick = null, Action onClose = null) =>
Show(
title,
text,
NotificationType.Information,
waitingExit,
onClick,
onClose);

public static void ShowSuccess(string title, string text, bool waitingExit = false, Action onClick = null, Action onClose = null) =>
Show(
title,
text,
NotificationType.Success,
waitingExit,
onClick,
onClose);

public static void ShowWarning(string title, string text, bool waitingExit = false, Action onClick = null, Action onClose = null) =>
Show(
title,
text,
NotificationType.Warning,
waitingExit,
onClick,
onClose);

public static void ShowError(string title, string text, bool waitingExit = false, Action onClick = null, Action onClose = null) =>
Show(
title,
text,
NotificationType.Error,
waitingExit,
onClick,
onClose);
}
}
4 changes: 2 additions & 2 deletions src/Ryujinx/UI/ViewModels/AboutWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public string Version

public AboutWindowViewModel()
{
Version = App.FullAppName + "\n" + Program.Version;
Version = RyujinxApp.FullAppName + "\n" + Program.Version;
UpdateLogoTheme(ConfigurationState.Instance.UI.BaseStyle.Value);

ThemeManager.ThemeChanged += ThemeManager_ThemeChanged;
Expand All @@ -64,7 +64,7 @@ private void ThemeManager_ThemeChanged(object sender, EventArgs e)

private void UpdateLogoTheme(string theme)
{
bool isDarkTheme = theme == "Dark" || (theme == "Auto" && App.DetectSystemTheme() == ThemeVariant.Dark);
bool isDarkTheme = theme == "Dark" || (theme == "Auto" && RyujinxApp.DetectSystemTheme() == ThemeVariant.Dark);

string basePath = "resm:Ryujinx.UI.Common.Resources.";
string themeSuffix = isDarkTheme ? "Dark.png" : "Light.png";
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx/UI/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2051,7 +2051,7 @@ public void AppHost_AppExit(object sender, EventArgs e)

Dispatcher.UIThread.InvokeAsync(() =>
{
Title = App.FormatTitle();
Title = RyujinxApp.FormatTitle();
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx/UI/Windows/AmiiboWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public AmiiboWindow(bool showAll, string lastScannedAmiiboId, string titleId)

InitializeComponent();

Title = App.FormatTitle(LocaleKeys.Amiibo);
Title = RyujinxApp.FormatTitle(LocaleKeys.Amiibo);
}

public AmiiboWindow()
Expand All @@ -27,7 +27,7 @@ public AmiiboWindow()

if (Program.PreviewerDetached)
{
Title = App.FormatTitle(LocaleKeys.Amiibo);
Title = RyujinxApp.FormatTitle(LocaleKeys.Amiibo);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx/UI/Windows/CheatWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public CheatWindow()

InitializeComponent();

Title = App.FormatTitle(LocaleKeys.CheatWindowTitle);
Title = RyujinxApp.FormatTitle(LocaleKeys.CheatWindowTitle);
}

public CheatWindow(VirtualFileSystem virtualFileSystem, string titleId, string titleName, string titlePath)
Expand Down Expand Up @@ -93,7 +93,7 @@ public CheatWindow(VirtualFileSystem virtualFileSystem, string titleId, string t

DataContext = this;

Title = App.FormatTitle(LocaleKeys.CheatWindowTitle);
Title = RyujinxApp.FormatTitle(LocaleKeys.CheatWindowTitle);
}

public void Save()
Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx/UI/Windows/MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public MainWindow()

UiHandler = new AvaHostUIHandler(this);

ViewModel.Title = App.FormatTitle();
ViewModel.Title = RyujinxApp.FormatTitle();

TitleBar.ExtendsContentIntoTitleBar = !ConfigurationState.Instance.ShowTitleBar;
TitleBar.TitleBarHitTestType = (ConfigurationState.Instance.ShowTitleBar) ? TitleBarHitTestType.Simple : TitleBarHitTestType.Complex;
Expand Down Expand Up @@ -117,7 +117,7 @@ public MainWindow()
/// </summary>
private static void OnPlatformColorValuesChanged(object sender, PlatformColorValues e)
{
if (Application.Current is App app)
if (Application.Current is RyujinxApp app)
app.ApplyConfiguredTheme(ConfigurationState.Instance.UI.BaseStyle);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx/UI/Windows/SettingsWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public partial class SettingsWindow : StyleableAppWindow

public SettingsWindow(VirtualFileSystem virtualFileSystem, ContentManager contentManager)
{
Title = App.FormatTitle(LocaleKeys.Settings);
Title = RyujinxApp.FormatTitle(LocaleKeys.Settings);

DataContext = ViewModel = new SettingsViewModel(virtualFileSystem, contentManager);

Expand Down
8 changes: 4 additions & 4 deletions src/Ryujinx/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static async Task BeginUpdateAsync(bool showVersionUpToDate = false)

if (!Version.TryParse(Program.Version, out Version currentVersion))
{
Logger.Error?.Print(LogClass.Application, $"Failed to convert the current {App.FullAppName} version!");
Logger.Error?.Print(LogClass.Application, $"Failed to convert the current {RyujinxApp.FullAppName} version!");

await ContentDialogHelper.CreateWarningDialog(
LocaleManager.Instance[LocaleKeys.DialogUpdaterConvertFailedMessage],
Expand Down Expand Up @@ -159,7 +159,7 @@ await ContentDialogHelper.CreateErrorDialog(

if (!Version.TryParse(_buildVer, out Version newVersion))
{
Logger.Error?.Print(LogClass.Application, $"Failed to convert the received {App.FullAppName} version from GitHub!");
Logger.Error?.Print(LogClass.Application, $"Failed to convert the received {RyujinxApp.FullAppName} version from GitHub!");

await ContentDialogHelper.CreateWarningDialog(
LocaleManager.Instance[LocaleKeys.DialogUpdaterConvertFailedGithubMessage],
Expand Down Expand Up @@ -266,7 +266,7 @@ private static async Task UpdateRyujinx(string downloadUrl)
SubHeader = LocaleManager.Instance[LocaleKeys.UpdaterDownloading],
IconSource = new SymbolIconSource { Symbol = Symbol.Download },
ShowProgressBar = true,
XamlRoot = App.MainWindow,
XamlRoot = RyujinxApp.MainWindow,
};

taskDialog.Opened += (s, e) =>
Expand Down Expand Up @@ -490,7 +490,7 @@ private static void DoUpdateWithSingleThreadWorker(TaskDialog taskDialog, string
bytesWritten += readSize;

taskDialog.SetProgressBarState(GetPercentage(bytesWritten, totalBytes), TaskDialogProgressState.Normal);
App.SetTaskbarProgressValue(bytesWritten, totalBytes);
RyujinxApp.SetTaskbarProgressValue(bytesWritten, totalBytes);

updateFileStream.Write(buffer, 0, readSize);
}
Expand Down

0 comments on commit 16a60fd

Please sign in to comment.