Exemplo n.º 1
0
        protected override async void OnActivated(IActivatedEventArgs args)
        {
            Logger.LogInformation("OnActivated() {0}", args.GetType());
            if (args is ToastNotificationActivatedEventArgs toastArgs)
            {
                bool createdMainWindow = await CreateMainWindow(toastArgs.Argument);

                if (!createdMainWindow)
                {
                    if (args is IViewSwitcherProvider viewSwitcherProvider && viewSwitcherProvider.ViewSwitcher != null)
                    {
                        ActivationViewSwitcher switcher = viewSwitcherProvider.ViewSwitcher;
                        int currentId = toastArgs.CurrentlyShownApplicationViewId;
                        if (viewSwitcherProvider.ViewSwitcher.IsViewPresentedOnActivationVirtualDesktop(toastArgs.CurrentlyShownApplicationViewId))
                        {
                            await Views[currentId].Dispatcher.RunTaskAsync(() =>
                            {
                                Logger.LogInformation("OnActivated() selecting conversation");
                                Views[currentId].Locator.MainPageInstance.SelectConversation(toastArgs.Argument);
                            });
                            await ApplicationViewSwitcher.TryShowAsStandaloneAsync(currentId);
                        }
                        else
                        {
                            await CreateSecondaryWindow(switcher, toastArgs.Argument);
                        }
                    }
                    else
                    {
                        Logger.LogError("OnActivated() has no ViewSwitcher");
                    }
                }
            }
Exemplo n.º 2
0
        private Task ShowOrCreateWindowAsync(ActivationViewSwitcher viewSwitcher)
        {
            var viewModel = _mainViewModels.Find(o => o.ApplicationView.Id == _activeWindowId) ??
                            _mainViewModels.LastOrDefault();

            return(viewModel == null
                ? CreateTerminalAsync(_settingsService.GetDefaultShellProfile(), NewTerminalLocation.Tab, viewSwitcher)
                : ShowAsStandaloneAsync(viewModel, viewSwitcher));
        }
Exemplo n.º 3
0
        private Task ShowAsStandaloneAsync(MainViewModel viewModel, ActivationViewSwitcher viewSwitcher = null)
        {
            var viewId = viewModel.ApplicationView.Id;

            if (viewSwitcher != null)
            {
                return(viewModel.ApplicationView.ExecuteOnUiThreadAsync(async() => await viewSwitcher.ShowAsStandaloneAsync(viewId)));
            }

            return(ApplicationViewSwitcher.TryShowAsStandaloneAsync(viewId).AsTask());
        }
Exemplo n.º 4
0
 private async Task ShowOrCreateWindow(ActivationViewSwitcher viewSwitcher)
 {
     if (_mainViewModels.Count == 0)
     {
         await CreateTerminal(_settingsService.GetDefaultShellProfile(), NewTerminalLocation.Tab, viewSwitcher);
     }
     else
     {
         var viewModel = _mainViewModels.Find(o => o.ApplicationView.Id == _activeWindowId) ?? _mainViewModels.Last();
         await ShowAsStandaloneAsync(viewModel, viewSwitcher);
     }
 }
Exemplo n.º 5
0
        private async Task ShowAsStandaloneAsync(MainViewModel viewModel, ActivationViewSwitcher viewSwitcher = null)
        {
            int viewId = viewModel.ApplicationView.Id;

            if (viewSwitcher != null)
            {
                await viewModel.ApplicationView.RunOnDispatcherThread(async() => await viewSwitcher.ShowAsStandaloneAsync(viewId));
            }
            else
            {
                await ApplicationViewSwitcher.TryShowAsStandaloneAsync(viewId);
            }
        }
Exemplo n.º 6
0
        protected override async void OnActivated(IActivatedEventArgs args)
        {
            Logger.LogInformation("OnActivated() {0}", args.GetType());
            DisappearingMessagesManager.DeleteExpiredMessages();
            if (args is ToastNotificationActivatedEventArgs toastArgs)
            {
                string requestedConversation = toastArgs.Argument;
                bool   createdMainWindow     = await CreateMainWindow(requestedConversation);

                if (!createdMainWindow)
                {
                    if (args is IViewSwitcherProvider viewSwitcherProvider && viewSwitcherProvider.ViewSwitcher != null)
                    {
                        ActivationViewSwitcher switcher = viewSwitcherProvider.ViewSwitcher;
                        int currentId = toastArgs.CurrentlyShownApplicationViewId;
                        if (viewSwitcherProvider.ViewSwitcher.IsViewPresentedOnActivationVirtualDesktop(toastArgs.CurrentlyShownApplicationViewId))
                        {
                            var   taskCompletionSource = new TaskCompletionSource <bool>();
                            await Views[currentId].Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                try
                                {
                                    Logger.LogInformation("OnActivated() selecting conversation");
                                    Views[currentId].Locator.MainPageInstance.TrySelectConversation(requestedConversation);
                                }
                                catch (Exception e)
                                {
                                    Logger.LogError("OnActivated() TrySelectConversation() failed: {0}\n{1}", e.Message, e.StackTrace);
                                }
                                finally
                                {
                                    taskCompletionSource.SetResult(false);
                                }
                            });
                            await taskCompletionSource.Task;
                            await viewSwitcherProvider.ViewSwitcher.ShowAsStandaloneAsync(currentId);
                        }
                        else
                        {
                            await CreateSecondaryWindowOrShowMain(switcher, requestedConversation);
                        }
                    }
                    else
                    {
                        Logger.LogError("OnActivated() has no ViewSwitcher");
                    }
                }
            }
