Beispiel #1
0
        /// <summary>
        /// Clears and re-creates all custom items in the app's jump list.
        /// </summary>
        public async Task RefreshJumpList()
        {
            if (!JumpList.IsSupported())
            {
                return;
            }

            try
            {
                JumpList jumpList = await JumpList.LoadCurrentAsync();

                jumpList.Items.Clear();
                jumpList.SystemGroupKind = JumpListSystemGroupKind.None;
                string packageId = Package.Current.Id.Name;

                foreach (string color in new[] { "Blue", "Green", "Red", "Yellow" })
                {
                    var item = JumpListItem.CreateWithArguments(color, $"ms-resource://{packageId}/Resources/{color}NavItem/Content");
                    item.GroupName = $"ms-resource://{packageId}/Resources/JumpListGroupColors";
                    item.Logo      = new Uri($"ms-appx:///Assets/JumpList/{color}.png");
                    jumpList.Items.Add(item);
                }

                await jumpList.SaveAsync();
            }
            catch (Exception ex)
            {
                // TODO: Proper error handling. SaveAsync may fail, for example with exception
                //   "Unable to remove the file to be replaced." (Exception from HRESULT 0x80070497)
                Debug.WriteLine(ex);
            }
        }
Beispiel #2
0
        private async Task RefreshJumpList()
        {
            if (JumpList.IsSupported())
            {
                var instance = await JumpList.LoadCurrentAsync();

                // Disable automatic jumplist. It doesn't work with Files UWP.
                instance.SystemGroupKind = JumpListSystemGroupKind.None;

                var jumpListItems = instance.Items.ToList();

                // Clear all items to avoid localization issues
                instance.Items.Clear();

                foreach (var temp in jumpListItems)
                {
                    var jumplistItem = JumpListItem.CreateWithArguments(temp.Arguments, temp.DisplayName);
                    jumplistItem.Description = jumplistItem.Arguments;
                    jumplistItem.GroupName   = "ms-resource:///Resources/JumpListRecentGroupHeader";
                    jumplistItem.Logo        = new Uri("ms-appx:///Assets/FolderIcon.png");
                    instance.Items.Add(jumplistItem);
                }

                await instance.SaveAsync();
            }
        }
Beispiel #3
0
        public static async void InitJumpList()
        {
            try
            {
                var jumpList = await JumpList.LoadCurrentAsync();

                jumpList.SystemGroupKind = JumpListSystemGroupKind.None;
                jumpList.Items.Clear();

                if (!Credentials.Authenticated)
                {
                    return;
                }

                var item = JumpListItem.CreateWithArguments("https://myanimelist.net/anime.php", "Search");
                item.Logo = new Uri("ms-appx:///Assets/EmptySquare.png");
                jumpList.Items.Add(item);
                item      = JumpListItem.CreateWithArguments("https://myanimelist.net/mymessages.php", "Messages");
                item.Logo = new Uri("ms-appx:///Assets/EmptySquare.png");
                jumpList.Items.Add(item);
                item      = JumpListItem.CreateWithArguments("https://myanimelist.net/forum", "Forum");
                item.Logo = new Uri("ms-appx:///Assets/EmptySquare.png");;
                jumpList.Items.Add(item);

                await jumpList.SaveAsync();
            }
            catch (Exception)
            {
                //jumplist unavailable
            }
        }
        private async Task UpdateJumpList()
        {
            if (!JumpList.IsSupported())
            {
                return;
            }

            try
            {
                JumpList jumpList = await JumpList.LoadCurrentAsync();

                jumpList.SystemGroupKind = JumpListSystemGroupKind.None;
                jumpList.Items.Clear();

                foreach (DirectionViewModel directionViewModel in AvailableDirections)
                {
                    string itemName  = string.Format("{0} → {1}", directionViewModel.OriginLanguage, directionViewModel.DestinationLanguage);
                    string arguments = "dict:" + directionViewModel.OriginLanguageCode + directionViewModel.DestinationLanguageCode;

                    JumpListItem jumpListItem = JumpListItem.CreateWithArguments(arguments, itemName);

                    jumpListItem.Logo = LanguageCodes.GetCountryFlagUri(directionViewModel.OriginLanguageCode);

                    jumpList.Items.Add(jumpListItem);
                }

                await jumpList.SaveAsync();
            }
            catch
            {
                // in rare cases, SaveAsync may fail with HRESULT 0x80070497: "Unable to remove the file to be replaced."
                // this appears to be a common problem without a solution, so we simply ignore any errors here
            }
        }
