Ejemplo n.º 1
0
        public static async void MinimizeWindow()
        {
            IList <AppDiagnosticInfo> infos = await AppDiagnosticInfo.RequestInfoForAppAsync();

            IList <AppResourceGroupInfo> resourceInfos = infos[0].GetResourceGroups();
            await resourceInfos[0].StartSuspendAsync();
        }
Ejemplo n.º 2
0
        async Task PlatformAnnotate(NGContact contact, NGAnnotations annotations)
        {
            ContactAnnotationOperations winAnnotations = (ContactAnnotationOperations)annotations;

            if (winAnnotations == ContactAnnotationOperations.None)
            {
                winAnnotations = ContactAnnotationOperations.ContactProfile;
            }

            // Annotate this contact with a remote ID, which you can then retrieve when the Contact Panel is activated.
            var contactAnnotation = new ContactAnnotation
            {
                ContactId           = contact.Id,
                RemoteId            = contact.RemoteId,
                SupportedOperations = winAnnotations
            };

            // Annotate that this contact can load this app's Contact Panel or Contact Share.
            var infos = await AppDiagnosticInfo.RequestInfoForAppAsync();

            contactAnnotation.ProviderProperties.Add("ContactPanelAppID", infos[0].AppInfo.AppUserModelId);
            if ((winAnnotations & ContactAnnotationOperations.Share) == ContactAnnotationOperations.Share)
            {
                contactAnnotation.ProviderProperties.Add("ContactShareAppID", infos[0].AppInfo.AppUserModelId);
            }

            var annotationList = await FindOrRegisterAnnotationList();

            await annotationList.TrySaveAnnotationAsync(contactAnnotation);
        }
Ejemplo n.º 3
0
        private async Task Minimize()
        {
            IList <AppDiagnosticInfo> infos = await AppDiagnosticInfo.RequestInfoForAppAsync();

            IList <AppResourceGroupInfo> resourceInfos = infos[0].GetResourceGroups();
            await resourceInfos[0].StartSuspendAsync();
        }
