Hot-reload the elevated state?

This commit is contained in:
Mike Griese 2021-09-02 11:12:07 -05:00
parent 58c6646132
commit e5dc64e085
2 changed files with 8 additions and 12 deletions

View file

@ -869,9 +869,6 @@ namespace winrt::TerminalApp::implementation
void AppLogic::_RegisterSettingsChange()
{
const std::filesystem::path settingsPath{ std::wstring_view{ CascadiaSettings::SettingsPath() } };
const std::filesystem::path statePath{ std::wstring_view{ ApplicationState::SharedInstance().FilePath() } };
// const std::filesystem::path elevatedStatePath{ std::wstring_view{ ElevatedState::SharedInstance().FilePath() } };
_reader.create(
settingsPath.parent_path().c_str(),
false,
@ -880,14 +877,17 @@ namespace winrt::TerminalApp::implementation
// editors, who will write a temp file, then rename it to be the
// actual file you wrote. So listen for that too.
wil::FolderChangeEvents::FileName | wil::FolderChangeEvents::LastWriteTime,
[=](wil::FolderChangeEvent, PCWSTR fileModified) {
[this, settingsPath](wil::FolderChangeEvent, PCWSTR fileModified) {
static const std::filesystem::path statePath{ std::wstring_view{ ApplicationState::SharedInstance().FilePath() } };
static const std::filesystem::path elevatedStatePath{ std::wstring_view{ ElevatedState::SharedInstance().FilePath() } };
const auto modifiedBasename = std::filesystem::path{ fileModified }.filename();
if (modifiedBasename == settingsPath.filename())
{
_reloadSettings->Run();
}
else if (modifiedBasename == statePath.filename() /*|| modifiedBasename == elevatedStatePath.filename()*/)
else if (modifiedBasename == statePath.filename() || modifiedBasename == elevatedStatePath.filename())
{
_reloadState();
}

View file

@ -1313,25 +1313,21 @@ namespace winrt::TerminalApp::implementation
bool TerminalPage::_shouldPromptForCommandline(const winrt::hstring& cmdline) const
{
bool doAdminWarning = true;
if (_isElevated())
{
bool commandlineWasAllowed = false;
if (const auto& allowedCommandlines{ ElevatedState::SharedInstance().AllowedCommandlines() })
{
for (const auto& approved : allowedCommandlines)
{
if (approved == cmdline)
{
commandlineWasAllowed = true;
break;
return false;
}
}
}
doAdminWarning = !commandlineWasAllowed;
}
return doAdminWarning;
return true; // TODO! Change this to false. This is defaulted to true for testing.
}
// Method Description: