Skip to content

Commit

Permalink
Merge pull request #35 from macadmins/dev
Browse files Browse the repository at this point in the history
v1.0.4
  • Loading branch information
almenscorner authored May 31, 2024
2 parents 0dad8bb + 789936a commit c6b14d2
Show file tree
Hide file tree
Showing 35 changed files with 1,415 additions and 138 deletions.
9 changes: 5 additions & 4 deletions App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
</Application.DataTemplates>
<TrayIcon.Icons>
<TrayIcons>
<TrayIcon Icon="/Assets/appicon.png" ToolTipText="Support Companion">
<TrayIcon Icon="/Assets/trayicon.png" ToolTipText="Support Companion">
<TrayIcon.Menu>
<NativeMenu>
<NativeMenuItem Header="Open Support Companion 🚀" Command="{Binding OpenApp}" />
<NativeMenuItem Header="Software Updates 🔄" Command="{Binding OpenSystemUpdates}" />
<NativeMenuItem Header="{Binding NativeMenuOpenText}" Command="{Binding OpenApp}" />
<NativeMenuItem Header="{Binding NativeMenuSystemUpdatesText}"
Command="{Binding OpenSystemUpdates}" />
<NativeMenuItemSeparator />
<NativeMenuItem Header="Exit" Command="{Binding QuitApp}" />
<NativeMenuItem Header="{Binding NativeMenuQuitAppText}" Command="{Binding QuitApp}" />
</NativeMenu>
</TrayIcon.Menu>
</TrayIcon>
Expand Down
62 changes: 56 additions & 6 deletions App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
using System;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
Expand All @@ -13,14 +17,14 @@ namespace SupportCompanion;

public class App : Application
{
public static AppConfiguration Config { get; private set; }
public IServiceProvider ServiceProvider { get; private set; }

public App()
{
RegisterAppServices();
}


public static AppConfiguration Config { get; private set; }
public IServiceProvider ServiceProvider { get; private set; }

public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
Expand All @@ -34,12 +38,57 @@ public override void Initialize()
var logger = ServiceProvider.GetRequiredService<LoggerService>();
logger.Log("App initialization", "Error loading preferences: " + e.Message, 2);
}

Config = AppConfigHelper.Config;
}

public override void OnFrameworkInitializationCompleted()
private async Task InitializeCultureAsync()
{
var actionService = ServiceProvider.GetRequiredService<ActionsService>();
var mainViewModel = ServiceProvider.GetRequiredService<MainWindowViewModel>();

try
{
// Run the command asynchronously and await the result
var locale = await actionService.RunCommandWithOutput("defaults read NSGlobalDomain AppleLocale");

// Verify and trim the locale string
locale = locale?.Trim().Replace("_", "-");
// Remove unsupported parts from the locale string
if (locale.Contains("@"))
{
locale = locale.Split('@')[0];
}

if (!string.IsNullOrEmpty(locale))
{
// Dynamically set the culture based on the macOS locale
var cultureInfo = new CultureInfo(locale);
Assets.Resources.Culture = cultureInfo;
}
else
// Fallback to a default culture if locale is empty
Assets.Resources.Culture = CultureInfo.CurrentCulture;
}
catch (Exception ex)
{
// Handle exceptions (log them, set a default culture, etc.)
Console.WriteLine($"Failed to set culture: {ex.Message}");
Assets.Resources.Culture = CultureInfo.CurrentCulture; // or set a default culture
}

// Update localized strings for menu items
mainViewModel.NativeMenuOpenText = Assets.Resources.Open + " Support Companion";
mainViewModel.NativeMenuSystemUpdatesText = Assets.Resources.NativeMenuSystemUpdates;
mainViewModel.NativeMenuActionsHeader = Assets.Resources.Actions;
mainViewModel.NativeMenuQuitAppText = Assets.Resources.Exit;
}

public override async void OnFrameworkInitializationCompleted()
{
RegisterAppServices();
await InitializeCultureAsync(); // Ensure the culture is set before proceeding

if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
DataContext = ServiceProvider.GetRequiredService<MainWindowViewModel>();
Expand All @@ -53,8 +102,9 @@ public override void OnFrameworkInitializationCompleted()

if (Config.Actions != null && Config.Actions.Count > 0)
{
var mainViewModel = ServiceProvider.GetRequiredService<MainWindowViewModel>();
// Create the main "Actions" menu item
var actionsMenuItem = new NativeMenuItem { Header = "Actions ✅" };
var actionsMenuItem = new NativeMenuItem { Header = mainViewModel.NativeMenuActionsHeader };
actionsMenuItem.Menu = new NativeMenu();

// Iterate over the Config.Actions and add them as sub-items
Expand Down
Loading

0 comments on commit c6b14d2

Please sign in to comment.