Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bringing back JumpList support #191

Open
wants to merge 2 commits into
base: uno
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Calculator.Droid/Calculator.Droid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.2</Version>
</PackageReference>
<PackageReference Include="Uno.UI" Version="1.46.0-dev.2304" />
<PackageReference Include="Uno.UI" Version="1.46.199-dev.2497" />
<PackageReference Include="Uno.UniversalImageLoader" Version="1.9.32" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Filter" Version="1.1.1" />
Expand Down
110 changes: 76 additions & 34 deletions src/Calculator.Shared/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Threading.Tasks;
using Windows.UI.StartScreen;
using CalculatorApp.Common;
using Windows.ApplicationModel.Resources.Core;
using Windows.ApplicationModel.Resources;

#if HAS_UNO
using Microsoft.Extensions.Logging;
Expand All @@ -30,14 +35,14 @@ namespace CalculatorApp
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App : Application
{
static bool m_isAnimationEnabled = true;

/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
static bool m_isAnimationEnabled = true;

/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
#if HAS_UNO
ConfigureFilters(Uno.Extensions.LogExtensionPoint.AmbientLoggerFactory);
Expand All @@ -58,13 +63,13 @@ public App()
/// 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 void OnLaunched(LaunchActivatedEventArgs e)
protected override async void OnLaunched(LaunchActivatedEventArgs e)
{
#if DEBUG
if (System.Diagnostics.Debugger.IsAttached)
{
// this.DebugSettings.EnableFrameRateCounter = true;
}
if (System.Diagnostics.Debugger.IsAttached)
{
// this.DebugSettings.EnableFrameRateCounter = true;
}
#endif

#if !HAS_UNO
Expand Down Expand Up @@ -114,9 +119,14 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
// parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
else
{
(rootFrame.Content as MainPage)?.SetMode(e.Arguments);
}
// Ensure the current window is active
Windows.UI.Xaml.Window.Current.Activate();
}
await SetupJumpListAsync();
}

#if HAS_UNO
Expand Down Expand Up @@ -161,38 +171,70 @@ static void ConfigureFilters(ILoggerFactory factory)
}
#endif

private async Task SetupJumpListAsync()
{
try
{
if (JumpList.IsSupported())
{
var calculatorOptions = NavCategoryGroup.CreateCalculatorCategory();

var jumpList = await JumpList.LoadCurrentAsync();

jumpList.Items.Clear();
jumpList.SystemGroupKind = JumpListSystemGroupKind.None;
var resourceLoader = new ResourceLoader();


foreach (var option in calculatorOptions.Categories)
{
var mode = option.Mode;
var item = JumpListItem.CreateWithArguments(((int)mode).ToString(), resourceLoader.GetString(NavCategory.GetNameResourceKey(mode)));
item.Description = resourceLoader.GetString(NavCategory.GetNameResourceKey(mode));
item.Logo = new Uri("ms-appx:///Assets/" + mode.ToString() + ".png");

jumpList.Items.Add(item);
}

await jumpList.SaveAsync();
}
}
catch (Exception)
{
}
}

/// <summary>
/// Return True if animation is enabled by user setting.
/// </summary>
public static bool IsAnimationEnabled()
{
return m_isAnimationEnabled;
}

/// <summary>
/// Return the current application view state. The value
/// will match one of the constants in the ViewState namespace.
/// </summary>
public static string GetAppViewState()
{
String newViewState;
{
return m_isAnimationEnabled;
}

/// <summary>
/// Return the current application view state. The value
/// will match one of the constants in the ViewState namespace.
/// </summary>
public static string GetAppViewState()
{
String newViewState;
#if NETFX_CORE
CoreWindow window = CoreWindow.GetForCurrentThread();
#else
var window = Windows.UI.Xaml.Window.Current;
#endif
if ((window.Bounds.Width >= 560) && (window.Bounds.Height >= 356))
{
newViewState = ViewState.DockedView;
}
else
{
newViewState = ViewState.Snap;
}
{
newViewState = ViewState.DockedView;
}
else
{
newViewState = ViewState.Snap;
}

return newViewState;
}
return newViewState;
}

/// <summary>
/// Invoked when Navigation to a certain page fails
Expand All @@ -203,7 +245,7 @@ void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception($"Failed to load Page {e.SourcePageType}: {e.Exception}");

}
}

/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
Expand Down
2 changes: 1 addition & 1 deletion src/Calculator.Shared/Common/NavCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ public static CalculatorObservableCollection<NavCategoryGroup> CreateMenuOptions
return menuOptions;
}

static NavCategoryGroup CreateCalculatorCategory()
public static NavCategoryGroup CreateCalculatorCategory()
{
return new NavCategoryGroup(NavCategory.s_categoryGroupManifest[0].Value);
}
Expand Down
11 changes: 11 additions & 0 deletions src/Calculator.Shared/Views/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
Initialize();
}

public void SetMode(string mode)
{
if (mode != null)
{
if (int.TryParse(mode, out var intParameter))
{
m_model.Mode = (ViewMode)intParameter;
}
}
}

void WindowSizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
{
// We don't use layout aware page's view states, we have our own
Expand Down
2 changes: 1 addition & 1 deletion src/Calculator.UWP/Calculator.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<Version>4.3.1</Version>
</PackageReference>
<PackageReference Include="Uno.UI">
<Version>1.46.0-dev.2304</Version>
<Version>1.46.199-dev.2497</Version>
</PackageReference>
</ItemGroup>
<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Calculator.Wasm/Calculator.Wasm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Filter" Version="1.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="Uno.UI" Version="1.46.0-dev.2304" />
<PackageReference Include="Uno.UI" Version="1.46.199-dev.2497" />
<PackageReference Include="Uno.UI.Sample.Banner" Version="1.44.0-dev.23" />
<PackageReference Include="Uno.Wasm.Bootstrap" Version="1.0.0-dev.300" />
<DotNetCliToolReference Include="Uno.Wasm.Bootstrap.Cli" Version="1.0.0-dev.298" />
Expand Down
2 changes: 1 addition & 1 deletion src/Calculator.iOS/Calculator.iOS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
<PackageReference Include="Newtonsoft.Json">
<Version>12.0.2</Version>
</PackageReference>
<PackageReference Include="Uno.UI" Version="1.46.0-dev.2304" />
<PackageReference Include="Uno.UI" Version="1.46.199-dev.2497" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Filter" Version="1.1.1" />
</ItemGroup>
Expand Down