コード例 #1
0
        private int ToolbarHeight => SystemInformation.CaptionHeight + 6; // couldn't find a proper property returning "29" which is the height I need

        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)
            {
                MainGrid.ColumnDefinitions[0].Width = new GridLength(dimensions.LeftSideWidth, GridUnitType.Star);
                MainGrid.ColumnDefinitions[2].Width = new GridLength(dimensions.RightSideWidth, GridUnitType.Star);
            }

            if (AllowsTransparency)
            {
                ToggleEditMode.Content = "Transparente";
                Splitter.Visibility    = Visibility.Hidden;
            }
            else
            {
                ToggleEditMode.Content = "Normal";
                ResetWindowPositionButton.Visibility = Visibility.Visible;
            }

            icon = TrayIconManager.Init((o, e) => ShowWindow(), (o, e) => Close(), ConfigureShortcut, (o, e) => ToggleEditModeChecked(o, null));

            var shortcut = SettingsManager.Shortcut;

            HotkeyManager.RegisterHotKey(this, (Keys) new KeysConverter().ConvertFromString(shortcut));
        }
コード例 #2
0
        internal static void CreateAutorunShortcut()
        {
            if (App.IsUWP)
            {
                return;
            }

            try
            {
                File.Create(StartupFullPath).Close();

                var lnk = ShellLinkHelper.OpenShellLink(StartupFullPath);

                lnk.Path      = App.AppFullPath;
                lnk.Arguments = "/autorun"; // silent
                lnk.SetIconLocation(App.AppFullPath, 0);
                lnk.WorkingDirectory = App.AppPath;

                lnk.Save(StartupFullPath);
            }
            catch (Exception)
            {
                TrayIconManager.ShowNotification("", "Failed to add QuickLook to Startup folder.");
            }
        }
コード例 #3
0
        internal static void CreateAutorunShortcut()
        {
            if (App.IsUWP)
            {
                return;
            }

            try
            {
                File.Create(StartupFullPath).Close();

                var shl = new Shell();
                var dir = shl.NameSpace(Path.GetDirectoryName(StartupFullPath));
                var itm = dir.Items().Item(Path.GetFileName(StartupFullPath));
                var lnk = (ShellLinkObject)itm.GetLink;

                lnk.Path      = App.AppFullPath;
                lnk.Arguments = "/autorun"; // silent
                lnk.SetIconLocation(App.AppFullPath, 0);
                lnk.WorkingDirectory = App.AppPath;

                lnk.Save(StartupFullPath);
            }
            catch (Exception)
            {
                TrayIconManager.GetInstance().ShowNotification("", "Failed to add QuickLook to Startup folder.");
            }
        }
コード例 #4
0
        public static void CollectAndShowReleaseNotes()
        {
            Task.Run(() =>
            {
                try
                {
                    var json = DownloadJson("https://api.github.com/repos/xupefei/QuickLook/releases");

                    var notes = string.Empty;

                    foreach (var item in json)
                    {
                        notes += $"# {item["name"]}\r\n\r\n";
                        notes += item["body"] + "\r\n\r\n";
                    }

                    var changeLogPath = Path.GetTempFileName() + ".md";
                    File.WriteAllText(changeLogPath, notes);

                    PipeServerManager.SendMessage(PipeMessages.Invoke, changeLogPath);
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                    Application.Current.Dispatcher.Invoke(
                        () => TrayIconManager.ShowNotification("",
                                                               string.Format(TranslationHelper.GetString("Update_Error"), e.Message)));
                }
            });
        }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: jonjetjon/hath-client
        private void MainForm_Load(object sender, EventArgs e)
        {
            if (Cmd.States.Silent)
            {
                this.Hide();
            }

            Init.Start();
            SqlManager.Connect();

            IconManager = new TrayIconManager(TrayIcon);

            Log.Destination = LogBox;
            Log.Debug       = Cmd.States.Debug;

            MainStats.ConnectionsChange      += new MainStats.EventInt(MainStats_ConnectionsChange);
            MainStats.Downloaded             += new MainStats.EventLong(MainStats_Downloaded);
            MainStats.FileDownloaded         += new MainStats.EventInt(MainStats_FileDownloaded);
            MainStats.FileUploaded           += new MainStats.EventInt(MainStats_FileUploaded);
            MainStats.Uploaded               += new MainStats.EventLong(MainStats_Uploaded);
            MainStats.ConnectionsChangeTotal += new MainStats.EventInt(MainStats_ConnectionsChangeTotal);
            MainStats.CacheUsed              += new MainStats.EventLong(MainStats_CacheUsed);
            MainStats.FileInCache            += new MainStats.EventInt(MainStats_FileInCache);
            MainStats.Pendingfiles           += new MainStats.EventInt(MainStats_Pendingfiles);
            MainStats.CacheUsedPercent       += new MainStats.EventDouble(MainStats_CacheUsedPercent);
            MainStats.KAlive += new MainStats.EventInt(MainStats_KAlive);

            MainStats.Start();
            GCollector.Start();
        }
