示例#1
0
        private async void ShowCompactView()
        {
            CoreApplicationView compactView = CoreApplication.CreateNewView();
            await compactView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var frame     = new Frame();
                compactViewId = ApplicationView.GetForCurrentView().Id;
                frame.Navigate(typeof(CompactOverlayPage));
                Window.Current.Content = frame;
                Window.Current.Activate();
                ApplicationView.GetForCurrentView().TitleBar.ButtonBackgroundColor = Colors.Transparent;
            });



            ViewModePreferences compactOptions = ViewModePreferences.CreateDefault(ApplicationViewMode.CompactOverlay);

            compactOptions.CustomSize = new Windows.Foundation.Size(120, 120);
            bool viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(compactViewId, ApplicationViewMode.CompactOverlay, compactOptions);

            string X = XText.Text;
            string Y = YText.Text;
            string W = WText.Text;
            string H = HText.Text;
            await compactView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var frame          = (Frame)Window.Current.Content;
                var compactOverlay = (CompactOverlayPage)frame.Content;
                compactOverlay.SetMeasurements(X, Y, W, H);
            });
        }
示例#2
0
文件: Notifier.cs 项目: Bigsby/PoC
        public async void Notify(NotifyViewModel viewModel)
        {
            var compactViewId = 0;
            await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var applicationView = ApplicationView.GetForCurrentView();
                compactViewId       = applicationView.Id;
                var appTitleBar     = applicationView.TitleBar;
                appTitleBar.ButtonBackgroundColor         = Colors.White;
                appTitleBar.ButtonForegroundColor         = Colors.White;
                appTitleBar.ButtonHoverBackgroundColor    = Colors.White;
                appTitleBar.ButtonHoverForegroundColor    = Colors.White;
                appTitleBar.ButtonInactiveBackgroundColor = Colors.White;
                appTitleBar.ButtonInactiveForegroundColor = Colors.White;
                appTitleBar.ButtonPressedBackgroundColor  = Colors.White;
                appTitleBar.ButtonPressedForegroundColor  = Colors.White;


                var notifyPage         = new NotifyPage(viewModel);
                Window.Current.Content = notifyPage;
                //Window.Current.SetTitleBar(notifyPage);
                Window.Current.Activate();
                CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
            });

            bool viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(compactViewId, ApplicationViewMode.CompactOverlay);
        }
示例#3
0
        /// <summary>
        ///     Open the compact overlay view
        /// </summary>
        /// <returns></returns>
        public static async Task SwitchToCompactView()
        {
            var compactView   = CoreApplication.CreateNewView();
            var compactViewId = -1;

            // Create a new window within the view
            await compactView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                // Create a new frame and navigate it to the overlay view
                var overlayFrame = new Frame();
                overlayFrame.Navigate(typeof(OverlayView));

                // Set the window content and activate it
                Window.Current.Content = overlayFrame;
                Window.Current.Activate();

                // Get the Id back
                compactViewId = ApplicationView.GetForCurrentView().Id;
            });

            // Make the overlay small
            var compactOptions = ViewModePreferences.CreateDefault(ApplicationViewMode.CompactOverlay);

            compactOptions.CustomSize = new Size(350, 150);

            // Display as compact overlay
            await ApplicationViewSwitcher.TryShowAsViewModeAsync(compactViewId, ApplicationViewMode.CompactOverlay,
                                                                 compactOptions);
        }
示例#4
0
        internal async Task ShowLyricWindow()
        {
            await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var frame   = new Frame();
                lyricViewID = ApplicationView.GetForCurrentView().Id;
                frame.Navigate(typeof(LyricView), Context.NowPlayingList[Context.CurrentIndex]);
                Window.Current.Content = frame;
                Window.Current.Activate();
                CoreApplication.GetCurrentView().TitleBar.ExtendViewIntoTitleBar = true;
                ApplicationViewTitleBar titleBar       = ApplicationView.GetForCurrentView().TitleBar;
                titleBar.ButtonBackgroundColor         = Colors.Transparent;
                titleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
                titleBar.ButtonHoverBackgroundColor    = Color.FromArgb(0x33, 0x00, 0x00, 0x00);
                titleBar.ButtonForegroundColor         = Colors.Black;
                titleBar.ButtonHoverForegroundColor    = Colors.White;
                titleBar.ButtonInactiveForegroundColor = Colors.Gray;
            });

            ViewModePreferences compactOptions = ViewModePreferences.CreateDefault(ApplicationViewMode.CompactOverlay);

            compactOptions.CustomSize         = new Size(1000, 100);
            compactOptions.ViewSizePreference = ViewSizePreference.Custom;
            bool viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(lyricViewID, ApplicationViewMode.CompactOverlay, compactOptions);
        }
