From 3442081d20b8b1084f92bbecb13c78ee4568cf12 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Fri, 7 Feb 2014 22:10:00 +0800 Subject: [PATCH] "start wox on system startup" config changes. --- Wox.Infrastructure/UAC.cs | 1 - .../UserSettings/UserSetting.cs | 2 ++ Wox/App.xaml.cs | 11 +++++-- Wox/MainWindow.xaml.cs | 32 ++++--------------- Wox/SettingWindow.xaml.cs | 13 ++++++-- 5 files changed, 28 insertions(+), 31 deletions(-) diff --git a/Wox.Infrastructure/UAC.cs b/Wox.Infrastructure/UAC.cs index 565c56a602..3f7fd707f6 100644 --- a/Wox.Infrastructure/UAC.cs +++ b/Wox.Infrastructure/UAC.cs @@ -66,7 +66,6 @@ namespace Wox.Infrastructure var process = new Process(); process.StartInfo = psi; process.Start(); - process.WaitForExit(); } catch (Exception e) { diff --git a/Wox.Infrastructure/UserSettings/UserSetting.cs b/Wox.Infrastructure/UserSettings/UserSetting.cs index 79528a67b7..2ee4f7bf5d 100644 --- a/Wox.Infrastructure/UserSettings/UserSetting.cs +++ b/Wox.Infrastructure/UserSettings/UserSetting.cs @@ -9,6 +9,8 @@ namespace Wox.Infrastructure.UserSettings public bool ReplaceWinR { get; set; } public List WebSearches { get; set; } + public bool StartWoxOnSystemStartup { get; set; } + public List LoadDefaultWebSearches() { List webSearches = new List(); diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index 39de278bd8..4c8710e91d 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -67,13 +67,20 @@ namespace Wox base.OnStartup(e); window = new MainWindow(); - window.ShowApp(); + if (e.Args.Length == 0 || e.Args[0].ToLower() != "starthide") + { + window.ShowApp(); + } + window.ParseArgs(e.Args); } public void Activate(string[] args) { - window.ShowApp(); + if (args.Length == 0 || args[0].ToLower() != "starthide") + { + window.ShowApp(); + } window.ParseArgs(args); } } diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 9ccc201adb..a63ae70797 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -38,6 +38,7 @@ namespace Wox { InitializeComponent(); + InitialTray(); hook.KeyPressed += OnHotKey; hook.RegisterHotKey(XModifierKeys.Alt, Keys.Space); resultCtrl.resultItemChangedEvent += resultCtrl_resultItemChangedEvent; @@ -151,7 +152,7 @@ namespace Wox }, TimeSpan.FromSeconds(1), tbQuery.Text); } - }, TimeSpan.FromMilliseconds(300)); + }, TimeSpan.FromMilliseconds(150)); } private void StartProgress() @@ -196,41 +197,22 @@ namespace Wox tbQuery.SelectAll(); } break; + + case "starthide": + HideApp(); + break; } } } - private void SetAutoStart(bool IsAtuoRun) - { - //string LnkPath = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "//Wox.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 = "Wox"; - // shortcut.Save(); - //} - //else - //{ - // System.IO.File.Delete(LnkPath); - //} - } - private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) { Left = (SystemParameters.PrimaryScreenWidth - ActualWidth) / 2; Top = (SystemParameters.PrimaryScreenHeight - ActualHeight) / 3; - Plugins.Init(); - InitialTray(); - SetAutoStart(true); WakeupApp(); + Plugins.Init(); - //var engine = new Jurassic.ScriptEngine(); - //MessageBox.Show(engine.Evaluate("5 * 10 + 2").ToString()); keyboardListener.hookedKeyboardCallback += KListener_hookedKeyboardCallback; } diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index be8c241b80..385a891dc3 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -53,6 +53,7 @@ namespace Wox themeComboBox.SelectedItem = CommonStorage.Instance.UserSetting.Theme; cbReplaceWinR.IsChecked = CommonStorage.Instance.UserSetting.ReplaceWinR; webSearchView.ItemsSource = CommonStorage.Instance.UserSetting.WebSearches; + cbStartWithWindows.IsChecked = CommonStorage.Instance.UserSetting.StartWoxOnSystemStartup; } public void ReloadWebSearchView() @@ -111,15 +112,21 @@ namespace Wox } } - private void CbStartWithWindows_OnChecked(object sender, RoutedEventArgs e) { - OnStartWithWindowsChecked(); + if (!CommonStorage.Instance.UserSetting.StartWoxOnSystemStartup) + { + CommonStorage.Instance.UserSetting.StartWoxOnSystemStartup = true; + OnStartWithWindowsChecked(); + CommonStorage.Instance.Save(); + } } private void CbStartWithWindows_OnUnchecked(object sender, RoutedEventArgs e) { + CommonStorage.Instance.UserSetting.StartWoxOnSystemStartup = false; OnStartWithWindowUnChecked(); + CommonStorage.Instance.Save(); } [MethodImpl(MethodImplOptions.NoInlining)] @@ -142,7 +149,7 @@ namespace Wox { if (startup) { - rk.SetValue("Wox",Path.Combine(Directory.GetCurrentDirectory(),"Wox.exe startHide")); + rk.SetValue("Wox", Path.Combine(Directory.GetCurrentDirectory(), "Wox.exe startHide")); } else {