Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
NoobNotFound committed Dec 5, 2024
2 parents 8a797f3 + 3eb5d05 commit b8a908d
Show file tree
Hide file tree
Showing 20 changed files with 235 additions and 148 deletions.
58 changes: 34 additions & 24 deletions Emerald/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@
using System;
using Emerald.Helpers;

namespace Emerald;
namespace Emerald;
public partial class App : Application
{

/* Unmerged change from project 'Emerald (net8.0-windows10.0.22621)'
Before:
private Helpers.Settings.SettingsSystem SS;
/// <summary>
After:
private SettingsSystem SS;
/// <summary>
*/
private Services.SettingsService SS;
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
Expand Down Expand Up @@ -41,16 +50,22 @@ private void ConfigureServices(IServiceCollection services)
services.AddTransient(provider => new ModpackStore(typeof(ModpackStore).Log()));

//Settings

/* Unmerged change from project 'Emerald (net8.0-windows10.0.22621)'
Before:
services.AddSingleton<Helpers.Settings.SettingsSystem>();
After:
services.AddSingleton<SettingsSystem>();
*/
services.AddSingleton<Services.SettingsService>();


}

protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
var logPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"Emerald",
DirectResoucres.LocalDataPath,
"logs",
"app_.log");

Expand Down Expand Up @@ -86,8 +101,20 @@ protected override async void OnLaunched(LaunchActivatedEventArgs args)
//Help me.
ServiceLocator.SetLocatorProvider(() => new Emerald.Services.ServiceProviderLocator(Host!.Services));


/* Unmerged change from project 'Emerald (net8.0-windows10.0.22621)'
Before:
SS = ServiceLocator.Current.GetInstance<Helpers.Settings.SettingsSystem>();
this.Log().LogInformation("New Instance was created. Logs are being saved at: {logPath}",logPath);
After:
SS = ServiceLocator.Current.GetInstance<SettingsSystem>();
this.Log().LogInformation("New Instance was created. Logs are being saved at: {logPath}",logPath);
*/
SS = ServiceLocator.Current.GetInstance<Services.SettingsService>();
this.Log().LogInformation("New Instance was created. Logs are being saved at: {logPath}",logPath);

//load settings,
SS.LoadData();

// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
Expand All @@ -96,9 +123,6 @@ protected override async void OnLaunched(LaunchActivatedEventArgs args)
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();

//load settings,
SS.LoadData();

// Place the frame in the current Window
MainWindow.Content = rootFrame;
}
Expand Down Expand Up @@ -130,31 +154,22 @@ private void MainWindow_Closed(object sender, WindowEventArgs args)
#region UnhandledExceptions
private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
{
var logPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"Emerald");
e.Handled = true;
LogUnhandledException(e.Exception, "UI UnhandledException");
ShowPlatformErrorDialog($"An unexpected error occurred. The application needs to be closed.\n see logs at {logPath} for more details");
ShowPlatformErrorDialog($"An unexpected error occurred. The application needs to be closed.\nSee crash details at {DirectResoucres.LocalDataPath} for more details");
}

private void CurrentDomain_UnhandledException(object sender, System.UnhandledExceptionEventArgs e)
{
var logPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"Emerald");
LogUnhandledException((Exception)e.ExceptionObject, "AppDomain UnhandledException");
ShowPlatformErrorDialog($"A critical error occurred. The application needs to be closed.\n see logs at {logPath} for more details");
ShowPlatformErrorDialog($"A critical error occurred. The application needs to be closed.\nSee crash details at {DirectResoucres.LocalDataPath} for more details");
}

private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
var logPath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"Emerald");
e.SetObserved();
LogUnhandledException(e.Exception, "Task UnobservedException");
ShowPlatformErrorDialog($"A unobserved error occurred. The application needs to be closed.\n see logs at {logPath} for more details");
ShowPlatformErrorDialog($"A unobserved error occurred. The application needs to be closed.\nSee crash details at {DirectResoucres.LocalDataPath} for more details");
}

