diff --git a/Wox/Helper/WallpaperPathRetrieval.cs b/Wox/Helper/WallpaperPathRetrieval.cs new file mode 100644 index 0000000000..000146ebe1 --- /dev/null +++ b/Wox/Helper/WallpaperPathRetrieval.cs @@ -0,0 +1,48 @@ +using System; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Windows.Media; +using Microsoft.Win32; + +namespace Wox.Helper +{ + public static class WallpaperPathRetrieval + { + [DllImport("user32.dll", CharSet = CharSet.Unicode)] + private static extern Int32 SystemParametersInfo(UInt32 action, + Int32 uParam, StringBuilder vParam, UInt32 winIni); + private static readonly UInt32 SPI_GETDESKWALLPAPER = 0x73; + private static int MAX_PATH = 260; + + public static string GetWallpaperPath() + { + var wallpaper = new StringBuilder(MAX_PATH); + SystemParametersInfo(SPI_GETDESKWALLPAPER, MAX_PATH, wallpaper, 0); + + var str = wallpaper.ToString(); + if (string.IsNullOrEmpty(str)) + return null; + + return str; + } + + public static Color GetWallpaperColor() + { + RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Colors", true); + var result = key.GetValue(@"Background", null); + if (result != null && result is string) + { + try + { + var parts = result.ToString().Trim().Split(new char[] {' '}, 3).Select(byte.Parse).ToList(); + return Color.FromRgb(parts[0], parts[1], parts[2]); + } + catch + { + } + } + return Colors.Transparent; + } + } +} diff --git a/Wox/SettingWindow.xaml b/Wox/SettingWindow.xaml index 9893c58d3f..b179df311d 100644 --- a/Wox/SettingWindow.xaml +++ b/Wox/SettingWindow.xaml @@ -6,7 +6,7 @@ Title="Wox Setting" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" - Height="407.447" Width="843.989"> + Height="600" Width="800"> @@ -172,11 +172,8 @@ - - - - - + + @@ -186,21 +183,24 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/Wox/SettingWindow.xaml.cs b/Wox/SettingWindow.xaml.cs index d01f024753..2a7c4027de 100644 --- a/Wox/SettingWindow.xaml.cs +++ b/Wox/SettingWindow.xaml.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Media; +using System.Windows.Media.Imaging; using IWshRuntimeLibrary; using Microsoft.VisualBasic.ApplicationServices; using Wox.Infrastructure; @@ -99,7 +100,7 @@ namespace Wox new Result() { Title = "Search applications", - SubTitle = "Search applications, files (via everything plugin) and chrome bookmarks", + SubTitle = "Search applications, files (via everything plugin) and browser bookmarks", IcoPath = "Images/work.png", PluginDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) }, @@ -122,6 +123,20 @@ namespace Wox SubTitle = "get more themes from http://www.getwox.com/theme", IcoPath = "Images/work.png", PluginDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + }, + new Result() + { + Title = "Plugins support", + SubTitle = "get more plugins from http://www.getwox.com/plugin", + IcoPath = "Images/work.png", + PluginDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + }, + new Result() + { + Title = "Wox is an open-source software", + SubTitle = "Wox benefits from the open-source community a lot", + IcoPath = "Images/work.png", + PluginDirectory = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) } }); @@ -142,6 +157,20 @@ namespace Wox cbEnablePythonPlugins.IsChecked = UserSettingStorage.Instance.EnablePythonPlugins; cbStartWithWindows.IsChecked = File.Exists(woxLinkPath); + var wallpaper = WallpaperPathRetrieval.GetWallpaperPath(); + if (wallpaper != null && File.Exists(wallpaper)) + { + var brush = new ImageBrush(new BitmapImage(new Uri(wallpaper))); + brush.Stretch = Stretch.UniformToFill; + this.PreviewPanel.Background = brush; + } + else + { + var wallpaperColor = WallpaperPathRetrieval.GetWallpaperColor(); + this.PreviewPanel.Background = new SolidColorBrush(wallpaperColor); + } + + //PreviewPanel settingsLoaded = true; App.Window.SetTheme(UserSettingStorage.Instance.Theme); } @@ -366,11 +395,21 @@ namespace Wox { if (!settingsLoaded) return; FamilyTypeface typeface = (FamilyTypeface) cbQueryBoxFontFaces.SelectedItem; - UserSettingStorage.Instance.QueryBoxFontStretch = typeface.Stretch.ToString(); - UserSettingStorage.Instance.QueryBoxFontWeight = typeface.Weight.ToString(); - UserSettingStorage.Instance.QueryBoxFontStyle = typeface.Style.ToString(); - UserSettingStorage.Instance.Save(); - App.Window.SetTheme(UserSettingStorage.Instance.Theme); + if (typeface == null) + { + if (cbQueryBoxFontFaces.Items.Count > 0) + cbQueryBoxFontFaces.SelectedIndex = 0; + + return; + } + else + { + UserSettingStorage.Instance.QueryBoxFontStretch = typeface.Stretch.ToString(); + UserSettingStorage.Instance.QueryBoxFontWeight = typeface.Weight.ToString(); + UserSettingStorage.Instance.QueryBoxFontStyle = typeface.Style.ToString(); + UserSettingStorage.Instance.Save(); + App.Window.SetTheme(UserSettingStorage.Instance.Theme); + } } private void CbResultItemFont_OnSelectionChanged(object sender, SelectionChangedEventArgs e) @@ -388,11 +427,21 @@ namespace Wox { if (!settingsLoaded) return; FamilyTypeface typeface = (FamilyTypeface)cbResultItemFontFaces.SelectedItem; - UserSettingStorage.Instance.ResultItemFontStretch = typeface.Stretch.ToString(); - UserSettingStorage.Instance.ResultItemFontWeight = typeface.Weight.ToString(); - UserSettingStorage.Instance.ResultItemFontStyle = typeface.Style.ToString(); - UserSettingStorage.Instance.Save(); - App.Window.SetTheme(UserSettingStorage.Instance.Theme); + if (typeface == null) + { + if (cbResultItemFontFaces.Items.Count > 0) + cbResultItemFontFaces.SelectedIndex = 0; + + return; + } + else + { + UserSettingStorage.Instance.ResultItemFontStretch = typeface.Stretch.ToString(); + UserSettingStorage.Instance.ResultItemFontWeight = typeface.Weight.ToString(); + UserSettingStorage.Instance.ResultItemFontStyle = typeface.Style.ToString(); + UserSettingStorage.Instance.Save(); + App.Window.SetTheme(UserSettingStorage.Instance.Theme); + } } #endregion } diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index 9eef3d314b..e0c4c518aa 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -113,6 +113,7 @@ + ProgramSourceSetting.xaml