コード例 #6
0
        protected override void OnStartup(StartupEventArgs e)
        {
            var window     = new MainWindow();
            var notifyView = new NotifyView();

            var mainNavManager  = new NavigationManager(Dispatcher, window.FrameContent);
            var trayIconManager = new TrayIconManager(new CommandFactory(), notifyView);

            container.Register(Component
                               .For <INavigationManager>()
                               .Instance(mainNavManager));

            container.Register(Component
                               .For <ITrayIconManager>()
                               .Instance(trayIconManager));

            var helpViewModel    = container.Resolve <HelpViewModel>();
            var buffersViewModel = container.Resolve <BuffersViewModel>();
            var windowViewModel  = container.Resolve <MainWindowViewModel>();
            var notifyViewModel  = container.Resolve <NotifyViewModel>();

            window.DataContext     = windowViewModel;
            notifyView.DataContext = notifyViewModel;

            mainNavManager.Register <HelpViewModel, HelpView>(
                helpViewModel, NavigationKeys.HelpView);

            mainNavManager.Register <BuffersViewModel, BuffersView>(
                buffersViewModel, NavigationKeys.BuffersView);

            mainNavManager.Navigate(NavigationKeys.HelpView);
            window.Show();
        }
コード例 #7
0
        internal static void CreateAutorunShortcut()
        {
            if (App.IsUWP)
            {
                return;
            }

            try
            {
                RemoveAutorunShortcut();

                var lnk = (IShellLinkW) new ShellLink();

                lnk.SetPath(App.AppFullPath);
                lnk.SetArguments("/autorun"); // silent
                lnk.SetIconLocation(App.AppFullPath, 0);
                lnk.SetWorkingDirectory(App.AppPath);
                ((IPersistFile)lnk).Save(StartupFullPath, false);
            }
            catch (Exception e)
            {
                ProcessHelper.WriteLog(e.ToString());
                TrayIconManager.ShowNotification("", "Failed to add QuickLook to Startup folder.");
            }
        }
コード例 #8
0
 private void Settings_SettingsLoaded(object sender, System.Configuration.SettingsLoadedEventArgs e)
 {
     if (Default.TrayMinimize)
     {
         TrayIconManager.Enable(WindowManager.ProjectPreviewScreen, WindowManager.InProgressScreen, WindowManager.ResultsScreen);
     }
 }
コード例 #9
0
ファイル: MainWindow.cs プロジェクト: Athanasius/EDEngineer
        private void MainWindowLoaded(object sender, RoutedEventArgs args)
        {
            var dimensions = SettingsManager.Dimensions;

            Width = dimensions.Width;
            Left  = dimensions.Left;

            if (AllowsTransparency)
            {
                Top    = dimensions.Top;
                Height = dimensions.Height;
                ToggleEditMode.Content = "Unlock Window";
            }
            else
            {
                Top    = dimensions.Top - SystemInformation.ToolWindowCaptionHeight;
                Height = dimensions.Height + SystemInformation.ToolWindowCaptionHeight;
                ToggleEditMode.Content = "Lock Window";
                ResetWindowPositionButton.Visibility = Visibility.Visible;
                ShowZeroesToggleButton.Visibility    = Visibility.Hidden;
            }

            icon = TrayIconManager.Init((o, e) => ShowWindow(), (o, e) => Close(), ConfigureShortcut);

            var shortcut = SettingsManager.Shortcut;

            HotkeyManager.RegisterHotKey(this, (Keys) new KeysConverter().ConvertFromString(shortcut));
        }
コード例 #10
0
        protected override void OnActivated(EventArgs e)
        {
            base.OnActivated(e);
            TrayIconManager.SetDefault();

            if (winAlarm != null)
            {
                winAlarm.Hide();
            }
        }
