Exemplo n.º 1
0
        public static async Task SetBothAsync(StorageFile savedFile)
        {
            Events.LogSetAsBoth();

            var uc = new LoadingTextControl()
            {
                LoadingText = ResourcesHelper.GetResString("SettingDesktopAndLockHint")
            };
            await PopupService.Instance.ShowAsync(uc, solidBackground : false).ConfigureAwait(true);

            var file = await PrepareImageFileAsync(savedFile).ConfigureAwait(true);

            if (file != null)
            {
                var result0 = await UserProfilePersonalizationSettings.Current.TrySetWallpaperImageAsync(file);

                var result1 = await UserProfilePersonalizationSettings.Current.TrySetLockScreenImageAsync(file);

                if (!result0 || !result1)
                {
                    ShowFailedToast();
                }
            }

            PopupService.Instance.TryHide(500);
        }
Exemplo n.º 2
0
        private static async Task <StorageFile> PrepareImageFileAsync(StorageFile resultFile)
        {
            if (!UserProfilePersonalizationSettings.IsSupported())
            {
                ToastService.SendToast(ResourcesHelper.GetResString("SettingWallpaperNotSupported"));
                return(null);
            }

            try
            {
                if (resultFile != null)
                {
                    //WTF, the file should be copy to LocalFolder to make the setting wallpaer api work.
                    var         folder = ApplicationData.Current.LocalFolder;
                    StorageFile file;
                    if (await folder.TryGetItemAsync(resultFile.Name) is StorageFile oldFile)
                    {
                        await resultFile.CopyAndReplaceAsync(oldFile);

                        file = oldFile;
                    }
                    else
                    {
                        file = await resultFile.CopyAsync(folder);
                    }
                    return(file);
                }
            }
            catch (FileNotFoundException)
            {
                ShowFailedToast();
            }

            return(null);
        }
Exemplo n.º 3
0
        public static async Task SetupJumpList()
        {
            var jumpList = await JumpList.LoadCurrentAsync();

            jumpList.Items.Clear();

            var searchItem = JumpListItem.CreateWithArguments(Value.SEARCH, ResourcesHelper.GetResString("SearchContent"));

            searchItem.Logo = new Uri("ms-appx:///Assets/Icon/search.png");
            jumpList.Items.Add(searchItem);

            await jumpList.SaveAsync();
        }
        public static async Task UnregisterAsync()
        {
            var status = await BackgroundExecutionManager.RequestAccessAsync();

            if (status != BackgroundAccessStatus.AlwaysAllowed &&
                status != BackgroundAccessStatus.AllowedSubjectToSystemPolicy)
            {
                ToastService.SendToast(ResourcesHelper.GetResString("BackgroundRegisterFailed"), TimeSpan.FromMilliseconds(5000));
                return;
            }

            foreach (var cur in BackgroundTaskRegistration.AllTasks)
            {
                if (cur.Value.Name == NAME)
                {
                    cur.Value.Unregister(true);
                }
            }

            Debug.WriteLine($"===================unregistered===================");
        }
        private static async Task <BackgroundTaskRegistration> RegisterBackgroundTask(Type taskEntryPoint,
                                                                                      IBackgroundTrigger trigger,
                                                                                      IBackgroundCondition condition)
        {
            var status = await BackgroundExecutionManager.RequestAccessAsync();

            if (status != BackgroundAccessStatus.AlwaysAllowed &&
                status != BackgroundAccessStatus.AllowedSubjectToSystemPolicy)
            {
                ToastService.SendToast(ResourcesHelper.GetResString("BackgroundRegisterFailed"), TimeSpan.FromMilliseconds(5000));
                return(null);
            }

            foreach (var cur in BackgroundTaskRegistration.AllTasks)
            {
                if (cur.Value.Name == NAME)
                {
                    cur.Value.Unregister(true);
                }
            }

            var builder = new BackgroundTaskBuilder
            {
                Name           = NAME,
                TaskEntryPoint = taskEntryPoint.FullName
            };

            builder.SetTrigger(trigger);

            if (condition != null)
            {
                builder.AddCondition(condition);
            }

            BackgroundTaskRegistration task = builder.Register();

            Debug.WriteLine($"===================Task {NAME} registered successfully===================");

            return(task);
        }
        public static async Task SetAsLockscreenAsync(StorageFile savedFile)
        {
            var uc = new LoadingTextControl()
            {
                LoadingText = ResourcesHelper.GetResString("SettingLockHint")
            };
            await PopupService.Instance.ShowAsync(uc, solidBackground : false);

            var file = await PrepareImageFileAsync(savedFile);

            if (file != null)
            {
                var result = await UserProfilePersonalizationSettings.Current.TrySetLockScreenImageAsync(file);

                if (!result)
                {
                    ShowFailedToast();
                }
            }

            PopupService.Instance.TryHide(500);
        }
Exemplo n.º 7
0
 private static void ShowFailedToast()
 {
     ToastService.SendToast(ResourcesHelper.GetResString("FailedToSetHint"));
 }