Ejemplo n.º 4
0
        private async void runBack()
        {
            IList <AppDiagnosticInfo> infos = await AppDiagnosticInfo.RequestInfoForAppAsync();

            IList <AppResourceGroupInfo> appResources = infos[0].GetResourceGroups();

            await appResources[0].StartSuspendAsync();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs e)
        {
            _logger.LogInformation("=== Start Application ===");

            _settingsService.SetProgramLanguage(null);

            SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;

            var rootFrame = Window.Current.Content as Frame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new Frame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (e.PrelaunchActivated == false)
            {
                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
                    rootFrame.Navigate(typeof(MainPage), e.Arguments);
                }

                // Ensure the current window is active
                Window.Current.Activate();

                Settings settings = _settingsService.Load();

                if (settings.StartAppMinimized.HasValue && settings.StartAppMinimized.Value)
                {
                    IList <AppDiagnosticInfo> infos = await AppDiagnosticInfo.RequestInfoForAppAsync();

                    AppDiagnosticInfo appDiagnosticInfo = infos.FirstOrDefault();

                    if (appDiagnosticInfo != null)
                    {
                        IList <AppResourceGroupInfo> resourceInfos = appDiagnosticInfo.GetResourceGroups();
                        await resourceInfos[0].StartSuspendAsync();
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public static async Task StartTerminateAsync()
        {
            IList <AppDiagnosticInfo> infos = await AppDiagnosticInfo.RequestInfoForAppAsync();

            IList <AppResourceGroupInfo> resourceInfos = infos[0].GetResourceGroups();
            var pid = Windows.System.Diagnostics.ProcessDiagnosticInfo.GetForCurrentProcess().ProcessId;
            await resourceInfos.Single(r => r.GetProcessDiagnosticInfos()[0].ProcessId == pid).StartTerminateAsync();

            //Application.Current.Exit();
        }
        public static async Task SuspendAppAsync()
        {
            AppResourceGroupInfo appResourceGroupInfo = null;

            // for Windows v1803 aka build 17134 and above, we can minimize by suspending

            // cannot minimize a full screen window, so take the app out of full screen
            ApplicationView view = ApplicationView.GetForCurrentView();

            if (view.IsFullScreenMode)
            {
                view.ExitFullScreenMode();
            }

            // figure out if we can suspend and can get the references we need
            if (ConfigurationService.DoesOSBuildSupportSuspend())
            {
                // get app diagnostic information
                IList <AppDiagnosticInfo> diagnosticInformations = await AppDiagnosticInfo.RequestInfoForAppAsync();

                // if we got them
                if ((null != diagnosticInformations) && (diagnosticInformations.Count > 0))
                {
                    // loop through the informations
                    foreach (AppDiagnosticInfo diagnosticInformation in diagnosticInformations)
                    {
                        // if we find one with Id = "App"
                        if (0 == String.Compare(diagnosticInformation.AppInfo.Id, "App", true))
                        {
                            // get the resource groups from that diagnostic information
                            IList <AppResourceGroupInfo> resourceGroups = diagnosticInformation.GetResourceGroups();

                            // if we got them
                            if ((null != resourceGroups) && (resourceGroups.Count > 0))
                            {
                                // take the first resource group
                                appResourceGroupInfo = resourceGroups[0];
                            }
                        }
                    }
                }
            }

            // if we got a suspendable object, use it
            if (null != appResourceGroupInfo)
            {
                // we can suspend and got an resource info object to use
                AppExecutionStateChangeResult result = await appResourceGroupInfo.StartSuspendAsync();
            }
            else
            {
                // we can't suspend, so must exit
                App.Current.Exit();
            }
        }
Ejemplo n.º 8
0
        public async Task ExitApp()
        {
            StopRecording();
            ClearExtendedExecution();
            await Utils.JumpListMenu.Clear();

            IList <AppDiagnosticInfo> infos = await AppDiagnosticInfo.RequestInfoForAppAsync();

            IList <AppResourceGroupInfo> resourceInfos = infos[0].GetResourceGroups();
            await resourceInfos[0].StartTerminateAsync(); // terminate the app
        }
Ejemplo n.º 9
0
        public async void Minimize()
        {
            try
            {
                IList <AppDiagnosticInfo> infos = await AppDiagnosticInfo.RequestInfoForAppAsync();

                IList <AppResourceGroupInfo> resourceInfos = infos[0].GetResourceGroups();
                resourceInfos[0].StartSuspendAsync();
            }
            catch (Exception ex)
            {
                Debug.Write(ex);
            }
        }
Ejemplo n.º 10
0
        static async void ThreadProc()
        {
            var result = await AppDiagnosticInfo.RequestAccessAsync();

            if (result == DiagnosticAccessStatus.Allowed)
            {
                string baseAddress = "http://localhost:5000/";
                WebApp.Start <Startup>(url: baseAddress);
            }

            var info = await AppDiagnosticInfo.RequestInfoForAppAsync();

            var watcher = info.FirstOrDefault().CreateResourceGroupWatcher();

            watcher.ExecutionStateChanged += Watcher_ExecutionStateChanged;
            watcher.Start();
        }
Ejemplo n.º 11
0
        private async void MediaPlayer_CurrentStateChanged(MediaPlayer sender, object args)
        {
            if (sender.PlaybackSession.PlaybackState == MediaPlaybackState.Playing)
            {
                session        = new ExtendedExecutionForegroundSession();
                session.Reason = ExtendedExecutionForegroundReason.BackgroundAudio;
                var result = await session.RequestExtensionAsync();

                if (result != ExtendedExecutionForegroundResult.Allowed)
                {
                    throw new Exception("EE denied");
                }

                IList <AppDiagnosticInfo> infos = await AppDiagnosticInfo.RequestInfoForAppAsync();

                IList <AppResourceGroupInfo> resourceInfos = infos[0].GetResourceGroups();
                await resourceInfos[0].StartSuspendAsync();
            }
        }
Ejemplo n.º 12
0
        private async void NotiBootstrap()
        {
            var builder = new ToastContentBuilder();

            try
            {
                var infos = await AppDiagnosticInfo.RequestInfoForAppAsync();

                var   resourceInfos = infos[0].GetResourceGroups();
                await resourceInfos[0].StartSuspendAsync();

                if (UWPAppEnvironment.toastNotifier == null)
                {
                    UWPAppEnvironment.toastNotifier = ToastNotificationManager.CreateToastNotifier();
                }

                var notiUWP = new NotiScheduleUWP();

                notiUWP.CancelAll();
                notiUWP.ScheduleAll();

                builder.AddToastActivationInfo("BootNotiRegister", ToastActivationType.Foreground);
                builder.AddText(AppResources.BootAlarmRegisterSuccess);
            }
            catch (Exception)
            {
                builder.AddText(AppResources.BootAlarmRegisterFail);
            }
            finally
            {
                if (builder != null)
                {
                    UWPAppEnvironment.toastNotifier.AddToSchedule(new ScheduledToastNotification(builder.GetToastContent().GetXml(), DateTime.Now.AddSeconds(3)));
                }

                await Task.Delay(3000);

                Exit();
            }
        }
Ejemplo n.º 13
0
        // If we are activated and CloseRequested is called, most likely user tried to close the window with the X in the Titlebar.
        //      - In this case we will minimize the app if we are recording, otherwise we will allow the app to exit
        // If we are not activated and CloseRequested is called, most likely user tried to close the window with the "Close Window" comand
        // with the app's icon menu.
        //      - In this case we will always allow the app to exit
        // These scenarios are arbitrary. Feel free to adjust the behavior to suit the needs of your app.
        // You can also use a dialog to ask the user if they want to exit the app. For example
        //      CloseAppDialog dialog = new CloseAppDialog();
        //      var result = await dialog.ShowAsync();
        //      var minimize = result == ContentDialogResult.Primary;
        public async void OnCloseRequested(object sender, SystemNavigationCloseRequestedPreviewEventArgs args)
        {
            var deferral = args.GetDeferral();

            // If the ExtendedExecutionForegroundSession is active, don't allow the app to exit unless the user wants it to exit.
            if (m_session != null && m_isWindowActivated)
            {
                args.Handled = true;

                IList <AppDiagnosticInfo> infos = await AppDiagnosticInfo.RequestInfoForAppAsync();

                IList <AppResourceGroupInfo> resourceInfos = infos[0].GetResourceGroups();
                await resourceInfos[0].StartSuspendAsync(); // minimize the app. App will keep running due to the ExtendedSession
            }
            else
            {
                args.Handled = false;
                await ExitApp();
            }

            deferral.Complete();
            deferral = null;
        }