Ejemplo n.º 1
0
        private void OnStartup(object sender, StartupEventArgs e)
        {
            var splashScreenThread = new Thread(() =>
            {
                var splashScreen        = new Windows.SplashScreen();
                _splashScreenDispatcher = splashScreen.Dispatcher;
                splashScreen.Show();
                Dispatcher.Run();
                splashScreen.Close();
            });

            splashScreenThread.SetApartmentState(ApartmentState.STA);
            splashScreenThread.Start();

            var mainWindow = new MainWindow();

            MainWindow         = mainWindow;
            mainWindow.Loaded += async(sender2, e2) =>
                                 await mainWindow.Dispatcher.InvokeAsync(() =>
            {
                _splashScreenDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);
                mainWindow.Activate();
                WatchStart.Stop();
                var elapsedStartMs = WatchStart.ElapsedMilliseconds;
                Logger.Info(
                    $"Popcorn started in {elapsedStartMs} milliseconds.");
            });

            mainWindow.Show();
        }
Ejemplo n.º 2
0
        private void OnStartup(object sender, StartupEventArgs e)
        {
            var splashScreenThread = new Thread(() =>
            {
                var splashScreen        = new Windows.SplashScreen();
                _splashScreenDispatcher = splashScreen.Dispatcher;
                _splashScreenDispatcher.ShutdownStarted += (o, args) => splashScreen.Close();
                splashScreen.Show();
                Dispatcher.Run();
            });

            splashScreenThread.SetApartmentState(ApartmentState.STA);
            splashScreenThread.Start();

            var mainWindow = new MainWindow();

            MainWindow         = mainWindow;
            mainWindow.Loaded += async(sender2, e2) =>
                                 await mainWindow.Dispatcher.InvokeAsync(() =>
            {
                _splashScreenDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);
                mainWindow.Activate();
                var vm = mainWindow.DataContext as WindowViewModel;
                if (_firstRun && vm != null)
                {
                    vm.OpenWelcomeCommand.Execute(null);
                }
                WatchStart.Stop();
                var elapsedStartMs = WatchStart.ElapsedMilliseconds;
                Logger.Info(
                    $"Popcorn started in {elapsedStartMs} milliseconds.");
            });

            mainWindow.Show();
        }
Ejemplo n.º 3
0
        private void OnStartup(object sender, StartupEventArgs e)
        {
            var splashScreenThread = new Thread(() =>
            {
                var splashScreen        = new Windows.SplashScreen();
                _splashScreenDispatcher = splashScreen.Dispatcher;
                splashScreen.Show();
                Dispatcher.Run();
                splashScreen.Close();
            });

            splashScreenThread.SetApartmentState(ApartmentState.STA);
            splashScreenThread.Start();

            var mainWindow = new MainWindow();

            MainWindow         = mainWindow;
            mainWindow.Loaded += async(sender2, e2) =>
                                 await mainWindow.Dispatcher.InvokeAsync(() =>
            {
                _splashScreenDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);
                mainWindow.Activate();
            });

            mainWindow.Show();
        }
Ejemplo n.º 4
0
        private async void OnStartup(object sender, StartupEventArgs e)
        {
            var splashScreenThread = new Thread(() =>
            {
                var splashScreen        = new Windows.SplashScreen();
                _splashScreenDispatcher = splashScreen.Dispatcher;
                _splashScreenDispatcher.ShutdownStarted += (o, args) => splashScreen.Close();
                splashScreen.Show();
                Dispatcher.Run();
            });

            splashScreenThread.SetApartmentState(ApartmentState.STA);
            splashScreenThread.Start();

            ViewModelLocator.Setup();
            try
            {
                Akavache.Sqlite3.Registrations.Start("Popcorn", SQLitePCL.Batteries_V2.Init);
                var userService = SimpleIoc.Default.GetInstance <IUserService>();
                await userService.GetUser();
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }

            var mainWindow = new MainWindow {
                Topmost = true
            };

            MainWindow         = mainWindow;
            mainWindow.Loaded += async(sender2, e2) =>
                                 await mainWindow.Dispatcher.InvokeAsync(async() =>
            {
                await _windowLoadedSemaphore.WaitAsync();
                if (!WatchStart.IsRunning)
                {
                    return;
                }

                _splashScreenDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);
                mainWindow.Activate();
                if (mainWindow.DataContext is WindowViewModel vm)
                {
                    vm.InitializeAsyncCommand.Execute(null);
                }

                WatchStart.Stop();
                var elapsedStartMs = WatchStart.ElapsedMilliseconds;
                Logger.Info(
                    $"Popcorn started in {elapsedStartMs} milliseconds.");
                _windowLoadedSemaphore.Release();
            });

            mainWindow.Show();
        }
Ejemplo n.º 5
0
        private void OnStartup(object sender, StartupEventArgs e)
        {
            var splashScreenThread = new Thread(() =>
            {
                var splashScreen        = new Windows.SplashScreen();
                _splashScreenDispatcher = splashScreen.Dispatcher;
                _splashScreenDispatcher.ShutdownStarted += (o, args) => splashScreen.Close();
                splashScreen.Show();
                Dispatcher.Run();
            });

            splashScreenThread.SetApartmentState(ApartmentState.STA);
            splashScreenThread.Start();

            var mainWindow = new MainWindow();

            mainWindow.Topmost = true;
            MainWindow         = mainWindow;
            mainWindow.Loaded += async(sender2, e2) =>
                                 await mainWindow.Dispatcher.InvokeAsync(async() =>
            {
                await _windowLoadedSemaphore.WaitAsync();
                if (!WatchStart.IsRunning)
                {
                    return;
                }
                _splashScreenDispatcher.InvokeShutdown();
                mainWindow.Activate();
                var vm = mainWindow.DataContext as WindowViewModel;
                if (vm != null)
                {
                    vm.InitializeAsyncCommand.Execute(null);
                    if (_firstRun)
                    {
                        vm.OpenWelcomeCommand.Execute(null);
                    }
                }
                WatchStart.Stop();
                var elapsedStartMs = WatchStart.ElapsedMilliseconds;
                Logger.Info(
                    $"Popcorn started in {elapsedStartMs} milliseconds.");
                _windowLoadedSemaphore.Release();
            });

            mainWindow.Show();
        }