private void LogUnhandledException(Exception exception, string source)
Expand All @@ -169,12 +184,7 @@ private void LogUnhandledException(Exception exception, string source)

// Save to crash file (platform-specific path)
var crashPath = Path.Combine(
#if WINDOWS
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
#else
Environment.GetFolderPath(Environment.SpecialFolder.Personal),
#endif
"Emerald",
DirectResoucres.LocalDataPath,
"crashes",
$"crash_{DateTime.Now:yyyyMMdd_HHmmss}.txt"
);
Expand Down
Binary file added Emerald/Assets/NavigationViewIcons/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Emerald/Assets/NavigationViewIcons/logs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Emerald/Assets/NavigationViewIcons/news.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Emerald/Assets/NavigationViewIcons/store.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Emerald/Assets/NavigationViewIcons/tasks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions Emerald/DirectResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ public static string Platform
return "Skia";
#else
return "Unknown";
#endif
}
}
public static string LocalDataPath
{
get
{
#if WINDOWS
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Emerald");
#else
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Emerald");
#endif
}
}
Expand Down
6 changes: 6 additions & 0 deletions Emerald/Emerald.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@

<ItemGroup>
<None Remove="Assets\icon.png" />
<None Remove="Assets\NavigationViewIcons\home.png" />
<None Remove="Assets\NavigationViewIcons\logs.png" />
<None Remove="Assets\NavigationViewIcons\news.png" />
<None Remove="Assets\NavigationViewIcons\settings.png" />
<None Remove="Assets\NavigationViewIcons\store.png" />
<None Remove="Assets\NavigationViewIcons\tasks.png" />
<None Remove="UserControls\ArgumentsListView.xaml" />
<None Remove="UserControls\Titlebar.xaml" />
<None Remove="Views\Settings\AppearancePage.xaml" />
Expand Down
15 changes: 12 additions & 3 deletions Emerald/Helpers/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,17 @@ public static ContentDialog ToContentDialog(this UIElement content, string title
Content = content,
Padding = new(12)
} : content,

