Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainWindow"/> class.
        /// </summary>
        /// <param name="eventAggregator">The event aggregator.</param>
        /// <param name="sdk">The SDK.</param>
        public MainWindow(EventAggregator eventAggregator, SDKMonitor sdk)
        {
            SdkMonitor = sdk;
            Aggregator = eventAggregator;
            InitializeComponent();

            // the following line is to allow ElementName bindings in the Context menu to resolve properly
            // Context menu's are not in the Visual Tree.
            NameScope.SetNameScope(contextMenu, NameScope.GetNameScope(this));

            _notificationSubscription = eventAggregator.GetEvent <ShowNotificationEvent>().Subscribe((msg) =>
            {
                RunOnDisplayThread(() =>
                {
                    MainViewModel mvm = DataContext as MainViewModel;
                    if (mvm != null && mvm.IsShuttingDown)
                    {
                        return;
                    }
                });

                TaskbarIconControl.ShowBalloonTip(msg.Title, msg.Text, msg.Icon);
            });

            _showMainViewSubscription = eventAggregator.GetEvent <ShowViewEvent>().Subscribe((msg) =>
            {
                if (msg.ID == Common.ViewList.Views.MainWindow)
                {
                    RunOnDisplayThread(() =>
                    {
                        if (msg.Show)
                        {
                            Visibility  = Visibility.Visible;
                            WindowState = WindowState.Normal;
                            BringIntoView();
                            Activate();
                        }
                        else
                        {
                            Visibility  = Visibility.Hidden;
                            WindowState = WindowState.Normal;
                        }
                    });
                }
            });

            Loaded += OnLoaded;
        }
Example #2
0
        /// <summary>
        /// Raises and handles the <see cref="E:System.Windows.Application.Startup" /> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.StartupEventArgs" /> that contains the event data.</param>
        protected override async void OnStartup(StartupEventArgs e)
        {
            ConfigureLogger();
            ConfigureContainer();
            _logger.Info("++++++++++  Starting Application ");
            _logger.Info($"Version: {Assembly.GetExecutingAssembly().GetName().Version}");

            base.OnStartup(e);

            // Configure HockeySDK client
#if !DEBUG
            try
            {
                HockeyClient.Current.Configure(Helpers.Resource.Get <string>("HOCKEYAPP_APP_ID", string.Empty));
                await HockeyClient.Current.SendCrashesAsync(true);
            }
            catch
            {
                // Ignore
            }
#endif

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            var mainWindows = ContainerInstance.GetInstance <MainWindow>();

            SDKMonitor      sdkmonitor = ContainerInstance.GetInstance <SDKMonitor>();
            EventAggregator aggregator = ContainerInstance.GetInstance <EventAggregator>();

            if (Settings.Default.CallUpgrade)
            {
                // put any first run logic in here.
                Settings.Default.ShowHideNotification = true;
                Settings.Default.CallUpgrade          = false;
                Settings.Default.Save();
            }

            if (sdkmonitor.HideApplicationOnStartup)
            {
                Task.Factory.StartNew(() =>
                {
                    RunOnDisplayThread(() =>
                    {
                        mainWindows.Visibility = Visibility.Hidden;
                        MainWindow             = mainWindows;
                        aggregator.Publish <ShowViewEvent>(new ShowViewEvent {
                            ID = Common.ViewList.Views.MainWindow, Show = false
                        });
                        if (Settings.Default.ShowHideNotification)
                        {
                            aggregator.Publish <ShowNotificationEvent>(new ShowNotificationEvent
                            {
                                Title = WLVpn.Resources.Strings.SETTINGS_APPLICATION_STARTUP,
                                Text  = WLVpn.Resources.Strings.SETTINGS_SYSTEM_STARTUP_OPTION2
                            });
                            Settings.Default.ShowHideNotification = false;
                            Settings.Default.Save();
                        }
                    });
                });
            }
            else
            {
                mainWindows.Show();
            }
        }