2020-08-22 02:39:44 +01:00
|
|
|
/******************************************************************************
|
|
|
|
|
// RomRepoMgr - ROM repository manager
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as
|
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2024-11-08 19:13:57 +00:00
|
|
|
// Copyright © 2020-2024 Natalia Portillo
|
2020-08-22 02:39:44 +01:00
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
2020-08-22 13:32:43 +01:00
|
|
|
using System.Collections.Generic;
|
2020-08-21 22:22:24 +01:00
|
|
|
using Avalonia;
|
2020-08-22 02:39:44 +01:00
|
|
|
using Avalonia.Controls;
|
2020-08-21 22:22:24 +01:00
|
|
|
using Avalonia.Controls.ApplicationLifetimes;
|
|
|
|
|
using Avalonia.Markup.Xaml;
|
2020-08-22 13:36:39 +01:00
|
|
|
using RomRepoMgr.Core.EventArgs;
|
|
|
|
|
using RomRepoMgr.Core.Models;
|
2020-08-21 22:22:24 +01:00
|
|
|
using RomRepoMgr.ViewModels;
|
|
|
|
|
using RomRepoMgr.Views;
|
|
|
|
|
|
2024-11-09 01:37:59 +00:00
|
|
|
namespace RomRepoMgr;
|
|
|
|
|
|
|
|
|
|
public class App : Application
|
2020-08-21 22:22:24 +01:00
|
|
|
{
|
2024-11-09 01:37:59 +00:00
|
|
|
List<RomSetModel> _romSets;
|
2020-08-22 13:32:43 +01:00
|
|
|
|
2024-11-09 01:37:59 +00:00
|
|
|
public override void Initialize() => AvaloniaXamlLoader.Load(this);
|
2020-08-21 22:22:24 +01:00
|
|
|
|
2024-11-09 01:37:59 +00:00
|
|
|
public override void OnFrameworkInitializationCompleted()
|
|
|
|
|
{
|
|
|
|
|
if(ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
2020-08-21 22:22:24 +01:00
|
|
|
{
|
2024-11-09 01:37:59 +00:00
|
|
|
var splashWindow = new SplashWindow();
|
|
|
|
|
var swvm = new SplashWindowViewModel();
|
|
|
|
|
swvm.WorkFinished += OnSplashFinished;
|
|
|
|
|
swvm.GotRomSets += OnGotRomSets;
|
|
|
|
|
splashWindow.DataContext = swvm;
|
|
|
|
|
desktop.MainWindow = splashWindow;
|
2020-08-21 22:22:24 +01:00
|
|
|
}
|
2020-08-22 02:39:44 +01:00
|
|
|
|
2024-11-09 01:37:59 +00:00
|
|
|
base.OnFrameworkInitializationCompleted();
|
|
|
|
|
}
|
2020-08-22 13:32:43 +01:00
|
|
|
|
2024-11-09 01:37:59 +00:00
|
|
|
void OnGotRomSets(object sender, RomSetsEventArgs e) => _romSets = e.RomSets;
|
2020-08-22 02:39:44 +01:00
|
|
|
|
2024-11-09 01:37:59 +00:00
|
|
|
void OnSplashFinished(object sender, EventArgs e)
|
|
|
|
|
{
|
2024-11-12 06:17:14 +00:00
|
|
|
if(ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop) return;
|
2020-08-22 02:39:44 +01:00
|
|
|
|
2024-11-09 01:37:59 +00:00
|
|
|
// Ensure not exit
|
|
|
|
|
desktop.ShutdownMode = ShutdownMode.OnExplicitShutdown;
|
2020-08-22 02:39:44 +01:00
|
|
|
|
2024-11-09 01:37:59 +00:00
|
|
|
// Close splash window
|
|
|
|
|
desktop.MainWindow.Close();
|
2020-08-22 02:39:44 +01:00
|
|
|
|
2024-11-09 01:37:59 +00:00
|
|
|
// Create and show main window
|
|
|
|
|
desktop.MainWindow = new MainWindow();
|
|
|
|
|
desktop.MainWindow.DataContext = new MainWindowViewModel(desktop.MainWindow as MainWindow, _romSets);
|
|
|
|
|
desktop.MainWindow.Show();
|
2020-08-22 03:13:49 +01:00
|
|
|
|
2024-11-09 01:37:59 +00:00
|
|
|
// Now can close when all windows are closed
|
|
|
|
|
desktop.ShutdownMode = ShutdownMode.OnLastWindowClose;
|
|
|
|
|
}
|
2020-08-22 03:13:49 +01:00
|
|
|
|
2024-11-09 01:37:59 +00:00
|
|
|
void OnAboutClicked(object sender, EventArgs args)
|
|
|
|
|
{
|
2024-11-12 06:18:24 +00:00
|
|
|
if(ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime
|
|
|
|
|
{
|
|
|
|
|
MainWindow: MainWindow
|
|
|
|
|
{
|
|
|
|
|
DataContext: MainWindowViewModel mainWindowViewModel
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-11-09 01:37:59 +00:00
|
|
|
return;
|
2020-08-22 03:13:49 +01:00
|
|
|
|
2024-11-09 01:37:59 +00:00
|
|
|
mainWindowViewModel.ExecuteAboutCommand();
|
|
|
|
|
}
|
2020-08-22 03:13:49 +01:00
|
|
|
|
2024-11-09 01:37:59 +00:00
|
|
|
void OnQuitClicked(object sender, EventArgs args)
|
|
|
|
|
{
|
2024-11-12 06:18:24 +00:00
|
|
|
if(ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime
|
|
|
|
|
{
|
|
|
|
|
MainWindow: MainWindow
|
|
|
|
|
{
|
|
|
|
|
DataContext: MainWindowViewModel mainWindowViewModel
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-11-09 01:37:59 +00:00
|
|
|
return;
|
2020-08-22 03:13:49 +01:00
|
|
|
|
2024-11-09 01:37:59 +00:00
|
|
|
mainWindowViewModel.ExecuteExitCommand();
|
|
|
|
|
}
|
2020-08-22 03:13:49 +01:00
|
|
|
|
2024-11-09 01:37:59 +00:00
|
|
|
void OnPreferencesClicked(object sender, EventArgs args)
|
|
|
|
|
{
|
2024-11-12 06:18:24 +00:00
|
|
|
if(ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime
|
|
|
|
|
{
|
|
|
|
|
MainWindow: MainWindow
|
|
|
|
|
{
|
|
|
|
|
DataContext: MainWindowViewModel mainWindowViewModel
|
|
|
|
|
}
|
|
|
|
|
})
|
2024-11-09 01:37:59 +00:00
|
|
|
return;
|
|
|
|
|
|
2025-07-07 22:41:08 +01:00
|
|
|
_ = mainWindowViewModel.ExecuteSettingsCommandAsync();
|
2020-08-21 22:22:24 +01:00
|
|
|
}
|
|
|
|
|
}
|