示例#5
0
        private async void SymbolIcon_Tapped_1(object sender, TappedRoutedEventArgs e)
        {
            Employee        employee = employeeView.DataContext as Employee;
            ApplicationView newView = null;
            await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var frame = new Frame();
                frame.Navigate(typeof(EmployeePage), employee);
                Window.Current.Content = frame;
                Window.Current.Activate();
                newView = ApplicationView.GetForCurrentView();
                newView.SetPreferredMinSize(new Size(200, 200));
                newView.Title = employee.Name;
                newView.SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);
                newView.TitleBar.BackgroundColor = Windows.UI.Colors.Transparent;
            });

            var compactOptions = ViewModePreferences.CreateDefault(ApplicationViewMode.CompactOverlay);

            compactOptions.CustomSize         = new Size(300, 200);
            compactOptions.ViewSizePreference = ViewSizePreference.Custom;
            await ApplicationViewSwitcher.TryShowAsViewModeAsync(newView.Id, ApplicationViewMode.CompactOverlay, compactOptions);

            employeeView.Visibility = Visibility.Collapsed;
        }
示例#6
0
        public async static Task <int> ShowInCallUI()
        {
            int compactViewId = 0;

            Size previoussize = new Size(0, 0);

            // Workaround for window spawn bug
            await CoreApplication.GetCurrentView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var view  = ApplicationView.GetForCurrentView();
                var frame = (Window.Current.Content as Frame);

                previoussize = new Size(frame.ActualWidth, frame.ActualHeight);
                view.SetPreferredMinSize(new Size {
                    Width = 400, Height = 100
                });
            });

            var preferences = ViewModePreferences.CreateDefault(ApplicationViewMode.Default);

            preferences.CustomSize = new Size {
                Width = 400, Height = 100
            };

            await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var frame = new Frame();
                var view  = ApplicationView.GetForCurrentView();

                compactViewId = view.Id;
                frame.Navigate(typeof(CallUIPage));
                Window.Current.Content = frame;

                Window.Current.Activate();

                view.Title = "Call";

                Window.Current.Closed += (object sender, CoreWindowEventArgs e) =>
                {
                    var view = ApplicationView.GetForCurrentView();

                    view.SetPreferredMinSize(new Size(0, 0));
                    view.TryResizeView(previoussize);
                };
            });

            bool viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(compactViewId, ApplicationViewMode.Default, preferences);

            // Workaround for window spawn bug
            await CoreApplication.GetCurrentView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var view = ApplicationView.GetForCurrentView();

                view.SetPreferredMinSize(new Size(0, 0));
                view.TryResizeView(previoussize);
            });

            return(compactViewId);
        }
