public MainWindow(MainViewModel viewmodel) { InitializeComponent(); var settings = PeerCastStation.Core.PeerCastApplication.Current.Settings.Get<WPFSettings>(); if (IsFinite(settings.WindowLeft)) this.Left = settings.WindowLeft; if (IsFinite(settings.WindowTop)) this.Top = settings.WindowTop; if (IsFinite(settings.WindowWidth)) this.Width = settings.WindowWidth; if (IsFinite(settings.WindowHeight)) this.Height = settings.WindowHeight; if (IsFinite(this.Left) && IsFinite(this.Width)) { if (this.Width>SystemParameters.VirtualScreenWidth) { this.Width = SystemParameters.VirtualScreenWidth; } if (this.Left+this.Width/2<SystemParameters.VirtualScreenLeft) { this.Left = SystemParameters.VirtualScreenLeft; } if (this.Left+this.Width/2>SystemParameters.VirtualScreenWidth+SystemParameters.VirtualScreenLeft) { this.Left = SystemParameters.VirtualScreenWidth+SystemParameters.VirtualScreenLeft - this.Width; } } if (IsFinite(this.Top) && IsFinite(this.Height)) { if (this.Height>SystemParameters.VirtualScreenHeight) { this.Height = SystemParameters.VirtualScreenHeight; } if (this.Top<SystemParameters.VirtualScreenTop) { this.Top = SystemParameters.VirtualScreenTop; } if (this.Top+this.Height/2>SystemParameters.VirtualScreenHeight+SystemParameters.VirtualScreenTop) { this.Top = SystemParameters.VirtualScreenHeight+SystemParameters.VirtualScreenTop - this.Height; } } this.DataContext = viewmodel; }
protected override void OnStart() { notifyIconThread = new Thread(() => { #if !DEBUG try #endif { notifyIconManager = new NotifyIconManager(Application.PeerCast); notifyIconManager.CheckVersionClicked += (sender, e) => versionChecker.CheckVersion(); notifyIconManager.QuitClicked += (sender, e) => Application.Stop(); notifyIconManager.ShowWindowClicked += (sender, e) => { if (mainWindow!=null) { mainWindow.Dispatcher.Invoke(new Action(() => { mainWindow.Show(); if (mainWindow.WindowState==WindowState.Minimized) { mainWindow.WindowState = WindowState.Normal; } mainWindow.Activate(); })); } }; versionChecker = new AppCastReader( new Uri(Settings.Default.UpdateURL, UriKind.Absolute), Settings.Default.CurrentVersion); versionChecker.NewVersionFound += (sender, e) => { notifyIconManager.NewVersionInfo = e.VersionDescription; }; versionChecker.CheckVersion(); notifyIconManager.Run(); } #if !DEBUG catch (Exception e) { logger.Fatal("Unhandled exception"); logger.Fatal(e); throw; } #endif }); notifyIconThread.SetApartmentState(ApartmentState.STA); notifyIconThread.Start(); mainThread = new Thread(() => { #if !DEBUG try #endif { var app = new Application(); viewModel = new MainViewModel(Application); var settings = Application.Settings.Get<WPFSettings>(); mainWindow = new MainWindow(viewModel); if (settings.ShowWindowOnStartup) mainWindow.Show(); app.Run(); viewModel.Dispose(); } #if !DEBUG catch (Exception e) { logger.Fatal("Unhandled exception"); logger.Fatal(e); throw; } #endif }); mainThread.Name = "WPF UI Thread"; mainThread.SetApartmentState(ApartmentState.STA); mainThread.Start(); }