Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to FocusWShell. Each release has its notes in [`.github/rele

Todos los cambios importantes de FocusWShell. Cada versión tiene sus notas en [`.github/release-notes/`](.github/release-notes/).

## Unreleased / Sin publicar

- Fixed: Store apps whose window does not give its app ID (WhatsApp) showed an internal name ("WhatsApp.Root") and a generic icon. They now take the name and icon of the Start menu. / Corregido: las apps de la Store cuya ventana no da su id de app (WhatsApp) salían con un nombre interno («WhatsApp.Root») y un icono genérico. Ahora toman el nombre y el icono del menú Inicio.

## 0.5.0-alpha

Sites in Activity, private windows kept private, and apps that go back to their panel however you open them. / Sitios en Actividad, ventanas privadas que se quedan privadas, y apps que vuelven a su panel las abras como las abras.
Expand Down
4 changes: 4 additions & 0 deletions src/FocusWShell.App/AppIcons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ public static class AppIcons

// Si la ruta quedó vieja (la app se actualizó estando cerrada), la de la versión nueva.
var path = app.ExecutablePath is { } stored ? ExecutableLocator.Resolve(stored) ?? stored : null;
// Una app de la Store sin AUMID en su ventana (WhatsApp): el icono de su paquete, el de Inicio. El de su
// ejecutable puede ser uno genérico.
var packaged = app.Aumid is null ? PackagedApps.AumidFor(path) : null;
var icon = (app.Aumid is { } aumid ? FromShell(ShellIcon.ForAumid(aumid, Size)) : null)
?? (packaged is not null ? FromShell(ShellIcon.ForAumid(packaged, Size)) : null)
?? (path is not null ? FromExecutable(path) ?? FromShell(ShellIcon.For(path, Size)) : null)
?? (ExecutablePaths.GuessPackagedAumid(path) is { } guessed ? FromShell(ShellIcon.ForAumid(guessed, Size)) : null);
Cache[key] = icon;
Expand Down
2 changes: 2 additions & 0 deletions src/FocusWShell.Win32/AppLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public static class AppLauncher
/// </summary>
public static string? FriendlyName(string? executablePath, string? aumid) =>
(aumid is not null && (aumid.Contains('!', StringComparison.Ordinal) || IsWebApp(aumid)) ? PackagedName(aumid) : null)
// Una app de la Store cuya ventana no dice su AUMID (WhatsApp): el de su paquete.
?? (aumid is null && PackagedApps.AumidFor(executablePath) is { } packaged ? PackagedName(packaged) : null)
?? FriendlyName(executablePath);

/// <summary>Si el AUMID es de una app web instalada desde Chrome o Edge (<c>Chrome._crx_…</c>).</summary>
Expand Down
84 changes: 84 additions & 0 deletions src/FocusWShell.Win32/PackagedApps.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using System.Collections.Concurrent;
using System.Xml;

namespace FocusWShell.Win32;

/// <summary>
/// Las apps de la Store (empaquetadas en <c>WindowsApps</c>) cuya ventana no dice su AUMID, como WhatsApp: su
/// ejecutable se describe con un nombre interno («WhatsApp.Root») y trae un icono genérico. Su AUMID sale del
/// paquete: la familia (nombre e id del editor, de la carpeta) y el id de la aplicación cuyo ejecutable es ese,
/// leído de su <c>AppxManifest.xml</c>. Con él, Windows da el nombre y el icono que muestra en Inicio.
/// </summary>
public static class PackagedApps
{
private static readonly ConcurrentDictionary<string, string?> Cache = new(StringComparer.OrdinalIgnoreCase);

/// <summary>El AUMID de un ejecutable empaquetado, o <c>null</c> si no lo es o no se encuentra.</summary>
public static string? AumidFor(string? executablePath)
{
if (string.IsNullOrWhiteSpace(executablePath))
{
return null;
}

return Cache.GetOrAdd(executablePath, Find);
}

private static string? Find(string path)
{
var parts = path.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
int index = Array.FindIndex(parts, p => string.Equals(p, "WindowsApps", StringComparison.OrdinalIgnoreCase));
if (index < 0 || index + 2 >= parts.Length)
{
return null;
}

// Nombre_Versión_Arquitectura_Recurso_Editor → familia Nombre_Editor.
var fields = parts[index + 1].Split('_');
if (fields.Length < 5 || fields[0].Length == 0 || fields[^1].Length == 0)
{
return null;
}

var packageFolder = string.Join(Path.DirectorySeparatorChar, parts.Take(index + 2));
var relative = string.Join('\\', parts.Skip(index + 2));
var appId = AppIdFor(Path.Combine(packageFolder, "AppxManifest.xml"), relative);
return appId is null ? null : $"{fields[0]}_{fields[^1]}!{appId}";
}

/// <summary>El id de la aplicación del manifiesto cuyo <c>Executable</c> es ese archivo.</summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1031", Justification = "Un manifiesto ilegible: la app sigue con el nombre y el icono de su ejecutable.")]
private static string? AppIdFor(string manifest, string relativeExe)
{
try
{
if (!File.Exists(manifest))
{
return null;
}

var doc = new XmlDocument { XmlResolver = null };
using (var reader = XmlReader.Create(manifest, new XmlReaderSettings { DtdProcessing = DtdProcessing.Prohibit, XmlResolver = null }))
{
doc.Load(reader);
}

string Normal(string p) => p.Replace('/', '\\').TrimStart('\\');
foreach (XmlElement app in doc.GetElementsByTagName("Application", "*"))
{
var exe = app.GetAttribute("Executable");
if (exe.Length > 0 && string.Equals(Normal(exe), Normal(relativeExe), StringComparison.OrdinalIgnoreCase))
{
var id = app.GetAttribute("Id");
return id.Length > 0 ? id : null;
}
}

return null;
}
catch (Exception)
{
return null;
}
}
}
Loading