Skip to content

Commit

Permalink
feat: Add support for additional Package properties
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Oct 5, 2022
1 parent fa4033c commit b7f1f4b
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 57 deletions.
4 changes: 2 additions & 2 deletions src/Uno.UWP/ApplicationModel/Package.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace Windows.ApplicationModel
{
public partial class Package
{
public string DisplayName =>
private string GetDisplayName() =>
Application.Context.ApplicationInfo.LoadLabel(Application.Context.PackageManager);

private string GetInstalledLocation()
=> "assets://" + ContextHelper.Current.PackageCodePath;

private bool GetInnerIsDevelopmentMode()
private bool GetIsDevelopmentMode()
{
try
{
Expand Down
24 changes: 9 additions & 15 deletions src/Uno.UWP/ApplicationModel/Package.Other.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public partial class Package
private string _logo = "ms-appx://logo";
private bool _manifestParsed;

private bool GetInnerIsDevelopmentMode() => false;
private bool GetIsDevelopmentMode() => false;

private DateTimeOffset GetInstallDate() => DateTimeOffset.Now;
private DateTimeOffset GetInstallDate() => new DateTimeOffset(2000, 1, 1, 0, 0, 0, TimeSpan.Zero);

private string GetInstalledLocation()
{
Expand All @@ -37,22 +37,16 @@ private string GetInstalledLocation()
}
}

public string DisplayName
private string GetDisplayName()
{
get
{
TryParsePackageManifest();
return _displayName;
}
TryParsePackageManifest();
return _displayName;
}

public Uri Logo
private Uri GetLogo()
{
get
{
TryParsePackageManifest();
return new Uri(_logo, UriKind.RelativeOrAbsolute);
}
TryParsePackageManifest();
return new Uri(_logo, UriKind.RelativeOrAbsolute);
}

internal static void SetEntryAssembly(Assembly entryAssembly)
Expand All @@ -62,7 +56,7 @@ internal static void SetEntryAssembly(Assembly entryAssembly)

private void TryParsePackageManifest()
{
if(_entryAssembly != null && !_manifestParsed)
if (_entryAssembly != null && !_manifestParsed)
{
var manifest = _entryAssembly.GetManifestResourceStream(PackageManifestName);

Expand Down
162 changes: 143 additions & 19 deletions src/Uno.UWP/ApplicationModel/Package.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Uno.Diagnostics.Eventing;
using Windows.Storage;

namespace Windows.ApplicationModel
Expand All @@ -10,51 +11,174 @@ internal Package()
{
}

public bool IsDevelopmentMode => GetInnerIsDevelopmentMode();
/// <summary>
/// Gets the package for the current app.
/// </summary>
public static Package Current { get; } = new Package();

public PackageId Id => new PackageId();
/// <summary>
/// Gets the packages on which the current package depends.
/// </summary>
[Uno.NotImplemented]
public IReadOnlyList<Package> Dependencies => new List<Package>();

/// <summary>
/// Gets the description of the package.
/// </summary>
[Uno.NotImplemented]
public string Description => "";

public DateTimeOffset InstallDate => GetInstallDate();
/// <summary>
/// Gets the display name of the package.
/// </summary>
public string DisplayName => GetDisplayName();

/// <summary>
/// Gets the location of the machine-wide or per-user external folder specified
/// in the package manifest for the current package, depending on how the app is installed.
/// </summary>
public StorageFolder EffectiveExternalLocation => null;

/// <summary>
/// Gets the path of the machine-wide or per-user external folder specified
/// in the package manifest for the current package, depending on how the app is installed.
/// </summary>
public string EffectiveExternalPath => "";

/// <summary>
/// Gets either the location of the installed folder or the mutable folder
/// for the installed package, depending on whether the app is declared
/// to be mutable in its package manifest.
/// </summary>
public StorageFolder EffectiveLocation => MutableLocation ?? InstalledLocation;

/// <summary>
/// Gets either the path of the installed folder or the mutable folder
/// for the installed package, depending on whether the app is declared
/// to be mutable in its package manifest.
/// </summary>
public string EffectivePath => EffectiveLocation?.Path ?? "";

/// <summary>
/// Gets the package identity of the current package.
/// </summary>
public PackageId Id => new PackageId();

/// <summary>
/// Same as InstalledDate, gets the date the application package was installed on the user's phone.
/// </summary>
public DateTimeOffset InstallDate => InstalledDate;

/// <summary>
/// Gets the date on which the application package was installed or last updated.
/// </summary>
/// <remarks>
/// On platforms where this value is not available
/// this returns 1st January 2000.
/// </remarks>
public DateTimeOffset InstalledDate => GetInstallDate();

public static Package Current { get; } = new Package();
/// <summary>
/// Gets the current package's location in the original install folder for the current package.
/// </summary>
public StorageFolder InstalledLocation => new StorageFolder(GetInstalledLocation());

[Uno.NotImplemented]
public IReadOnlyList<Package> Dependencies => new List<Package>();
/// <summary>
/// Gets the current package's path in the original install folder for the current package.
/// </summary>
public string InstalledPath => InstalledLocation?.Path ?? "";

public StorageFolder InstalledLocation
=> new StorageFolder(GetInstalledLocation());
/// <summary>
/// Indicates whether the package is a bundle package.
/// </summary>
public bool IsBundle => false;

[Uno.NotImplemented]
public bool IsFramework => false;
/// <summary>
/// Indicates whether the package is installed in development mode.
/// </summary>
public bool IsDevelopmentMode => GetIsDevelopmentMode();

[Uno.NotImplemented]
public string Description => "";
/// <summary>
/// Indicates whether other packages can declare a dependency on this package.
/// </summary>
public bool IsFramework => false;

[Uno.NotImplemented]
public bool IsBundle => false;
/// <summary>
/// Indicates whether the package is optional.
/// </summary>
public bool IsOptional => false;

[Uno.NotImplemented]
/// <summary>
/// Indicates whether the package is a resource package.
/// </summary>
public bool IsResourcePackage => false;

/// <summary>
/// Gets a value that indicates whether the application in the current package is a stub application.
/// </summary>
public bool IsStub => false;

/// <summary>
/// Gets the logo of the package.
/// </summary>
#if (__IOS__ || __ANDROID__ || __MACOS__)
[global::Uno.NotImplemented]
public global::System.Uri Logo => new Uri("http://example.com");
#else
public Uri Logo => GetLogo();
#endif

/// <summary>
/// Gets the location of the machine-wide external folder specified
/// in the package manifest for the current package.
/// </summary>
public StorageFolder MachineExternalLocation => null;

/// <summary>
/// Gets the path of the machine-wide external folder specified
/// in the package manifest for the current package.
/// </summary>
public string MachineExternalPath => MachineExternalLocation?.Path ?? "";

/// <summary>
/// Gets the current package's location in the mutable folder for the installed package,
/// if the app is declared to be mutable in its package manifest.
/// </summary>
public StorageFolder MutableLocation => null;

/// <summary>
/// Gets the current package's path in the mutable folder for the installed package,
/// if the app is declared to be mutable in its package manifest.
/// </summary>
public string MutablePath => MutableLocation?.Path ?? "";

/// <summary>
/// Gets the publisher display name of the package.
/// </summary>
[Uno.NotImplemented]
public string PublisherDisplayName => "";

/// <summary>
/// How the app package is signed.
/// </summary>
[Uno.NotImplemented]
public PackageStatus Status => new PackageStatus();
public PackageSignatureKind SignatureKind => PackageSignatureKind.None;

/// <summary>
/// Get the current status of the package for the user.
/// </summary>
[Uno.NotImplemented]
public bool IsOptional => false;
public PackageStatus Status => new PackageStatus();

[Uno.NotImplemented]
public PackageSignatureKind SignatureKind => PackageSignatureKind.None;
/// <summary>
/// Gets the location of the per-user external folder specified in the package manifest for the current package.
/// </summary>
public StorageFolder UserExternalLocation => null;

/// <summary>
/// Gets the path of the per-user external folder specified in the package manifest for the current package.
/// </summary>
public string UserExternalPath => UserExternalLocation?.Path ?? "";

[Uno.NotImplemented]
public Foundation.IAsyncOperation<IReadOnlyList<Core.AppListEntry>> GetAppListEntriesAsync()
Expand Down
7 changes: 4 additions & 3 deletions src/Uno.UWP/ApplicationModel/Package.iOSmacOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ public partial class Package
{
private const string BundleDisplayNameKey = "CFBundleDisplayName";

public string DisplayName => NSBundle.MainBundle.InfoDictionary[BundleDisplayNameKey]?.ToString() ?? string.Empty;
private string GetDisplayName() =>
NSBundle.MainBundle.InfoDictionary[BundleDisplayNameKey]?.ToString() ?? string.Empty;

#if __IOS__
private bool GetInnerIsDevelopmentMode() => IsAdHoc;
private bool GetIsDevelopmentMode() => IsAdHoc;
#else
private bool GetInnerIsDevelopmentMode() => false; //detection not possible on macOS
private bool GetIsDevelopmentMode() => false; //detection not possible on macOS
#endif

private string GetInstalledLocation()
Expand Down
35 changes: 35 additions & 0 deletions src/Uno.UWP/ApplicationModel/PackageSignatureKind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace Windows.ApplicationModel;

/// <summary>
/// Provides information about the package's signature and the kind of certificate used to create it.
/// </summary>
public enum PackageSignatureKind
{
/// <summary>
/// The package is not signed. For example, a Visual Studio project that is running from layout (F5).
/// </summary>
None = 0,

/// <summary>
/// The package is signed with a trusted certificate that is not categorized as Enterirse, Store, or System.
/// For example, an application signed by an ISV for distrubution outside of the application store.
/// </summary>
Developer = 1,

/// <summary>
/// The package is signed using a certificate issued by a root authority that has higher verification requirements than general public authorities.
/// </summary>
Enterprise = 2,

/// <summary>
/// The package is signed by an application store.
/// </summary>
Store = 3,

/// <summary>
/// The package is signed by a certificate that's also used to sign the operating system.
/// These packages can have additional capabilities not granted to normal apps.
/// For example, the built-in system apps.
/// </summary>
System = 4,
}
Loading

0 comments on commit b7f1f4b

Please sign in to comment.