Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fixed an issue where execution via URI or alias could run different version of Files #15371

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/deploy-preview-legacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ jobs:
$xmlDoc.Package.Identity.Publisher="$env:SIDELOAD_PUBLISHER_SECRET"
$xmlDoc.Package.Properties.DisplayName="Files - Preview"
$xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files - Preview"
$nsmgr = New-Object System.Xml.XmlNamespaceManager($xmlDoc.NameTable)
$nsmgr.AddNamespace("pkg", "http://schemas.microsoft.com/appx/manifest/foundation/windows10")
$alias = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Applications/pkg:Application/pkg:Extensions/uap5:Extension[@Name='windows.protocol']", $nsmgr)
$alias.Value="files-pre.exe"
$uriScheme = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Applications/pkg:Application/pkg:Extensions/uap5:Extension[@Name='windows.appExecutionAlias']", $nsmgr)
$uriScheme.Value="files-pre:"
$xmlDoc.Save("$env:PACKAGE_PROJECT_DIR\Package.appxmanifest")
env:
SIDELOAD_PUBLISHER_SECRET: ${{ secrets.SIDELOAD_PUBLISHER_SECRET }}
Expand Down Expand Up @@ -94,6 +100,26 @@ jobs:
env:
GH_OAUTH_CLIENT_ID: ${{ secrets.GH_OAUTH_CLIENT_ID }}

- name: Inject the application execution alias
run: |
Get-ChildItem "$env:WORKING_DIR\src" -Include *.cs -recurse | ForEach-Object -Process `
{ `
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "files.alias.key", "files-pre.exe" }) | `
Set-Content $_ -NoNewline `
}
env:
GH_OAUTH_CLIENT_ID: ${{ secrets.GH_OAUTH_CLIENT_ID }}

- name: Inject the application URI scheme
run: |
Get-ChildItem "$env:WORKING_DIR\src" -Include *.cs -recurse | ForEach-Object -Process `
{ `
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "files.urischeme.key", "files-pre:" }) | `
Set-Content $_ -NoNewline `
}
env:
GH_OAUTH_CLIENT_ID: ${{ secrets.GH_OAUTH_CLIENT_ID }}

- name: Use Windows SDK Preview
shell: cmd
run: |
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/deploy-stable-legacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ jobs:
$xmlDoc.Package.Identity.Publisher="$env:SIDELOAD_PUBLISHER_SECRET"
$xmlDoc.Package.Properties.DisplayName="Files"
$xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files"
$nsmgr = New-Object System.Xml.XmlNamespaceManager($xmlDoc.NameTable)
$nsmgr.AddNamespace("pkg", "http://schemas.microsoft.com/appx/manifest/foundation/windows10")
$alias = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Applications/pkg:Application/pkg:Extensions/uap5:Extension[@Name='windows.appExecutionAlias']", $nsmgr)
$alias.Value="files.exe"
$alias = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Applications/pkg:Application/pkg:Extensions/uap5:Extension[@Name='windows.protocol']", $nsmgr)
$alias.Value="files-pre.exe"
$xmlDoc.Save("$env:PACKAGE_PROJECT_DIR\Package.appxmanifest")
env:
SIDELOAD_PUBLISHER_SECRET: ${{ secrets.SIDELOAD_PUBLISHER_SECRET }}
Expand Down Expand Up @@ -94,6 +100,26 @@ jobs:
env:
GH_OAUTH_CLIENT_ID: ${{ secrets.GH_OAUTH_CLIENT_ID }}

- name: Inject the application execution alias
run: |
Get-ChildItem "$env:WORKING_DIR\src" -Include *.cs -recurse | ForEach-Object -Process `
{ `
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "files.alias.key", "files.exe" }) | `
Set-Content $_ -NoNewline `
}
env:
GH_OAUTH_CLIENT_ID: ${{ secrets.GH_OAUTH_CLIENT_ID }}

- name: Inject the application URI scheme
run: |
Get-ChildItem "$env:WORKING_DIR\src" -Include *.cs -recurse | ForEach-Object -Process `
{ `
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "files.urischeme.key", "files:" }) | `
Set-Content $_ -NoNewline `
}
env:
GH_OAUTH_CLIENT_ID: ${{ secrets.GH_OAUTH_CLIENT_ID }}