コード例 #11
0
        public static void CheckForUpdates(bool silent = false)
        {
            if (App.IsUWP)
            {
                if (!silent)
                {
                    Process.Start("ms-windows-store://pdp/?productid=9NV4BS3L1H4S");
                }

                return;
            }

            Task.Run(() =>
            {
                try
                {
                    var json = DownloadJson("https://api.github.com/repos/xupefei/QuickLook/releases/latest");

                    var nVersion = (string)json["tag_name"];
                    //nVersion = "9.2.1";

                    if (new Version(nVersion) <= Assembly.GetExecutingAssembly().GetName().Version)
                    {
                        if (!silent)
                        {
                            Application.Current.Dispatcher.Invoke(
                                () => TrayIconManager.ShowNotification("",
                                                                       TranslationHelper.Get("Update_NoUpdate")));
                        }
                        return;
                    }

                    CollectAndShowReleaseNotes();

                    Application.Current.Dispatcher.Invoke(
                        () =>
                    {
                        TrayIconManager.ShowNotification("",
                                                         string.Format(TranslationHelper.Get("Update_Found"), nVersion),
                                                         timeout: 20000,
                                                         clickEvent:
                                                         () => Process.Start(
                                                             @"https://github.com/xupefei/QuickLook/releases/latest"));
                    });
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                    Application.Current.Dispatcher.Invoke(
                        () => TrayIconManager.ShowNotification("",
                                                               string.Format(TranslationHelper.Get("Update_Error"), e.Message)));
                }
            });
        }
コード例 #12
0
ファイル: Updater.cs プロジェクト: Milly/QuickLook
        public static void CheckForUpdates(bool silent = false)
        {
            Task.Run(() =>
            {
                try
                {
                    var web = new WebClientEx(15 * 1000);
                    web.Headers.Add(HttpRequestHeader.UserAgent, "Wget/1.9.1");

                    var response = web.DownloadDataStream("https://api.github.com/repos/xupefei/QuickLook/releases");

                    var json = JsonConvert.DeserializeObject <dynamic>(new StreamReader(response).ReadToEnd());

                    var nVersion = (string)json[0]["tag_name"];
                    //nVersion = "0.2.1";

                    if (new Version(nVersion) <= Assembly.GetExecutingAssembly().GetName().Version)
                    {
                        if (!silent)
                        {
                            Application.Current.Dispatcher.Invoke(
                                () => TrayIconManager.GetInstance().ShowNotification("",
                                                                                     "You are now on the latest version."));
                        }
                        return;
                    }

                    string notes = CollectReleaseNotes(json);

                    var changeLogPath = Path.GetTempFileName() + ".md";
                    File.WriteAllText(changeLogPath, notes);

                    Application.Current.Dispatcher.Invoke(
                        () =>
                    {
                        ViewWindowManager.GetInstance().InvokeViewer(changeLogPath);
                        TrayIconManager.GetInstance().ShowNotification("",
                                                                       $"New version {nVersion} is released. Click here to open the download page.",
                                                                       clickEvent: () => Process.Start(
                                                                           @"https://github.com/xupefei/QuickLook/releases/latest"));
                    });
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                    Application.Current.Dispatcher.Invoke(
                        () => TrayIconManager.GetInstance().ShowNotification("",
                                                                             $"Error occured when checking for updates: {e.Message}"));
                }
            });
        }
コード例 #13
0
ファイル: MainWindow.cs プロジェクト: Andargor/EDEngineer
        private void MainWindowLoaded(object sender, RoutedEventArgs args)
        {
            icon = TrayIconManager.Init((o, e) => ShowWindow(), (o, e) => Close(), ConfigureShortcut);

            var shortcut  = Properties.Settings.Default.Shortcut;
            var converter = new KeysConverter();

            if (string.IsNullOrEmpty(shortcut))
            {
                shortcut = Properties.Settings.Default.Shortcut = converter.ConvertToString(Keys.F10 | Keys.Control);
                Properties.Settings.Default.Save();
            }

            HotkeyManager.RegisterHotKey(this, (Keys) new KeysConverter().ConvertFromString(shortcut));
        }
コード例 #14
0
        public StartWindow()
        {
            InitializeComponent();
            var bootstrapper = new StartBootstrapper();
            DataContext = bootstrapper;
            bootstrapper.OpenMainWindow.Subscribe(_ =>
            {
                var mainWindow = new MainWindow();
                mainWindow.Show();
                Closing -= StartWindow_Closing;
                Close();
            });

            _trayIconManager = Locator.CurrentMutable.GetService<TrayIconManager>();
            _trayIconManager.Exit += (_, __) => Close();
            Closing += StartWindow_Closing;
        }
コード例 #15
0
        internal static void RemoveAutorunShortcut()
        {
            if (App.IsUWP)
            {
                return;
            }

            try
            {
                File.Delete(StartupFullPath);
            }
            catch (Exception e)
            {
                ProcessHelper.WriteLog(e.ToString());
                TrayIconManager.ShowNotification("", "Failed to delete QuickLook startup shortcut.");
            }
        }
コード例 #16
0
        internal void Activate(string[] p)
        {
//#if Develop
//            if (MainWindow == null)
//                MainWindow = new MFPlannerWindow();
//#else
            if (MainWindow == null)
            {
                MainWindow = new MainWindow();
            }
//#endif

            MainWindow.Show();
            MainWindow.Activate();

            TrayIconManager.Init();
        }
コード例 #17
0
        public MainWindow()
        {
            InitializeComponent();

            this.Loaded += MainWindow_Loaded;
            this.Closed += MainWindow_Closed;

            this.Left = SystemParameters.PrimaryScreenWidth - 250;
            this.Top  = SystemParameters.PrimaryScreenHeight - 100;

            this._timer.Elapsed += _timer_Elapsed;
            this._timer.Start();

            if (!EventLog.SourceExists("NetMonSource"))
            {
                EventLog.CreateEventSource("NetMonSource", "Application");
            }

            eventLog.Source = "NetMonSource";

            TrayIconManager.SetupTrayIcon();
        }
コード例 #18
0
        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();
            }
        }
コード例 #19
0
 private void SetupTrayIconManager()
 {
     _trayIconManager = new TrayIconManager(this);
     _trayIconManager.Initialize();
 }
コード例 #20
0
ファイル: MainWindow.cs プロジェクト: yorikqq/EDEngineer
        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();
            }
        }
コード例 #21
0
        protected override void OnExit(ExitEventArgs e)
        {
            TrayIconManager.Dispose();

            base.OnExit(e);
        }
