Skip to content

Commit

Permalink
pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dabhattimsft authored and Darshak Bhatti committed May 15, 2024
1 parent 49c1871 commit 0f564ee
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 35 deletions.
9 changes: 9 additions & 0 deletions tools/Utilities/src/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@
<value>Hosts File Editor</value>
<comment>;Locked={"Hosts"}</comment>
</data>
<data name="LaunchButton.Text" xml:space="preserve">
<value>Launch</value>
</data>
<data name="NavigationPane.Content" xml:space="preserve">
<value>Utilities</value>
<comment>Utilities</comment>
Expand All @@ -146,4 +149,10 @@
<data name="RegistryPreviewUtilityTitle" xml:space="preserve">
<value>Registry Preview</value>
</data>
<data name="SupportsLaunchAsAdmin.OffContent" xml:space="preserve">
<value>Launch as administrator</value>
</data>
<data name="SupportsLaunchAsAdmin.OnContent" xml:space="preserve">
<value>Launch as administrator</value>
</data>
</root>
6 changes: 3 additions & 3 deletions tools/Utilities/src/ViewModels/UtilitiesMainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ public UtilitiesMainPageViewModel(IExperimentationService experimentationService
Description = stringResource.GetLocalized("HostsFileEditorUtilityDesc"),
NavigateUri = "https://go.microsoft.com/fwlink/?Linkid=2271355",
ImageSource = Path.Combine(AppContext.BaseDirectory, "Assets\\HostsUILib", "Hosts.ico"),
LaunchAsAdminVisibility = Microsoft.UI.Xaml.Visibility.Visible,
SupportsLaunchAsAdmin = Microsoft.UI.Xaml.Visibility.Visible,
},
new(Path.Combine(appExAliasAbsFolderPath, "DevHome.RegistryPreviewApp.exe"))
{
Title = stringResource.GetLocalized("RegistryPreviewUtilityTitle"),
Description = stringResource.GetLocalized("RegistryPreviewUtilityDesc"),
NavigateUri = "https://go.microsoft.com/fwlink/?Linkid=2270966",
ImageSource = Path.Combine(AppContext.BaseDirectory, "Assets\\RegistryPreview", "RegistryPreview.ico"),
LaunchAsAdminVisibility = Microsoft.UI.Xaml.Visibility.Collapsed,
SupportsLaunchAsAdmin = Microsoft.UI.Xaml.Visibility.Collapsed,
},
new(Path.Combine(appExAliasAbsFolderPath, "DevHome.EnvironmentVariablesApp.exe"))
{
Title = stringResource.GetLocalized("EnvVariablesEditorUtilityTitle"),
Description = stringResource.GetLocalized("EnvVariablesEditorUtilityDesc"),
NavigateUri = "https://go.microsoft.com/fwlink/?Linkid=2270894",
ImageSource = Path.Combine(AppContext.BaseDirectory, "Assets\\EnvironmentVariables", "EnvironmentVariables.ico"),
LaunchAsAdminVisibility = Microsoft.UI.Xaml.Visibility.Visible,
SupportsLaunchAsAdmin = Microsoft.UI.Xaml.Visibility.Visible,
},
new(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), $"Microsoft\\WindowsApps\\{Package.Current.Id.FamilyName}\\devhome.pi.exe"), experimentationService, "ProjectIronsidesExperiment")
{
Expand Down
34 changes: 8 additions & 26 deletions tools/Utilities/src/ViewModels/UtilityViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Windows.Input;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using DevHome.Common.Services;
using DevHome.Telemetry;
Expand All @@ -14,7 +15,7 @@

namespace DevHome.Utilities.ViewModels;

public class UtilityViewModel : INotifyPropertyChanged
public partial class UtilityViewModel : ObservableObject
{
#nullable enable

Expand All @@ -39,8 +40,6 @@ public bool Visible
}
}

private bool launchAsAdmin;

public string Title { get; set; }

public string Description { get; set; }
Expand All @@ -51,27 +50,10 @@ public bool Visible

public ICommand LaunchCommand { get; set; }

public Visibility LaunchAsAdminVisibility { get; set; }

public bool LaunchAsAdmin
{
get => launchAsAdmin;

set
{
if (launchAsAdmin != value)
{
launchAsAdmin = value;
}
}
}

public event PropertyChangedEventHandler PropertyChanged;
public Visibility SupportsLaunchAsAdmin { get; set; }

protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
[ObservableProperty]
private bool _launchAsAdmin;

#nullable enable
public UtilityViewModel(string exeName, IExperimentationService? experimentationService = null, string? experimentalFeature = null)
Expand All @@ -86,15 +68,15 @@ public UtilityViewModel(string exeName, IExperimentationService? experimentation

private void Launch()
{
_log.Information($"Launching {_exeName}, as admin: {launchAsAdmin}");
_log.Information($"Launching {_exeName}, as admin: {LaunchAsAdmin}");

// We need to start the process with ShellExecute to run elevated
var processStartInfo = new ProcessStartInfo
{
FileName = _exeName,
UseShellExecute = true,

Verb = launchAsAdmin ? "runas" : "open",
Verb = LaunchAsAdmin ? "runas" : "open",
};

try
Expand All @@ -111,6 +93,6 @@ private void Launch()
_log.Error(ex, "Failed to start process {ExeName}", _exeName);
}

TelemetryFactory.Get<DevHome.Telemetry.ITelemetry>().Log("Utilities_UtilitiesLaunchEvent", LogLevel.Critical, new UtilitiesLaunchEvent(Title, launchAsAdmin), null);
TelemetryFactory.Get<DevHome.Telemetry.ITelemetry>().Log("Utilities_UtilitiesLaunchEvent", LogLevel.Critical, new UtilitiesLaunchEvent(Title, LaunchAsAdmin), null);
}
}
10 changes: 4 additions & 6 deletions tools/Utilities/src/Views/UtilityView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@
</StackPanel>
</ScrollViewer>

<SplitButton
<ToggleSwitch
x:Uid="SupportsLaunchAsAdmin"
Grid.Row="2"
IsOn="{x:Bind ViewModel.LaunchAsAdmin, Mode=TwoWay}"
Visibility="{x:Bind ViewModel.LaunchAsAdminVisibility, Mode=OneWay}"
OnContent="Launch as administrator"
OffContent="Launch as administrator"
Visibility="{x:Bind ViewModel.SupportsLaunchAsAdmin, Mode=OneWay}"
Margin="15 0 0 5"/>

<Button
Expand All @@ -74,8 +73,7 @@
Command="{x:Bind ViewModel.LaunchCommand}">

<StackPanel Orientation="Horizontal">
<TextBlock Text="Launch" Margin="0 0 5 0" />
<FontIcon Glyph="&#xE8A7;" FontSize="12" />
<TextBlock x:Uid="LaunchButton" />
</StackPanel>
</Button>

Expand Down

0 comments on commit 0f564ee

Please sign in to comment.