Skip to content

Commit

Permalink
Improve configure user experience (#3158)
Browse files Browse the repository at this point in the history
This change improves the `configure` user experience by:
1. Ensuring that the configuration file exists before doing any other initialization. This speeds up the time to getting the error dramatically if the file does not exist.
2. Creating a better mechanism to report progress of async activities and using it to give the user information on what is happening during the beginning of the `configure` command.
3. Adding specific error strings for every known configuration error and error source, as well as generic fallbacks.
4. Outputting the result description in the event that it is supplied, and informing the user that there is additional information in the log file in case it is truncated or the `Details` property is not empty.

It also logs the entire configuration file input stream to the log in verbose, and improves the progress reporting for the pre-check of the apply flow.

The initialization phases are reported as:
- "Initializing configuration system" while creating the server process and factory objects.
- "Reading configuration file" while parsing the configuration file (this is usually fast enough that you won't see it).
- "Retrieving configuration details" while we wait for the detailed information to come in about each configuration unit. This is reported repeatedly any time we are still waiting on more details.
  • Loading branch information
JohnMcPMS committed Apr 17, 2023
1 parent 02d2f93 commit 16fd465
Show file tree
Hide file tree
Showing 38 changed files with 478 additions and 81 deletions.
1 change: 0 additions & 1 deletion src/AppInstallerCLICore/ChannelStreams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace AppInstaller::CLI::Execution
{
using namespace Settings;
using namespace VirtualTerminal;

size_t GetConsoleWidth()
Expand Down
2 changes: 2 additions & 0 deletions src/AppInstallerCLICore/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "Command.h"
#include "Resources.h"
#include <winget/UserSettings.h>
#include <AppInstallerRuntime.h>
#include <winget/Locale.h>

using namespace std::string_view_literals;
using namespace AppInstaller::Utility::literals;
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/Commands/ConfigureCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace AppInstaller::CLI
void ConfigureCommand::ExecuteInternal(Execution::Context& context) const
{
context <<
VerifyFile(Execution::Args::Type::ConfigurationFile) <<
CreateConfigurationProcessor <<
OpenConfigurationSet <<
ShowConfigurationSet <<
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/Commands/ConfigureShowCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace AppInstaller::CLI
void ConfigureShowCommand::ExecuteInternal(Execution::Context& context) const
{
context <<
VerifyFile(Execution::Args::Type::ConfigurationFile) <<
CreateConfigurationProcessor <<
OpenConfigurationSet <<
ShowConfigurationSet;
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/Commands/RootCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.
#include "pch.h"
#include "RootCommand.h"
#include <AppInstallerRuntime.h>

#include "InstallCommand.h"
#include "ShowCommand.h"
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/Commands/ValidateCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Workflows/WorkflowBase.h"
#include "Workflows/DependenciesFlow.h"
#include "Resources.h"
#include <winget/ManifestYamlParser.h>

namespace AppInstaller::CLI
{
Expand Down
3 changes: 2 additions & 1 deletion src/AppInstallerCLICore/CompletionData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
#include "pch.h"
#include "CompletionData.h"
#include "Resources.h"
#include <AppInstallerLogging.h>
#include <AppInstallerErrors.h>

namespace AppInstaller::CLI
{
using namespace std::string_view_literals;
using namespace Utility::literals;
using namespace Settings;

// Completion takes in the following values:
// Word :: The token from the command line that is being targeted for completion.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the MIT License.
#include "pch.h"
#include "ConfigurationSetProcessorFactoryRemoting.h"
#include <AppInstallerLogging.h>
#include <AppInstallerRuntime.h>

using namespace winrt::Windows::Foundation;
using namespace winrt::Microsoft::Management::Configuration;
Expand Down
10 changes: 8 additions & 2 deletions src/AppInstallerCLICore/ExecutionProgress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ namespace AppInstaller::CLI::Execution

void ProgressVisualizerBase::SetMessage(std::string_view message)
{
m_message = message;
std::atomic_store(&m_message, std::make_shared<std::string>(message));
}

std::shared_ptr<std::string> ProgressVisualizerBase::GetMessage()
{
return std::atomic_load(&m_message);
}
}

Expand Down Expand Up @@ -213,7 +218,8 @@ namespace AppInstaller::CLI::Execution
ApplyStyle(i % repetitionCount, repetitionCount, true);
m_out << '\r' << indent << spinnerChars[i % ARRAYSIZE(spinnerChars)];
m_out.RestoreDefault();
m_out << ' ' << m_message << std::flush;
std::shared_ptr<std::string> message = this->GetMessage();
m_out << ' ' << (message ? *message : std::string{}) << std::flush;
Sleep(250);
}

Expand Down
4 changes: 3 additions & 1 deletion src/AppInstallerCLICore/ExecutionProgress.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <atomic>
#include <future>
#include <istream>
#include <memory>
#include <ostream>
#include <string>
#include <vector>
Expand All @@ -28,11 +29,11 @@ namespace AppInstaller::CLI::Execution
void SetStyle(AppInstaller::Settings::VisualStyle style) { m_style = style; }

void SetMessage(std::string_view message);
std::shared_ptr<std::string> GetMessage();

protected:
BaseStream& m_out;
Settings::VisualStyle m_style = AppInstaller::Settings::VisualStyle::Accent;
std::string m_message;

bool UseVT() const { return m_enableVT && m_style != AppInstaller::Settings::VisualStyle::NoVT; }

Expand All @@ -43,6 +44,7 @@ namespace AppInstaller::CLI::Execution

private:
bool m_enableVT = false;
std::shared_ptr<std::string> m_message;
};
}

Expand Down
42 changes: 42 additions & 0 deletions src/AppInstallerCLICore/ExecutionReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.
#include "pch.h"
#include "ExecutionReporter.h"
#include <AppInstallerErrors.h>


namespace AppInstaller::CLI::Execution
Expand Down Expand Up @@ -246,9 +247,50 @@ namespace AppInstaller::CLI::Execution
GetBasicOutputStream() << VirtualTerminal::Cursor::Visibility::EnableShow;
};

Reporter::AsyncProgressScope::AsyncProgressScope(Reporter& reporter, IProgressSink* sink, bool hideProgressWhenDone) :
m_reporter(reporter), m_callback(sink)
{
reporter.SetProgressCallback(&m_callback);
sink->BeginProgress();
m_hideProgressWhenDone = hideProgressWhenDone;
}

Reporter::AsyncProgressScope::~AsyncProgressScope()
{
m_reporter.get().SetProgressCallback(nullptr);
m_callback.GetSink()->EndProgress(m_hideProgressWhenDone);
}

ProgressCallback& Reporter::AsyncProgressScope::Callback()
{
return m_callback;
}

IProgressCallback* Reporter::AsyncProgressScope::operator->()
{
return &m_callback;
}

bool Reporter::AsyncProgressScope::HideProgressWhenDone() const
{
return m_hideProgressWhenDone;
}

void Reporter::AsyncProgressScope::HideProgressWhenDone(bool value)
{
m_hideProgressWhenDone.store(value);
}

std::unique_ptr<Reporter::AsyncProgressScope> Reporter::BeginAsyncProgress(bool hideProgressWhenDone)
{
return std::make_unique<AsyncProgressScope>(*this, m_progressSink.load(), hideProgressWhenDone);
}

void Reporter::SetProgressCallback(ProgressCallback* callback)
{
auto lock = m_progressCallbackLock.lock_exclusive();
// Attempting two progress operations at the same time; not supported.
THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_INVALID_STATE), m_progressCallback != nullptr && callback != nullptr);
m_progressCallback = callback;
}