コード例 #22
0
        public MainBootstrapper()
        {
            _settings = Locator.CurrentMutable.GetService<Settings>();
            _trayIconManager = Locator.CurrentMutable.GetService<TrayIconManager>();
            Locator.CurrentMutable.Register(() => new MainView(), typeof(IViewFor<MainViewModel>));
            Locator.CurrentMutable.Register(() => new MatchOrderItemView(), typeof(IViewFor<MatchOrderItemViewModel>));
            Locator.CurrentMutable.Register(() => new SubmittingMatchOrderStatusView(), typeof(IViewFor<SubmittingMatchOrderStatusViewModel>));
            Locator.CurrentMutable.Register(() => new LookingForMatchStatusView(), typeof(IViewFor<SuccessStatusViewModel>));
            Locator.CurrentMutable.Register(() => new SubmitErrorRetryingStatusView(), typeof(IViewFor<ErrorRetryOrderMatchStatusViewModel>));
            Locator.CurrentMutable.Register(() => new CheckingMatchOrderErrorRetryingStatusView(), typeof(IViewFor<ErrorRetryGetHasActiveMatchOrderStatusViewModel>));
            Locator.CurrentMutable.Register(() => new UnknownErrorStatusView(), typeof(IViewFor<UnknownErrorStatusViewModel>));
            Locator.CurrentMutable.Register(() => new UserKeyErrorStatusView(), typeof(IViewFor<UserKeyErrorStatusViewModel>));
            Locator.CurrentMutable.Register(() => new SuspendedStatusView(), typeof(IViewFor<SuspendedStatusViewModel>));
            Locator.CurrentMutable.Register(() => new MatchFoundView(), typeof(IViewFor<MatchFoundViewModel>));
            Locator.CurrentMutable.Register(() => new BrowseGameFileView(), typeof(IViewFor<BrowseGameFileViewModel>));
            Locator.CurrentMutable.Register(() => new MatchOrdersSummaryView(), typeof(IViewFor<MatchOrdersSummaryViewModel>));
            Locator.CurrentMutable.Register(() => new ScriptMatchOrdersSummaryView(), typeof(IViewFor<ScriptMatchOrdersSummaryViewModel>));
            Locator.CurrentMutable.Register(() => new ServerFilterMatchOrdersSummaryView(), typeof(IViewFor<ServerFilterMatchOrdersSummaryViewModel>));
            Locator.CurrentMutable.Register(() => new MatchOrdersSummaryParametersView(), typeof(IViewFor<MatchOrdersSummaryParametersViewModel>));

            _mainViewModel = new MainViewModel();
            var matchFoundViewModel = new MatchFoundViewModel();
            var browseGameFileViewModel = new BrowseGameFileViewModel();
            ReactiveObject viewModelBeforeBrowseGameFile = null;

            ViewModel = _mainViewModel;

            var schedulerProvider = Locator.CurrentMutable.GetService<ISchedulerProvider>();
            MessageBus.Current.Listen<GameServerSuggestion>()
                .ObserveOn(schedulerProvider.Dispatcher)
                .Subscribe(suggestion =>
                {
                    _trayIconManager.SetIconType(NotifyIconType.Success);
                    UpdateMatchFoundViewModel(matchFoundViewModel, suggestion);
                    ViewModel = matchFoundViewModel;
                    _mainViewModel.CancelMatchOrder.Execute(null);
                    ViewModels.Notification.NotificationViewModel.MatchFound.GameServerLink = matchFoundViewModel.GameServerLink;
                    ViewModels.Notification.NotificationViewModel.MatchFound.IsJoinButtonVisible =
                        !string.IsNullOrEmpty(_settings.GameFilePath);
                    if (_mainViewModel.IsJoinMatchesAutomatically)
                    {
                        OpenGameServerInGame(matchFoundViewModel.GameServerLink);
                    }
                    else
                    {
                        ShowNotification.Execute(ViewModels.Notification.NotificationViewModel.MatchFound);
                    }
                });
            _mainViewModel.ShowNotification.Subscribe(a => ShowNotification.Execute(a));
            MessageBus.Current.Listen<BrowseGameFileEvent>().Subscribe(a =>
            {
                if (ViewModel != browseGameFileViewModel)
                {
                    viewModelBeforeBrowseGameFile = ViewModel;
                    ViewModel = browseGameFileViewModel;
                }
            });
            MessageBus.Current.Listen<JoinMatchEvent>().Subscribe(a => OpenGameServerInGame(a.GameServerLink));

            matchFoundViewModel.Cancel.Subscribe(_ =>
            {
                _trayIconManager.SetIconType(NotifyIconType.Idle);
                ViewModel = _mainViewModel;
            });
            browseGameFileViewModel.Close.Subscribe(_ =>
            {
                ViewModel = viewModelBeforeBrowseGameFile;
            });
            _mainViewModel.CancelMatchOrder.Subscribe(_ =>
            {
                if (ViewModel == _mainViewModel)
                {
                    _trayIconManager.SetIconType(NotifyIconType.Idle);
                }
            });
            _mainViewModel.WhenAny(x => x.SearchingMatchStatus, x => x.Value).Subscribe(status =>
            {
                if (status == SearchingMatchStatuses.SubmittingMatchOrder ||
                    status == SearchingMatchStatuses.Success)
                {
                    _trayIconManager.SetIconType(NotifyIconType.Searching);
                }
                if (status == SearchingMatchStatuses.ErrorRepeatOrderMatch ||
                    status == SearchingMatchStatuses.ErrorRepeatGetHasActiveMatchOrder)
                {
                    _trayIconManager.SetIconType(NotifyIconType.Warning);
                }
                if (status == SearchingMatchStatuses.UserKeyError ||
                    status == SearchingMatchStatuses.Suspended ||
                    status == SearchingMatchStatuses.UnknownError)
                {
                    _trayIconManager.SetIconType(NotifyIconType.Error);
                }
            });
        }
