Skip to content

Commit

Permalink
merged master
Browse files Browse the repository at this point in the history
  • Loading branch information
nmetulev committed Nov 16, 2017
2 parents 70c08e6 + 881155d commit 0e9a854
Show file tree
Hide file tree
Showing 8 changed files with 466 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@
</Content>
<Content Include="SamplePages\HeaderedItemsControl\HeaderedItemsControlXaml.bind" />
<Content Include="SamplePages\HeaderedContentControl\HeaderedContentControlXaml.bind" />
<Content Include="SamplePages\AppPinManager\AppPinManagerHelperCode.bind" />
<Content Include="SamplePages\Mouse\MouseCursorPage.bind" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -494,6 +495,9 @@
<Compile Include="SamplePages\AdvancedCollectionView\AdvancedCollectionViewPage.xaml.cs">
<DependentUpon>AdvancedCollectionViewPage.xaml</DependentUpon>
</Compile>
<Compile Include="SamplePages\AppPinManager\AppPinManagerHelperPage.xaml.cs">
<DependentUpon>AppPinManagerHelperPage.xaml</DependentUpon>
</Compile>
<Compile Include="SamplePages\BluetoothLEHelper\BluetoothLEHelperPage.xaml.cs">
<DependentUpon>BluetoothLEHelperPage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -773,6 +777,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SamplePages\AppPinManager\AppPinManagerHelperPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SamplePages\Carousel\CarouselPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//Specific app pin to StartMenu
var appList = (await Package.Current.GetAppListEntriesAsync())[0];
var pinResult = await AppPinManager.PinSpecificAppToStartMenuAsync(appList);

//User Specific app in StartMenu
var userInfo = await User.FindAllAsync();
if (userInfo.Count > 0)
{
var appList = (await Package.Current.GetAppListEntriesAsync())[0];
var pinResult = await AppPinManager.PinUserSpecificAppToStartMenuAsync(userInfo[0], appList);
}

//Current app pin to TaskBar
var pinResult = await AppPinManager.PinCurrentAppToTaskBarAsync();


//Specific app pin to TaskBar
var appList = (await Package.Current.GetAppListEntriesAsync())[0];
var pinResult = await AppPinManager.PinSpecificAppToTaskBarAsync(appList);

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<Page
x:Class="Microsoft.Toolkit.Uwp.SampleApp.SamplePages.AppPinManagerHelperPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Microsoft.Toolkit.Uwp.SampleApp.SamplePages"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls"
mc:Ignorable="d">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid Background="{StaticResource Brush-Grey-05}">

<StackPanel VerticalAlignment="Top">
<StackPanel Margin="0 5 0 0">
<TextBlock Text="AppPinManager" Margin="5" FontSize="30"/>
<StackPanel Margin="10">
<TextBlock Text="Pin to StartMenu" Margin="5" FontSize="20"/>

<Button x:Name="SpecificAppSMenuButton"
Margin="5"
Click="SpecificAppSMenuButton_OnClick"
Content="Pin Specific App To StartMenu" />

<Button x:Name="UserSpecificAppSMenuButton"
Margin="5"
Click="UserSpecificAppSMenuButton_OnClick"
Content="Pin User Specific App To StartMenu" />
</StackPanel>
<StackPanel Margin="10">
<TextBlock Text="Pin to TaskBar" Margin="5" FontSize="20"/>

<Button x:Name="CurrentAppTBarButton"
Margin="5"
Click="CurrentAppTBarButton_OnClick"
Content="Pin Current App To TaskBar" />

<Button x:Name="SpecificAppTBarButton"
Margin="5"
Click="SpecificAppTBarButton_OnClick"
Content="Pin Specific App To TaskBar" />
</StackPanel>
<StackPanel Margin="5"
Orientation="Horizontal">
<TextBlock x:Name="StatusMessage" FontSize="25" />
</StackPanel>
</StackPanel>
</StackPanel>


<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Full">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="600" />
</VisualState.StateTriggers>
</VisualState>
<VisualState x:Name="Small">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="0" />
</VisualState.StateTriggers>

