Skip to content

Commit

Permalink
优化开始菜单布局
Browse files Browse the repository at this point in the history
  • Loading branch information
wherewhere committed Jul 24, 2024
1 parent 2a61cf8 commit a2d2887
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 35 deletions.
116 changes: 107 additions & 9 deletions WinGetStore/WinGetStore/Helpers/TilesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using System.Security.AccessControl;
using System.Security.Principal;
using System.Threading.Tasks;
using Windows.ApplicationModel.Resources;
using Windows.ApplicationModel.Resources.Core;
using Windows.Data.Xml.Dom;
using Windows.Storage;
using Windows.UI.Notifications;
Expand Down Expand Up @@ -179,15 +181,13 @@ public static async Task UpdateStartMenuCompanionAsync(this AdaptiveCard adaptiv
{
try
{
StorageFolder storageDir = await ApplicationData.Current.LocalFolder.CreateFolderAsync("StartMenu", CreationCollisionOption.OpenIfExists);
StorageFile file = await StorageFileHelper.WriteTextToLocalFileAsync(adaptiveCard.ToJson(), fileName).ConfigureAwait(false);

DirectoryInfo dirInfo = new(storageDir.Path);
DirectorySecurity dirSec = dirInfo.GetAccessControl();
FileInfo info = new(file.Path);
FileSecurity security = info.GetAccessControl();
// Add Shell Experience Capability SID
dirSec.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier("S-1-15-3-1024-3167453650-624722384-889205278-321484983-714554697-3592933102-807660695-1632717421"), FileSystemRights.ReadAndExecute, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));
dirInfo.SetAccessControl(dirSec);

await storageDir.WriteTextToFileAsync(adaptiveCard.ToJson(), fileName).ConfigureAwait(false);
security.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier("S-1-15-3-1024-3167453650-624722384-889205278-321484983-714554697-3592933102-807660695-1632717421"), FileSystemRights.ReadAndExecute, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow));
info.SetAccessControl(security);
}
catch (Exception ex)
{
Expand All @@ -197,8 +197,106 @@ public static async Task UpdateStartMenuCompanionAsync(this AdaptiveCard adaptiv

public static AdaptiveCard CreateStartMenuCompanion(IEnumerable<CatalogPackage> catalogPackages)
{
AdaptiveCard card = new(new AdaptiveSchemaVersion(1, 1));
card.Body.AddRange(catalogPackages.Select(x => new AdaptiveTextBlock(x.Name)));
AdaptiveCard card = new(new AdaptiveSchemaVersion(1, 1))
{
Body =
{
new AdaptiveColumnSet
{
Columns =
{
new AdaptiveColumn
{
Width = "8px"
},
new AdaptiveColumn
{
Items =
{
new AdaptiveTextBlock(ResourceLoader.GetForViewIndependentUse().GetString("StartMenuTitle"))
{
Weight = AdaptiveTextWeight.Bolder,
Size = AdaptiveTextSize.Large,
Spacing = AdaptiveSpacing.None
}
}
},
new AdaptiveColumn
{
Width = "8px"
}
},
Spacing = AdaptiveSpacing.None
}
}
};
card.Body.AddRange(catalogPackages.Select(CreateCard));
static AdaptiveContainer CreateCard(CatalogPackage catalogPackage)
{
return new AdaptiveContainer
{
Items =
{
new AdaptiveColumnSet
{
Columns =
{
new AdaptiveColumn
{
Width = "8px"
},
new AdaptiveColumn
{
Items =
{
new AdaptiveTextBlock(catalogPackage.Name)
{
Weight = AdaptiveTextWeight.Bolder
},
new AdaptiveColumnSet
{
Columns =
{
new AdaptiveColumn
{
Items =
{
new AdaptiveTextBlock(catalogPackage.Id)
{
IsSubtle = true,
Size = AdaptiveTextSize.Small,
Spacing = AdaptiveSpacing.None
}
}
},
new AdaptiveColumn
{
Items =
{
new AdaptiveTextBlock(catalogPackage.IsUpdateAvailable ? "可更新" : " ")
{
Color = AdaptiveTextColor.Accent,
IsSubtle = true,
Size = AdaptiveTextSize.Small,
Spacing = AdaptiveSpacing.None
}
},
Width = "auto"
}
},
Spacing = AdaptiveSpacing.Small
}
}
},
new AdaptiveColumn
{
Width = "8px"
}
}
}
}
};
}
return card;
}

Expand Down
15 changes: 7 additions & 8 deletions WinGetStore/WinGetStore/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,18 @@
<uap3:AppExtension
Name="com.microsoft.startmenucompanion"
Id="18184wherewhere.WinGetStore.Companion"
DisplayName="WinGet Store"
Description="WinGet Store Start Menu Companion"
DisplayName="ms-resource:AppName"
Description="ms-resource:AppDescription"
PublicFolder="public">
<uap3:Properties>
<AdaptiveCardAppDataLocalRelativePath>StartMenu/StartMenuCompanion.json</AdaptiveCardAppDataLocalRelativePath>
<AdaptiveCardAppDataLocalRelativePath>StartMenuCompanion.json</AdaptiveCardAppDataLocalRelativePath>
<PlacementPreference>Left</PlacementPreference>
<RefreshCardLaunchUri>ms-phone:startup?ref=StartMenu</RefreshCardLaunchUri>
<Icon>ms-appx:///Assets/StoreLogo.png</Icon>
<CompanionSettingName>WinGet Store</CompanionSettingName>
<CompanionSettingExtendedName>WinGet Store Start Menu Companion</CompanionSettingExtendedName>
<DetailedSettingsSettingName>Report bugs</DetailedSettingsSettingName>
<CompanionSettingName>ms-resource:AppName</CompanionSettingName>
<CompanionSettingExtendedName>ms-resource:AppDescription</CompanionSettingExtendedName>
<DetailedSettingsSettingName>ms-resource:Report</DetailedSettingsSettingName>
<DetailedSettingsLaunchName>GitHub</DetailedSettingsLaunchName>
<DetailedSettingsLaunchUri>https://github.com/thebookisclosed/StartMenuCompanionSample</DetailedSettingsLaunchUri>
<DetailedSettingsLaunchUri>https://github.com/wherewhere/WinGet-Store/issues</DetailedSettingsLaunchUri>
<DefaultState>Available</DefaultState>
</uap3:Properties>
</uap3:AppExtension>
Expand Down
40 changes: 23 additions & 17 deletions WinGetStore/WinGetStore/Strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -59,46 +59,46 @@
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace"/>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0"/>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string"/>
<xsd:attribute name="type" type="xsd:string"/>
<xsd:attribute name="mimetype" type="xsd:string"/>
<xsd:attribute ref="xml:space"/>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string"/>
<xsd:attribute name="name" type="xsd:string"/>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2"/>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1"/>
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3"/>
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4"/>
<xsd:attribute ref="xml:space"/>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1"/>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
Expand Down Expand Up @@ -145,4 +145,10 @@
<data name="Yes" xml:space="preserve">
<value>Yes</value>
</data>
<data name="Report" xml:space="preserve">
<value>Report bugs</value>
</data>
<data name="StartMenuTitle" xml:space="preserve">
<value>WinGet App List</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,13 @@ private async Task<FindPackagesResult> TryFindPackageInCatalogAsync(PackageCatal
private async Task UpdateTileAsync()
{
await ThreadSwitcher.ResumeBackgroundAsync();
CatalogPackage[] available = MatchResults.Where(x => x.IsUpdateAvailable).ToArray();
Task task = TilesHelper.CreateStartMenuCompanion(matchResults).UpdateStartMenuCompanionAsync();
CatalogPackage[] available = matchResults.Where(x => x.IsUpdateAvailable).ToArray();
TilesHelper.SetBadgeNumber((uint)available.Length);
available.Take(5)
.Select(TilesHelper.CreateTile)
.UpdateTiles();
await task;
}
}
}

0 comments on commit a2d2887

Please sign in to comment.