public MainWindow() { var procName = Process.GetCurrentProcess().ProcessName; var processes = Process.GetProcessesByName(procName); if (processes.Length > 1) { System.Windows.Forms.MessageBox.Show($"EDEngineer already running, you can bring it up with your shortcut ({SettingsManager.Shortcut}).", "Oops", MessageBoxButtons.OK, MessageBoxIcon.Warning); Application.Current.Shutdown(); return; } SettingsManager.Init(); try { ReleaseNotesManager.ShowReleaseNotesIfNecessary(); } catch { // silently fail if release notes can't be shown } Languages.InitLanguages(); InitializeComponent(); if (Properties.Settings.Default.WindowUnlocked) { AllowsTransparency = false; WindowStyle = WindowStyle.SingleBorderWindow; Topmost = false; ShowInTaskbar = true; } else { AllowsTransparency = true; WindowStyle = WindowStyle.None; Topmost = true; ShowInTaskbar = false; } viewModel = new MainWindowViewModel(Languages.Instance); DataContext = viewModel; RefreshCargoSources(); viewModel.PropertyChanged += (o, e) => { if (e.PropertyName == "ShowOnlyForFavorites" || e.PropertyName == "ShowZeroes" || e.PropertyName == "CurrentCommander") { RefreshCargoSources(); } }; serverBridge = new ServerBridge(viewModel, SettingsManager.AutoRunServer); }
public MainWindow() { var procName = Process.GetCurrentProcess().ProcessName; var processes = Process.GetProcessesByName(procName); if (processes.Length > 1) { System.Windows.Forms.MessageBox.Show($"EDEngineer already running, you can bring it up with your shortcut ({SettingsManager.Shortcut}).", "Oops", MessageBoxButtons.OK, MessageBoxIcon.Warning); Application.Current.Shutdown(); return; } InitializeComponent(); SettingsManager.Init(); try { ReleaseNotesManager.ShowReleaseNotesIfNecessary(); if (ReleaseNotesManager.RequireReset) { Properties.Settings.Default.ClearAggregation = true; Properties.Settings.Default.Save(); } } catch { // silently fail if release notes can't be shown } NotificationSettingsWindow.InitNotifications(); if (Properties.Settings.Default.WindowUnlocked) { AllowsTransparency = false; WindowStyle = WindowStyle.SingleBorderWindow; Topmost = false; ShowInTaskbar = true; } else { AllowsTransparency = true; WindowStyle = WindowStyle.None; Topmost = true; ShowInTaskbar = false; } var dimensions = SettingsManager.Dimensions; Width = dimensions.Width; Left = dimensions.Left; Top = dimensions.Top; Height = dimensions.Height; WindowState = SettingsManager.Maximized ? WindowState.Maximized : WindowState; var logDirectory = Helpers.RetrieveLogDirectory(false, null); var task = Task.Factory.StartNew(() => { viewModel = new MainWindowViewModel(Languages.Instance, logDirectory); if (ReleaseNotesManager.RequireReset) { viewModel.ChangeAllFilters(true); } viewModel.PropertyChanged += (o, e) => { if (e.PropertyName == "ShowOnlyForFavorites" || e.PropertyName == "ShowZeroes" || e.PropertyName == "CurrentCommander" || e.PropertyName == "MaterialSubkindFilter" || e.PropertyName == "IngredientsGrouped") { RefreshCargoSources(); } if (e.PropertyName == "IngredientsGrouped") { viewModel.CurrentComparer = viewModel.CurrentComparer; } }; }); task.ContinueWith(t => { new Popups.ErrorWindow(t.Exception?.Flatten() ?? new Exception("Unknown Error")).ShowDialog(); Close(); }, CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, TaskScheduler.FromCurrentSynchronizationContext()); task.ContinueWith(t => { serverBridge = new ServerBridge(viewModel, SettingsManager.AutoRunServer); DataContext = viewModel; RefreshCargoSources(); PostLoad(dimensions); if (!SettingsManager.SilentLaunch) { var sb = (Storyboard)FindResource("HideSplash"); Storyboard.SetTarget(sb, Splash); sb.Begin(); } viewModel.InitiateWatch(); }, CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.FromCurrentSynchronizationContext()); if (SettingsManager.SilentLaunch) { Splash.Visibility = Visibility.Collapsed; if (Properties.Settings.Default.WindowUnlocked) { WindowState = WindowState.Minimized; } else { Opacity = 0.001; } } }
private void PostLoad(WindowDimensions dimensions) { if (dimensions.LeftSideWidth != 1 || dimensions.RightSideWidth != 1) { ContentGrid.ColumnDefinitions[0].Width = new GridLength(dimensions.LeftSideWidth, GridUnitType.Star); ContentGrid.ColumnDefinitions[2].Width = new GridLength(dimensions.RightSideWidth, GridUnitType.Star); } if (AllowsTransparency) { ToggleEditMode.Content = viewModel.Languages.Translate("Unlock Window"); MainSplitter.Visibility = Visibility.Hidden; } else { ToggleEditMode.Content = viewModel.Languages.Translate("Lock Window"); ResetWindowPositionButton.Visibility = Visibility.Visible; } menu = TrayIconManager.BuildContextMenu((o, e) => ShowWindow(), (o, e) => Close(), ConfigureShortcut, (o, e) => ToggleEditModeChecked(o, null), (o, e) => ResetWindowPositionButtonClicked(o, null), (o, e) => Languages.PromptLanguage(viewModel.Languages), () => serverBridge.Toggle(), serverBridge.Running, (o, e) => { ReleaseNotesManager.ShowReleaseNotes(); }, Properties.Settings.Default.CurrentVersion, (o, e) => { new NotificationSettingsWindow(viewModel.Languages).ShowDialog(); }, (o, e) => { new GraphicSettingsWindow(viewModel.GraphicSettings).ShowDialog(); }, (o, e) => { System.Diagnostics.Process.Start($"http://localhost:{SettingsManager.ServerPort}/{viewModel.CurrentCommander.Key}/chart"); }, (o, e) => ClearAggregationAndRestart(o, null), (o, e) => { new SettingsExportWindow(Restart, RefreshShoppingList).ShowDialog(); }); icon = TrayIconManager.Init(menu); try { var shortcut = SettingsManager.Shortcut; var hotKey = (Keys) new KeysConverter().ConvertFromString(shortcut); HotkeyManager.RegisterHotKey(this, hotKey); } catch { SettingsManager.Shortcut = null; ConfigureShortcut(this, EventArgs.Empty); ShowWindow(); } Blueprints.UpdateLayout(); ShoppingList.UpdateLayout(); if (!AllowsTransparency) { saveDimensionScheduler = new PostponeScheduler(SaveDimensions, 500); SizeChanged += (o, e) => saveDimensionScheduler.Schedule(); LocationChanged += (o, e) => saveDimensionScheduler.Schedule(); MainSplitter.DragCompleted += (o, e) => saveDimensionScheduler.Schedule(); } }
private void ContentDialog_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) { ReleaseNotesManager.ShownReleaseNotes(); }
private void MainWindowLoaded(object sender, RoutedEventArgs args) { var dimensions = SettingsManager.Dimensions; Width = dimensions.Width; Left = dimensions.Left; Top = dimensions.Top; Height = dimensions.Height; if (dimensions.LeftSideWidth != 1 || dimensions.RightSideWidth != 1) { ContentGrid.ColumnDefinitions[0].Width = new GridLength(dimensions.LeftSideWidth, GridUnitType.Star); ContentGrid.ColumnDefinitions[2].Width = new GridLength(dimensions.RightSideWidth, GridUnitType.Star); } if (AllowsTransparency) { ToggleEditMode.Content = viewModel.Languages.Translate("Unlock Window"); MainSplitter.Visibility = Visibility.Hidden; } else { ToggleEditMode.Content = viewModel.Languages.Translate("Lock Window"); ResetWindowPositionButton.Visibility = Visibility.Visible; } menu = TrayIconManager.BuildContextMenu((o, e) => ShowWindow(), (o, e) => Close(), ConfigureShortcut, (o, e) => ToggleEditModeChecked(o, null), (o, e) => ResetWindowPositionButtonClicked(o, null), (o, e) => Languages.PromptLanguage(viewModel.Languages), () => serverBridge.Toggle(), serverBridge.Running, (o, e) => { ReleaseNotesManager.ShowReleaseNotes(); }, Properties.Settings.Default.CurrentVersion, (o, e) => { ThresholdsManagerWindow.ShowThresholds(viewModel.Languages, viewModel.CurrentCommander.Value.State.Cargo, viewModel.CurrentCommander.Key); }, (o, e) => { new NotificationSettingsWindow(viewModel.Languages).ShowDialog(); }, (o, e) => { new GraphicSettingsWindow(viewModel.GraphicSettings).ShowDialog(); }); icon = TrayIconManager.Init(menu); try { var shortcut = SettingsManager.Shortcut; var hotKey = (Keys) new KeysConverter().ConvertFromString(shortcut); HotkeyManager.RegisterHotKey(this, hotKey); } catch { SettingsManager.Shortcut = null; ConfigureShortcut(this, EventArgs.Empty); ShowWindow(); } Blueprints.UpdateLayout(); ShoppingList.UpdateLayout(); if (!AllowsTransparency) { saveDimensionScheduler = new PostponeScheduler(SaveDimensions, 500); SizeChanged += (o, e) => saveDimensionScheduler.Schedule(); LocationChanged += (o, e) => saveDimensionScheduler.Schedule(); MainSplitter.DragCompleted += (o, e) => saveDimensionScheduler.Schedule(); } }