- name: Use Windows SDK Preview
shell: cmd
run: |
Expand Down
4 changes: 2 additions & 2 deletions src/Files.App (Package)/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@
</uap3:Extension>

<uap:Extension Category="windows.protocol">
<uap:Protocol ReturnResults="none" Name="files-uwp" />
<uap:Protocol ReturnResults="none" Name="files-dev" />
</uap:Extension>

<uap5:Extension Category="windows.appExecutionAlias">
<uap5:AppExecutionAlias>
<uap5:ExecutionAlias Alias="files.exe" />
<uap5:ExecutionAlias Alias="files-dev.exe" />
</uap5:AppExecutionAlias>
</uap5:Extension>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task ExecuteAsync(object? parameter = null)
foreach (ListedItem listedItem in items)
{
var selectedItemPath = (listedItem as ShortcutItem)?.TargetPath ?? listedItem.ItemPath;
var folderUri = new Uri($"files-uwp:?folder={@selectedItemPath}");
var folderUri = new Uri(Constants.AutomatedWorkflowInjectionKeys.FilesUriSchemaVariable + $"?folder={@selectedItemPath}");

await Launcher.LaunchUriAsync(folderUri);
}
Expand Down
21 changes: 21 additions & 0 deletions src/Files.App/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ public static class AutomatedWorkflowInjectionKeys
public const string GitHubClientId = "githubclientid.secret";

public const string BingMapsSecret = "bingmapskey.secret";

public const string FilesExecutionAliasVariable = "files.alias.key";

public const string FilesExecutionAliasVariableEscaped = "files/alias/key";

public const string FilesExecutionAliasStaticStable = "files.exe";

public const string FilesExecutionAliasStaticPreview = "files-pre.exe";

public const string FilesExecutionAliasStaticDev = "files-dev.exe";

public const string FilesUriSchemaVariable = "files.urischeme.key";

public const string FilesUriSchemaVariableEscaped = "files/urischeme/key";

public const string FilesUriSchemaStaticStable = "files:";

public const string FilesUriSchemaStaticPreview = "files-pre:";

public const string FilesUriSchemaStaticDev = "files-dev:";

}

public static class KnownImageFormats
Expand Down
12 changes: 11 additions & 1 deletion src/Files.App/Helpers/Application/AppLifecycleHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public static class AppLifecycleHelper
_ => Constants.AssetPaths.StableLogo
});

public static string AppExecutionAlias { get; } =
Constants.AutomatedWorkflowInjectionKeys.FilesExecutionAliasVariable == Constants.AutomatedWorkflowInjectionKeys.FilesExecutionAliasVariableEscaped.Replace('/', '.')
? Constants.AutomatedWorkflowInjectionKeys.FilesExecutionAliasStaticDev
: Constants.AutomatedWorkflowInjectionKeys.FilesExecutionAliasVariable;

public static string AppURIScheme { get; } =
Constants.AutomatedWorkflowInjectionKeys.FilesUriSchemaVariable == Constants.AutomatedWorkflowInjectionKeys.FilesUriSchemaVariableEscaped.Replace('/', '.')
? Constants.AutomatedWorkflowInjectionKeys.FilesUriSchemaStaticDev
: Constants.AutomatedWorkflowInjectionKeys.FilesUriSchemaVariable;

/// <summary>
/// Initializes the app components.
/// </summary>
Expand Down Expand Up @@ -359,7 +369,7 @@ public static void HandleAppUnhandledException(Exception? ex, bool showToastNoti
// Try to re-launch and start over
MainWindow.Instance.DispatcherQueue.EnqueueOrInvokeAsync(async () =>
{
await Launcher.LaunchUriAsync(new Uri("files-uwp:"));
await Launcher.LaunchUriAsync(new Uri(Constants.AutomatedWorkflowInjectionKeys.FilesUriSchemaVariable));
})
.Wait(100);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Files.App/Helpers/Navigation/NavigationHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@ public static Task<bool> OpenPathInNewWindowAsync(string? path)
if (string.IsNullOrWhiteSpace(path))
return Task.FromResult(false);

var folderUri = new Uri($"files-uwp:?folder={Uri.EscapeDataString(path)}");
var folderUri = new Uri(Constants.AutomatedWorkflowInjectionKeys.FilesUriSchemaVariable + $"?folder={Uri.EscapeDataString(path)}");

return Launcher.LaunchUriAsync(folderUri).AsTask();
}

