Exemple #1
0
        public DiscordJoinRequestDialog(DiscordJoinRequest args, CancellationToken cancellation = default(CancellationToken))
        {
            cancellation.Register(async() => {
                await Task.Delay(200);
                CloseWithResult(MessageBoxResult.Cancel);
            });

            Owner       = null;
            DataContext = this;
            InitializeComponent();
            Buttons = new Control[0];

            TitleBlock.Text = $"User {args.UserName} wants to join. Allow?";

            if (!string.IsNullOrWhiteSpace(args.AvatarUrl))
            {
                Image.Filename = $"{args.AvatarUrl}?size=128";
            }
            else
            {
                Image.Visibility = Visibility.Collapsed;
            }

            this.OnActualUnload(OnUnload);

            var config = new IniFile(AcPaths.GetCfgControlsFilename());

            _yes = new ControlsInput(config["__CM_DISCORD_REQUEST_ACCEPT"], Keys.Enter);
            _no  = new ControlsInput(config["__CM_DISCORD_REQUEST_DENY"], Keys.Back);

            try {
                SetDevices().Ignore();
                _yes.SetIcon(YesIcon, this);
                _no.SetIcon(NoIcon, this);
            } catch (Exception e) {
                Logging.Error(e);
            }

            _inGameAppParams = new CmInGameAppJoinRequestParams(args.UserName, args.UserId, args.AvatarUrl,
                                                                b => (b ? YesCommand : NoCommand).ExecuteAsync().Ignore());
            CompositionTargetEx.Rendering += OnRendering;
        }