示例#7
0
        public async void ShowCallUIWindow()
        {
            int  compactViewId = 0;
            Size previoussize  = new Size(0, 0);

            // Workaround for window spawn bug
            await MainWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var view  = ApplicationView.GetForCurrentView();
                var frame = (Window.Current.Content as Frame);

                previoussize = new Size(frame.ActualWidth, frame.ActualHeight);
                view.SetPreferredMinSize(new Size {
                    Width = 400, Height = 100
                });
            });

            ViewModePreferences preferences = ViewModePreferences.CreateDefault(ApplicationViewMode.CompactOverlay);

            preferences.CustomSize = new Size {
                Width = 400, Height = 100
            };

            CoreApplicationView view = CoreApplication.CreateNewView();

            await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                CallUIWindow           = Window.Current;
                Frame frame            = new Frame();
                Window.Current.Content = frame;
                frame.Navigate(typeof(CallUIPage));
                Window.Current.Activate();

                ApplicationView view = ApplicationView.GetForCurrentView();
                view.Title           = App.Current.ResourceLoader.GetString(CALL_UI_PAGE);
                compactViewId        = view.Id;

                Window.Current.Closed += (object sender, CoreWindowEventArgs e) =>
                {
                    var view = ApplicationView.GetForCurrentView();

                    view.SetPreferredMinSize(new Size(0, 0));
                    view.TryResizeView(previoussize);
                };
            });

            bool viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(compactViewId, ApplicationViewMode.CompactOverlay, preferences);

            // Workaround for window spawn bug
            await CoreApplication.GetCurrentView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var view = ApplicationView.GetForCurrentView();

                view.SetPreferredMinSize(new Size(0, 0));
                view.TryResizeView(previoussize);
            });
        }
示例#8
0
        private async void AppBarButton_Click(object sender, RoutedEventArgs e)
        {
            ApplicationViewMode target = _viewMode == ApplicationViewMode.CompactOverlay ?
                                         ApplicationViewMode.Default : ApplicationViewMode.CompactOverlay;

            _viewMode = target;
            await ApplicationViewSwitcher.TryShowAsViewModeAsync(ViewID, target);

            VisualStateManager.GoToState(this, target.ToString(), false);
        }
示例#9
0
        // Displays a view in the specified view mode
        public async Task <ViewLifetimeControl> TryShowAsViewModeAsync(string windowTitle, Type pageType, ApplicationViewMode viewMode = ApplicationViewMode.Default)
        {
            ViewLifetimeControl viewControl = await CreateViewLifetimeControlAsync(windowTitle, pageType);

            SecondaryViews.Add(viewControl);
            viewControl.StartViewInUse();
            var viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(viewControl.Id, viewMode);

            viewControl.StopViewInUse();
            return(viewControl);
        }
示例#10
0
        public static async Task OpenChannelWindowAsync(DiscordChannel channel, ApplicationViewMode mode = ApplicationViewMode.Default)
        {
            if (!MultipleWindowsSupported)
            {
                return;
            }

            if (await ActivateOtherWindow(channel))
            {
                return;
            }

            var viewId   = 0;
            var coreView = CoreApplication.CreateNewView();
            await coreView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var coreWindow = coreView.CoreWindow;
                var window     = Window.Current;

                var frame = new Frame();
                try { ThemeManager.LoadCurrentTheme(frame.Resources); } catch { }

                window.Content = frame;
                window.Activate();

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

                var applicationView = ApplicationView.GetForCurrentView();
                viewId = applicationView.Id;

                void OnConsolidated(ApplicationView sender, ApplicationViewConsolidatedEventArgs args)
                {
                    if (sender.Id == viewId && sender.Id != _mainWindowId)
                    {
                        if (args.IsAppInitiated)
                        {
                            return;
                        }

                        sender.Consolidated -= OnConsolidated;
                        _windowChannelDictionary.TryRemove(sender.Id, out _);
                    }
                }

                applicationView.Consolidated += OnConsolidated;
            });

            //var prefs = ViewModePreferences.CreateDefault(ApplicationViewMode.Default);
            await ApplicationViewSwitcher.TryShowAsViewModeAsync(viewId, mode);
        }
示例#11
0
        private async void ShowCompactView()
        {
            await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var frame     = new Frame();
                compactViewId = ApplicationView.GetForCurrentView().Id;
                frame.Navigate(typeof(ShowCompactPage), img_sample_url);
                Window.Current.Content = frame;
                Window.Current.Activate();
                ApplicationView.GetForCurrentView().Title = "CompactOverlay Window";
            });

            bool viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(compactViewId, ApplicationViewMode.CompactOverlay);
        }
