Beispiel #1
0
        private void ThresholdToastCheck(string item)
        {
            if (!SettingsManager.ThresholdWarningEnabled)
            {
                return;
            }

            var translator = Languages.Instance;

            if (!state.Cargo.ContainsKey(item))
            {
                return;
            }

            var entry = state.Cargo[item];

            if (entry.Threshold.HasValue && entry.Threshold <= entry.Count)
            {
                try
                {
                    var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText02);

                    var stringElements = toastXml.GetElementsByTagName("text");
                    var content        = string.Format(
                        translator.Translate(
                            "Reached {0} {1} - threshold set at {2} (click this to configure your thresholds)"),
                        entry.Count, translator.Translate(entry.Data.Name), entry.Threshold);
                    stringElements[0].AppendChild(toastXml.CreateTextNode(translator.Translate("Threshold Reached!")));
                    stringElements[1].AppendChild(toastXml.CreateTextNode(content));

                    var imagePath = "file:///" + Path.GetFullPath("Resources/Images/elite-dangerous-clean.png");

                    var imageElements = toastXml.GetElementsByTagName("image");
                    imageElements[0].Attributes.GetNamedItem("src").NodeValue = imagePath;

                    var toast = new ToastNotification(toastXml);
                    toast.Activated +=
                        (o, e) => Application.Current.Dispatcher.Invoke(() => ThresholdsManagerWindow.ShowThresholds(translator, state.Cargo, commanderName));

                    ToastNotificationManager.CreateToastNotifier("EDEngineer").Show(toast);
                }
                catch (Exception)
                {
                    // silently fail for platforms not supporting toasts
                }
            }
        }
        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;
            }

            icon = TrayIconManager.Init((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) =>
            {
                HideWindow();
                ReleaseNotesManager.ShowReleaseNotes();
            },
                                        Properties.Settings.Default.CurrentVersion,
                                        (o, e) =>
            {
                HideWindow();
                ThresholdsManagerWindow.ShowThresholds(viewModel.Languages, viewModel.CurrentCommander.Value.State.Cargo, viewModel.CurrentCommander.Key);
            });

            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();
        }