mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 11:17:53 +01:00
[Hosts] Consolidate launch (#27173)
* consolidate hosts editor launch * improve readability * improve readability
This commit is contained in:
committed by
GitHub
parent
53e104e858
commit
b0cb40eaff
@@ -147,7 +147,17 @@ public:
|
||||
if (m_enabled && err == ERROR_SUCCESS)
|
||||
{
|
||||
Logger::trace(L"{} event was signaled", CommonSharedConstants::SHOW_HOSTS_EVENT);
|
||||
launch_process(false);
|
||||
|
||||
if (is_process_running())
|
||||
{
|
||||
bring_process_to_front();
|
||||
}
|
||||
else
|
||||
{
|
||||
launch_process(false);
|
||||
}
|
||||
|
||||
Trace::ActivateEditor();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -156,7 +166,17 @@ public:
|
||||
if (m_enabled && err == ERROR_SUCCESS)
|
||||
{
|
||||
Logger::trace(L"{} event was signaled", CommonSharedConstants::SHOW_HOSTS_ADMIN_EVENT);
|
||||
launch_process(true);
|
||||
|
||||
if (is_process_running())
|
||||
{
|
||||
bring_process_to_front();
|
||||
}
|
||||
else
|
||||
{
|
||||
launch_process(true);
|
||||
}
|
||||
|
||||
Trace::ActivateEditor();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -209,31 +229,8 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual void call_custom_action(const wchar_t* action) override
|
||||
virtual void call_custom_action(const wchar_t* /*action*/) override
|
||||
{
|
||||
try
|
||||
{
|
||||
PowerToysSettings::CustomActionObject action_object =
|
||||
PowerToysSettings::CustomActionObject::from_json_string(action);
|
||||
|
||||
if (is_process_running())
|
||||
{
|
||||
bring_process_to_front();
|
||||
}
|
||||
else if (action_object.get_name() == L"Launch")
|
||||
{
|
||||
launch_process(false);
|
||||
}
|
||||
else if (action_object.get_name() == L"LaunchAdministrator")
|
||||
{
|
||||
launch_process(true);
|
||||
}
|
||||
Trace::ActivateEditor();
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
Logger::error(L"Failed to parse action. {}", action);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void set_config(const wchar_t* /*config*/) override
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading;
|
||||
using global::Windows.System;
|
||||
using interop;
|
||||
@@ -10,7 +9,6 @@ using Microsoft.PowerToys.Settings.UI.Controls;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Telemetry.Events;
|
||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||
using Microsoft.PowerToys.Settings.UI.Views;
|
||||
using Microsoft.PowerToys.Telemetry;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
@@ -54,13 +52,14 @@ namespace Microsoft.PowerToys.Settings.UI.Flyout
|
||||
case "Hosts": // Launch Hosts
|
||||
{
|
||||
bool launchAdmin = SettingsRepository<HostsSettings>.GetInstance(new SettingsUtils()).SettingsConfig.Properties.LaunchAdministrator;
|
||||
var actionName = "Launch";
|
||||
if (!App.IsElevated && launchAdmin)
|
||||
{
|
||||
actionName = "LaunchAdministrator";
|
||||
}
|
||||
string eventName = !App.IsElevated && launchAdmin
|
||||
? Constants.ShowHostsAdminSharedEvent()
|
||||
: Constants.ShowHostsSharedEvent();
|
||||
|
||||
Views.ShellPage.SendDefaultIPCMessage("{\"action\":{\"Hosts\":{\"action_name\":\"" + actionName + "\", \"value\":\"\"}}}");
|
||||
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName))
|
||||
{
|
||||
eventHandle.Set();
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.Threading;
|
||||
using interop;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.OOBE.Enums;
|
||||
using Microsoft.PowerToys.Settings.UI.OOBE.ViewModel;
|
||||
@@ -35,14 +37,14 @@ namespace Microsoft.PowerToys.Settings.UI.OOBE.Views
|
||||
private void Launch_Hosts_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
|
||||
{
|
||||
bool launchAdmin = SettingsRepository<HostsSettings>.GetInstance(new SettingsUtils()).SettingsConfig.Properties.LaunchAdministrator;
|
||||
var actionName = "Launch";
|
||||
string eventName = !App.IsElevated && launchAdmin
|
||||
? Constants.ShowHostsAdminSharedEvent()
|
||||
: Constants.ShowHostsSharedEvent();
|
||||
|
||||
if (!App.IsElevated && launchAdmin)
|
||||
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName))
|
||||
{
|
||||
actionName = "LaunchAdministrator";
|
||||
eventHandle.Set();
|
||||
}
|
||||
|
||||
ShellPage.SendDefaultIPCMessage("{\"action\":{\"Hosts\":{\"action_name\":\"" + actionName + "\", \"value\":\"\"}}}");
|
||||
}
|
||||
|
||||
private void Launch_Settings_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
|
||||
|
||||
@@ -4,7 +4,9 @@
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using global::PowerToys.GPOWrapper;
|
||||
using interop;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
@@ -155,14 +157,14 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
|
||||
public void Launch()
|
||||
{
|
||||
var actionName = "Launch";
|
||||
string eventName = !_isElevated && LaunchAdministrator
|
||||
? Constants.ShowHostsAdminSharedEvent()
|
||||
: Constants.ShowHostsSharedEvent();
|
||||
|
||||
if (!_isElevated && LaunchAdministrator)
|
||||
using (var eventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName))
|
||||
{
|
||||
actionName = "LaunchAdministrator";
|
||||
eventHandle.Set();
|
||||
}
|
||||
|
||||
SendConfigMSG("{\"action\":{\"Hosts\":{\"action_name\":\"" + actionName + "\", \"value\":\"\"}}}");
|
||||
}
|
||||
|
||||
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
|
||||
Reference in New Issue
Block a user