示例#12
0
        private async void NavigateToMainView()
        {
            var currentViewId = -1;

            await CoreWindow.GetForCurrentThread().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                currentViewId = ApplicationView.GetForCurrentView().Id;
            });

            await ApplicationViewSwitcher.TryShowAsViewModeAsync(_mainAppViewId, ApplicationViewMode.Default);

            // Switch to this window
            await ApplicationViewSwitcher.SwitchAsync(_mainAppViewId, currentViewId,
                                                      ApplicationViewSwitchingOptions.ConsolidateViews);
        }
        //Button click event for CompactOverlayButton to Create a Frame in CompactOverlay mode
        public async void CompactOverlayButton_ClickAsync(object sender, RoutedEventArgs e)
        {
            int compactViewId = ApplicationView.GetForCurrentView().Id;      //Initializing compactViewId to the Current View ID
            await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var frame     = new Frame();
                compactViewId = ApplicationView.GetForCurrentView().Id;
                frame.Navigate(typeof(VideosPage));
                Window.Current.Content = frame;
                Window.Current.Activate();
                ApplicationView.GetForCurrentView().Title = "";
            });

            bool viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(compactViewId, ApplicationViewMode.CompactOverlay);
        }
示例#14
0
 private async void OpenView(object sender, RoutedEventArgs e)
 {
     var grouping = PreferredMode;
     await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
     {
         Window.Current.Content = new Frame();
         ((Frame)Window.Current.Content).Navigate(typeof(BlankPage1));
         Window.Current.Activate();
         var viewModePreferences = ViewModePreferences.CreateDefault(ApplicationViewMode.Default);
         viewModePreferences.GroupingPreference = grouping;
         await ApplicationViewSwitcher.TryShowAsViewModeAsync(
             ApplicationView.GetApplicationViewIdForWindow(Window.Current.CoreWindow),
             ApplicationViewMode.Default,
             viewModePreferences);
     });
 }
示例#15
0
        public async Task CreateNewView <T>(Func <T> newViewObjectFactory, Action <T> loadAction)
            where T : UIElement
        {
            CoreApplicationView newView = CoreApplication.CreateNewView();
            var newViewId = 0;
            await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
                var newViewContent     = newViewObjectFactory();
                Window.Current.Content = newViewContent;
                Window.Current.Activate();
                newViewId = ApplicationView.GetForCurrentView().Id;

                loadAction(newViewContent);
            });

            var viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(newViewId, ApplicationViewMode.CompactOverlay);
        }
示例#16
0
        public async Task <ViewLifetimeControl> TryShowAsViewModeAsync(string windowTitle, Type pageType, ApplicationViewMode viewMode = ApplicationViewMode.Default)
        {
            ViewLifetimeControl viewControl = await CreateViewLifetimeControlAsync(windowTitle, pageType);

            SecondaryViews.Add(viewControl);
            viewControl.StartViewInUse();

            ViewModePreferences compactOptions = ViewModePreferences.CreateDefault(viewMode);

            compactOptions.CustomSize = MediumSize;

            var viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(viewControl.Id, viewMode, compactOptions);

            viewControl.StopViewInUse();
            return(viewControl);
        }
示例#17
0
        public async Task <ViewLifetimeControl> OpenAsync(ViewServiceParams parameters)
        {
            //if (ApiInformation.IsPropertyPresent("Windows.UI.ViewManagement.ApplicationView", "PersistedStateId"))
            //{
            //    try
            //    {
            //        ApplicationView.ClearPersistedState("Calls");
            //    }
            //    catch { }
            //}

            var newView    = CoreApplication.CreateNewView();
            var dispatcher = new DispatcherContext(newView.DispatcherQueue);

            var newControl = await dispatcher.DispatchAsync(async() =>
            {
                var newWindow  = Window.Current;
                var newAppView = ApplicationView.GetForCurrentView();

                newAppView.Title = parameters.Title ?? string.Empty;

                if (ApiInformation.IsPropertyPresent("Windows.UI.ViewManagement.ApplicationView", "PersistedStateId"))
                {
                    newAppView.PersistedStateId = parameters.PersistentId;
                }

                var control       = ViewLifetimeControl.GetForCurrentView();
                control.Released += (s, args) =>
                {
                    newWindow.Close();
                };

                newWindow.Content = parameters.Content(control);
                newWindow.Activate();

                var preferences        = ViewModePreferences.CreateDefault(parameters.ViewMode);
                preferences.CustomSize = new Size(parameters.Width, parameters.Height);

                await ApplicationViewSwitcher.TryShowAsViewModeAsync(newAppView.Id, parameters.ViewMode, preferences);
                //newAppView.TryResizeView(new Size(parameters.Width, parameters.Height));

                return(control);
            }).ConfigureAwait(false);

            return(newControl);
        }
