-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Workspaces] Implement PWA recognition, launch. (#35913)
* [Workspaces] PWA: first steps: implement PWA app searcher, add basic controls to the editor * spell checker * Snapshot tool: adding command line args for edge * PWA: add icon handling, add launch of PWA * Impllement Aumid getters and comparison to connect PWA windows and processes. Update LauncherUI, Launcher * Minor fixes, simplifications * Spell checker * Removing manual PWA selection, spell checker * Fix merge conflict * Trying to convince spell checker, that "PEB" is a correct word. * XAML format fix * Extending snapshot tool by logs for better testablility * spell checker fix * extending logs * extending logs * Removing some logs, modifying search criteria for pwa helper process search * extending PWA detection for the case the directory with the app-id is missing * Fix issue when pwaAppId is null * fix missing pwa-app-id handling in the editor. Removed unused property (code cleaning) and updating json parser in Launcher * Code cleaning: Moving duplicate code to a common project * Fix issue: adding new Guid as app id if it is empty * Code cleanup: moving Pwa related code from snapshotUtils to PwaHelper * Code cleaning * Code cleanup: Move common Application model to Csharp Library * code cleanup * modifying package name * Ading project reference to Common.UI * Code cleaning, fixing references --------- Co-authored-by: donlaci <donlaci@yahoo.com>
- Loading branch information
Showing
26 changed files
with
967 additions
and
538 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
217 changes: 217 additions & 0 deletions
217
src/modules/Workspaces/WorkspacesCsharpLibrary/Models/BaseApplication.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.ComponentModel; | ||
using System.Drawing; | ||
using System.Drawing.Drawing2D; | ||
using System.Drawing.Imaging; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text.Json.Serialization; | ||
using System.Text.RegularExpressions; | ||
using System.Windows.Media.Imaging; | ||
using Windows.Management.Deployment; | ||
|
||
namespace WorkspacesCsharpLibrary.Models | ||
{ | ||
public class BaseApplication : INotifyPropertyChanged, IDisposable | ||
{ | ||
public event PropertyChangedEventHandler PropertyChanged; | ||
|
||
public void OnPropertyChanged(PropertyChangedEventArgs e) | ||
{ | ||
PropertyChanged?.Invoke(this, e); | ||
} | ||
|
||
public string PwaAppId { get; set; } | ||
|
||
public string AppPath { get; set; } | ||
|
||
private bool _isNotFound; | ||
|
||
public string PackagedId { get; set; } | ||
|
||
public string PackagedName { get; set; } | ||
|
||
public string PackagedPublisherID { get; set; } | ||
|
||
public string Aumid { get; set; } | ||
|
||
[JsonIgnore] | ||
public bool IsNotFound | ||
{ | ||
get | ||
{ | ||
return _isNotFound; | ||
} | ||
|
||
set | ||
{ | ||
if (_isNotFound != value) | ||
{ | ||
_isNotFound = value; | ||
OnPropertyChanged(new PropertyChangedEventArgs(nameof(IsNotFound))); | ||
} | ||
} | ||
} | ||
|
||
private Icon _icon; | ||
|
||
public Icon Icon | ||
{ | ||
get | ||
{ | ||
if (_icon == null) | ||
{ | ||
try | ||
{ | ||
if (IsPackagedApp) | ||
{ | ||
Uri uri = GetAppLogoByPackageFamilyName(); | ||
var bitmap = new Bitmap(uri.LocalPath); | ||
var iconHandle = bitmap.GetHicon(); | ||
_icon = Icon.FromHandle(iconHandle); | ||
} | ||
else if (IsEdge || IsChrome) | ||
{ | ||
string iconFilename = PwaHelper.GetPwaIconFilename(PwaAppId); | ||
if (!string.IsNullOrEmpty(iconFilename)) | ||
{ | ||
Bitmap bitmap; | ||
if (iconFilename.EndsWith("ico", StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
bitmap = new Bitmap(iconFilename); | ||
} | ||
else | ||
{ | ||
bitmap = (Bitmap)Image.FromFile(iconFilename); | ||
} | ||
|
||
var iconHandle = bitmap.GetHicon(); | ||
_icon = Icon.FromHandle(iconHandle); | ||
} | ||
} | ||
|
||
if (_icon == null) | ||
{ | ||
_icon = Icon.ExtractAssociatedIcon(AppPath); | ||
} | ||
} | ||
catch (Exception) | ||
{ | ||
IsNotFound = true; | ||
_icon = new Icon(@"Assets\Workspaces\DefaultIcon.ico"); | ||
} | ||
} | ||
|
||
return _icon; | ||
} | ||
} | ||
|
||
private BitmapImage _iconBitmapImage; | ||
|
||
public BitmapImage IconBitmapImage | ||
{ | ||
get | ||
{ | ||
if (_iconBitmapImage == null) | ||
{ | ||
try | ||
{ | ||
Bitmap previewBitmap = new Bitmap(32, 32); | ||
using (Graphics graphics = Graphics.FromImage(previewBitmap)) | ||
{ | ||
graphics.SmoothingMode = SmoothingMode.AntiAlias; | ||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; | ||
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; | ||
|
||
graphics.DrawIcon(Icon, new Rectangle(0, 0, 32, 32)); | ||
} | ||
|
||
using (var memory = new MemoryStream()) | ||
{ | ||
previewBitmap.Save(memory, ImageFormat.Png); | ||
memory.Position = 0; | ||
|
||
BitmapImage bitmapImage = new BitmapImage(); | ||
bitmapImage.BeginInit(); | ||
bitmapImage.StreamSource = memory; | ||
bitmapImage.CacheOption = BitmapCacheOption.OnLoad; | ||
bitmapImage.EndInit(); | ||
bitmapImage.Freeze(); | ||
|
||
_iconBitmapImage = bitmapImage; | ||
} | ||
} | ||
catch (Exception) | ||
{ | ||
} | ||
} | ||
|
||
return _iconBitmapImage; | ||
} | ||
} | ||
|
||
public bool IsEdge | ||
{ | ||
get => AppPath.EndsWith("edge.exe", StringComparison.InvariantCultureIgnoreCase); | ||
} | ||
|
||
public bool IsChrome | ||
{ | ||
get => AppPath.EndsWith("chrome.exe", StringComparison.InvariantCultureIgnoreCase); | ||
} | ||
|
||
public Uri GetAppLogoByPackageFamilyName() | ||
{ | ||
var pkgManager = new PackageManager(); | ||
var pkg = pkgManager.FindPackagesForUser(string.Empty, PackagedId).FirstOrDefault(); | ||
|
||
if (pkg == null) | ||
{ | ||
return null; | ||
} | ||
|
||
return pkg.Logo; | ||
} | ||
|
||
private bool? _isPackagedApp; | ||
|
||
public bool IsPackagedApp | ||
{ | ||
get | ||
{ | ||
if (_isPackagedApp == null) | ||
{ | ||
if (!AppPath.StartsWith("C:\\Program Files\\WindowsApps\\", StringComparison.InvariantCultureIgnoreCase)) | ||
{ | ||
_isPackagedApp = false; | ||
} | ||
else | ||
{ | ||
string appPath = AppPath.Replace("C:\\Program Files\\WindowsApps\\", string.Empty); | ||
Regex packagedAppPathRegex = new Regex(@"(?<APPID>[^_]*)_\d+.\d+.\d+.\d+_x64__(?<PublisherID>[^\\]*)", RegexOptions.ExplicitCapture | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase); | ||
Match match = packagedAppPathRegex.Match(appPath); | ||
_isPackagedApp = match.Success; | ||
if (match.Success) | ||
{ | ||
PackagedName = match.Groups["APPID"].Value; | ||
PackagedPublisherID = match.Groups["PublisherID"].Value; | ||
PackagedId = $"{PackagedName}_{PackagedPublisherID}"; | ||
Aumid = $"{PackagedId}!App"; | ||
} | ||
} | ||
} | ||
|
||
return _isPackagedApp.Value; | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
GC.SuppressFinalize(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// The Microsoft Corporation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace WorkspacesCsharpLibrary | ||
{ | ||
public class PwaApp | ||
{ | ||
public required string Name { get; set; } | ||
|
||
public required string IconFilename { get; set; } | ||
|
||
public required string AppId { get; set; } | ||
} | ||
} |
Oops, something went wrong.