/* Unmerged change from project 'Emerald (net8.0-windows10.0.22621)'
Before:
RequestedTheme = (ElementTheme)ServiceLocator.Current.GetInstance< Helpers.Settings.SettingsSystem>().Settings.App.Appearance.Theme
};
After:
RequestedTheme = (ElementTheme)ServiceLocator.Current.GetInstance< SettingsSystem>().Settings.App.Appearance.Theme
};
*/
RequestedTheme = (ElementTheme)ServiceLocator.Current.GetInstance< Services.SettingsService>().Settings.App.Appearance.Theme
};
App.Current.Log().LogInformation("Created ContentDialog with title: {title}", title);
return dialog;
}
Expand Down Expand Up @@ -140,9 +149,9 @@ public static string Localize(this string resourceKey)
{
try
{
string s = Windows.ApplicationModel.Resources.ResourceLoader
.GetForViewIndependentUse()
.GetString(resourceKey);
string s = Windows.ApplicationModel.Resources.ResourceLoader
.GetForViewIndependentUse()
.GetString(resourceKey);

return string.IsNullOrEmpty(s) ? resourceKey : s;
}
Expand Down
18 changes: 18 additions & 0 deletions Emerald/Helpers/MessageBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,17 @@ private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDia
public static async Task<MessageBoxResults> Show(string title, string caption, MessageBoxButtons buttons, string customResult1 = null, string customResult2 = null, bool waitUntilOpens = true)
{
var theme = ServiceLocator.IsLocationProviderSet ?

/* Unmerged change from project 'Emerald (net8.0-windows10.0.22621)'
Before:
(ElementTheme)ServiceLocator.Current.GetInstance<Settings.SettingsSystem>().Settings.App.Appearance.Theme :
ElementTheme.Default;
After:
(ElementTheme)ServiceLocator.Current.GetInstance<SettingsSystem>().Settings.App.Appearance.Theme :
ElementTheme.Default;
*/
(ElementTheme)ServiceLocator.Current.GetInstance<Services.SettingsService>().Settings.App.Appearance.Theme :
ElementTheme.Default;
var d = new MessageBox(title, caption, buttons, customResult1, customResult2)
{
XamlRoot = App.Current.MainWindow.Content.XamlRoot,
Expand Down Expand Up @@ -171,8 +180,17 @@ public static async Task<MessageBoxResults> Show(string title, string caption, M
public static async Task<MessageBoxResults> Show(string text)
{
var theme = ServiceLocator.IsLocationProviderSet ?

/* Unmerged change from project 'Emerald (net8.0-windows10.0.22621)'
Before:
(ElementTheme)ServiceLocator.Current.GetInstance<Settings.SettingsSystem>().Settings.App.Appearance.Theme :
ElementTheme.Default;
After:
(ElementTheme)ServiceLocator.Current.GetInstance<SettingsSystem>().Settings.App.Appearance.Theme :
ElementTheme.Default;
*/
(ElementTheme)ServiceLocator.Current.GetInstance<Services.SettingsService>().Settings.App.Appearance.Theme :
ElementTheme.Default;
var d = new MessageBox("Information".Localize(), text, MessageBoxButtons.Ok)
{
XamlRoot = App.Current.MainWindow.Content.XamlRoot,
Expand Down
2 changes: 1 addition & 1 deletion Emerald/Helpers/Settings/JSON.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public partial class Appearance : JSON
private int _MicaType = 0;

[ObservableProperty]
private (int A, int R, int G, int B)? _CustomMicaTintColor;
private Color? _CustomMicaTintColor;


[ObservableProperty]
Expand Down
8 changes: 3 additions & 5 deletions Emerald/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<DataTemplate x:DataType="models:SquareNavigationViewItem">
<NavigationViewItem
Height="64"
x:DefaultBindMode="OneWay"
IsEnabled="{x:Bind IsEnabled, Mode=OneWay}"
IsSelected="{x:Bind IsSelected, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Tag="{x:Bind Name}">
Expand All @@ -89,20 +90,17 @@
VerticalAlignment="Top"
Content="{x:Bind InfoBadge}" />
<Image
x:Load="{x:Bind SS.Settings.App.Appearance.NavIconType.Equals(1), Mode=OneWay}"
x:Name="Image"
Width="28"
Height="28"
Visibility="{x:Bind ImageVisibility}"
Source="{x:Bind Thumbnail}" />
<FontIcon
x:Name="fontIcon"
x:Load="{x:Bind SS.Settings.App.Appearance.NavIconType.Equals(0), Mode=OneWay}"
Visibility="{x:Bind FontIconVisibility}"
FontSize="22"
Foreground="{ThemeResource SystemBaseMediumColor}"
Glyph="{x:Bind FontIconGlyph}" />
<FontIcon
x:Name="fontIconSolid"
x:Load="{x:Bind SS.Settings.App.Appearance.NavIconType.Equals(0), Mode=OneWay}"
Visibility="{x:Bind SolidFontIconVisibility}"
FontSize="22"
Foreground="{ThemeResource AccentTextFillColorPrimaryBrush}"
Expand Down
39 changes: 20 additions & 19 deletions Emerald/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ namespace Emerald;

public sealed partial class MainPage : Page
{
private readonly Helpers.Settings.SettingsSystem SS;
private readonly Services.SettingsService SS;
public MainPage()
{
SS = ServiceLocator.Current.GetInstance<Helpers.Settings.SettingsSystem>();
SS = ServiceLocator.Current.GetInstance<Services.SettingsService>();
this.InitializeComponent();
this.Loaded += MainPage_Loaded;
NavView.ItemInvoked += MainNavigationView_ItemInvoked;
Expand Down Expand Up @@ -52,16 +52,17 @@ void TintColor()
break;
case Helpers.Settings.Enums.MicaTintColor.CustomColor:
var c = SS.Settings.App.Appearance.CustomMicaTintColor;
MainGrid.Background = new SolidColorBrush()
{
Color = c == null ? Color.FromArgb(255, 234, 0, 94) : Color.FromArgb((byte)c.Value.A, (byte)c.Value.R, (byte)c.Value.G, (byte)c.Value.B),
MainGrid.Background = new SolidColorBrush()
{
Color = c ?? Color.FromArgb(255, 234, 0, 94),
Opacity = (double)SS.Settings.App.Appearance.TintOpacity / 100
};
break;
}
}
TintColor();

this.GetThemeService().SetThemeAsync((AppTheme)SS.Settings.App.Appearance.Theme);

//Mica (Windows 11)
var mica = WindowManager.IntializeWindow(App.Current.MainWindow);
#if WINDOWS
Expand All @@ -78,52 +79,52 @@ void InitializeNavView()

NavView.MenuItems.Add(new SquareNavigationViewItem("Home".Localize())
{
Thumbnail = "ms-appx:///Assets/NavigationViewIcons/home.png",
FontIconGlyph = "\xE80F",
Tag = "Home",
SolidFontIconGlyph = "\xEA8A",
IsSelected = true,
ShowFontIcons = true
IsSelected = true
});
NavView.MenuItems.Add(new SquareNavigationViewItem("Store".Localize())
{
Thumbnail = "ms-appx:///Assets/NavigationViewIcons/store.png",
Tag = "Store",
FontIconGlyph = "\xE7BF",
SolidFontIconGlyph = "\xE7BF",
IsSelected = false,
ShowFontIcons = true
IsSelected = false
});
NavView.MenuItems.Add(new SquareNavigationViewItem("News".Localize())
{
Thumbnail = "ms-appx:///Assets/NavigationViewIcons/news.png",
Tag = "News",
FontIconGlyph = "\xF57E",
SolidFontIconGlyph = "\xF57E",
IsSelected = false,
ShowFontIcons = true
IsSelected = false
});

NavView.FooterMenuItems.Add(new SquareNavigationViewItem("Tasks".Localize())
{
Thumbnail = "ms-appx:///Assets/NavigationViewIcons/tasks.png",
Tag = "Tasks",
FontIconGlyph = "\xE9D5",
SolidFontIconGlyph = "\xE9D5",
IsSelected = false,
ShowFontIcons = true
IsSelected = false
});
NavView.FooterMenuItems.Add(new SquareNavigationViewItem("Logs".Localize())
{
Thumbnail = "ms-appx:///Assets/NavigationViewIcons/logs.png",
Tag = "Logs",
FontIconGlyph = "\xE756",
SolidFontIconGlyph = "\xE756",
IsSelected = false,
ShowFontIcons = true
IsSelected = false
});
NavView.FooterMenuItems.Add(new SquareNavigationViewItem("Settings".Localize())
{
Thumbnail = "ms-appx:///Assets/NavigationViewIcons/settings.png",
Tag = "Settings",
FontIconGlyph = "\xE713",
SolidFontIconGlyph = "\xE713",
IsSelected = false,
ShowFontIcons = true
IsSelected = false
});

NavView.SelectedItem = NavView.MenuItems[0];
Expand All @@ -139,8 +140,8 @@ private void MainPage_Loaded(object sender, RoutedEventArgs e)
#if WINDOWS
Emerald.Helpers.WindowManager.SetTitleBar(App.Current.MainWindow, AppTitleBar);
#endif
InitializeNavView();
InitializeAppearance();
InitializeNavView();
}

private Thickness GetNavViewHeaderMargin()
Expand Down
Loading

0 comments on commit b8a908d

Please sign in to comment.