示例#18
0
        private async void openpopupplayer_click(object sender, RoutedEventArgs e)
        {
            PopupPlayer         newPlayer = null;
            CoreApplicationView newView   = CoreApplication.CreateNewView();
            var newViewId = 0;
            await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                newPlayer = new PopupPlayer();
                Window.Current.Content = newPlayer;
                Window.Current.Activate();
                newViewId = ApplicationView.GetForCurrentView().Id;

                var player = ((App)Application.Current).Player;
                newPlayer.SetPlayer(player);

                newPlayer.HoookVideo();
            });

            var viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(newViewId, ApplicationViewMode.CompactOverlay);
        }
示例#19
0
        private async void ShowCompactView(string Name, object content)
        {
            await CoreApplication.CreateNewView().Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var frame     = new Frame();
                compactViewId = ApplicationView.GetForCurrentView().Id;
                if (Name == "Pic")
                {
                    frame.Navigate(typeof(PicinPic), content);
                }
                else if (Name == "Text")
                {
                    frame.Navigate(typeof(TextinText), content);
                }
                Window.Current.Content = frame;
                Window.Current.Activate();
                ApplicationView.GetForCurrentView().Title = "CompactOverlay Window";
            });

            bool viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(compactViewId, ApplicationViewMode.CompactOverlay);
        }
示例#20
0
        public static async Task CreateWindowAsync(FrameworkElement content, string title)
        {
            var currentView = ApplicationView.GetForCurrentView();

            currentView.Title = title;

            var file = await BitmapImageHelper.SaveBitmapImageToFile(content, "render.jpg");

            var size = new Size(content.ActualWidth, content.ActualHeight);

            var newView = CoreApplication.CreateNewView();
            await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                var image = await BitmapImageHelper.ReadBitmapImageFromFile(size, file);
                var brush = new ImageBrush
                {
                    ImageSource = image,
                    Stretch     = Stretch.None,
                    AlignmentX  = AlignmentX.Center,
                    AlignmentY  = AlignmentY.Center
                };

                var window     = Window.Current;
                window.Content = new Grid {
                    Background = brush
                };
                Window.Current.Activate();

                var preferences = ViewModePreferences.CreateDefault(ApplicationViewMode.CompactOverlay);
                preferences.ViewSizePreference = ViewSizePreference.Custom;
                preferences.CustomSize         = new Size(size.Width * 1.25, size.Height * 1.25);

                var view = ApplicationView.GetForCurrentView();
                await ApplicationViewSwitcher.TryShowAsViewModeAsync(view.Id, ApplicationViewMode.CompactOverlay, preferences);
            });
        }
