This repository was archived by the owner on Jun 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Activate application from .winget
files
#2379
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ac30475
File activation
AmelBawa-msft 43f6e6f
Navigation
AmelBawa-msft 59cef98
CE
AmelBawa-msft 3bde22c
CE
AmelBawa-msft 51e1191
Handle edge cases
AmelBawa-msft b2beaa2
CE
AmelBawa-msft 7413bb8
Added logs
AmelBawa-msft ad80f91
CE
AmelBawa-msft a3bf87b
Resolved conflict
AmelBawa-msft 0511b3a
Address comment
AmelBawa-msft 1a4df2d
Merge branch 'main' of https://github.com/microsoft/devhome into user…
AmelBawa-msft d577797
Fix build
AmelBawa-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
{ | ||
"profiles": { | ||
"DevHome (Package)": { | ||
"commandName": "MsixPackage" | ||
|
This file contains hidden or 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 hidden or 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,103 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System.Diagnostics; | ||
using DevHome.Activation; | ||
using DevHome.Common.Extensions; | ||
using DevHome.Common.Services; | ||
using DevHome.SetupFlow.Common.Helpers; | ||
using DevHome.SetupFlow.Services; | ||
using DevHome.SetupFlow.ViewModels; | ||
using Microsoft.UI.Xaml; | ||
using Windows.ApplicationModel.Activation; | ||
using Windows.Storage; | ||
|
||
namespace DevHome.Services; | ||
|
||
/// <summary> | ||
/// Class that handles the activation of the application when a DSC file (*.winget) is opened | ||
/// </summary> | ||
public class DSCFileActivationHandler : ActivationHandler<FileActivatedEventArgs> | ||
{ | ||
private const string WinGetFileExtension = ".winget"; | ||
private readonly ISetupFlowStringResource _setupFlowStringResource; | ||
private readonly INavigationService _navigationService; | ||
private readonly SetupFlowViewModel _setupFlowViewModel; | ||
private readonly SetupFlowOrchestrator _setupFlowOrchestrator; | ||
private readonly WindowEx _mainWindow; | ||
|
||
public DSCFileActivationHandler( | ||
ISetupFlowStringResource setupFlowStringResource, | ||
INavigationService navigationService, | ||
SetupFlowOrchestrator setupFlowOrchestrator, | ||
SetupFlowViewModel setupFlowViewModel, | ||
WindowEx mainWindow) | ||
{ | ||
_setupFlowStringResource = setupFlowStringResource; | ||
_setupFlowViewModel = setupFlowViewModel; | ||
_setupFlowOrchestrator = setupFlowOrchestrator; | ||
_navigationService = navigationService; | ||
_mainWindow = mainWindow; | ||
} | ||
|
||
protected override bool CanHandleInternal(FileActivatedEventArgs args) | ||
{ | ||
return args.Files.Count > 0 && args.Files[0] is StorageFile file && file.FileType == WinGetFileExtension; | ||
} | ||
|
||
protected async override Task HandleInternalAsync(FileActivatedEventArgs args) | ||
{ | ||
Debug.Assert(_navigationService.Frame != null, "Main window content is expected to be set before activation handlers are executed"); | ||
var file = (StorageFile)args.Files[0]; | ||
AmelBawa-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
async void DSCActivationFlowHandlerAsync(object sender, RoutedEventArgs e) | ||
{ | ||
// Only execute once | ||
_navigationService.Frame!.Loaded -= DSCActivationFlowHandlerAsync; | ||
await DSCActivationFlowAsync(file); | ||
} | ||
|
||
// If the application was activated from a file, the XamlRoot here is null | ||
if (_navigationService.Frame.XamlRoot == null) | ||
{ | ||
// Wait until the frame is loaded before starting the flow | ||
Log.Logger?.ReportInfo("DSC flow activated from a file but the application is not yet ready. Activation will start once the page is loaded."); | ||
_navigationService.Frame!.Loaded += DSCActivationFlowHandlerAsync; | ||
} | ||
else | ||
{ | ||
// If the application was already running, start the flow immediately | ||
await DSCActivationFlowAsync(file); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Navigates to the setup flow and starts the DSC activation flow | ||
/// </summary> | ||
/// <param name="file">The DSC file to activate</param> | ||
private async Task DSCActivationFlowAsync(StorageFile file) | ||
{ | ||
try | ||
{ | ||
// Don't interrupt the user if the machine configuration is in progress | ||
if (_setupFlowOrchestrator.IsMachineConfigurationInProgress) | ||
{ | ||
Log.Logger?.ReportWarn("Cannot activate the DSC flow because the machine configuration is in progress"); | ||
await _mainWindow.ShowErrorMessageDialogAsync( | ||
_setupFlowStringResource.GetLocalized(StringResourceKey.ConfigurationViewTitle, file.Name), | ||
_setupFlowStringResource.GetLocalized(StringResourceKey.ConfigurationActivationFailedBusy), | ||
_setupFlowStringResource.GetLocalized(StringResourceKey.Close)); | ||
} | ||
else | ||
{ | ||
// Start the setup flow with the DSC file | ||
Log.Logger?.ReportInfo("Starting DSC file activation"); | ||
_navigationService.NavigateTo(typeof(SetupFlowViewModel).FullName!); | ||
await _setupFlowViewModel.StartFileActivationFlowAsync(file); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Logger?.ReportError("Error executing the DSC activation flow", ex); | ||
} | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
using DevHome.Common.Services; | ||
using DevHome.Contracts.Services; | ||
using Microsoft.UI.Xaml.Navigation; | ||
using Microsoft.Windows.AppLifecycle; | ||
|
||
namespace DevHome.ViewModels; | ||
|
||
|
@@ -51,13 +52,16 @@ public ShellViewModel( | |
|
||
public async Task OnLoaded() | ||
{ | ||
if (await _localSettingsService.ReadSettingAsync<bool>(WellKnownSettingsKeys.IsNotFirstRun)) | ||
switch (AppInstance.GetCurrent().GetActivatedEventArgs().Kind) | ||
{ | ||
NavigationService.NavigateTo(NavigationService.DefaultPage); | ||
} | ||
else | ||
{ | ||
NavigationService.NavigateTo(typeof(WhatsNewViewModel).FullName!); | ||
case ExtendedActivationKind.File: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create an issue to consider moving this methods logic to an activation handler instead |
||
// Allow the file activation handler to navigate to the appropriate page. | ||
break; | ||
case ExtendedActivationKind.Launch: | ||
default: | ||
var isNotFirstRun = await _localSettingsService.ReadSettingAsync<bool>(WellKnownSettingsKeys.IsNotFirstRun); | ||
NavigationService.NavigateTo(isNotFirstRun ? NavigationService.DefaultPage : typeof(WhatsNewViewModel).FullName!); | ||
break; | ||
} | ||
} | ||
|
||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.