Expand Down
41 changes: 30 additions & 11 deletions src/AppInstallerCLICore/ExecutionReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <atomic>
#include <iomanip>
#include <istream>
#include <memory>
#include <optional>
#include <ostream>
#include <string>
Expand Down Expand Up @@ -116,23 +117,41 @@ namespace AppInstaller::CLI::Execution
void SetProgressMessage(std::string_view message) override;
void EndProgress(bool hideProgressWhenDone) override;

// Contains the objects used for async progress and the lifetime of said progress.
struct AsyncProgressScope
{
AsyncProgressScope(Reporter& reporter, IProgressSink* sink, bool hideProgressWhenDone);
~AsyncProgressScope();

AsyncProgressScope(const AsyncProgressScope&) = delete;
AsyncProgressScope& operator=(const AsyncProgressScope&) = delete;

AsyncProgressScope(AsyncProgressScope&&) = delete;
AsyncProgressScope& operator=(AsyncProgressScope&&) = delete;

ProgressCallback& Callback();
IProgressCallback* operator->();

bool HideProgressWhenDone() const;
void HideProgressWhenDone(bool value);

private:
std::reference_wrapper<Reporter> m_reporter;
ProgressCallback m_callback;
std::atomic_bool m_hideProgressWhenDone;
};

// Runs the given callable of type: auto(IProgressCallback&)
template <typename F>
auto ExecuteWithProgress(F&& f, bool hideProgressWhenDone = false)
{
IProgressSink* sink = m_progressSink.load();
ProgressCallback callback(sink);
SetProgressCallback(&callback);
sink->BeginProgress();

auto hideProgress = wil::scope_exit([this, hideProgressWhenDone]()
{
SetProgressCallback(nullptr);
m_progressSink.load()->EndProgress(hideProgressWhenDone);
});
return f(callback);
auto progressScope = BeginAsyncProgress(hideProgressWhenDone);
return f(progressScope->Callback());
}