示例#21
0
        public async Task <ViewLifetimeControl> OpenAsync(Func <ViewLifetimeControl, UIElement> content, object parameter, double width, double height, ApplicationViewMode viewMode)
        {
            if (_windows.TryGetValue(parameter, out IDispatcherContext value))
            {
                var newControl = await value.DispatchAsync(async() =>
                {
                    var control    = ViewLifetimeControl.GetForCurrentView();
                    var newAppView = ApplicationView.GetForCurrentView();

                    var preferences        = ViewModePreferences.CreateDefault(viewMode);
                    preferences.CustomSize = new Size(width, height);

                    await ApplicationViewSwitcher
                    .TryShowAsViewModeAsync(newAppView.Id, viewMode, preferences);

                    return(control);
                }).ConfigureAwait(false);

                return(newControl);
            }
            else
            {
                var newView    = CoreApplication.CreateNewView();
                var dispatcher = new DispatcherContext(newView.Dispatcher);
                _windows[parameter] = dispatcher;

                var newControl = await dispatcher.DispatchAsync(async() =>
                {
                    var newWindow     = Window.Current;
                    newWindow.Closed += (s, args) =>
                    {
                        _windows.TryRemove(parameter, out _);
                    };
                    newWindow.CoreWindow.Closed += (s, args) =>
                    {
                        _windows.TryRemove(parameter, out _);
                    };

                    var newAppView           = ApplicationView.GetForCurrentView();
                    newAppView.Consolidated += (s, args) =>
                    {
                        _windows.TryRemove(parameter, out _);
                        newWindow.Close();
                    };

                    if (ApiInformation.IsPropertyPresent("Windows.UI.ViewManagement.ApplicationView", "PersistedStateId"))
                    {
                        newAppView.PersistedStateId = "Calls";
                    }

                    var control       = ViewLifetimeControl.GetForCurrentView();
                    control.Released += (s, args) =>
                    {
                        _windows.TryRemove(parameter, out _);
                        newWindow.Close();
                    };

                    newWindow.Content = content(control);
                    newWindow.Activate();

                    var preferences        = ViewModePreferences.CreateDefault(viewMode);
                    preferences.CustomSize = new Size(width, height);

                    await ApplicationViewSwitcher.TryShowAsViewModeAsync(newAppView.Id, viewMode, preferences);

                    return(control);
                }).ConfigureAwait(false);

                return(newControl);
            }
        }
示例#22
0
        private async void OnRequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
        {
            var deferral = args.GetDeferral();
            var message  = args.Request.Message;

            try
            {
                if (message.ContainsKey("caption") && message.ContainsKey("request"))
                {
                    var caption = message["caption"] as string;
                    var buffer  = message["request"] as string;
                    var req     = TLSerializationService.Current.Deserialize(buffer);

                    if (caption.Equals("voip.getUser") && req is TLPeerUser userPeer)
                    {
                        var user = InMemoryCacheService.Current.GetUser(userPeer.UserId);
                        if (user != null)
                        {
                            await args.Request.SendResponseAsync(new ValueSet { { "result", TLSerializationService.Current.Serialize(user) } });
                        }
                        else
                        {
                            await args.Request.SendResponseAsync(new ValueSet { { "error", TLSerializationService.Current.Serialize(new TLRPCError {
                                        ErrorMessage = "USER_NOT_FOUND", ErrorCode = 404
                                    }) } });
                        }
                    }
                    else if (caption.Equals("voip.getConfig"))
                    {
                        var config = InMemoryCacheService.Current.GetConfig();
                        await args.Request.SendResponseAsync(new ValueSet { { "result", TLSerializationService.Current.Serialize(config) } });
                    }
                    else if (caption.Equals("voip.callInfo") && req is byte[] data)
                    {
                        using (var from = new TLBinaryReader(data))
                        {
                            var tupleBase = new TLTuple <int, TLPhoneCallBase, TLUserBase, string>(from);
                            var tuple     = new TLTuple <TLPhoneCallState, TLPhoneCallBase, TLUserBase, string>((TLPhoneCallState)tupleBase.Item1, tupleBase.Item2, tupleBase.Item3, tupleBase.Item4);

                            if (tuple.Item2 is TLPhoneCallDiscarded)
                            {
                                if (_phoneView != null)
                                {
                                    var newView = _phoneView;
                                    _phoneViewExists = false;
                                    _phoneView       = null;

                                    await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                                    {
                                        newView.SetCall(tuple);
                                        newView.Dispose();
                                        Window.Current.Close();
                                    });
                                }

                                return;
                            }

                            if (_phoneViewExists == false)
                            {
                                VoIPCallTask.Log("Creating VoIP UI", "Creating VoIP UI");

                                _phoneViewExists = true;

                                PhoneCallPage       newPlayer = null;
                                CoreApplicationView newView   = CoreApplication.CreateNewView();
                                var newViewId = 0;
                                await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                                {
                                    newPlayer = new PhoneCallPage();
                                    Window.Current.Content = newPlayer;
                                    Window.Current.Activate();
                                    newViewId = ApplicationView.GetForCurrentView().Id;

                                    newPlayer.SetCall(tuple);
                                    _phoneView = newPlayer;
                                });

                                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                                {
                                    if (ApiInformation.IsMethodPresent("Windows.UI.ViewManagement.ApplicationView", "IsViewModeSupported") && ApplicationView.GetForCurrentView().IsViewModeSupported(ApplicationViewMode.CompactOverlay))
                                    {
                                        var preferences        = ViewModePreferences.CreateDefault(ApplicationViewMode.CompactOverlay);
                                        preferences.CustomSize = new Size(340, 200);

                                        var viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(newViewId, ApplicationViewMode.CompactOverlay, preferences);
                                    }
                                    else
                                    {
                                        //await ApplicationViewSwitcher.SwitchAsync(newViewId);
                                        await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
                                    }
                                });
                            }
                            else if (_phoneView != null)
                            {
                                VoIPCallTask.Log("VoIP UI already exists", "VoIP UI already exists");

                                await _phoneView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                                {
                                    _phoneView.SetCall(tuple);
                                });
                            }
                        }
                    }
                    else if (caption.Equals("voip.signalBars") && req is byte[] data2)
                    {
                        using (var from = new TLBinaryReader(data2))
                        {
                            var tuple = new TLTuple <int>(from);

                            if (_phoneView != null)
                            {
                                await _phoneView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                                {
                                    _phoneView.SetSignalBars(tuple.Item1);
                                });
                            }
                        }
                    }
                    else if (caption.Equals("voip.setCallRating") && req is TLInputPhoneCall peer)
                    {
                        Execute.BeginOnUIThread(async() =>
                        {
                            var dialog  = new PhoneCallRatingView();
                            var confirm = await dialog.ShowQueuedAsync();
                            if (confirm == ContentDialogResult.Primary)
                            {
                                await MTProtoService.Current.SetCallRatingAsync(peer, dialog.Rating, dialog.Rating >= 0 && dialog.Rating <= 3 ? dialog.Comment : null);
                            }
                        });
                    }
                    else
                    {
                        var response = await MTProtoService.Current.SendRequestAsync <object>(caption, req as TLObject);

                        if (response.IsSucceeded)
                        {
                            await args.Request.SendResponseAsync(new ValueSet { { "result", TLSerializationService.Current.Serialize(response.Result) } });
                        }
                        else
                        {
                            await args.Request.SendResponseAsync(new ValueSet { { "error", TLSerializationService.Current.Serialize(response.Error) } });
                        }
                    }
                }
            }
            finally
            {
                deferral.Complete();
            }
        }
