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

Enforce single install across winget processes #3118

Merged
merged 5 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ corecrt
count'th
countof
countryregion
CPIL
cplusplus
createmanifestmetadata
cswinrt
Expand Down
5 changes: 5 additions & 0 deletions src/AppInstallerCLICore/COMContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ namespace AppInstaller::CLI::Execution
FireCallbacks(ReportType::Progressing, current, maximum, progressType, m_executionStage);
}

void COMContext::SetProgressMessage(std::string_view)
{
// TODO: Consider sending message to COM progress
}

void COMContext::EndProgress(bool)
{
FireCallbacks(ReportType::EndProgress, 0, 0, ProgressType::None, m_executionStage);
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/COMContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ namespace AppInstaller::CLI::Execution
// IProgressSink
void BeginProgress() override;
void OnProgress(uint64_t current, uint64_t maximum, ProgressType type) override;
void SetProgressMessage(std::string_view message) override;
void EndProgress(bool) override;

//Execution::Context
Expand Down
40 changes: 24 additions & 16 deletions src/AppInstallerCLICore/ExecutionProgress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@ namespace AppInstaller::CLI::Execution
LOG_HR(E_UNEXPECTED);
}
}

void ProgressVisualizerBase::ClearLine()
{
if (UseVT())
{
m_out << TextModification::EraseLineEntirely << '\r';
}
else
{
// Best effort when no VT (arbitrary number of spaces that seems to work)
m_out << "\r \r";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: How about something like m_out << '\r' << std::string(N, ' ') << '\r'; so that we know how many spaces there are and can extend it if needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to get the current console width.

}
}

void ProgressVisualizerBase::SetMessage(std::string_view message)
{
m_message = message;
}
}

void IndefiniteSpinner::ShowSpinner()
Expand Down Expand Up @@ -188,17 +206,19 @@ namespace AppInstaller::CLI::Execution
}

// Indent two spaces for the spinner, but three here so that we can overwrite it in the loop.
m_out << " ";
std::string_view indent = " ";

for (size_t i = 0; !m_canceled; ++i)
{
constexpr size_t repetitionCount = 20;
ApplyStyle(i % repetitionCount, repetitionCount, true);
m_out << '\b' << spinnerChars[i % ARRAYSIZE(spinnerChars)] << std::flush;
m_out << '\r' << indent << spinnerChars[i % ARRAYSIZE(spinnerChars)];
m_out.RestoreDefault();
m_out << ' ' << m_message << std::flush;
Sleep(250);
}

m_out << "\b \r";
ClearLine();

if (UseVT())
{
Expand All @@ -217,6 +237,7 @@ namespace AppInstaller::CLI::Execution
ClearLine();
}

// TODO: Progress bar does not currently use message
if (UseVT())
{
ShowProgressWithVT(current, maximum, type);
Expand Down Expand Up @@ -255,19 +276,6 @@ namespace AppInstaller::CLI::Execution
}
}

void ProgressBar::ClearLine()
{
if (UseVT())
{
m_out << TextModification::EraseLineEntirely << '\r';
}
else
{
// Best effort when no VT (arbitrary number of spaces that seems to work)
m_out << "\r \r";
}
}

void ProgressBar::ShowProgressNoVT(uint64_t current, uint64_t maximum, ProgressType type)
{
m_out << "\r ";
Expand Down
9 changes: 5 additions & 4 deletions src/AppInstallerCLICore/ExecutionProgress.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,20 @@ namespace AppInstaller::CLI::Execution

void SetStyle(AppInstaller::Settings::VisualStyle style) { m_style = style; }

void SetMessage(std::string_view message);

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; }

// Applies the selected visual style.
void ApplyStyle(size_t i, size_t max, bool foregroundOnly);

void ClearLine();

private:
bool m_enableVT = false;
};
Expand Down Expand Up @@ -70,14 +75,10 @@ namespace AppInstaller::CLI::Execution

void EndProgress(bool hideProgressWhenDone);

void SetStyle(AppInstaller::Settings::VisualStyle style) { m_style = style; }

private:
std::atomic<bool> m_isVisible = false;
uint64_t m_lastCurrent = 0;

void ClearLine();

void ShowProgressNoVT(uint64_t current, uint64_t maximum, ProgressType type);

void ShowProgressWithVT(uint64_t current, uint64_t maximum, ProgressType type);
Expand Down
14 changes: 14 additions & 0 deletions src/AppInstallerCLICore/ExecutionReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,19 @@ namespace AppInstaller::CLI::Execution
}
}

void Reporter::SetProgressMessage(std::string_view message)
{
if (m_spinner)
{
m_spinner->SetMessage(message);
}

if (m_progressBar)
{
m_progressBar->SetMessage(message);
}
}

void Reporter::BeginProgress()
{
GetBasicOutputStream() << VirtualTerminal::Cursor::Visibility::DisableShow;
Expand All @@ -229,6 +242,7 @@ namespace AppInstaller::CLI::Execution
{
m_progressBar->EndProgress(hideProgressWhenDone);
}
SetProgressMessage({});
GetBasicOutputStream() << VirtualTerminal::Cursor::Visibility::EnableShow;
};

Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/ExecutionReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ namespace AppInstaller::CLI::Execution
// IProgressSink
void BeginProgress() override;
void OnProgress(uint64_t current, uint64_t maximum, ProgressType type) override;
void SetProgressMessage(std::string_view message) override;
void EndProgress(bool hideProgressWhenDone) override;

// Runs the given callable of type: auto(IProgressCallback&)
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(InstallFlowStartingPackageInstall);
WINGET_DEFINE_RESOURCE_STRINGID(InstallLocationNotProvided);
WINGET_DEFINE_RESOURCE_STRINGID(InstallScopeDescription);
WINGET_DEFINE_RESOURCE_STRINGID(InstallWaitingOnAnother);
WINGET_DEFINE_RESOURCE_STRINGID(InteractiveArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(InvalidAliasError);
WINGET_DEFINE_RESOURCE_STRINGID(InvalidArgumentSpecifierError);
Expand Down
Loading