Repository: veler/DevToys
File: src/app/dev/platforms/desktop/DevToys.Linux/LinuxProgram.cs (C#)

Code before:
using DevToys.Linux.Components;
using DevToys.Linux.Core;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using DevToys.Core.Logging;
using DevToys.Core.Tools;
using Gio;
using Constants = DevToys.Linux.Core.Constants;
using FileHelper = DevToys.Core.FileHelper;

namespace DevToys.Linux;

internal partial class LinuxProgram
{
    internal static ILogger? Logger;
    private static MefComposer? MefComposer;

    private readonly WindowService _windowService = new();
    private readonly ServiceCollection _serviceCollection = new();
    private readonly DateTime _startTime = DateTime.Now;

    private MainWindow? _mainWindow;

    internal LinuxProgram()
    {
        Gio.Module.Initialize();
        Application = Gtk.Application.New(null, Gio.ApplicationFlags.NonUnique);

        GLib.Functions.SetPrgname("DevToys");
        // Set the human-readable application name for app bar and task list.
        GLib.Functions.SetApplicationName("DevToys");

        Application.OnActivate += OnApplicationActivate;
        Application.OnShutdown += OnApplicationShutdown;
    }

    internal Gtk.Application Application { get; }

    private void OnApplicationActivate(object sender, object e)
    {
        // Initialize services and logging.
        ServiceProvider serviceProvider = InitializeServices();

        // Listen for unhandled exceptions.
        AppDomain.CurrentDomain.UnhandledException += (_, ex) =>
        {
            LogUnhandledException((Exception)ex.ExceptionObject);
        };

        // Clear older temp files.
        FileHelper.ClearTempFiles(Constants.AppTempFolder);

Review comment (refactor):
You can remove this line. This is part of the sample as the Gio.Module is not initialized automatically. 

For Libadwaita and GTK applications this is done automatically via the `Gtk.Application` class for all GTK dependencies including Gio.

- [Gtk.Application](https://github.com/gircore/gir.core/blob/main/src/Libs/Gtk-4.0/Public/Application.cs) calls `Gtk.Module.Initialize`
- `Gtk.Module.Initialize` calls [Gdk.Module.Initialize](https://github.com/gircore/gir.core/blob/295288990b0f2972d0cbf898c937eea48f6109b8/src/Libs/Gtk-4.0/Public/Module.cs#L35)
- `Gdk.Module.Initialze` calls [Gio.Module.Initialize](https://github.com/gircore/gir.core/blob/295288990b0f2972d0cbf898c937eea48f6109b8/src/Libs/Gdk-4.0/Public/Module.cs#L38)

Code after:
using DevToys.Linux.Components;
using DevToys.Linux.Core;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using DevToys.Core.Logging;
using DevToys.Core.Tools;
using Gio;
using Constants = DevToys.Linux.Core.Constants;
using FileHelper = DevToys.Core.FileHelper;

namespace DevToys.Linux;

internal partial class LinuxProgram
{
    internal static ILogger? Logger;
    private static MefComposer? MefComposer;

    private readonly WindowService _windowService = new();
    private readonly ServiceCollection _serviceCollection = new();
    private readonly DateTime _startTime = DateTime.Now;

    private MainWindow? _mainWindow;

    internal LinuxProgram()
    {
        Application = Gtk.Application.New(null, Gio.ApplicationFlags.NonUnique);

        GLib.Functions.SetPrgname("DevToys");
        // Set the human-readable application name for app bar and task list.
        GLib.Functions.SetApplicationName("DevToys");

        Application.OnActivate += OnApplicationActivate;
        Application.OnShutdown += OnApplicationShutdown;
    }

    internal Gtk.Application Application { get; }

    private void OnApplicationActivate(object sender, object e)
    {
        // Initialize services and logging.
        ServiceProvider serviceProvider = InitializeServices();

        // Listen for unhandled exceptions.
        AppDomain.CurrentDomain.UnhandledException += (_, ex) =>
        {
            LogUnhandledException((Exception)ex.ExceptionObject);
        };

        // Clear older temp files.
        FileHelper.ClearTempFiles(Constants.AppTempFolder);