From aa64577b21e54fca0f514cfb90caf6c35953748d Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Thu, 13 Sep 2012 16:13:43 -0400 Subject: Improved BaseApplication --- MediaBrowser.Common/UI/BaseApplication.cs | 66 ++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 5 deletions(-) (limited to 'MediaBrowser.Common/UI') diff --git a/MediaBrowser.Common/UI/BaseApplication.cs b/MediaBrowser.Common/UI/BaseApplication.cs index ea3e3718a0..12e423f60c 100644 --- a/MediaBrowser.Common/UI/BaseApplication.cs +++ b/MediaBrowser.Common/UI/BaseApplication.cs @@ -1,21 +1,34 @@ -using System; -using System.Windows; -using MediaBrowser.Common.Kernel; +using MediaBrowser.Common.Kernel; using MediaBrowser.Common.Logging; using MediaBrowser.Model.Progress; +using Microsoft.Shell; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Windows; namespace MediaBrowser.Common.UI { /// /// Serves as a base Application class for both the UI and Server apps. /// - public abstract class BaseApplication : Application + public abstract class BaseApplication : Application, INotifyPropertyChanged, ISingleInstanceApp { private IKernel Kernel { get; set; } protected abstract IKernel InstantiateKernel(); protected abstract Window InstantiateMainWindow(); + public event PropertyChangedEventHandler PropertyChanged; + + public void OnPropertyChanged(String info) + { + if (PropertyChanged != null) + { + PropertyChanged(this, new PropertyChangedEventArgs(info)); + } + } + protected override void OnStartup(StartupEventArgs e) { // Without this the app will shutdown after the splash screen closes @@ -43,7 +56,10 @@ namespace MediaBrowser.Common.UI splash.Close(); ShutdownMode = System.Windows.ShutdownMode.OnLastWindowClose; - InstantiateMainWindow().ShowDialog(); + + OnKernelLoaded(); + + InstantiateMainWindow().Show(); } catch (Exception ex) { @@ -60,11 +76,51 @@ namespace MediaBrowser.Common.UI } } + protected virtual void OnKernelLoaded() + { + + } + protected override void OnExit(ExitEventArgs e) { base.OnExit(e); Kernel.Dispose(); } + + public bool SignalExternalCommandLineArgs(IList args) + { + OnSecondInstanceLaunched(args); + + return true; + } + + protected virtual void OnSecondInstanceLaunched(IList args) + { + if (this.MainWindow.WindowState == WindowState.Minimized) + { + this.MainWindow.WindowState = WindowState.Maximized; + } + } + + public static void RunApplication(string uniqueKey) + where TApplicationType : BaseApplication, IApplication, new() + { + if (SingleInstance.InitializeAsFirstInstance(uniqueKey)) + { + var application = new TApplicationType(); + application.InitializeComponent(); + + application.Run(); + + // Allow single instance code to perform cleanup operations + SingleInstance.Cleanup(); + } + } + } + + public interface IApplication + { + void InitializeComponent(); } } -- cgit v1.2.3