mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
Merge master
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using Newtonsoft.Json;
|
||||
using Wox.Plugin;
|
||||
using System.Windows;
|
||||
|
||||
namespace Wox.Core.Plugin
|
||||
{
|
||||
@@ -47,22 +47,24 @@ namespace Wox.Core.Plugin
|
||||
.Replace("*", "_")
|
||||
.Replace("|", "_")
|
||||
+ "-" + Guid.NewGuid();
|
||||
string newPluginPath = Path.Combine(pluginFolerPath,newPluginName);
|
||||
string content = string.Format(
|
||||
"Do you want to install following plugin?\r\n\r\nName: {0}\r\nVersion: {1}\r\nAuthor: {2}",
|
||||
plugin.Name, plugin.Version, plugin.Author);
|
||||
string newPluginPath = Path.Combine(pluginFolerPath, newPluginName);
|
||||
string content = $"Do you want to install following plugin?{Environment.NewLine}{Environment.NewLine}" +
|
||||
$"Name: {plugin.Name}{Environment.NewLine}" +
|
||||
$"Version: {plugin.Version}{Environment.NewLine}" +
|
||||
$"Author: {plugin.Author}";
|
||||
PluginPair existingPlugin = PluginManager.GetPluginForId(plugin.ID);
|
||||
|
||||
if (existingPlugin != null)
|
||||
{
|
||||
content = string.Format(
|
||||
"Do you want to update following plugin?\r\n\r\nName: {0}\r\nOld Version: {1}\r\nNew Version: {2}\r\nAuthor: {3}",
|
||||
plugin.Name, existingPlugin.Metadata.Version, plugin.Version, plugin.Author);
|
||||
content = $"Do you want to update following plugin?{Environment.NewLine}{Environment.NewLine}" +
|
||||
$"Name: {plugin.Name}{Environment.NewLine}" +
|
||||
$"Old Version: {existingPlugin.Metadata.Version}" +
|
||||
$"{Environment.NewLine}New Version: {plugin.Version}" +
|
||||
$"{Environment.NewLine}Author: {plugin.Author}";
|
||||
}
|
||||
|
||||
DialogResult result = System.Windows.Forms.MessageBox.Show(content, "Install plugin", MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question);
|
||||
if (result == DialogResult.Yes)
|
||||
var result = MessageBox.Show(content, "Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question);
|
||||
if (result == MessageBoxResult.Yes)
|
||||
{
|
||||
if (existingPlugin != null && Directory.Exists(existingPlugin.Metadata.PluginDirectory))
|
||||
{
|
||||
@@ -81,17 +83,11 @@ namespace Wox.Core.Plugin
|
||||
//{
|
||||
// Plugins.Init();
|
||||
//}
|
||||
if (MessageBox.Show("You have installed plugin " + plugin.Name + " successfully.\r\n Restart Wox to take effect?", "Install plugin",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
if (MessageBox.Show($"You have installed plugin {plugin.Name} successfully.{Environment.NewLine}" +
|
||||
" Restart Wox to take effect?",
|
||||
"Install plugin", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
|
||||
{
|
||||
ProcessStartInfo Info = new ProcessStartInfo();
|
||||
Info.Arguments = "/C ping 127.0.0.1 -n 1 && \"" +
|
||||
System.Windows.Forms.Application.ExecutablePath + "\"";
|
||||
Info.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
Info.CreateNoWindow = true;
|
||||
Info.FileName = "cmd.exe";
|
||||
Process.Start(Info);
|
||||
PluginManager.API.CloseApp();
|
||||
PluginManager.API.RestarApp();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,7 +110,7 @@ namespace Wox.Core.Plugin
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
string error = string.Format("Parse plugin config {0} failed: json format is not valid", configPath);
|
||||
string error = $"Parse plugin config {configPath} failed: json format is not valid";
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw new System.Exception(error);
|
||||
@@ -126,8 +122,7 @@ namespace Wox.Core.Plugin
|
||||
|
||||
if (!AllowedLanguage.IsAllowed(metadata.Language))
|
||||
{
|
||||
string error = string.Format("Parse plugin config {0} failed: invalid language {1}", configPath,
|
||||
metadata.Language);
|
||||
string error = $"Parse plugin config {configPath} failed: invalid language {metadata.Language}";
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw new System.Exception(error);
|
||||
@@ -137,8 +132,7 @@ namespace Wox.Core.Plugin
|
||||
}
|
||||
if (!File.Exists(metadata.ExecuteFilePath))
|
||||
{
|
||||
string error = string.Format("Parse plugin config {0} failed: ExecuteFile {1} didn't exist", configPath,
|
||||
metadata.ExecuteFilePath);
|
||||
string error = $"Parse plugin config {configPath} failed: ExecuteFile {metadata.ExecuteFilePath} didn't exist";
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw new System.Exception(error);
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace Wox.Core.Plugin
|
||||
Concat(new JsonRPCPluginLoader<PythonPlugin>().LoadPlugin(metadatas));
|
||||
|
||||
//load plugin i18n languages
|
||||
ResourceMerger.ApplyPluginLanguages();
|
||||
ResourceMerger.UpdatePluginLanguages();
|
||||
|
||||
foreach (PluginPair pluginPair in AllPlugins)
|
||||
{
|
||||
|
||||
@@ -1,36 +1,5 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Wox.Core")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Wox.Core")]
|
||||
[assembly: AssemblyCopyright("The MIT License (MIT)")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("693aa0e5-741b-4759-b740-fdbb011a3280")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: Guid("693aa0e5-741b-4759-b740-fdbb011a3280")]
|
||||
@@ -1,10 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Wox.Core.Theme
|
||||
{
|
||||
interface ITheme
|
||||
{
|
||||
void ChangeTheme(string themeName);
|
||||
List<string> LoadAvailableThemes();
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,10 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using Wox.Core.UI;
|
||||
using Wox.Core.UserSettings;
|
||||
@@ -12,7 +14,7 @@ using Wox.Infrastructure.Logger;
|
||||
|
||||
namespace Wox.Core.Theme
|
||||
{
|
||||
public class Theme : IUIResource,ITheme
|
||||
public class Theme : IUIResource
|
||||
{
|
||||
public const string DirectoryName = "Themes";
|
||||
private static List<string> themeDirectories = new List<string>();
|
||||
@@ -55,8 +57,14 @@ namespace Wox.Core.Theme
|
||||
|
||||
UserSettingStorage.Instance.Theme = themeName;
|
||||
UserSettingStorage.Instance.Save();
|
||||
ResourceMerger.UpdateResource(this);
|
||||
|
||||
ResourceMerger.ApplyThemeResource(this);
|
||||
// Exception of FindResource can't be cathed if global exception handle is set
|
||||
var isBlur = Application.Current.TryFindResource("ThemeBlurEnabled");
|
||||
if (isBlur is bool)
|
||||
{
|
||||
SetBlurForWindow(Application.Current.MainWindow, (bool)isBlur);
|
||||
}
|
||||
}
|
||||
|
||||
public ResourceDictionary GetResourceDictionary()
|
||||
@@ -89,7 +97,6 @@ namespace Wox.Core.Theme
|
||||
Setter[] setters = new Setter[] { fontFamily, fontStyle, fontWeight, fontStretch };
|
||||
Array.ForEach(new Style[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle }, o => Array.ForEach(setters, p => o.Setters.Add(p)));
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
@@ -119,5 +126,77 @@ namespace Wox.Core.Theme
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
#region Blur Handling
|
||||
/*
|
||||
Found on https://github.com/riverar/sample-win10-aeroglass
|
||||
*/
|
||||
private enum AccentState
|
||||
{
|
||||
ACCENT_DISABLED = 0,
|
||||
ACCENT_ENABLE_GRADIENT = 1,
|
||||
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
|
||||
ACCENT_ENABLE_BLURBEHIND = 3,
|
||||
ACCENT_INVALID_STATE = 4
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct AccentPolicy
|
||||
{
|
||||
public AccentState AccentState;
|
||||
public int AccentFlags;
|
||||
public int GradientColor;
|
||||
public int AnimationId;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct WindowCompositionAttributeData
|
||||
{
|
||||
public WindowCompositionAttribute Attribute;
|
||||
public IntPtr Data;
|
||||
public int SizeOfData;
|
||||
}
|
||||
|
||||
private enum WindowCompositionAttribute
|
||||
{
|
||||
WCA_ACCENT_POLICY = 19
|
||||
}
|
||||
[DllImport("user32.dll")]
|
||||
private static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the blur for a window via SetWindowCompositionAttribute
|
||||
/// </summary>
|
||||
/// <param name="wind">window to blur</param>
|
||||
/// <param name="isBlur">true/false - on or off correspondingly</param>
|
||||
private void SetBlurForWindow(Window wind, bool isBlur)
|
||||
{
|
||||
if (isBlur)
|
||||
{
|
||||
SetWindowAccent(wind, AccentState.ACCENT_ENABLE_BLURBEHIND);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetWindowAccent(Window wind, AccentState themeAccentMode)
|
||||
{
|
||||
var windowHelper = new WindowInteropHelper(wind);
|
||||
var accent = new AccentPolicy { AccentState = themeAccentMode };
|
||||
var accentStructSize = Marshal.SizeOf(accent);
|
||||
|
||||
var accentPtr = Marshal.AllocHGlobal(accentStructSize);
|
||||
Marshal.StructureToPtr(accent, accentPtr, false);
|
||||
|
||||
var data = new WindowCompositionAttributeData
|
||||
{
|
||||
Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY,
|
||||
SizeOfData = accentStructSize,
|
||||
Data = accentPtr
|
||||
};
|
||||
|
||||
SetWindowCompositionAttribute(windowHelper.Handle, ref data);
|
||||
|
||||
Marshal.FreeHGlobal(accentPtr);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using Wox.Core.i18n;
|
||||
@@ -9,34 +10,34 @@ namespace Wox.Core.UI
|
||||
{
|
||||
public static class ResourceMerger
|
||||
{
|
||||
private static void RemoveResource(string resourceDirectoryName)
|
||||
private static void RemoveResource(string directoryName)
|
||||
{
|
||||
var mergedDictionaries = Application.Current.Resources.MergedDictionaries;
|
||||
foreach (var resource in mergedDictionaries)
|
||||
directoryName = $"{Path.DirectorySeparatorChar}{directoryName}";
|
||||
var dictionaries = Application.Current.Resources.MergedDictionaries;
|
||||
foreach (var resource in dictionaries)
|
||||
{
|
||||
int directoryPosition = resource.Source.Segments.Length - 2;
|
||||
string currentDirectoryName = resource.Source.Segments[directoryPosition];
|
||||
if (currentDirectoryName == resourceDirectoryName)
|
||||
string currentDirectoryName = Path.GetDirectoryName(resource.Source.AbsolutePath);
|
||||
if (currentDirectoryName == directoryName)
|
||||
{
|
||||
mergedDictionaries.Remove(resource);
|
||||
dictionaries.Remove(resource);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void ApplyThemeResource(Theme.Theme t)
|
||||
public static void UpdateResource(Theme.Theme t)
|
||||
{
|
||||
RemoveResource(Theme.Theme.DirectoryName);
|
||||
Application.Current.Resources.MergedDictionaries.Add(t.GetResourceDictionary());
|
||||
}
|
||||
|
||||
public static void ApplyLanguageResources(Internationalization i)
|
||||
public static void UpdateResources(Internationalization i)
|
||||
{
|
||||
RemoveResource(Internationalization.DirectoryName);
|
||||
Application.Current.Resources.MergedDictionaries.Add(i.GetResourceDictionary());
|
||||
}
|
||||
|
||||
internal static void ApplyPluginLanguages()
|
||||
internal static void UpdatePluginLanguages()
|
||||
{
|
||||
RemoveResource(PluginManager.DirectoryName);
|
||||
foreach (var languageFile in PluginManager.GetPluginsForInterface<IPluginI18n>().
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace Wox.Core.Updater
|
||||
public class UpdaterManager
|
||||
{
|
||||
private static UpdaterManager instance;
|
||||
private const string VersionCheckURL = "https://api.getwox.com/release/latest/";
|
||||
private const string VersionCheckURL = "http://api.getwox.com/release/latest/";
|
||||
private const string UpdateFeedURL = "http://upgrade.getwox.com/update.xml";
|
||||
//private const string UpdateFeedURL = "http://127.0.0.1:8888/update.xml";
|
||||
private static SemanticVersion currentVersion;
|
||||
|
||||
@@ -117,6 +117,8 @@ namespace Wox.Core.UserSettings
|
||||
get { return "config"; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void IncreaseActivateTimes()
|
||||
{
|
||||
ActivateTimes++;
|
||||
|
||||
@@ -42,8 +42,8 @@
|
||||
<HintPath>..\packages\NAppUpdate.Framework.0.3.2.0\lib\net20\NAppUpdate.Framework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="PresentationCore" />
|
||||
@@ -57,6 +57,9 @@
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\SolutionAssemblyInfo.cs">
|
||||
<Link>Properties\SolutionAssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="APIServer.cs" />
|
||||
<Compile Include="Updater\Release.cs" />
|
||||
<Compile Include="Updater\UpdaterManager.cs" />
|
||||
@@ -67,7 +70,6 @@
|
||||
<Compile Include="i18n\Internationalization.cs" />
|
||||
<Compile Include="i18n\InternationalizationManager.cs" />
|
||||
<Compile Include="i18n\Language.cs" />
|
||||
<Compile Include="Theme\ITheme.cs" />
|
||||
<Compile Include="Theme\ThemeManager.cs" />
|
||||
<Compile Include="UI\IUIResource.cs" />
|
||||
<Compile Include="UI\ResourceMerger.cs" />
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Wox.Core.i18n
|
||||
{
|
||||
@@ -8,6 +8,7 @@ namespace Wox.Core.i18n
|
||||
public static Language Chinese = new Language("zh-cn", "中文");
|
||||
public static Language Chinese_TW = new Language("zh-tw", "中文(繁体)");
|
||||
public static Language Russian = new Language("ru", "Русский");
|
||||
public static Language French = new Language("fr", "Français");
|
||||
|
||||
public static List<Language> GetAvailableLanguages()
|
||||
{
|
||||
@@ -17,6 +18,7 @@ namespace Wox.Core.i18n
|
||||
Chinese,
|
||||
Chinese_TW,
|
||||
Russian,
|
||||
French,
|
||||
};
|
||||
return languages;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace Wox.Core.i18n
|
||||
|
||||
UserSettingStorage.Instance.Language = language.LanguageCode;
|
||||
UserSettingStorage.Instance.Save();
|
||||
ResourceMerger.ApplyLanguageResources(this);
|
||||
ResourceMerger.UpdateResources(this);
|
||||
}
|
||||
|
||||
public ResourceDictionary GetResourceDictionary()
|
||||
@@ -88,20 +88,15 @@ namespace Wox.Core.i18n
|
||||
|
||||
public string GetTranslation(string key)
|
||||
{
|
||||
try
|
||||
var translation = Application.Current.TryFindResource(key);
|
||||
if (translation is string)
|
||||
{
|
||||
object translation = Application.Current.FindResource(key);
|
||||
if (translation == null)
|
||||
{
|
||||
return "NoTranslation";
|
||||
}
|
||||
return translation.ToString();
|
||||
}
|
||||
catch
|
||||
else
|
||||
{
|
||||
return "NoTranslation";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private string GetLanguagePath(string languageCode)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NAppUpdate.Framework" version="0.3.2.0" targetFramework="net452" />
|
||||
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net452" />
|
||||
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net452" />
|
||||
<package id="SharpZipLib" version="0.86.0" targetFramework="net452" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user