Fix admin launch and settings visibility
This commit is contained in:
151
MainWindow.xaml
151
MainWindow.xaml
@@ -115,8 +115,8 @@
|
|||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="Auto"/>
|
<RowDefinition Height="Auto"/>
|
||||||
<RowDefinition Height="16"/>
|
<RowDefinition Height="16"/>
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="*"/>
|
<RowDefinition Height="*"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
<Border Background="{DynamicResource AppPanelBrush}"
|
<Border Background="{DynamicResource AppPanelBrush}"
|
||||||
@@ -159,83 +159,86 @@
|
|||||||
|
|
||||||
<Separator Grid.Row="1" VerticalAlignment="Center"/>
|
<Separator Grid.Row="1" VerticalAlignment="Center"/>
|
||||||
|
|
||||||
<Border Grid.Row="2"
|
<ScrollViewer Grid.Row="2"
|
||||||
Background="{DynamicResource AppPanelBrush}"
|
VerticalScrollBarVisibility="Auto"
|
||||||
BorderBrush="{DynamicResource AppBorderBrush}"
|
HorizontalScrollBarVisibility="Disabled">
|
||||||
BorderThickness="1"
|
<Border Background="{DynamicResource AppPanelBrush}"
|
||||||
CornerRadius="12"
|
|
||||||
Padding="12">
|
|
||||||
<Grid>
|
|
||||||
<Grid.ColumnDefinitions>
|
|
||||||
<ColumnDefinition Width="110"/>
|
|
||||||
<ColumnDefinition Width="*"/>
|
|
||||||
<ColumnDefinition Width="Auto"/>
|
|
||||||
</Grid.ColumnDefinitions>
|
|
||||||
<Grid.RowDefinitions>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
<RowDefinition Height="Auto"/>
|
|
||||||
</Grid.RowDefinitions>
|
|
||||||
|
|
||||||
<TextBlock Text="Title" VerticalAlignment="Center" Margin="0,0,8,8"/>
|
|
||||||
<TextBox x:Name="TitleBox" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,0,0,8"
|
|
||||||
TextChanged="PreviewField_Changed"/>
|
|
||||||
|
|
||||||
<TextBlock Text="Type" Grid.Row="1" VerticalAlignment="Center" Margin="0,0,8,8"/>
|
|
||||||
<ComboBox x:Name="TypeBox" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,0,0,8"
|
|
||||||
SelectionChanged="TypeBox_SelectionChanged"/>
|
|
||||||
|
|
||||||
<TextBlock Text="Target" Grid.Row="2" VerticalAlignment="Center" Margin="0,0,8,8"/>
|
|
||||||
<TextBox x:Name="TargetBox" Grid.Row="2" Grid.Column="1" Margin="0,0,8,8"
|
|
||||||
TextChanged="PreviewField_Changed"/>
|
|
||||||
<StackPanel Grid.Row="2" Grid.Column="2" Orientation="Horizontal" Margin="0,0,0,8">
|
|
||||||
<Button Content="File" Click="BrowseFile_Click" Margin="0,0,6,0" Padding="8,4"/>
|
|
||||||
<Button Content="Folder" Click="BrowseFolder_Click" Padding="8,4"/>
|
|
||||||
</StackPanel>
|
|
||||||
|
|
||||||
<TextBlock Text="Arguments" Grid.Row="3" VerticalAlignment="Center" Margin="0,0,8,8"/>
|
|
||||||
<TextBox x:Name="ArgumentsBox" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,0,0,8"/>
|
|
||||||
|
|
||||||
<TextBlock Text="Icon Path" Grid.Row="4" VerticalAlignment="Center" Margin="0,0,8,0"/>
|
|
||||||
<TextBox x:Name="IconPathBox" Grid.Row="4" Grid.Column="1" Margin="0,0,8,8"
|
|
||||||
TextChanged="PreviewField_Changed"/>
|
|
||||||
<StackPanel Grid.Row="4" Grid.Column="2" Orientation="Horizontal" Margin="0,0,0,8">
|
|
||||||
<Button Content="Icon" Click="BrowseIcon_Click" Padding="8,4" Margin="0,0,6,0"/>
|
|
||||||
<Button Content="Reset" Click="ResetIcon_Click" Padding="8,4"/>
|
|
||||||
</StackPanel>
|
|
||||||
|
|
||||||
<TextBlock Text="Selected Item Display" Grid.Row="5" VerticalAlignment="Center" Margin="0,0,8,8"/>
|
|
||||||
<ComboBox x:Name="ItemDisplayModeBox" Grid.Row="5" Grid.Column="1" Grid.ColumnSpan="2"
|
|
||||||
Margin="0,0,0,8" SelectionChanged="ItemDisplayModeBox_SelectionChanged"/>
|
|
||||||
|
|
||||||
<TextBlock Text="Launch Options" Grid.Row="6" VerticalAlignment="Center" Margin="0,0,8,8"/>
|
|
||||||
<CheckBox x:Name="RunAsAdminBox" Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="2"
|
|
||||||
Content="Run as administrator"
|
|
||||||
Margin="0,0,0,8"
|
|
||||||
Checked="RunAsAdminBox_Changed"
|
|
||||||
Unchecked="RunAsAdminBox_Changed"/>
|
|
||||||
|
|
||||||
<TextBlock Text="Preview" Grid.Row="7" VerticalAlignment="Top" Margin="0,4,8,0"/>
|
|
||||||
<Border Grid.Row="7" Grid.Column="1" Grid.ColumnSpan="2"
|
|
||||||
BorderThickness="1"
|
|
||||||
BorderBrush="{DynamicResource AppBorderBrush}"
|
BorderBrush="{DynamicResource AppBorderBrush}"
|
||||||
Background="{DynamicResource AppSurfaceBrush}"
|
BorderThickness="1"
|
||||||
CornerRadius="12"
|
CornerRadius="12"
|
||||||
Padding="10" MinHeight="76">
|
Padding="12">
|
||||||
<StackPanel>
|
<Grid>
|
||||||
<ContentControl x:Name="PreviewHost"/>
|
<Grid.ColumnDefinitions>
|
||||||
<TextBlock x:Name="PreviewNote" Margin="0,8,0,0"
|
<ColumnDefinition Width="110"/>
|
||||||
Foreground="{DynamicResource AppMutedTextBrush}"
|
<ColumnDefinition Width="*"/>
|
||||||
TextWrapping="Wrap"/>
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
<RowDefinition Height="Auto"/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
|
||||||
|
<TextBlock Text="Title" VerticalAlignment="Center" Margin="0,0,8,8"/>
|
||||||
|
<TextBox x:Name="TitleBox" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,0,0,8"
|
||||||
|
TextChanged="PreviewField_Changed"/>
|
||||||
|
|
||||||
|
<TextBlock Text="Type" Grid.Row="1" VerticalAlignment="Center" Margin="0,0,8,8"/>
|
||||||
|
<ComboBox x:Name="TypeBox" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,0,0,8"
|
||||||
|
SelectionChanged="TypeBox_SelectionChanged"/>
|
||||||
|
|
||||||
|
<TextBlock Text="Target" Grid.Row="2" VerticalAlignment="Center" Margin="0,0,8,8"/>
|
||||||
|
<TextBox x:Name="TargetBox" Grid.Row="2" Grid.Column="1" Margin="0,0,8,8"
|
||||||
|
TextChanged="PreviewField_Changed"/>
|
||||||
|
<StackPanel Grid.Row="2" Grid.Column="2" Orientation="Horizontal" Margin="0,0,0,8">
|
||||||
|
<Button Content="File" Click="BrowseFile_Click" Margin="0,0,6,0" Padding="8,4"/>
|
||||||
|
<Button Content="Folder" Click="BrowseFolder_Click" Padding="8,4"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|
||||||
|
<TextBlock Text="Arguments" Grid.Row="3" VerticalAlignment="Center" Margin="0,0,8,8"/>
|
||||||
|
<TextBox x:Name="ArgumentsBox" Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="2" Margin="0,0,0,8"/>
|
||||||
|
|
||||||
|
<TextBlock Text="Icon Path" Grid.Row="4" VerticalAlignment="Center" Margin="0,0,8,0"/>
|
||||||
|
<TextBox x:Name="IconPathBox" Grid.Row="4" Grid.Column="1" Margin="0,0,8,8"
|
||||||
|
TextChanged="PreviewField_Changed"/>
|
||||||
|
<StackPanel Grid.Row="4" Grid.Column="2" Orientation="Horizontal" Margin="0,0,0,8">
|
||||||
|
<Button Content="Icon" Click="BrowseIcon_Click" Padding="8,4" Margin="0,0,6,0"/>
|
||||||
|
<Button Content="Reset" Click="ResetIcon_Click" Padding="8,4"/>
|
||||||
|
</StackPanel>
|
||||||
|
|
||||||
|
<TextBlock Text="Selected Item Display" Grid.Row="5" VerticalAlignment="Center" Margin="0,0,8,8"/>
|
||||||
|
<ComboBox x:Name="ItemDisplayModeBox" Grid.Row="5" Grid.Column="1" Grid.ColumnSpan="2"
|
||||||
|
Margin="0,0,0,8" SelectionChanged="ItemDisplayModeBox_SelectionChanged"/>
|
||||||
|
|
||||||
|
<TextBlock Text="Launch Options" Grid.Row="6" VerticalAlignment="Center" Margin="0,0,8,8"/>
|
||||||
|
<CheckBox x:Name="RunAsAdminBox" Grid.Row="6" Grid.Column="1" Grid.ColumnSpan="2"
|
||||||
|
Content="Run as administrator"
|
||||||
|
Margin="0,0,0,8"
|
||||||
|
Checked="RunAsAdminBox_Changed"
|
||||||
|
Unchecked="RunAsAdminBox_Changed"/>
|
||||||
|
|
||||||
|
<TextBlock Text="Preview" Grid.Row="7" VerticalAlignment="Top" Margin="0,4,8,0"/>
|
||||||
|
<Border Grid.Row="7" Grid.Column="1" Grid.ColumnSpan="2"
|
||||||
|
BorderThickness="1"
|
||||||
|
BorderBrush="{DynamicResource AppBorderBrush}"
|
||||||
|
Background="{DynamicResource AppSurfaceBrush}"
|
||||||
|
CornerRadius="12"
|
||||||
|
Padding="10" MinHeight="76">
|
||||||
|
<StackPanel>
|
||||||
|
<ContentControl x:Name="PreviewHost"/>
|
||||||
|
<TextBlock x:Name="PreviewNote" Margin="0,8,0,0"
|
||||||
|
Foreground="{DynamicResource AppMutedTextBrush}"
|
||||||
|
TextWrapping="Wrap"/>
|
||||||
|
</StackPanel>
|
||||||
|
</Border>
|
||||||
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
</Grid>
|
</ScrollViewer>
|
||||||
</Border>
|
|
||||||
|
|
||||||
<TextBlock x:Name="StatusText" Grid.Row="3" Margin="4,14,4,0"
|
<TextBlock x:Name="StatusText" Grid.Row="3" Margin="4,14,4,0"
|
||||||
Foreground="{DynamicResource AppMutedTextBrush}"
|
Foreground="{DynamicResource AppMutedTextBrush}"
|
||||||
|
|||||||
@@ -276,18 +276,20 @@ public sealed class LauncherController : IDisposable
|
|||||||
}
|
}
|
||||||
|
|
||||||
string target = Environment.ExpandEnvironmentVariables(item.Target);
|
string target = Environment.ExpandEnvironmentVariables(item.Target);
|
||||||
|
bool runAsAdmin = item.RunAsAdmin && CanRunAsAdmin(item.Type);
|
||||||
|
string launchTarget = runAsAdmin ? ResolveExecutableTarget(target) : target;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ProcessStartInfo startInfo = new()
|
ProcessStartInfo startInfo = new()
|
||||||
{
|
{
|
||||||
FileName = target,
|
FileName = launchTarget,
|
||||||
Arguments = item.Arguments ?? "",
|
Arguments = item.Arguments ?? "",
|
||||||
UseShellExecute = true,
|
UseShellExecute = true,
|
||||||
WorkingDirectory = Directory.Exists(target) ? target : ConfigService.AppFolder
|
WorkingDirectory = Directory.Exists(target) ? target : ConfigService.AppFolder
|
||||||
};
|
};
|
||||||
|
|
||||||
if (item.RunAsAdmin && CanRunAsAdmin(item.Type))
|
if (runAsAdmin)
|
||||||
{
|
{
|
||||||
startInfo.Verb = "runas";
|
startInfo.Verb = "runas";
|
||||||
}
|
}
|
||||||
@@ -306,4 +308,32 @@ public sealed class LauncherController : IDisposable
|
|||||||
{
|
{
|
||||||
return itemType is LauncherItemType.App or LauncherItemType.File;
|
return itemType is LauncherItemType.App or LauncherItemType.File;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string ResolveExecutableTarget(string target)
|
||||||
|
{
|
||||||
|
if (Path.IsPathRooted(target) || Path.GetDirectoryName(target) is { Length: > 0 })
|
||||||
|
{
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
|
string[] searchFolders =
|
||||||
|
[
|
||||||
|
Environment.CurrentDirectory,
|
||||||
|
Environment.GetFolderPath(Environment.SpecialFolder.Windows),
|
||||||
|
Environment.GetFolderPath(Environment.SpecialFolder.System),
|
||||||
|
.. (Environment.GetEnvironmentVariable("PATH") ?? "")
|
||||||
|
.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach (string folder in searchFolders.Where(Directory.Exists).Distinct(StringComparer.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
string candidate = Path.Combine(folder, target);
|
||||||
|
if (File.Exists(candidate))
|
||||||
|
{
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return target;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,8 @@
|
|||||||
<Authors>Ray Berezowski</Authors>
|
<Authors>Ray Berezowski</Authors>
|
||||||
<ApplicationIcon>Assets\AppIcon.ico</ApplicationIcon>
|
<ApplicationIcon>Assets\AppIcon.ico</ApplicationIcon>
|
||||||
<Version>1.0.1</Version>
|
<Version>1.0.1</Version>
|
||||||
<AssemblyVersion>1.0.1.18</AssemblyVersion>
|
<AssemblyVersion>1.0.1.19</AssemblyVersion>
|
||||||
<FileVersion>1.0.1.18</FileVersion>
|
<FileVersion>1.0.1.19</FileVersion>
|
||||||
<InformationalVersion>1.0.1</InformationalVersion>
|
<InformationalVersion>1.0.1</InformationalVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user