Add run as administrator option
This commit is contained in:
@@ -616,6 +616,7 @@ public partial class MainWindow : Window
|
||||
IconPathBox.Text = item.IconPath ?? "";
|
||||
loadedAutoIconPath = GetAutomaticIconPath(item);
|
||||
ItemDisplayModeBox.SelectedItem = item.DisplayMode;
|
||||
RunAsAdminBox.IsChecked = item.RunAsAdmin;
|
||||
UpdateTargetAvailability();
|
||||
isLoadingSelection = false;
|
||||
UpdatePreview();
|
||||
@@ -633,6 +634,7 @@ public partial class MainWindow : Window
|
||||
IconPathBox.Text = "";
|
||||
loadedAutoIconPath = null;
|
||||
ItemDisplayModeBox.SelectedItem = controller?.Config.DisplayMode;
|
||||
RunAsAdminBox.IsChecked = false;
|
||||
UpdateTargetAvailability();
|
||||
isLoadingSelection = false;
|
||||
UpdatePreview();
|
||||
@@ -657,6 +659,7 @@ public partial class MainWindow : Window
|
||||
{
|
||||
selectedItem.DisplayMode = itemMode;
|
||||
}
|
||||
selectedItem.RunAsAdmin = LauncherController.CanRunAsAdmin(selectedItem.Type) && RunAsAdminBox.IsChecked == true;
|
||||
|
||||
if (selectedItem.Type != LauncherItemType.Menu)
|
||||
{
|
||||
@@ -966,6 +969,7 @@ public partial class MainWindow : Window
|
||||
IconPath = item.IconPath,
|
||||
IsFavorite = item.IsFavorite,
|
||||
IsDisabled = item.IsDisabled,
|
||||
RunAsAdmin = item.RunAsAdmin,
|
||||
DisplayMode = item.DisplayMode,
|
||||
Children = item.Children.Select(child => DuplicateItem(child, renameRoot: false)).ToList()
|
||||
};
|
||||
@@ -1781,6 +1785,20 @@ public partial class MainWindow : Window
|
||||
ThemeService.Apply(scheme);
|
||||
}
|
||||
|
||||
private void RunAsAdminBox_Changed(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (isLoadingSelection)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UpdatePreview();
|
||||
if (selectedItem is not null)
|
||||
{
|
||||
StatusText.Text = "Click Save to keep the selected item launch options.";
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureAutomaticIconPath()
|
||||
{
|
||||
if (TypeBox.SelectedItem is LauncherItemType.Menu)
|
||||
@@ -1860,6 +1878,8 @@ public partial class MainWindow : Window
|
||||
IconPath = string.IsNullOrWhiteSpace(IconPathBox.Text) ? null : IconPathBox.Text.Trim(),
|
||||
IsFavorite = selectedItem.IsFavorite,
|
||||
IsDisabled = selectedItem.IsDisabled,
|
||||
RunAsAdmin = LauncherController.CanRunAsAdmin(TypeBox.SelectedItem is LauncherItemType itemType ? itemType : LauncherItemType.App) &&
|
||||
RunAsAdminBox.IsChecked == true,
|
||||
DisplayMode = ItemDisplayModeBox.SelectedItem is LauncherDisplayMode mode
|
||||
? mode
|
||||
: selectedItem.DisplayMode
|
||||
@@ -1926,13 +1946,20 @@ public partial class MainWindow : Window
|
||||
private void UpdateTargetAvailability()
|
||||
{
|
||||
bool isMenu = TypeBox.SelectedItem is LauncherItemType.Menu;
|
||||
bool canRunAsAdmin = TypeBox.SelectedItem is LauncherItemType itemType && LauncherController.CanRunAsAdmin(itemType);
|
||||
TargetBox.IsEnabled = !isMenu;
|
||||
ArgumentsBox.IsEnabled = !isMenu;
|
||||
RunAsAdminBox.IsEnabled = canRunAsAdmin;
|
||||
if (isMenu && !isLoadingSelection)
|
||||
{
|
||||
TargetBox.Text = "";
|
||||
ArgumentsBox.Text = "";
|
||||
}
|
||||
|
||||
if (!canRunAsAdmin && !isLoadingSelection)
|
||||
{
|
||||
RunAsAdminBox.IsChecked = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user