<VisualState.Setters>
<Setter Target="ButtonsPanel.Orientation" Value="Vertical" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************

using System;
using Microsoft.Toolkit.Uwp.Helpers;
using Windows.ApplicationModel;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace Microsoft.Toolkit.Uwp.SampleApp.SamplePages
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class AppPinManagerHelperPage : Page
{
public AppPinManagerHelperPage()
{
this.InitializeComponent();
}

private async void SpecificAppSMenuButton_OnClick(object sender, RoutedEventArgs e)
{
var appList = (await Package.Current.GetAppListEntriesAsync())[0];
var pinResult = await AppPinManager.PinSpecificAppToStartMenuAsync(appList);
StatusMessage.Text = "SpecificApp in StartMenu : " + pinResult.ToString();
}

private async void UserSpecificAppSMenuButton_OnClick(object sender, RoutedEventArgs e)
{
var userInfo = await User.FindAllAsync();
if (userInfo.Count > 0)
{
var appList = (await Package.Current.GetAppListEntriesAsync())[0];
var pinResult = await AppPinManager.PinUserSpecificAppToStartMenuAsync(userInfo[0], appList);
StatusMessage.Text = "User SpecificApp in StartMenu : " + pinResult.ToString();
}
}

private async void CurrentAppTBarButton_OnClick(object sender, RoutedEventArgs e)
{
var pinResult = await AppPinManager.PinCurrentAppToTaskBarAsync();
StatusMessage.Text = "Current App in TaskBar : " + pinResult.ToString();
}

private async void SpecificAppTBarButton_OnClick(object sender, RoutedEventArgs e)
{
var appList = (await Package.Current.GetAppListEntriesAsync())[0];
var pinResult = await AppPinManager.PinSpecificAppToTaskBarAsync(appList);
StatusMessage.Text = "Specific App in TaskBar : " + pinResult.ToString();
}
}
}
10 changes: 10 additions & 0 deletions Microsoft.Toolkit.Uwp.SampleApp/SamplePages/samples.json
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,16 @@
"Icon": "/Assets/Helpers.png",
"DocumentationUrl": "https://raw.githubusercontent.com/Microsoft/UWPCommunityToolkit/master/docs/helpers/BackgroundTaskHelper.md"
},
{
"About": "The AppPinManager helps easily add app shortcuts to the Start Menu or the Taskbar",
"CodeFile": "AppPinManagerHelperCode.bind",
"CodeUrl": "https://github.com/Microsoft/UWPCommunityToolkit/blob/master/Microsoft.Toolkit.Uwp/Helpers/AppPinManager/AppPinManager.cs",
"DocumentationUrl": "https://raw.githubusercontent.com/Microsoft/UWPCommunityToolkit/master/docs/helpers/AppPinManager.md",
"Icon": "/Assets/Helpers.png",
"Name": "AppPinManager",
"Type": "AppPinManagerHelperPage",
"BadgeUpdateVersionRequired": "Creators Update required"
},
{
"Name": "NetworkHelper",
"Type": "NetworkHelperPage",
Expand Down
178 changes: 178 additions & 0 deletions Microsoft.Toolkit.Uwp/Helpers/AppPinManager/AppPinManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
// ******************************************************************
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE.
// ******************************************************************

using System;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
using Windows.Foundation.Metadata;
using Windows.System;
using Windows.UI.Shell;
using Windows.UI.StartScreen;

namespace Microsoft.Toolkit.Uwp.Helpers
{
/// <summary>
/// This class provides static helper methods help to add the app in startmenu or TaskBar.
/// </summary>
public static class AppPinManager
{
/// <summary>
/// Pin the current app in Windows TaskBar
/// </summary>
/// <returns>PinResult</returns>
public static async Task<PinResult> PinCurrentAppToTaskBarAsync()
{
var resultPinResult = PinResult.UnsupportedOs;

if (!ApiInformation.IsTypePresent("Windows.UI.Shell.TaskbarManager"))
{
return resultPinResult;
}

if (TaskbarManager.GetDefault().IsSupported)
{
if (TaskbarManager.GetDefault().IsPinningAllowed)
{
if (await TaskbarManager.GetDefault().IsCurrentAppPinnedAsync())
{
resultPinResult = PinResult.PinAlreadyPresent;
}
else
{
var result = await TaskbarManager.GetDefault().RequestPinCurrentAppAsync();
resultPinResult = result ? PinResult.PinPresent : PinResult.PinOperationFailed;
}
}
else
{
resultPinResult = PinResult.PinNotAllowed;
}
}
else
{
resultPinResult = PinResult.UnsupportedDevice;
}

return resultPinResult;
}

/// <summary>
/// Pin Specific App in Windows TaskBar
/// </summary>
/// <param name="appListEntry">AppListEntry</param>
/// <returns>PinResult</returns>
public static async Task<PinResult> PinSpecificAppToTaskBarAsync(AppListEntry appListEntry)
{
var resultPinResult = PinResult.UnsupportedOs;

if (!ApiInformation.IsTypePresent("Windows.UI.Shell.TaskbarManager"))
{
return resultPinResult;
}

if (TaskbarManager.GetDefault().IsSupported)
{
if (TaskbarManager.GetDefault().IsPinningAllowed)
{
if (await TaskbarManager.GetDefault().IsAppListEntryPinnedAsync(appListEntry))
{
resultPinResult = PinResult.PinAlreadyPresent;
}
else
{
var result = await TaskbarManager.GetDefault().RequestPinAppListEntryAsync(appListEntry);
resultPinResult = result ? PinResult.PinPresent : PinResult.PinOperationFailed;
}
}
else
{
resultPinResult = PinResult.PinNotAllowed;
}
}
else
{
resultPinResult = PinResult.UnsupportedDevice;
}

return resultPinResult;
}

/// <summary>
/// Pin Specific App in Windows StartMenu
/// </summary>
/// <param name="entry">AppListEntry</param>
/// <returns>PinResult</returns>
public static async Task<PinResult> PinSpecificAppToStartMenuAsync(AppListEntry entry)
{
var resultPinResult = PinResult.UnsupportedOs;

if (!ApiInformation.IsTypePresent("Windows.UI.StartScreen.StartScreenManager"))
{
return resultPinResult;
}

if (StartScreenManager.GetDefault().SupportsAppListEntry(entry))
{
if (await StartScreenManager.GetDefault().ContainsAppListEntryAsync(entry))
{
resultPinResult = PinResult.PinAlreadyPresent;
}
else
{
var result = await StartScreenManager.GetDefault().RequestAddAppListEntryAsync(entry);
resultPinResult = result ? PinResult.PinPresent : PinResult.PinOperationFailed;
}
}
else
{
resultPinResult = PinResult.UnsupportedDevice;
}

return resultPinResult;
}

/// <summary>
/// Pin Specific App in Windows StartMenu based on User
/// </summary>
/// <param name="user">User</param>
/// <param name="entry">AppListEntry</param>
/// <returns>PinResult</returns>
public static async Task<PinResult> PinUserSpecificAppToStartMenuAsync(User user, AppListEntry entry)
{
var resultPinResult = PinResult.UnsupportedOs;

if (!ApiInformation.IsTypePresent("Windows.UI.StartScreen.StartScreenManager"))
{
return resultPinResult;
}

if (StartScreenManager.GetForUser(user).SupportsAppListEntry(entry))
{
if (await StartScreenManager.GetForUser(user).ContainsAppListEntryAsync(entry))
{
resultPinResult = PinResult.PinAlreadyPresent;
}
else
{
var result = await StartScreenManager.GetForUser(user).RequestAddAppListEntryAsync(entry);
resultPinResult = result ? PinResult.PinPresent : PinResult.PinOperationFailed;
}
}
else
{
resultPinResult = PinResult.UnsupportedDevice;
}

return resultPinResult;
}
}
}
Loading

0 comments on commit 0e9a854

Please sign in to comment.