/// <summary> /// Adds an item to the app's jump list. /// </summary> /// <param name="info"></param> /// <returns>Awaitable task is returned.</returns> public async Task AddItemAsync(JumpItemInfo info) { if (!IsSupported) { return; } if (info == null || string.IsNullOrEmpty(info.Name)) { throw new ArgumentNullException(nameof(info)); } if (string.IsNullOrEmpty(info.Name)) { throw new ArgumentNullException(nameof(info.Name)); } try { var jumpList = await JumpList.LoadCurrentAsync(); if (jumpList.SystemGroupKind == JumpListSystemGroupKind.None) { jumpList.SystemGroupKind = JumpListSystemGroupKind.Recent; } // Remove item if already existing var existingItem = jumpList.Items.FirstOrDefault(f => f.DisplayName.Equals(info.Name, StringComparison.CurrentCultureIgnoreCase) || f.Arguments.Equals(info.Arguments, StringComparison.CurrentCultureIgnoreCase)); if (existingItem != null) { jumpList.Items.Remove(existingItem); } // Add item to the top of the list var item = JumpListItem.CreateWithArguments(info.Arguments, info.Name); item.Description = info.Description ?? string.Empty; if (!string.IsNullOrEmpty(info.GroupName)) { item.GroupName = info.GroupName; } //item.GroupName = info.GroupName ?? jumpList.SystemGroupKind.ToString(); item.Logo = info.Logo; jumpList.Items.Add(item); // Save the updated list await jumpList.SaveAsync(); } catch (Exception ex) { Platform.Current.Logger.LogError(ex, "Could not add to jump list!"); } }
/// <summary> /// Adds an item to the app's jump list. /// </summary> /// <param name="info"></param> /// <returns>Awaitable task is returned.</returns> public async Task AddItemAsync(JumpItemInfo info) { if (!IsSupported) return; if (info == null || string.IsNullOrEmpty(info.Name)) throw new ArgumentNullException(nameof(info)); if (string.IsNullOrEmpty(info.Name)) throw new ArgumentNullException(nameof(info.Name)); try { var jumpList = await JumpList.LoadCurrentAsync(); if (jumpList.SystemGroupKind == JumpListSystemGroupKind.None) jumpList.SystemGroupKind = JumpListSystemGroupKind.Recent; // Remove item if already existing var existingItem = jumpList.Items.FirstOrDefault(f => f.DisplayName.Equals(info.Name, StringComparison.CurrentCultureIgnoreCase) || f.Arguments.Equals(info.Arguments, StringComparison.CurrentCultureIgnoreCase)); if(existingItem != null) jumpList.Items.Remove(existingItem); // Add item to the top of the list var item = JumpListItem.CreateWithArguments(info.Arguments, info.Name); item.Description = info.Description ?? string.Empty; if(!string.IsNullOrEmpty(info.GroupName)) item.GroupName = info.GroupName; //item.GroupName = info.GroupName ?? jumpList.SystemGroupKind.ToString(); item.Logo = info.Logo; jumpList.Items.Add(item); // Save the updated list await jumpList.SaveAsync(); } catch(Exception ex) { Platform.Current.Logger.LogError(ex, "Could not add to jump list!"); } }