Beispiel #5
0
        /// <summary>
        /// Add history items.
        /// </summary>
        /// <param name="historyItems">History items.</param>
        public async Task ChangeHistoryItems(IDictionary <long, string> historyItems)
        {
            if (!JumpList.IsSupported())
            {
                return;
            }

            var jumpList = await JumpList.LoadCurrentAsync();

            var oldItems = jumpList.Items
                           .ToList()
                           .Where(a => a.GroupName == HistoryGroupName)
                           .ToList();

            foreach (var oldItem in oldItems)
            {
                jumpList.Items.Remove(oldItem);
            }

            foreach (var historyItem in historyItems)
            {
                var item = JumpListItem.CreateWithArguments($"releasecardhistory:{historyItem.Key}", historyItem.Value);
                item.GroupName = HistoryGroupName;
                jumpList.Items.Add(item);
            }

            OrderItems(jumpList);

            try {
                await jumpList.SaveAsync();
            }
            catch {
                // Sometimes it was cause application failure
            }
        }
Beispiel #6
0
        public static async Task CreateDefaultList(bool clear = false)
        {
            if (JumpList.IsSupported())
            {
                var jumplist = await JumpList.LoadCurrentAsync();

                if (!jumplist.Items.Any() || clear)
                {
                    jumplist.Items.Clear();
                    var args = new ToastNotificationArgs()
                    {
                        type          = "jumplist",
                        openBookmarks = true
                    };
                    var item = JumpListItem.CreateWithArguments(JsonConvert.SerializeObject(args), "Open Bookmarks");
                    item.Logo                = new Uri("ms-appx:///Assets/BadgeLogo.scale-100.png");
                    args.openBookmarks       = false;
                    args.openPrivateMessages = true;

                    var item2 = JumpListItem.CreateWithArguments(JsonConvert.SerializeObject(args), "Open Private Messages");
                    item2.Logo = new Uri("ms-appx:///Assets/BadgeLogo.scale-100.png");
                    jumplist.Items.Add(item);
                    jumplist.Items.Add(item2);
                    var seperate = JumpListItem.CreateSeparator();
                    jumplist.Items.Add(seperate);
                    await jumplist.SaveAsync();
                }
            }
        }
Beispiel #7
0
        public static async Task InitializeAsync()
        {
            if (!ApiInformation.IsTypePresent("Windows.UI.StartScreen.JumpList"))
            {
                return;
            }

            try
            {
                JumpList jumpList = await JumpList.LoadCurrentAsync();

                jumpList.Items.Clear();
                jumpList.SystemGroupKind = JumpListSystemGroupKind.None;

                var listItemAddPayment = JumpListItem.CreateWithArguments(AppConstants.AddPaymentId, Strings.AddPaymentLabel);
                listItemAddPayment.Logo = new Uri(INCOME_ICON);
                jumpList.Items.Add(listItemAddPayment);

                await jumpList.SaveAsync();
            }
            catch (Exception ex)
            {
                logger.Warn(ex);
            }
        }
        public static async Task UpdateAsync(ISettingsService settingsService)
        {
            if (!JumpList.IsSupported())
            {
                return;
            }

            try
            {
                var jumpList = await JumpList.LoadCurrentAsync();

                jumpList.Items.Clear();
                foreach (var profile in settingsService.GetAllProfiles())
                {
                    var item = JumpListItem.CreateWithArguments(ShellProfileFlag + profile.Id, profile.Name);
                    item.Description = profile.Location;
                    jumpList.Items.Add(item);
                }
                await jumpList.SaveAsync();
            }
            catch (Exception e)
            {
                Logger.Instance.Error(e, "JumpList Update Exception");
            }
        }
Beispiel #9
0
        public static async Task <JumpList> LoadJumpListAsync()
        {
            var jumpList = await JumpList.LoadCurrentAsync();

            var items = (from a in jumpList.Items where a.Arguments.StartsWith("as-music") select a).ToList();

            foreach (var j in items)
            {
                jumpList.Items.Remove(j);
            }

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i].Contains("action"))
                {
                    jumpList.Items.Add(CreateItem(args[i], Consts.Localizer.GetString(displays[i]), Consts.Localizer.GetString(groups[1]), Consts.Localizer.GetString(displays[i]), new Uri(pics[i])));
                }
                else
                {
                    jumpList.Items.Add(CreateItem(args[i], Consts.Localizer.GetString(displays[i]), Consts.Localizer.GetString(groups[0]), Consts.Localizer.GetString(displays[i]), new Uri(pics[i])));
                }
            }

            return(jumpList);
        }
