Beispiel #1
0
        public override async Task <WindowHandle> OpenChannelWindowAsync(DiscordChannel channel, WindowHandle currentWindow = null)
        {
            if (!Supported)
            {
                return(null);
            }

            if (await ActivateOtherWindowAsync(channel, currentWindow))
            {
                return(null);
            }

            Analytics.TrackEvent("AppWindowWindowingService_OpenChannelWindowAsync");

            var window = await AppWindow.TryCreateAsync();

            window.RequestMoveRelativeToCurrentViewContent(new Point(276, 0));
            window.RequestSize(new Size(Window.Current.Bounds.Width - 276, Window.Current.Bounds.Height));
            window.Title = NotificationUtils.GetChannelHeaderName(channel);

            var frame = new Frame();

            frame.Navigate(typeof(MainPage), new MainPageArgs()
            {
                ChannelId = channel.Id, FullFrame = true
            });

            ElementCompositionPreview.SetAppWindowContent(window, frame);
            var frame2 = ElementCompositionPreview.GetAppWindowContent(window);

            await window.TryShowAsync();

            var handle = (AppWindowHandle)CreateOrUpdateHandle(frame, window);

            window.Closed += (o, e) =>
            {
                _uiContextDictionary.TryRemove(handle.Context, out _);
                _windowChannelDictionary.TryRemove(handle, out _);

                handle        = null;
                frame.Content = null;
                window        = null;
            };

            HandleTitleBarForWindow(null, frame);

            return(handle);
        }
Beispiel #2
0
        private void UpdateBrush()
        {
            FrameworkElement root = _root;

            if (_window != null)
            {
                root = ElementCompositionPreview.GetAppWindowContent(_window) as FrameworkElement;
            }

            if (root == null || _settings == null || _accessibilitySettings == null || _fastEffects == null || _energySaver == null)
            {
                return;
            }

            bool useSolidColorFallback = !_settings.AdvancedEffectsEnabled || !_wallpaperBrushSupported || !_windowActivated || _fastEffects == false || _energySaver == true;


            Compositor compositor = Window.Current.Compositor;

            ElementTheme currentTheme = root.ActualTheme;
            Color        tintColor    = currentTheme == ElementTheme.Light ? Color.FromArgb(255, 243, 243, 243) : Color.FromArgb(255, 32, 32, 32);
            float        tintOpacity  = currentTheme == ElementTheme.Light ? 0.5f : 0.8f;

            if (_accessibilitySettings.HighContrast)
            {
                tintColor             = _settings.GetColorValue(UIColorType.Background);
                useSolidColorFallback = true;
            }

            FallbackColor = tintColor;

            CompositionBrush newBrush;

            if (useSolidColorFallback)
            {
                newBrush = compositor.CreateColorBrush(tintColor);
            }
            else
            {
                newBrush = BuildMicaEffectBrush(compositor, tintColor, tintOpacity, 1.0f);
            }

            CompositionBrush oldBrush = CompositionBrush;

            if (oldBrush == null || (CompositionBrush.Comment == "Crossfade") || (oldBrush is CompositionColorBrush && newBrush is CompositionColorBrush))
            {
                // Set new brush directly
                if (oldBrush != null)
                {
                    oldBrush.Dispose();
                }
                CompositionBrush = newBrush;
            }
            else
            {
                // Crossfade
                CompositionBrush        crossFadeBrush = CreateCrossFadeEffectBrush(compositor, oldBrush, newBrush);
                ScalarKeyFrameAnimation animation      = CreateCrossFadeAnimation(compositor);
                CompositionBrush = crossFadeBrush;

                var crossFadeAnimationBatch = compositor.CreateScopedBatch(CompositionBatchTypes.Animation);
                crossFadeBrush.StartAnimation("CrossFade.CrossFade", animation);
                crossFadeAnimationBatch.End();

                crossFadeAnimationBatch.Completed += (o, a) =>
                {
                    crossFadeBrush.Dispose();
                    oldBrush.Dispose();
                    CompositionBrush = newBrush;
                };
            }
        }