// Begins an asynchronous progress operation.
std::unique_ptr<AsyncProgressScope> BeginAsyncProgress(bool hideProgressWhenDone = false);

// Sets the in progress callback.
void SetProgressCallback(ProgressCallback* callback);

Expand Down
6 changes: 3 additions & 3 deletions src/AppInstallerCLICore/PackageCollection.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"

#include "PackageCollection.h"

#include "AppInstallerRuntime.h"
#include "winget/JsonSchemaValidation.h"
#include <AppInstallerLogging.h>
#include <AppInstallerRuntime.h>
#include <winget/JsonSchemaValidation.h>

#include "PackagesSchema.h"

Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/PortableInstaller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "Microsoft/PortableIndex.h"
#include "Microsoft/Schema/IPortableIndex.h"
#include <AppInstallerErrors.h>
#include <AppInstallerRuntime.h>

using namespace AppInstaller::Utility;
using namespace AppInstaller::Registry;
Expand Down
24 changes: 24 additions & 0 deletions src/AppInstallerCLICore/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,44 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationApply);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationAssert);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationDependencies);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationDescriptionWasTruncated);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationFailedToApply);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationFailedToGetDetails);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationFieldInvalid);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationFileArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationFileEmpty);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationFileInvalid);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationFileVersionUnknown);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationGettingDetails);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationInform);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationInitializing);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationLocal);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationModuleNameOnly);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationModuleWithDetails);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationReadingConfigFile);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationSettings);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationSuccessfullyApplied);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitAssertHadNegativeResult);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitFailed);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitFailedConfigSet);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitFailedDuringGet);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitFailedDuringSet);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitFailedDuringTest);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitFailedInternal);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitFailedPrecondition);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitFailedSystemState);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitFailedUnitProcessing);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitHasDuplicateIdentifier);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitHasMissingDependency);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitManuallySkipped);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitModuleConflict);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitModuleImportFailed);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitMultipleMatches);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitNotFound);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitNotFoundInModule);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitNotRunDueToDependency);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitNotRunDueToFailedAssert);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitReturnedInvalidResult);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitSkipped);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationWaitingOnAnother);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationWarning);
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/VTSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.
#include "pch.h"
#include "VTSupport.h"
#include <AppInstallerLogging.h>


namespace AppInstaller::CLI::VirtualTerminal
Expand Down
Loading

0 comments on commit 16fd465

Please sign in to comment.