示例#23
0
        public async Task <ViewLifetimeControl> OpenAsync(Func <UIElement> content, object parameter, double width, double height)
        {
            if (_windows.TryGetValue(parameter, out DispatcherWrapper value))
            {
                var newControl = await value.Dispatch(async() =>
                {
                    var control    = ViewLifetimeControl.GetForCurrentView();
                    var newAppView = ApplicationView.GetForCurrentView();

                    var preferences        = ViewModePreferences.CreateDefault(ApplicationViewMode.CompactOverlay);
                    preferences.CustomSize = new Size(width, height);

                    await ApplicationViewSwitcher
                    .TryShowAsViewModeAsync(newAppView.Id, ApplicationViewMode.CompactOverlay, preferences);

                    return(control);
                }).ConfigureAwait(false);

                return(newControl);
            }
            else
            {
                var newView    = CoreApplication.CreateNewView();
                var dispatcher = new DispatcherWrapper(newView.Dispatcher);
                _windows[parameter] = dispatcher;

                var bounds = Window.Current.Bounds;

                var newControl = await dispatcher.Dispatch(async() =>
                {
                    var newWindow     = Window.Current;
                    newWindow.Closed += (s, args) =>
                    {
                        _windows.TryRemove(parameter, out DispatcherWrapper ciccio);
                    };
                    newWindow.CoreWindow.Closed += (s, args) =>
                    {
                        _windows.TryRemove(parameter, out DispatcherWrapper ciccio);
                    };

                    var newAppView           = ApplicationView.GetForCurrentView();
                    newAppView.Consolidated += (s, args) =>
                    {
                        _windows.TryRemove(parameter, out DispatcherWrapper ciccio);
                        newWindow.Close();
                    };

                    var control       = ViewLifetimeControl.GetForCurrentView();
                    control.Released += (s, args) =>
                    {
                        _windows.TryRemove(parameter, out DispatcherWrapper ciccio);
                        newWindow.Close();
                    };

                    newWindow.Content = content();
                    newWindow.Activate();

                    var preferences        = ViewModePreferences.CreateDefault(ApplicationViewMode.CompactOverlay);
                    preferences.CustomSize = new Size(width, height);

                    await ApplicationViewSwitcher
                    .TryShowAsViewModeAsync(newAppView.Id, ApplicationViewMode.CompactOverlay, preferences);

                    return(control);
                }).ConfigureAwait(false);

                return(newControl);
            }
        }
