コード例 #1
0
        public async Task <bool> Handle(PriceCheckItemCommand request, CancellationToken cancellationToken)
        {
            // Close previously opened price views
            viewLocator.Close(View.ParserError);
            viewLocator.Close(View.Price);

            // Parses the item by copying the item under the cursor
            var item = request.Item;

            if (item == null)
            {
                var itemText = await clipboardProvider.Copy();

                item = await mediator.Send(new ParseItemCommand(itemText));
            }

            if (item == null)
            {
                // If the item can't be parsed, show an error
                viewLocator.Open(View.ParserError);
            }
            else
            {
                // If the item can be parsed, show the view
                viewLocator.Open(View.Price, item);
            }

            return(true);
        }
コード例 #2
0
        public async Task <bool> Handle(OpenMapInfoCommand request, CancellationToken cancellationToken)
        {
            await mediator.Send(new CloseMapViewCommand());

            // Close previously opened map views
            viewLocator.Close(View.ParserError);
            viewLocator.Close(View.Map);

            // Parses the item by copying the item under the cursor
            var item = await mediator.Send(new ParseItemCommand(await clipboardProvider.Copy()));

            if (item == null)
            {
                // If the item can't be parsed, show an error
                viewLocator.Open(View.ParserError);
            }
            else if (item.Properties.MapTier == 0)
            {
                // If the item is not a map
                viewLocator.Open(View.InvalidItemError);
            }
            else
            {
                // If the item can be parsed, show the view
                viewLocator.Open(View.Map, item);
            }

            return(true);
        }
コード例 #3
0
ファイル: EventsHandler.cs プロジェクト: mad2357/Sidekick
        private async Task <bool> Events_OnPriceCheck()
        {
            viewLocator.CloseAll();
            await clipboard.Copy();

            viewLocator.Open <PriceView>();
            return(true);
        }
コード例 #4
0
        private void InitContextMenu()
        {
            var cultureInfo = new CultureInfo(uiLanguageProvider.Current.Name);

            Thread.CurrentThread.CurrentCulture   = cultureInfo;
            Thread.CurrentThread.CurrentUICulture = cultureInfo;

            if (TrayIcon.ContextMenu == null)
            {
                TrayIcon.ContextMenu = new ContextMenu();
            }

            TrayIcon.ContextMenu.Items.Clear();
            TrayIcon.ContextMenu.Items.Add(new MenuItem()
            {
                Header  = TrayResources.Settings,
                Command = new RelayCommand(_ => viewLocator.Open <SettingsView>())
            });
            TrayIcon.ContextMenu.Items.Add(new MenuItem()
            {
                Header  = TrayResources.ShowLogs,
                Command = new RelayCommand(_ => ApplicationLogsController.Show())
            });
            TrayIcon.ContextMenu.Items.Add(new Separator());
            TrayIcon.ContextMenu.Items.Add(new MenuItem()
            {
                Header  = TrayResources.Exit,
                Command = new RelayCommand(_ => application.Shutdown())
            });
        }
コード例 #5
0
 public Task Handle(InitializationStarted notification, CancellationToken cancellationToken)
 {
     viewLocator.Close(View.Settings);
     viewLocator.Close(View.Setup);
     if (settings.ShowSplashScreen && !viewLocator.IsOpened(View.Initialization))
     {
         viewLocator.Open(View.Initialization);
     }
     return(Task.CompletedTask);
 }
コード例 #6
0
        public async Task Execute()
        {
            var text = await clipboardProvider.Copy();

            var item = await mediator.Send(new ParseItemCommand(text));

            if (item == null)
            {
                // If the item can't be parsed, show an error
                await viewLocator.Open(View.Error, ErrorType.Unparsable);

                return;
            }

            if (!await mediator.Send(new IsGameLanguageEnglishQuery()))
            {
                // Only available for english language
                await viewLocator.Open(View.Error, ErrorType.UnavailableTranslation);

                return;
            }

            if (string.IsNullOrEmpty(item.Metadata.Name))
            {
                // Most items will open the basetype wiki link.
                // Does not work for unique items that are not identified.
                await viewLocator.Open(View.Error, ErrorType.InvalidItem);

                return;
            }

            if (settings.Wiki_Preferred == WikiSetting.PoeDb)
            {
                await OpenPoeDb(item);
            }
            else
            {
                await OpenPoeWiki(item);
            }
        }
