mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
Refactoring "startup with windows" option.
This commit is contained in:
@@ -1,24 +1,21 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Permissions;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Microsoft.Win32;
|
||||
using Wox.Helper;
|
||||
using IWshRuntimeLibrary;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.UserSettings;
|
||||
using Application = System.Windows.Forms.Application;
|
||||
using File = System.IO.File;
|
||||
using MessageBox = System.Windows.MessageBox;
|
||||
|
||||
namespace Wox
|
||||
{
|
||||
public partial class SettingWidow : Window
|
||||
{
|
||||
string woxLinkPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "wox.lnk");
|
||||
public MainWindow MainWindow;
|
||||
|
||||
public SettingWidow()
|
||||
@@ -33,8 +30,6 @@ namespace Wox
|
||||
Loaded += Setting_Loaded;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void Setting_Loaded(object sender, RoutedEventArgs ev)
|
||||
{
|
||||
ctlHotkey.OnHotkeyChanged += ctlHotkey_OnHotkeyChanged;
|
||||
@@ -60,7 +55,7 @@ namespace Wox
|
||||
cbReplaceWinR.IsChecked = CommonStorage.Instance.UserSetting.ReplaceWinR;
|
||||
webSearchView.ItemsSource = CommonStorage.Instance.UserSetting.WebSearches;
|
||||
lvCustomHotkey.ItemsSource = CommonStorage.Instance.UserSetting.CustomPluginHotkeys;
|
||||
cbStartWithWindows.IsChecked = CommonStorage.Instance.UserSetting.StartWoxOnSystemStartup;
|
||||
cbStartWithWindows.IsChecked = File.Exists(woxLinkPath);
|
||||
}
|
||||
|
||||
public void ReloadWebSearchView()
|
||||
@@ -121,50 +116,30 @@ namespace Wox
|
||||
|
||||
private void CbStartWithWindows_OnChecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!CommonStorage.Instance.UserSetting.StartWoxOnSystemStartup)
|
||||
{
|
||||
CommonStorage.Instance.UserSetting.StartWoxOnSystemStartup = true;
|
||||
OnStartWithWindowsChecked();
|
||||
CommonStorage.Instance.Save();
|
||||
}
|
||||
CreateStartupFolderShortcut();
|
||||
}
|
||||
|
||||
private void CbStartWithWindows_OnUnchecked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
CommonStorage.Instance.UserSetting.StartWoxOnSystemStartup = false;
|
||||
OnStartWithWindowUnChecked();
|
||||
CommonStorage.Instance.Save();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private void OnStartWithWindowUnChecked()
|
||||
{
|
||||
UAC.ExecuteAdminMethod(() => SetStartup(false));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private void OnStartWithWindowsChecked()
|
||||
{
|
||||
UAC.ExecuteAdminMethod(() => SetStartup(true));
|
||||
}
|
||||
|
||||
private void SetStartup(bool startup)
|
||||
{
|
||||
RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
|
||||
|
||||
if (rk != null)
|
||||
if (File.Exists(woxLinkPath))
|
||||
{
|
||||
if (startup)
|
||||
{
|
||||
rk.SetValue("Wox", Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Wox.exe hidestart"));
|
||||
}
|
||||
else
|
||||
{
|
||||
rk.DeleteValue("Wox", false);
|
||||
}
|
||||
File.Delete(woxLinkPath);
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateStartupFolderShortcut()
|
||||
{
|
||||
WshShellClass wshShell = new WshShellClass();
|
||||
|
||||
IWshShortcut shortcut = (IWshShortcut)wshShell.CreateShortcut(woxLinkPath);
|
||||
shortcut.TargetPath = Application.ExecutablePath;
|
||||
shortcut.Arguments = "hideStart";
|
||||
shortcut.WorkingDirectory = Application.StartupPath;
|
||||
shortcut.Description = "Launch Wox";
|
||||
shortcut.IconLocation = Application.StartupPath + @"\App.ico";
|
||||
shortcut.Save();
|
||||
}
|
||||
|
||||
void ctlHotkey_OnHotkeyChanged(object sender, System.EventArgs e)
|
||||
{
|
||||
if (ctlHotkey.CurrentHotkeyAvailable)
|
||||
@@ -192,7 +167,7 @@ namespace Wox
|
||||
{
|
||||
CustomPluginHotkey item = lvCustomHotkey.SelectedItem as CustomPluginHotkey;
|
||||
if (item != null &&
|
||||
MessageBox.Show("Are your sure to delete " + item.Hotkey + " plugin hotkey?","Delete Custom Plugin Hotkey",
|
||||
MessageBox.Show("Are your sure to delete " + item.Hotkey + " plugin hotkey?", "Delete Custom Plugin Hotkey",
|
||||
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
|
||||
{
|
||||
CommonStorage.Instance.UserSetting.CustomPluginHotkeys.Remove(item);
|
||||
|
||||
@@ -290,6 +290,26 @@
|
||||
<Resource Include="Images\logoff.png" />
|
||||
<Resource Include="Images\work.png" />
|
||||
</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>
|
||||
<COMReference Include="Shell32">
|
||||
<Guid>{50A7E9B0-70EF-11D1-B75A-00A0C90564FE}</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