﻿// To start, implement IApplicationSplashScreen
// There you can customize the display.
// You have three options for how the splash screen displays (prioritized in this order):
// 1 - User set custom content (SplashScreenContent) - can be anything you want
// 2 - Application Icon centered image (AppIcon)
// 3 - Application Name centered text (AppName)

// The SplashScreen is set to only open the first time the window opens, so you you need to 
// Show/Hide the main window, it won't show each time

// This is the splash screen used by this sample app
public class SampleAppSplashScreen : IApplicationSplashScreen
{
    public SampleAppSplashScreen()
    {
        var al = AvaloniaLocator.Current.GetService<IAssetLoader>();
        using (var s = al.Open(new Uri("avares://FluentAvaloniaSamples/Assets/FAIcon.ico")))
            AppIcon = new Bitmap(s);
    }

    string IApplicationSplashScreen.AppName { get; }

    public IImage AppIcon { get; }

    object IApplicationSplashScreen.SplashScreenContent { get; }

    // You can also choose to set a minimum show time to hold the splash screen up if the background tasks
    // complete too quickly. This might be desired to prevent weird animation related visual artifacts
    int IApplicationSplashScreen.MinimumShowTime => 2000;


    // This is where you run any custom background tasks. This is called on a background thread so you
    // don't need to do your own Task.Run(); Note that any UI Thread related work must be posted to the
    // dispatcher from here to prevent errors
    void IApplicationSplashScreen.RunTasks()
    {
        
    }
}

public class MainWindow : CoreWindow
{
    public MainWindow()
    {
        InitializeComponent();

        // Set your splash screen and the rest is taken care of when you open the window
        SplashScreen = new SampleAppSplashScreen();
    }

    // NOTE: If you override OnOpened for custom logic, be sure to call base.OnOpened() FIRST
    // as that allows the SplashScreen to run which will hold the loading of window content
    // until it finishes (unless you must run something first).
    protected override void OnOpened()
    {
        base.OnOpened();
    }
}
