Skip to content

Commit f066ca7

Browse files
authored
GitHub: Follow up #16566 (#16567)
1 parent 4e24f7d commit f066ca7

File tree

2 files changed

+40
-62
lines changed

2 files changed

+40
-62
lines changed

.github/scripts/Configure-AppxManifest.ps1

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Licensed under the MIT License. See the LICENSE.
33

44
param(
5-
[string]$Branch = "",
5+
[string]$Branch = "", # This has to correspond with one of the AppEnvironment enum values
66
[string]$PackageManifestPath = "",
77
[string]$Publisher = "",
88
[string]$WorkingDir = "",
@@ -28,10 +28,26 @@ if ($Branch -eq "SideloadPreview")
2828
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "Assets\\AppTiles\\Dev", "Assets\AppTiles\Preview" }) | `
2929
Set-Content $_ -NoNewline `
3030
}
31+
}
32+
elseif ($Branch -eq "StorePreview")
33+
{
34+
# Set identities
35+
$xmlDoc.Package.Identity.Name="49306atecsolution.FilesPreview"
36+
$xmlDoc.Package.Properties.DisplayName="Files - Preview"
37+
$xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files - Preview"
38+
$xmlDoc.Package.Applications.Application.VisualElements.DefaultTile.ShortName="49306atecsolution.FilesPreview"
3139

32-
Get-ChildItem $WorkingDir -Include *.cs -recurse | ForEach-Object -Process `
40+
# Remove an capability that is used for the sideload
41+
$nsmgr = New-Object System.Xml.XmlNamespaceManager($xmlDoc.NameTable)
42+
$nsmgr.AddNamespace("pkg", "http://schemas.microsoft.com/appx/manifest/foundation/windows10")
43+
$nsmgr.AddNamespace("rescap", "http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities")
44+
$pm = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Capabilities/rescap:Capability[@Name='packageManagement']", $nsmgr)
45+
$xmlDoc.Package.Capabilities.RemoveChild($pm)
46+
$xmlDoc.Save($PackageManifestPath)
47+
48+
Get-ChildItem $WorkingDir -Include *.csproj, *.appxmanifest, *.wapproj, *.xaml -recurse | ForEach-Object -Process `
3349
{ `
34-
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "cd_app_env_placeholder", "SideloadPreview" }) | `
50+
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "Assets\\AppTiles\\Dev", "Assets\AppTiles\Preview" }) | `
3551
Set-Content $_ -NoNewline `
3652
}
3753
}
@@ -49,12 +65,6 @@ elseif ($Branch -eq "SideloadStable")
4965
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "Assets\\AppTiles\\Dev", "Assets\AppTiles\Release" }) | `
5066
Set-Content $_ -NoNewline `
5167
}
52-
53-
Get-ChildItem $WorkingDir -Include *.cs -recurse | ForEach-Object -Process `
54-
{ `
55-
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "cd_app_env_placeholder", "SideloadStable" }) | `
56-
Set-Content $_ -NoNewline `
57-
}
5868
}
5969
elseif ($Branch -eq "StoreStable")
6070
{
@@ -77,40 +87,12 @@ elseif ($Branch -eq "StoreStable")
7787
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "Assets\\AppTiles\\Dev", "Assets\AppTiles\Release" }) | `
7888
Set-Content $_ -NoNewline `
7989
}
80-
81-
Get-ChildItem $WorkingDir -Include *.cs -recurse | ForEach-Object -Process `
82-
{ `
83-
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "cd_app_env_placeholder", "StoreStable" }) | `
84-
Set-Content $_ -NoNewline `
85-
}
8690
}
87-
elseif ($Branch -eq "StorePreview")
88-
{
89-
# Set identities
90-
$xmlDoc.Package.Identity.Name="49306atecsolution.FilesPreview"
91-
$xmlDoc.Package.Properties.DisplayName="Files - Preview"
92-
$xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files - Preview"
93-
$xmlDoc.Package.Applications.Application.VisualElements.DefaultTile.ShortName="49306atecsolution.FilesPreview"
94-
95-
# Remove an capability that is used for the sideload
96-
$nsmgr = New-Object System.Xml.XmlNamespaceManager($xmlDoc.NameTable)
97-
$nsmgr.AddNamespace("pkg", "http://schemas.microsoft.com/appx/manifest/foundation/windows10")
98-
$nsmgr.AddNamespace("rescap", "http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities")
99-
$pm = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Capabilities/rescap:Capability[@Name='packageManagement']", $nsmgr)
100-
$xmlDoc.Package.Capabilities.RemoveChild($pm)
101-
$xmlDoc.Save($PackageManifestPath)
102-
103-
Get-ChildItem $WorkingDir -Include *.csproj, *.appxmanifest, *.wapproj, *.xaml -recurse | ForEach-Object -Process `
104-
{ `
105-
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "Assets\\AppTiles\\Dev", "Assets\AppTiles\Preview" }) | `
106-
Set-Content $_ -NoNewline `
107-
}
10891

