mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 11:17:53 +01:00
fix shutdown didn't work issue
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
@@ -44,7 +45,7 @@ namespace WinAlfred.Plugin.System
|
||||
SubTitle = "Shutdown Computer",
|
||||
Score = 100,
|
||||
IcoPath = "Images\\exit.png",
|
||||
Action = () => ExitWindowsEx(EWX_SHUTDOWN,0)
|
||||
Action = () => Process.Start("shutdown","/s /t 0")
|
||||
});
|
||||
availableResults.Add(new Result
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Application x:Class="WinAlfred.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
StartupUri="MainWindow.xaml">
|
||||
>
|
||||
<Application.Resources>
|
||||
<ResourceDictionary>
|
||||
<Style x:Key="defaultQueryBoxStyle" BasedOn="{x:Null}" TargetType="{x:Type TextBox}">
|
||||
|
||||
@@ -1,11 +1,28 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace WinAlfred
|
||||
{
|
||||
/// <summary>
|
||||
/// App.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
|
||||
namespace WinAlfred
|
||||
{
|
||||
/// <summary>
|
||||
/// App.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
base.OnStartup(e);
|
||||
bool startupFlag;
|
||||
Mutex mutex = new Mutex(true, "WinAlfred", out startupFlag);
|
||||
if (!startupFlag)
|
||||
{
|
||||
Environment.Exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
MainWindow mainWindow = new MainWindow();
|
||||
mainWindow.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Input;
|
||||
using IWshRuntimeLibrary;
|
||||
using Microsoft.Win32;
|
||||
using WinAlfred.Commands;
|
||||
using WinAlfred.Helper;
|
||||
using WinAlfred.Plugin;
|
||||
@@ -101,12 +103,31 @@ namespace WinAlfred
|
||||
}
|
||||
}
|
||||
|
||||
public void SetAutoStart(bool IsAtuoRun)
|
||||
{
|
||||
string LnkPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "//WinAlfred.lnk";
|
||||
if (IsAtuoRun)
|
||||
{
|
||||
WshShell shell = new WshShell();
|
||||
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(LnkPath);
|
||||
shortcut.TargetPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
|
||||
shortcut.WorkingDirectory = Environment.CurrentDirectory;
|
||||
shortcut.WindowStyle = 1; //normal window
|
||||
shortcut.Description = "WinAlfred";
|
||||
shortcut.Save();
|
||||
}
|
||||
else
|
||||
{
|
||||
System.IO.File.Delete(LnkPath);
|
||||
}
|
||||
}
|
||||
|
||||
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Plugins.Init(this);
|
||||
cmdDispatcher = new Command(this);
|
||||
InitialTray();
|
||||
|
||||
SetAutoStart(true);
|
||||
//var engine = new Jurassic.ScriptEngine();
|
||||
//MessageBox.Show(engine.Evaluate("5 * 10 + 2").ToString());
|
||||
}
|
||||
|
||||
@@ -189,6 +189,17 @@
|
||||
<ItemGroup>
|
||||
<Resource Include="app.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<COMReference Include="IWshRuntimeLibrary">
|
||||
<Guid>{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B}</Guid>
|
||||
<VersionMajor>1</VersionMajor>
|
||||
<VersionMinor>0</VersionMinor>
|
||||
<Lcid>0</Lcid>
|
||||
<WrapperTool>tlbimp</WrapperTool>
|
||||
<Isolated>False</Isolated>
|
||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||
</COMReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
||||
<PropertyGroup>
|
||||
|
||||
Reference in New Issue
Block a user