Exemplo n.º 7
0
        private async Task CreateTerminal(ShellProfile profile, NewTerminalLocation location, ActivationViewSwitcher viewSwitcher = null)
        {
            async Task ShowAsStandaloneAsync(MainViewModel viewModel)
            {
                int viewId = viewModel.ApplicationView.Id;

                if (viewSwitcher != null)
                {
                    await viewModel.ApplicationView.RunOnDispatcherThread(async() => await viewSwitcher.ShowAsStandaloneAsync(viewId));
                }
                else
                {
                    await ApplicationViewSwitcher.TryShowAsStandaloneAsync(viewId);
                }
            }

            if (!_alreadyLaunched)
            {
                var viewModel = _container.Resolve <MainViewModel>();
                await viewModel.AddTerminalAsync(profile);
                await CreateMainView(typeof(MainPage), viewModel, true).ConfigureAwait(true);
            }
            else if (location == NewTerminalLocation.Tab && _mainViewModels.Count > 0)
            {
                MainViewModel item = _mainViewModels.FirstOrDefault(o => o.ApplicationView.Id == _activeWindowId);
                if (item == null)
                {
                    item = _mainViewModels.Last();
                }

                await item.AddTerminalAsync(profile);
                await ShowAsStandaloneAsync(item);
            }
            else
            {
                var viewModel = await CreateNewTerminalWindow().ConfigureAwait(true);

                await viewModel.AddTerminalAsync(profile);
                await ShowAsStandaloneAsync(viewModel);
            }
        }
Exemplo n.º 8
0
        private async Task CreateTerminalAsync(ShellProfile profile, NewTerminalLocation location, ActivationViewSwitcher viewSwitcher = null)
        {
            if (!_alreadyLaunched)
            {
                var viewModel = _container.Resolve <MainViewModel>();
                await viewModel.AddTabAsync(profile);
                await CreateMainViewAsync(typeof(MainPage), viewModel, true);
            }
            else if (location == NewTerminalLocation.Tab && _mainViewModels.Count > 0)
            {
                var item = _mainViewModels.FirstOrDefault(o => o.ApplicationView.Id == _activeWindowId) ??
                           _mainViewModels.Last();

                await item.AddTabAsync(profile);
                await ShowAsStandaloneAsync(item, viewSwitcher);
            }
            else
            {
                var viewModel = await CreateNewTerminalWindowAsync();

                await viewModel.AddTabAsync(profile);
                await ShowAsStandaloneAsync(viewModel, viewSwitcher);
            }
        }
