Пример #1
0
        public void JoinRequest(DiscordJoinRequest request, CancellationToken cancellation, Action <DiscordJoinRequestReply> callback)
        {
            ActionExtension.InvokeInMainThreadAsync(async() => {
                try {
                    var dialog = new DiscordJoinRequestDialog(request);
                    cancellation.Register(() => ActionExtension.InvokeInMainThreadAsync(() => {
                        if (!dialog.IsLoaded)
                        {
                            dialog.Loaded += (s, e) => dialog.Close();
                        }
                        else if (dialog.IsVisible)
                        {
                            try {
                                dialog.Close();
                            } catch {
                                // ignored
                            }
                        }
                    }));

                    switch (await dialog.ShowAndWaitAsync())
                    {
                    case MessageBoxResult.Yes:
                        callback(DiscordJoinRequestReply.Yes);
                        break;

                    case MessageBoxResult.No:
                        callback(DiscordJoinRequestReply.No);
                        break;
                    }
                } catch (Exception e) {
                    Logging.Warning(e);
                }
            });
        }
Пример #2
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;
        }