mirror of
https://github.com/QL-Win/QuickLook.git
synced 2026-01-29 02:06:48 +08:00
Add restart button after plugin installation #1823
This commit is contained in:
@@ -7,6 +7,24 @@
|
||||
Height="200"
|
||||
FontSize="14"
|
||||
mc:Ignorable="d">
|
||||
<UserControl.Resources>
|
||||
<Style x:Key="UnderlineTextButtonStyle" TargetType="Button">
|
||||
<Setter Property="Background" Value="Transparent" />
|
||||
<Setter Property="BorderThickness" Value="0" />
|
||||
<Setter Property="Padding" Value="0" />
|
||||
<Setter Property="Cursor" Value="Hand" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource SystemControlForegroundAccentBrush}" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="Button">
|
||||
<TextBlock Foreground="{TemplateBinding Foreground}"
|
||||
Text="{TemplateBinding Content}"
|
||||
TextDecorations="Underline" />
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</UserControl.Resources>
|
||||
<Grid>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
@@ -51,15 +69,23 @@
|
||||
TextWrapping="WrapWithOverflow">
|
||||
I am a potato.
|
||||
</TextBlock>
|
||||
<Button x:Name="btnInstall"
|
||||
Grid.Row="6"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,20,0"
|
||||
HorizontalAlignment="Right"
|
||||
Content="Click here to install this plugin."
|
||||
FontWeight="SemiBold"
|
||||
Foreground="{DynamicResource WindowTextForegroundAlternative}"
|
||||
Style="{DynamicResource CaptionTextButtonStyle}" />
|
||||
<StackPanel Grid.Row="6"
|
||||
Grid.Column="1"
|
||||
Margin="0,0,20,0"
|
||||
HorizontalAlignment="Right"
|
||||
Orientation="Horizontal">
|
||||
<Button x:Name="btnInstall"
|
||||
Content="Click here to install this plugin."
|
||||
FontWeight="SemiBold"
|
||||
Foreground="{DynamicResource WindowTextForegroundAlternative}"
|
||||
Style="{DynamicResource CaptionTextButtonStyle}" />
|
||||
<Button x:Name="btnRestart"
|
||||
Margin="0,2,0,0"
|
||||
Content="Restart now..."
|
||||
Foreground="{DynamicResource AccentTextFillColorPrimaryBrush}"
|
||||
Style="{DynamicResource UnderlineTextButtonStyle}"
|
||||
Visibility="Collapsed" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -18,6 +18,8 @@
|
||||
using QuickLook.Common.ExtensionMethods;
|
||||
using QuickLook.Common.Plugin;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Threading.Tasks;
|
||||
@@ -42,6 +44,7 @@ public partial class PluginInfoPanel : UserControl
|
||||
ReadInfo();
|
||||
|
||||
btnInstall.Click += BtnInstall_Click;
|
||||
btnRestart.Click += BtnRestartNow_Click;
|
||||
}
|
||||
|
||||
private void BtnInstall_Click(object sender, RoutedEventArgs e)
|
||||
@@ -51,10 +54,37 @@ public partial class PluginInfoPanel : UserControl
|
||||
|
||||
var t = DoInstall();
|
||||
t.ContinueWith(_ =>
|
||||
Dispatcher.BeginInvoke(new Action(() => btnInstall.Content = "Done! Please restart QuickLook.")));
|
||||
Dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
btnInstall.Content = "Done! Please restart QuickLook.";
|
||||
btnRestart.Visibility = Visibility.Visible;
|
||||
}));
|
||||
t.Start();
|
||||
}
|
||||
|
||||
private void BtnRestartNow_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
using Process process = new()
|
||||
{
|
||||
StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AppDomain.CurrentDomain.FriendlyName),
|
||||
WorkingDirectory = Environment.CurrentDirectory,
|
||||
UseShellExecute = true,
|
||||
},
|
||||
};
|
||||
process.Start();
|
||||
}
|
||||
catch (Win32Exception)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Process.GetCurrentProcess().Kill();
|
||||
Environment.Exit('r' + 'e' + 's' + 't' + 'a' + 'r' + 't');
|
||||
}
|
||||
|
||||
private Task DoInstall()
|
||||
{
|
||||
var targetFolder = Path.Combine(App.UserPluginPath, _namespace);
|
||||
|
||||
Reference in New Issue
Block a user