109-
Get-ChildItem $WorkingDir -Include *.cs -recurse | ForEach-Object -Process `
110-
{ `
111-
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "cd_app_env_placeholder", "StorePreview" }) | `
112-
Set-Content $_ -NoNewline `
113-
}
92+
Get-ChildItem $WorkingDir -Include *.cs -recurse | ForEach-Object -Process `
93+
{ `
94+
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "cd_app_env_placeholder", $Branch }) | `
95+
Set-Content $_ -NoNewline `
11496
}
11597

11698
Get-ChildItem $WorkingDir -Include *.cs -recurse | ForEach-Object -Process `

src/Files.App/Helpers/Application/AppLifecycleHelper.cs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,10 @@ public static class AppLifecycleHelper
2929
/// <summary>
3030
/// Gets the value that provides application environment or branch name.
3131
/// </summary>
32-
public static AppEnvironment AppEnvironment
33-
{
34-
get
35-
{
36-
if (Enum.TryParse("cd_app_env_placeholder", true, out AppEnvironment appEnvironment))
37-
return appEnvironment;
38-
else
39-
return AppEnvironment.Dev;
40-
}
41-
}
32+
public static AppEnvironment AppEnvironment =>
33+
Enum.TryParse("cd_app_env_placeholder", true, out AppEnvironment appEnvironment))
34+
? appEnvironment;
35+
: AppEnvironment.Dev;
4236

4337
/// <summary>
4438
/// Gets application package version.
@@ -53,8 +47,7 @@ public static AppEnvironment AppEnvironment
5347
SystemIO.Path.Combine(Package.Current.InstalledLocation.Path, AppEnvironment switch
5448
{
5549
AppEnvironment.Dev => Constants.AssetPaths.DevLogo,
56-
AppEnvironment.SideloadPreview => Constants.AssetPaths.PreviewLogo,
57-
AppEnvironment.StorePreview => Constants.AssetPaths.PreviewLogo,
50+
AppEnvironment.SideloadPreview or AppEnvironment.StorePreview => Constants.AssetPaths.PreviewLogo,
5851
_ => Constants.AssetPaths.StableLogo
5952
});
6053

@@ -138,7 +131,7 @@ public static void ConfigureSentry()
138131
/// </summary>
139132
public static IHost ConfigureHost()
140133
{
141-
return Host.CreateDefaultBuilder()
134+
var builder = Host.CreateDefaultBuilder()
142135
.UseEnvironment(AppLifecycleHelper.AppEnvironment.ToString())
143136
.ConfigureLogging(builder => builder
144137
.ClearProviders()
@@ -187,13 +180,6 @@ public static IHost ConfigureHost()
187180
.AddSingleton<IStorageService, NativeStorageLegacyService>()
188181
.AddSingleton<IFtpStorageService, FtpStorageService>()
189182
.AddSingleton<IAddItemService, AddItemService>()
190-
#if SIDELOAD_STABLE || SIDELOAD_PREVIEW
191-
.AddSingleton<IUpdateService, SideloadUpdateService>()
192-
#elif STORE_STABLE || STORE_PREVIEW
193-
.AddSingleton<IUpdateService, StoreUpdateService>()
194-
#else
195-
.AddSingleton<IUpdateService, DummyUpdateService>()
196-
#endif
197183
.AddSingleton<IPreviewPopupService, PreviewPopupService>()
198184
.AddSingleton<IDateTimeFormatterFactory, DateTimeFormatterFactory>()
199185
.AddSingleton<IDateTimeFormatter, UserDateTimeFormatter>()
@@ -228,7 +214,17 @@ public static IHost ConfigureHost()
228214
.AddSingleton<FileTagsManager>()
229215
.AddSingleton<LibraryManager>()
230216
.AddSingleton<AppModel>()
231-
).Build();
217+
);
218+
219+
// Conditional DI
220+
if (AppEnvironment is AppEnvironment.SideloadPreview or AppEnvironment.SideloadStable)
221+
builder.ConfigureServices(s => s.AddSingleton<IUpdateService, SideloadUpdateService>());
222+
else if (AppEnvironment is AppEnvironment.StorePreview or AppEnvironment.StoreStable)
223+
builder.ConfigureServices(s => s.AddSingleton<IUpdateService, StoreUpdateService>());
224+
else
225+
builder.ConfigureServices(s => s.AddSingleton<IUpdateService, DummyUpdateService>());
226+
227+
return builder.Build();
232228
}
233229

234230
/// <summary>

0 commit comments

Comments
 (0)