コード例 #23
0
        public StartBootstrapper()
        {
            _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            _settings = (Settings)_config.Sections["settings"];
            Locator.CurrentMutable.RegisterConstant(_settings, typeof(Settings));

            _customObservable2 = new CustomObservable2();
            var schedulerProvider = new SchedulerProvider();
            if (_settings.IsFakeService)
            {
                _client = new FakeServiceClientHelper();
            }
            else
            {
                _client = new MainServiceClientHelper(_settings.ServiceUrl);
            }
            _trayIconManager = new TrayIconManager();
            _trayIconManager.Init();

            Locator.CurrentMutable.RegisterConstant(_customObservable2, typeof(ICustomObservable2));
            Locator.CurrentMutable.RegisterConstant(schedulerProvider, typeof(ISchedulerProvider));
            Locator.CurrentMutable.RegisterConstant(_config, typeof(Configuration));
            Locator.CurrentMutable.RegisterConstant(_client, typeof(IMainServiceClientHelper));
            Locator.CurrentMutable.RegisterConstant(_trayIconManager, typeof(TrayIconManager));
            _timerProvider = new TimerProvider();
            Locator.CurrentMutable.RegisterConstant(_timerProvider, typeof (ITimerProvider));
            Locator.CurrentMutable.RegisterConstant(new CheckingVersionView(), typeof(IViewFor<CheckingVersionViewModel>));
            Locator.CurrentMutable.RegisterConstant(new CheckingVersionErrorRetryingView(), typeof(IViewFor<CheckingVersionErrorRetryingViewModel>));
            Locator.CurrentMutable.RegisterConstant(new CheckingUserKeyView(), typeof(IViewFor<CheckingUserKeyViewModel>));
            Locator.CurrentMutable.RegisterConstant(new NewUserKeyView(), typeof(IViewFor<NewUserKeyViewModel>));
            Locator.CurrentMutable.RegisterConstant(new CheckingUserKeyErrorRetryingView(), typeof(IViewFor<CheckingUserKeyErrorRetryingViewModel>));
            Locator.CurrentMutable.RegisterConstant(new SuspendedView(), typeof(IViewFor<SuspendedViewModel>));
            Locator.CurrentMutable.RegisterConstant(new UnknownErrorView(), typeof(IViewFor<UnknownErrorViewModel>));
            Locator.CurrentMutable.RegisterConstant(new UnsupportedVersionView(), typeof(IViewFor<UnsupportedVersionViewModel>));

            NewUserKeyViewModel.Submit.Subscribe(_ =>
            {
                NewUserKeyViewModel.CanSubmit = false;
                ViewModel = CheckingUserKeyViewModel;
                HandleTryCheckUserKey(NewUserKeyViewModel.UserKey);

            });
            ViewModel = CheckingVersionViewModel;
            TryCheckVersion().Subscribe(a =>
            {
                if (a == CheckingVersionErrorRetryingViewModel)
                {
                    _trayIconManager.SetIconType(NotifyIconType.Warning);
                }
                else if (a == UnknownErrorViewModel || a == UnsupportedVersionViewModel)
                {
                    _trayIconManager.SetIconType(NotifyIconType.Error);
                }
                else
                {
                    _trayIconManager.SetIconType(NotifyIconType.Idle);
                }
                ViewModel = a;
                if (a == CheckingUserKeyViewModel)
                {
                    HandleTryCheckUserKey(_settings.UserKey);
                }
            });
        }
コード例 #24
0
        protected override async void OnStartup(StartupEventArgs e)
        {
            base.DispatcherUnhandledException          += App_DispatcherUnhandledException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            TaskScheduler.UnobservedTaskException      += TaskScheduler_UnobservedTaskException;

            await Host.StartAsync();

            SingleInstanceManager singleInstanceManager = Host.Services.GetRequiredService <SingleInstanceManager>();

            _logger.Value.LogInformation("Starting App.");

            if (!singleInstanceManager.IsFirstInstance)
            {
                _logger.Value.LogInformation("I am not the first instance. Shutting down ...");
                base.Shutdown(0);
                return;
            }

            base.ShutdownMode = ShutdownMode.OnExplicitShutdown;

            singleInstanceManager.SecondInstanceStarted += OnSecondInstanceStarted;

            bool createUi = true;

            foreach (string arg in e.Args)
            {
                switch (arg)
                {
                case "-tray":
                    createUi = false;
                    _logger.Value.LogInformation("Launch argument '{0}' found, don't create a UI.", arg);
                    break;

                default:
                    _logger.Value.LogWarning("Got invalid launch argument '{0}', ignoring.", arg);
                    break;
                }
            }

            _logger.Value.LogTrace("Setting up tray icon.");
            TrayIconManager trayIconManager = Host.Services.GetRequiredService <TrayIconManager>();

            trayIconManager.IconVisible    = true;
            trayIconManager.ItemExitClick += (sender, eventArgs) => _ = App.GracefulShutdownAsync();
            trayIconManager.DoubleClick   += (sender, eventArgs) => this.ShowCreateMainWindow();

            ProfileRepository profileRepository = Host.Services.GetRequiredService <ProfileRepository>();
            await profileRepository.LoadProfilesAsync();

            if (createUi)
            {
                _logger.Value.LogInformation("Creating MainWindow on startup.");
                this.ShowCreateMainWindow();
            }

            SimConnectManager scm = Host.Services.GetRequiredService <SimConnectManager>();
            await scm.StartAsync();

            _ = Host.Services.GetRequiredService <DeviceBindingManager>();
        }