Beispiel #10
0
        private async Task <bool> Initialize()
        {
            try
            {
                if (IsSupported)
                {
                    InnerList = await JumpList.LoadCurrentAsync();

                    InnerList.SystemGroupKind = JumpListSystemGroupKind.None;

                    bool ItemModified = false;

                    foreach (JumpListItem Item in InnerList.Items.Where((Item) => Item.RemovedByUser).ToArray())
                    {
                        InnerList.Items.Remove(Item);
                        ItemModified = true;
                    }

                    if (ItemModified)
                    {
                        await InnerList.SaveAsync();
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                return(false);
            }
        }
Beispiel #11
0
        public async Task When_Description_Is_Empty_No_Exception()
        {
            try
            {
                var item = JumpListItem.CreateWithArguments("Hello", "Test");
                item.Description = string.Empty;
                var jumpList = await JumpList.LoadCurrentAsync();

                jumpList.Items.Clear();
                jumpList.Items.Add(item);
                await jumpList.SaveAsync();

                // reload from native
                var newJumpList = await JumpList.LoadCurrentAsync();

                Assert.AreEqual(string.Empty, newJumpList.Items.First().Description);
            }
            finally
            {
                var jumpList = await JumpList.LoadCurrentAsync();

                jumpList.Items.Clear();
                await jumpList.SaveAsync();
            }
        }
Beispiel #12
0
        private async void RemoveJumpList_Click(object sender, RoutedEventArgs e)
        {
            var jumpList = await JumpList.LoadCurrentAsync();

            jumpList.SystemGroupKind = JumpListSystemGroupKind.None;
            jumpList.Items.Clear();
            await jumpList.SaveAsync();
        }
Beispiel #13
0
        /// <summary>
        /// Entries get added to the jump list when you play music via Cortana.
        /// This function removes them.
        /// </summary>
        public static async void DeleteRecentJumplistEntries()
        {
            var jumpList = await JumpList.LoadCurrentAsync();

            jumpList.SystemGroupKind = JumpListSystemGroupKind.None;
            jumpList.Items.Clear();

            await jumpList.SaveAsync();
        }
Beispiel #14
0
        public async Task ProvisionJumplistAsync()
        {
            if (!IsJumplistPresent)
            {
                throw new NotSupportedException("Jumplist requires contract Windows.Foundation.UniversalApiContract, version 2.0.");
            }

            try
            {
                var jumpList = await JumpList.LoadCurrentAsync();

                jumpList.Items.Clear();

                var albumMenuEntry = JumpListItem.CreateWithArguments("light-jumplist:viewallalbums",
                                                                      CommonSharedStrings.JumplistAlbumText);

                albumMenuEntry.GroupName   = CommonSharedStrings.CategoryGroupName;
                albumMenuEntry.Description = CommonSharedStrings.JumplistAlbumText;

                albumMenuEntry.Logo = new Uri(CommonSharedStrings.JumplistAlbumIconPath);

                var artistMenuEntry = JumpListItem.CreateWithArguments("light-jumplist:viewallartists",
                                                                       CommonSharedStrings.JumplistArtistText);

                artistMenuEntry.GroupName   = CommonSharedStrings.CategoryGroupName;
                artistMenuEntry.Description = CommonSharedStrings.JumplistArtistText;

                artistMenuEntry.Logo = new Uri(CommonSharedStrings.JumplistArtistIconPath);

                var songMenuEntry = JumpListItem.CreateWithArguments("light-jumplist:viewallsongs",
                                                                     CommonSharedStrings.JumplistSongText);

                songMenuEntry.GroupName   = CommonSharedStrings.CategoryGroupName;
                songMenuEntry.Description = CommonSharedStrings.JumplistSongText;

                songMenuEntry.Logo = new Uri(CommonSharedStrings.JumplistSongIconPath);

                var playlistMenuEntry = JumpListItem.CreateWithArguments("light-jumplist:viewallplaylist",
                                                                         CommonSharedStrings.JumplistPlaylistText);

                playlistMenuEntry.GroupName   = CommonSharedStrings.CategoryGroupName;
                playlistMenuEntry.Description = CommonSharedStrings.JumplistPlaylistText;

                playlistMenuEntry.Logo = new Uri(CommonSharedStrings.JumplistPlaylistIconPath);

                jumpList.Items.Add(albumMenuEntry);
                jumpList.Items.Add(artistMenuEntry);
                jumpList.Items.Add(songMenuEntry);
                jumpList.Items.Add(playlistMenuEntry);

                await jumpList.SaveAsync();
            }
            catch
            {
                // Ignore
            }
        }
Beispiel #15
0
        private async void MainPage_Unloaded(object sender, RoutedEventArgs e)
        {
            if (JumpList.IsSupported())
            {
                var list = await JumpList.LoadCurrentAsync();

                list.Items.Clear();//建议每次在添加之前清除掉原先已经存在的数据
                await list.SaveAsync();
            }
        }
Beispiel #16
0
        private async void CreateJumplist()
        {
            try
            {
                if (JumpList.IsSupported())
                {
                    JumpList jumpList = await JumpList.LoadCurrentAsync();

                    if (UtilityData.newUpdate)
                    {
                        jumpList.Items.Clear();
                    }

                    if (jumpList.Items.Count == 0 || jumpList.Items.Count != 6)
                    {
                        jumpList.Items.Clear();


                        JumpListItem Messenger = JumpListItem.CreateWithArguments("jplFacebook", "Facebook");
                        JumpListItem Skype     = JumpListItem.CreateWithArguments("jplTwitter", "Twitter");
                        JumpListItem Slack     = JumpListItem.CreateWithArguments("jplInstagram", "Instagram");
                        //JumpListItem WhatsApp = JumpListItem.CreateWithArguments("jplWhatsApp", "WhatsApp");
                        JumpListItem WeChat       = JumpListItem.CreateWithArguments("jplReddit", "Reddit");
                        JumpListItem jltSplitView = JumpListItem.CreateWithArguments("jplSplitView", "Split View");

                        Messenger.Logo = new Uri("ms-appx:///Assets/fb.png");
                        Skype.Logo     = new Uri("ms-appx:///Assets/twitter.png");
                        Slack.Logo     = new Uri("ms-appx:///Assets/instagram.png");
                        //WhatsApp.Logo = new Uri("ms-appx:///Assets/whatsapp.png");
                        WeChat.Logo       = new Uri("ms-appx:///Assets/reddit.png");
                        jltSplitView.Logo = new Uri("ms-appx:///Assets/splitview.png");

                        Messenger.GroupName = "Services";
                        Skype.GroupName     = "Services";
                        WeChat.GroupName    = "Services";
                        //WhatsApp.GroupName = "Services";
                        Slack.GroupName        = "Services";
                        jltSplitView.GroupName = "Services";

                        jumpList.Items.Add(Messenger);
                        jumpList.Items.Add(Skype);
                        jumpList.Items.Add(Slack);
                        //jumpList.Items.Add(WhatsApp);
                        jumpList.Items.Add(WeChat);
                        jumpList.Items.Add(jltSplitView);

                        await jumpList.SaveAsync();
                    }
                }
            }
            catch (Exception)
            {
            }
        }
 /// <summary>
 ///     Removes all jumplist items
 /// </summary>
 public static async Task RemoveAllAsync()
 {
     // Check if jumplists are supported
     if (!JumpList.IsSupported()) return;
     // Load the jumplist Items
     _systemJumpList = await JumpList.LoadCurrentAsync();
     // Clear all jumplist items
     _systemJumpList.Items.Clear();
     // Save the Jumplist Items
     await _systemJumpList.SaveAsync();
 }
        private static async Task SetupJumplist()
        {
            JumpList jumpList = await JumpList.LoadCurrentAsync();

            jumpList.Items.Clear();
            JumpListItem item1 = JumpListItem.CreateWithArguments("importphotos", "Import Images");

            item1.Logo = new Uri("ms-appx:///Assets/ImportPhotos.scale-200.png");
            jumpList.Items.Add(item1);
            await jumpList.SaveAsync();
        }
Beispiel #19
0
        private async void ClearJumplist()
        {
            //Quick Pad used to add items to the jumplist, this removes them if they were added in previous versions
            var all = await JumpList.LoadCurrentAsync();

            all.SystemGroupKind = JumpListSystemGroupKind.Recent;
            if (all.Items != null)
            {
                //Clear Jumplist
                all.Items.Clear();
            }
        }