示例#24
0
        public IAsyncOperation <ContentDialogBaseResult> ShowAsync(TLWebPage webPage)
        {
            if (ApplicationView.GetForCurrentView().IsCompactOverlaySupported())
            {
                return(AsyncInfo.Run(async token =>
                {
                    var w = webPage.EmbedWidth ?? 340;
                    var h = webPage.EmbedHeight ?? 200;

                    double ratioX = (double)340 / w;
                    double ratioY = (double)340 / h;
                    double ratio = Math.Min(ratioX, ratioY);

                    var preferences = ViewModePreferences.CreateDefault(ApplicationViewMode.CompactOverlay);
                    preferences.CustomSize = new Size(w * ratio, h * ratio);

                    var newView = CoreApplication.CreateNewView();
                    var newViewId = 0;
                    await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        var request = new HttpRequestMessage(HttpMethod.Get, new Uri(webPage.EmbedUrl));
                        request.Headers.Referer = new Uri("https://youtube.com");

                        var view = new WebView();
                        view.NavigateWithHttpRequestMessage(request);
                        //view.Navigate(new Uri(webPage.EmbedUrl));

                        var yolo = new GlyphButton();
                        yolo.HorizontalAlignment = HorizontalAlignment.Right;
                        yolo.VerticalAlignment = VerticalAlignment.Bottom;
                        yolo.Glyph = "\uE740";
                        yolo.Click += async(s, args) =>
                        {
                            var current = ApplicationView.GetForCurrentView();
                            if (current.ViewMode == ApplicationViewMode.CompactOverlay)
                            {
                                current.TryEnterFullScreenMode();
                            }
                            else
                            {
                                await current.TryEnterViewModeAsync(ApplicationViewMode.CompactOverlay, preferences);
                            }
                        };

                        var ciccio = new Grid();
                        ciccio.RequestedTheme = ElementTheme.Dark;
                        ciccio.Children.Add(view);
                        ciccio.Children.Add(yolo);

                        Window.Current.Content = ciccio;
                        Window.Current.Activate();
                        Window.Current.VisibilityChanged += (s, args) =>
                        {
                            if (args.Visible)
                            {
                                return;
                            }

                            view.NavigateToString(string.Empty);
                        };

                        newViewId = ApplicationView.GetForCurrentView().Id;

                        var coreTitleBar = CoreApplication.GetCurrentView().TitleBar;
                        coreTitleBar.ExtendViewIntoTitleBar = true;

                        var titleBar = ApplicationView.GetForCurrentView().TitleBar;
                        titleBar.ButtonBackgroundColor = Colors.Transparent;
                        titleBar.ButtonForegroundColor = Colors.White;
                        titleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
                        titleBar.ButtonInactiveForegroundColor = Colors.White;
                    });

                    var viewShown = await ApplicationViewSwitcher.TryShowAsViewModeAsync(newViewId, ApplicationViewMode.CompactOverlay, preferences);

                    return ContentDialogBaseResult.OK;
                }));
            }
            else
            {
                if (webPage.HasEmbedUrl)
                {
                    Image.Constraint = webPage;
                    View.Navigate(new Uri(webPage.EmbedUrl));
                }

                return(base.ShowAsync());
            }
        }