Exemplo n.º 9
0
        private void OnAppLaunch(IActivatedEventArgs args, string argument)
        {
            // Uncomment the following lines to display frame-rate and per-frame CPU usage info.
            //#if _DEBUG
            //    if (IsDebuggerPresent())
            //    {
            //        DebugSettings->EnableFrameRateCounter = true;
            //    }
            //#endif

            args.SplashScreen.Dismissed += DismissedEventHandler;

            var           rootFrame = (Window.Current.Content as Frame);
            WeakReference weak      = new WeakReference(this);

            float minWindowWidth  = (float)((double)Resources[ApplicationResourceKeys.Globals.AppMinWindowWidth]);
            float minWindowHeight = (float)((double)Resources[ApplicationResourceKeys.Globals.AppMinWindowHeight]);
            Size  minWindowSize   = SizeHelper.FromDimensions(minWindowWidth, minWindowHeight);

            ApplicationView          appView       = ApplicationView.GetForCurrentView();
            ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;

            // For very first launch, set the size of the calc as size of the default standard mode
            if (!localSettings.Values.ContainsKey("VeryFirstLaunch"))
            {
                localSettings.Values["VeryFirstLaunch"] = false;
                appView.SetPreferredMinSize(minWindowSize);
                appView.TryResizeView(minWindowSize);
            }
            else
            {
                ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.Auto;
            }

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                if (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons")) // PC Family
                {
                    // Disable the system view activation policy during the first launch of the app
                    // only for PC family devices and not for phone family devices
                    try
                    {
                        ApplicationViewSwitcher.DisableSystemViewActivationPolicy();
                    }
                    catch (Exception)
                    {
                        // Log that DisableSystemViewActionPolicy didn't work
                    }
                }

                // Create a Frame to act as the navigation context
                rootFrame = App.CreateFrame();

                // When the navigation stack isn't restored navigate to the first page,
                // configuring the new page by passing required information as a navigation
                // parameter
                if (!rootFrame.Navigate(typeof(MainPage), argument))
                {
                    // We couldn't navigate to the main page, kill the app so we have a good
                    // stack to debug
                    throw new SystemException();
                }

                SetMinWindowSizeAndThemeAndActivate(rootFrame, minWindowSize);
                m_mainViewId = ApplicationView.GetForCurrentView().Id;
                AddWindowToMap(WindowFrameService.CreateNewWindowFrameService(rootFrame, false, weak));
            }
            else
            {
                // For first launch, LaunchStart is logged in constructor, this is for subsequent launches.

                // !Phone check is required because even in continuum mode user interaction mode is Mouse not Touch
                if ((UIViewSettings.GetForCurrentView().UserInteractionMode == UserInteractionMode.Mouse) &&
                    (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons")))
                {
                    // If the pre-launch hasn't happened then allow for the new window/view creation
                    if (!m_preLaunched)
                    {
                        var newCoreAppView = CoreApplication.CreateNewView();
                        _ = newCoreAppView.Dispatcher.RunAsync(
                            CoreDispatcherPriority.Normal, async() =>
                        {
                            var that = weak.Target as App;
                            if (that != null)
                            {
                                var newRootFrame = App.CreateFrame();

                                SetMinWindowSizeAndThemeAndActivate(newRootFrame, minWindowSize);

                                if (!newRootFrame.Navigate(typeof(MainPage), argument))
                                {
                                    // We couldn't navigate to the main page, kill the app so we have a good
                                    // stack to debug
                                    throw new SystemException();
                                }

                                var frameService = WindowFrameService.CreateNewWindowFrameService(newRootFrame, true, weak);
                                that.AddWindowToMap(frameService);

                                var dispatcher = CoreWindow.GetForCurrentThread().Dispatcher;

                                // CSHARP_MIGRATION_ANNOTATION:
                                // class SafeFrameWindowCreation is being interpreted into a IDisposable class
                                // in order to enhance its RAII capability that was written in C++/CX
                                using (var safeFrameServiceCreation = new SafeFrameWindowCreation(frameService, that))
                                {
                                    int newWindowId = ApplicationView.GetApplicationViewIdForWindow(CoreWindow.GetForCurrentThread());

                                    ActivationViewSwitcher activationViewSwitcher = null;
                                    var activateEventArgs = (args as IViewSwitcherProvider);
                                    if (activateEventArgs != null)
                                    {
                                        activationViewSwitcher = activateEventArgs.ViewSwitcher;
                                    }

                                    if (activationViewSwitcher != null)
                                    {
                                        _ = activationViewSwitcher.ShowAsStandaloneAsync(newWindowId, ViewSizePreference.Default);
                                        safeFrameServiceCreation.SetOperationSuccess(true);
                                    }
                                    else
                                    {
                                        var activatedEventArgs = (args as IApplicationViewActivatedEventArgs);
                                        if ((activatedEventArgs != null) && (activatedEventArgs.CurrentlyShownApplicationViewId != 0))
                                        {
                                            // CSHARP_MIGRATION_ANNOTATION:
                                            // here we don't use ContinueWith() to interpret origin code because we would like to
                                            // pursue the design of class SafeFrameWindowCreate whichi was using RAII to ensure
                                            // some states get handled properly when its instance is being destructed.
                                            //
                                            // To achieve that, SafeFrameWindowCreate has been reinterpreted using IDisposable
                                            // pattern, which forces we use below way to keep async works being controlled within
                                            // a same code block.
                                            var viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(
                                                frameService.GetViewId(),
                                                ViewSizePreference.Default,
                                                activatedEventArgs.CurrentlyShownApplicationViewId,
                                                ViewSizePreference.Default);
                                            // SafeFrameServiceCreation is used to automatically remove the frame
                                            // from the list of frames if something goes bad.
                                            safeFrameServiceCreation.SetOperationSuccess(viewShown);
                                        }
                                    }
                                }
                            }
                        });
                    }
                    else
                    {
                        ActivationViewSwitcher activationViewSwitcher = null;
                        var activateEventArgs = (args as IViewSwitcherProvider);
                        if (activateEventArgs != null)
                        {
                            activationViewSwitcher = activateEventArgs.ViewSwitcher;
                        }

                        if (activationViewSwitcher != null)
                        {
                            _ = activationViewSwitcher.ShowAsStandaloneAsync(
                                ApplicationView.GetApplicationViewIdForWindow(CoreWindow.GetForCurrentThread()), ViewSizePreference.Default);
                        }
                        else
                        {
                            TraceLogger.GetInstance().LogError(ViewMode.None, "App.OnAppLaunch", "Null_ActivationViewSwitcher");
                        }
                    }
                    // Set the preLaunched flag to false
                    m_preLaunched = false;
                }
                else // for touch devices
                {
                    if (rootFrame.Content == null)
                    {
                        // When the navigation stack isn't restored navigate to the first page,
                        // configuring the new page by passing required information as a navigation
                        // parameter
                        if (!rootFrame.Navigate(typeof(MainPage), argument))
                        {
                            // We couldn't navigate to the main page,
                            // kill the app so we have a good stack to debug
                            throw new SystemException();
                        }
                    }
                    if (ApplicationView.GetForCurrentView().ViewMode != ApplicationViewMode.CompactOverlay)
                    {
                        if (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Phone.UI.Input.HardwareButtons"))
                        {
                            // for tablet mode: since system view activation policy is disabled so do ShowAsStandaloneAsync if activationViewSwitcher exists in
                            // activationArgs
                            ActivationViewSwitcher activationViewSwitcher = null;
                            var activateEventArgs = (args as IViewSwitcherProvider);
                            if (activateEventArgs != null)
                            {
                                activationViewSwitcher = activateEventArgs.ViewSwitcher;
                            }
                            if (activationViewSwitcher != null)
                            {
                                var viewId = (args as IApplicationViewActivatedEventArgs).CurrentlyShownApplicationViewId;
                                if (viewId != 0)
                                {
                                    _ = activationViewSwitcher.ShowAsStandaloneAsync(viewId);
                                }
                            }
                        }
                        // Ensure the current window is active
                        Window.Current.Activate();
                    }
                }
            }
        }
Exemplo n.º 10
0
        protected override async void OnActivated(IActivatedEventArgs args)
        {
            Logger.LogInformation("OnActivated() {0}", args.GetType());
            if (args.Kind == ActivationKind.Protocol)
            {
                ProtocolActivatedEventArgs protocolArgs = args as ProtocolActivatedEventArgs;
                // We support multiple protocols so check what scheme was used to launch the app
                if (protocolArgs.Uri.Scheme.ToLower() == "signalpassback")
                {
                    if (protocolArgs.Data.ContainsKey("token"))
                    {
                        string signalCaptchaToken   = (string)protocolArgs.Data["token"];
                        var    registerPageInstance = CurrentSignalWindowsFrontend(MainViewId).Locator.RegisterPageInstance;
                        registerPageInstance.CaptchaCode           = signalCaptchaToken;
                        registerPageInstance.CaptchaWebViewEnabled = false;
                        CurrentSignalWindowsFrontend(MainViewId).Locator.CaptchaPageInstance.View.Frame.GoBack();
                    }
                    else
                    {
                        Logger.LogError("App was launched with signalpassback:// but wasn't passed a token");
                    }
                    return;
                }
            }
            DisappearingMessagesManager.DeleteExpiredMessages();
            if (args is ToastNotificationActivatedEventArgs toastArgs)
            {
                string requestedConversation = toastArgs.Argument;
                bool   createdMainWindow     = await CreateMainWindow(requestedConversation);

                if (!createdMainWindow)
                {
                    if (args is IViewSwitcherProvider viewSwitcherProvider && viewSwitcherProvider.ViewSwitcher != null)
                    {
                        ActivationViewSwitcher switcher = viewSwitcherProvider.ViewSwitcher;
                        int currentId = toastArgs.CurrentlyShownApplicationViewId;
                        if (viewSwitcherProvider.ViewSwitcher.IsViewPresentedOnActivationVirtualDesktop(toastArgs.CurrentlyShownApplicationViewId))
                        {
                            var   taskCompletionSource = new TaskCompletionSource <bool>();
                            await Views[currentId].Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                try
                                {
                                    Logger.LogInformation("OnActivated() selecting conversation");
                                    Views[currentId].Locator.MainPageInstance.TrySelectConversation(requestedConversation);
                                }
                                catch (Exception e)
                                {
                                    Logger.LogError("OnActivated() TrySelectConversation() failed: {0}\n{1}", e.Message, e.StackTrace);
                                }
                                finally
                                {
                                    taskCompletionSource.SetResult(false);
                                }
                            });
                            await taskCompletionSource.Task;
                            await viewSwitcherProvider.ViewSwitcher.ShowAsStandaloneAsync(currentId);
                        }
                        else
                        {
                            await CreateSecondaryWindowOrShowMain(switcher, requestedConversation);
                        }
                    }
                    else
                    {
                        Logger.LogError("OnActivated() has no ViewSwitcher");
                    }
                }
            }