public static Task<bool> OpenTabInNewWindowAsync(string tabArgs)
{
var folderUri = new Uri($"files-uwp:?tab={Uri.EscapeDataString(tabArgs)}");
var folderUri = new Uri(Constants.AutomatedWorkflowInjectionKeys.FilesUriSchemaVariable + $"?tab={Uri.EscapeDataString(tabArgs)}");
return Launcher.LaunchUriAsync(folderUri).AsTask();
}

Expand All @@ -271,7 +271,7 @@ public static void OpenInSecondaryPane(IShellPage associatedInstance, ListedItem

public static Task LaunchNewWindowAsync()
{
var filesUWPUri = new Uri("files-uwp:?window=");
var filesUWPUri = new Uri(Constants.AutomatedWorkflowInjectionKeys.FilesUriSchemaVariable + $"?window=");
return Launcher.LaunchUriAsync(filesUWPUri).AsTask();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Files.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task InitializeApplicationAsync(object activatedEventArgs)
{
case ILaunchActivatedEventArgs launchArgs:
if (launchArgs.Arguments is not null &&
(CommandLineParser.SplitArguments(launchArgs.Arguments, true)[0].EndsWith($"files.exe", StringComparison.OrdinalIgnoreCase)
(CommandLineParser.SplitArguments(launchArgs.Arguments, true)[0].EndsWith(Constants.AutomatedWorkflowInjectionKeys.FilesExecutionAliasVariable, StringComparison.OrdinalIgnoreCase)
|| CommandLineParser.SplitArguments(launchArgs.Arguments, true)[0].EndsWith($"files", StringComparison.OrdinalIgnoreCase)))
{
// WINUI3: When launching from commandline the argument is not ICommandLineActivatedEventArgs (#10370)
Expand Down Expand Up @@ -101,7 +101,7 @@ public async Task InitializeApplicationAsync(object activatedEventArgs)
break;

case IProtocolActivatedEventArgs eventArgs:
if (eventArgs.Uri.AbsoluteUri == "files-uwp:")
if (eventArgs.Uri.AbsoluteUri == Constants.AutomatedWorkflowInjectionKeys.FilesUriSchemaVariable)
{
rootFrame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo());

Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static bool ProcessPathPredicate(Process p)
var cmdLaunchArgs = activatedArgs.Data is ILaunchActivatedEventArgs launchArgs &&
launchArgs.Arguments is not null &&
CommandLineParser.SplitArguments(launchArgs.Arguments, true).FirstOrDefault() is string arg0 &&
(arg0.EndsWith($"files.exe", StringComparison.OrdinalIgnoreCase) ||
(arg0.EndsWith(Constants.AutomatedWorkflowInjectionKeys.FilesExecutionAliasVariable, StringComparison.OrdinalIgnoreCase) ||
arg0.EndsWith($"files", StringComparison.OrdinalIgnoreCase)) ? launchArgs.Arguments : null;
var cmdProtocolArgs = activatedArgs.Data is IProtocolActivatedEventArgs protocolArgs &&
protocolArgs.Uri.Query.TrimStart('?').Split('=') is string[] parsedArgs &&
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/Utils/Taskbar/SystemTrayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private void OnLeftClicked()
{
_lastLaunchDate = DateTime.Now;

_ = Launcher.LaunchUriAsync(new Uri("files-uwp:"));
_ = Launcher.LaunchUriAsync(new Uri(Constants.AutomatedWorkflowInjectionKeys.FilesUriSchemaVariable));
}
else
MainWindow.Instance.Activate();
Expand Down
2 changes: 1 addition & 1 deletion src/Files.App/ViewModels/Settings/GeneralViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private async void DoRestartAsync()
AppLifecycleHelper.SaveSessionTabs();

// Launches a new instance of Files
await Launcher.LaunchUriAsync(new Uri("files-uwp:"));
await Launcher.LaunchUriAsync(new Uri(Constants.AutomatedWorkflowInjectionKeys.FilesUriSchemaVariable));

// Closes the current instance
Process.GetCurrentProcess().Kill();
Expand Down