コード例 #7
0
        public async Task <bool> Handle(OpenWikiPageCommand request, CancellationToken cancellationToken)
        {
            var text = await clipboardProvider.Copy();

            var item = await mediator.Send(new ParseItemCommand(text));

            if (item == null)
            {
                // If the item can't be parsed, show an error
                viewLocator.Open(View.ParserError);
                return(false);
            }

            if (!gameLanguageProvider.IsEnglish)
            {
                // Only available for english language
                viewLocator.Open(View.AvailableInEnglishError);
                return(false);
            }

            if (string.IsNullOrEmpty(item.Name))
            {
                // Most items will open the basetype wiki link.
                // Does not work for unique items that are not identified.
                viewLocator.Open(View.InvalidItemError);
                return(false);
            }

            if (settings.Wiki_Preferred == WikiSetting.PoeDb)
            {
                await OpenPoeDb(item);
            }
            else
            {
                await OpenPoeWiki(item);
            }

            return(true);
        }
コード例 #8
0
        public Task <bool> Handle(ToggleCheatsheetsCommand request, CancellationToken cancellationToken)
        {
            if (viewLocator.IsOpened(View.League))
            {
                viewLocator.Close(View.League);
            }
            else
            {
                viewLocator.Open(View.League);
            }

            return(Task.FromResult(true));
        }
コード例 #9
0
ファイル: TrayProvider.cs プロジェクト: domialex/Sidekick
        public void Initialize()
        {
            var menuItems = new List <MenuItem>()
            {
                new ()
                {
                    Label   = resources.Title + " - " + GetType().Assembly.GetName().Version.ToString(),
                    Type    = MenuType.normal,
                    Icon    = $"{webHostEnvironment.ContentRootPath}Assets/16x16.png",
                    Enabled = false,
                },

                new () { Type = MenuType.separator },

                new ()
                {
                    Label = resources.Cheatsheets,
                    Click = () => { viewLocator.Open(View.League); }
                },

                new ()
                {
                    Label = resources.About,
                    Click = () => { viewLocator.Open(View.About); }
                },

                new ()
                {
                    Label = resources.Settings,
                    Click = () => { viewLocator.Open(View.Settings); }
                },

                new () { Type = MenuType.separator },

                new ()
                {
                    Label = resources.Exit,
                    Click = () => ElectronNET.API.Electron.App.Quit()
                }
            };

            if (webHostEnvironment.IsDevelopment())
            {
                menuItems.InsertRange(0, GetDevelopmentMenu());
            }

            ElectronNET.API.Electron.Tray.Show($"{webHostEnvironment.ContentRootPath}Assets/icon.png", menuItems.ToArray());
            ElectronNET.API.Electron.Tray.OnDoubleClick += (_, _) => viewLocator.Open(View.Settings);
            ElectronNET.API.Electron.Tray.SetToolTip(resources.Title);
        }
コード例 #10
0
 private void Logs_Click(object sender, RoutedEventArgs e)
 {
     viewLocator.Open(View.Logs);
 }
コード例 #11
0
        public async Task Execute()
        {
            var itemText = await clipboardProvider.Copy();

            await viewLocator.Open(View.Map, itemText);
        }
コード例 #12
0
 public Task <Unit> Handle(SetupCommand request, CancellationToken cancellationToken)
 {
     viewLocator.Close(View.Initialization);
     viewLocator.Open(View.Setup);
     return(Unit.Task);
 }
コード例 #13
0
        protected override async void OnStartup(StartupEventArgs e)
        {
            Instance = this;

            base.OnStartup(e);

            AttachErrorHandlers();

            // Tooltip opened indefinitely until mouse is moved.
            ToolTipService.ShowDurationProperty.OverrideMetadata(typeof(DependencyObject), new FrameworkPropertyMetadata(int.MaxValue));

            serviceProvider = Sidekick.Startup.InitializeServices(this);

            logger            = serviceProvider.GetRequiredService <ILogger>();
            nativeProcess     = serviceProvider.GetRequiredService <INativeProcess>();
            nativeBrowser     = serviceProvider.GetRequiredService <INativeBrowser>();
            leagueDataService = serviceProvider.GetRequiredService <ILeagueDataService>();
            initializer       = serviceProvider.GetRequiredService <IInitializer>();
            viewLocator       = serviceProvider.GetRequiredService <IViewLocator>();
            settings          = serviceProvider.GetRequiredService <SidekickSettings>();

            trayIcon             = (TaskbarIcon)FindResource("TrayIcon");
            trayIcon.DataContext = serviceProvider.GetRequiredService <TrayIconViewModel>();

            await RunAutoUpdate();

            EnsureSingleInstance();

            leagueDataService.OnNewLeagues += () =>
            {
                Dispatcher.Invoke(() =>
                {
                    AdonisUI.Controls.MessageBox.Show(InitializerResources.Warn_NewLeagues, buttons: AdonisUI.Controls.MessageBoxButton.OK);
                });
            };

            if (settings.ShowSplashScreen)
            {
                initializer.OnProgress += (a) =>
                {
                    if (!viewLocator.IsOpened <SplashScreenView>())
                    {
                        Dispatcher.Invoke(() =>
                        {
                            viewLocator.Open <SplashScreenView>();
                        });
                    }
                };
            }

            initializer.OnError += (error) =>
            {
                AdonisUI.Controls.MessageBox.Show(InitializerResources.ErrorDuringInit, buttons: AdonisUI.Controls.MessageBoxButton.OK);
                base.Shutdown(1);
            };

            await initializer.Initialize();

            trayIcon.ShowBalloonTip(
                TrayResources.Notification_Title,
                string.Format(TrayResources.Notification_Message, settings.Key_CheckPrices.ToKeybindString(), settings.Key_CloseWindow.ToKeybindString()),
                trayIcon.Icon,
                largeIcon: true);

            serviceProvider.GetRequiredService <EventsHandler>();
        }
