mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-06 03:07:54 +08:00
fix #625
This commit is contained in:
parent
c42892ee35
commit
cddfd1b319
@ -43,7 +43,7 @@ namespace Wox.Core.UserSettings
|
|||||||
public bool DontPromptUpdateMsg { get; set; }
|
public bool DontPromptUpdateMsg { get; set; }
|
||||||
public bool EnableUpdateLog { get; set; }
|
public bool EnableUpdateLog { get; set; }
|
||||||
|
|
||||||
public bool StartWoxOnSystemStartup { get; set; }
|
public bool StartWoxOnSystemStartup { get; set; } = true;
|
||||||
public bool HideOnStartup { get; set; }
|
public bool HideOnStartup { get; set; }
|
||||||
public bool LeaveCmdOpen { get; set; }
|
public bool LeaveCmdOpen { get; set; }
|
||||||
public bool HideWhenDeactive { get; set; }
|
public bool HideWhenDeactive { get; set; }
|
||||||
|
@ -58,12 +58,24 @@ namespace Wox
|
|||||||
|
|
||||||
RegisterExitEvents();
|
RegisterExitEvents();
|
||||||
|
|
||||||
|
AutoStartup();
|
||||||
AutoUpdates();
|
AutoUpdates();
|
||||||
|
|
||||||
window.Show();
|
window.Show();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AutoStartup()
|
||||||
|
{
|
||||||
|
if (_settings.StartWoxOnSystemStartup)
|
||||||
|
{
|
||||||
|
if (!SettingWindow.StartupSet())
|
||||||
|
{
|
||||||
|
SettingWindow.SetStartup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void AutoUpdates()
|
private void AutoUpdates()
|
||||||
{
|
{
|
||||||
if (_settings.AutoUpdates)
|
if (_settings.AutoUpdates)
|
||||||
|
@ -30,6 +30,7 @@ namespace Wox
|
|||||||
{
|
{
|
||||||
public partial class SettingWindow
|
public partial class SettingWindow
|
||||||
{
|
{
|
||||||
|
private const string StartupPath = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
|
||||||
public readonly IPublicAPI _api;
|
public readonly IPublicAPI _api;
|
||||||
bool settingsLoaded;
|
bool settingsLoaded;
|
||||||
private Dictionary<ISettingProvider, Control> featureControls = new Dictionary<ISettingProvider, Control>();
|
private Dictionary<ISettingProvider, Control> featureControls = new Dictionary<ISettingProvider, Control>();
|
||||||
@ -117,7 +118,7 @@ namespace Wox
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
cbStartWithWindows.IsChecked = CheckApplicationIsStartupWithWindow();
|
cbStartWithWindows.IsChecked = _settings.StartWoxOnSystemStartup;
|
||||||
comboMaxResultsToShow.SelectionChanged += (o, e) =>
|
comboMaxResultsToShow.SelectionChanged += (o, e) =>
|
||||||
{
|
{
|
||||||
_settings.MaxResultsToShow = (int)comboMaxResultsToShow.SelectedItem;
|
_settings.MaxResultsToShow = (int)comboMaxResultsToShow.SelectedItem;
|
||||||
@ -227,43 +228,47 @@ namespace Wox
|
|||||||
|
|
||||||
private void CbStartWithWindows_OnChecked(object sender, RoutedEventArgs e)
|
private void CbStartWithWindows_OnChecked(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
AddApplicationToStartup();
|
SetStartup();
|
||||||
_settings.StartWoxOnSystemStartup = true;
|
_settings.StartWoxOnSystemStartup = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CbStartWithWindows_OnUnchecked(object sender, RoutedEventArgs e)
|
private void CbStartWithWindows_OnUnchecked(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
RemoveApplicationFromStartup();
|
RemoveStartup();
|
||||||
_settings.StartWoxOnSystemStartup = false;
|
_settings.StartWoxOnSystemStartup = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddApplicationToStartup()
|
public static void SetStartup()
|
||||||
{
|
{
|
||||||
using (
|
using (var key = Registry.CurrentUser.OpenSubKey(StartupPath, true))
|
||||||
RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
|
|
||||||
true))
|
|
||||||
{
|
{
|
||||||
key.SetValue("Wox", "\"" + Infrastructure.Wox.ProgramPath + "\" --hidestart");
|
var executable = Path.Combine(Infrastructure.Wox.ProgramPath, Infrastructure.Wox.Name + ".exe");
|
||||||
|
key?.SetValue(Infrastructure.Wox.Name, executable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RemoveApplicationFromStartup()
|
private void RemoveStartup()
|
||||||
{
|
{
|
||||||
using (
|
using (var key = Registry.CurrentUser.OpenSubKey(StartupPath, true))
|
||||||
RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
|
|
||||||
true))
|
|
||||||
{
|
{
|
||||||
key.DeleteValue("Wox", false);
|
key?.DeleteValue(Infrastructure.Wox.Name, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CheckApplicationIsStartupWithWindow()
|
public static bool StartupSet()
|
||||||
{
|
{
|
||||||
using (
|
using (var key = Registry.CurrentUser.OpenSubKey(StartupPath, true))
|
||||||
RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
|
|
||||||
true))
|
|
||||||
{
|
{
|
||||||
return key.GetValue("Wox") != null;
|
var path = key?.GetValue("Wox") as string;
|
||||||
|
if (path != null)
|
||||||
|
{
|
||||||
|
var executable = Path.Combine(Infrastructure.Wox.ProgramPath, Infrastructure.Wox.Name + ".exe");
|
||||||
|
return path == executable;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user