コード例 #14
0
        public async Task <Unit> Handle(InitializeCommand request, CancellationToken cancellationToken)
        {
            try
            {
                Completed = 0;
                Count     = request.FirstRun ? 10 : 7;

                // Report initial progress
                await ReportProgress();

                // Open a clean view of the initialization
                viewLocator.CloseAll();
                if (settings.ShowSplashScreen)
                {
                    await viewLocator.Open(View.Initialization);
                }

                // Set the UI language
                await RunCommandStep(new SetUiLanguageCommand(settings.Language_UI));

                // Check for updates
                if (request.AutoUpdate && await mediator.Send(new CheckForUpdate(), cancellationToken))
                {
                    viewLocator.Close(View.Initialization);
                    return(Unit.Value);
                }

                // Check to see if we should run Setup first before running the rest of the initialization process
                if (string.IsNullOrEmpty(settings.LeagueId) || string.IsNullOrEmpty(settings.Language_Parser) || string.IsNullOrEmpty(settings.Language_UI))
                {
                    viewLocator.Close(View.Initialization);
                    await viewLocator.Open(View.Setup);

                    return(Unit.Value);
                }

                // Set the game language
                await RunCommandStep(new SetGameLanguageCommand(settings.Language_Parser));

                if (request.FirstRun)
                {
                    var leagues = await mediator.Send(new GetLeaguesQuery(false));

                    var leaguesHash = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonSerializer.Serialize(leagues)));

                    if (leaguesHash != settings.LeaguesHash)
                    {
                        await mediator.Send(new ClearCacheCommand());

                        await mediator.Send(new SaveSettingCommand(nameof(ISidekickSettings.LeaguesHash), leaguesHash));
                    }

                    // Check to see if we should run Setup first before running the rest of the initialization process
                    if (string.IsNullOrEmpty(settings.LeagueId) || !leagues.Any(x => x.Id == settings.LeagueId))
                    {
                        await mediator.Send(new OpenNotificationCommand(resources.NewLeagues));

                        viewLocator.Close(View.Initialization);
                        await viewLocator.Open(View.Setup);

                        return(Unit.Value);
                    }
                }

                await Run(() => parserPatterns.Initialize());
                await Run(() => itemMetadataProvider.Initialize());
                await Run(() => itemStaticDataProvider.Initialize());
                await Run(() => modifierProvider.Initialize());
                await Run(() => pseudoModifierProvider.Initialize());

                if (request.FirstRun)
                {
                    await Run(() => processProvider.Initialize(cancellationToken));
                    await Run(() => keyboardProvider.Initialize());
                    await Run(() => keybindProvider.Initialize());
                }

                // If we have a successful initialization, we delay for half a second to show the "Ready" label on the UI before closing the view
                Completed = Count;
                await ReportProgress();

                await Task.Delay(500);

                // Show a system notification
                await mediator.Send(new OpenNotificationCommand(string.Format(resources.Notification_Message, settings.Trade_Key_Check.ToKeybindString(), settings.Key_Close.ToKeybindString()),
                                                                resources.Notification_Title));

                viewLocator.Close(View.Initialization);

                return(Unit.Value);
            }
            catch (Exception ex)
            {
                logger.LogError(ex.Message);
                await mediator.Send(new OpenNotificationCommand(resources.Error));

                await mediator.Send(new ShutdownCommand());

                return(Unit.Value);
            }
        }
コード例 #15
0
 public Task Execute()
 {
     viewLocator.Open(View.Settings);
     return(Task.CompletedTask);
 }
コード例 #16
0
 private void Logs_Click(object sender, RoutedEventArgs e)
 {
     viewLocator.Open <ApplicationLogsView>();
 }
コード例 #17
0
 public Task Execute()
 {
     viewLocator.Open(View.League, settings.Cheatsheets_Selected);
     return(Task.CompletedTask);
 }
コード例 #18
0
 public Task <bool> Handle(OpenSettingsCommand request, CancellationToken cancellationToken)
 {
     viewLocator.Open(View.Settings);
     return(Task.FromResult(true));
 }