mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 03:37:59 +01:00
Add ProgramSources settings (code only, without GUI) #42
This commit is contained in:
@@ -63,6 +63,7 @@ namespace Wox.Infrastructure
|
||||
Instance.UserSetting.Theme = "Dark";
|
||||
Instance.UserSetting.ReplaceWinR = true;
|
||||
Instance.UserSetting.WebSearches = Instance.UserSetting.LoadDefaultWebSearches();
|
||||
Instance.UserSetting.ProgramSources = Instance.UserSetting.LoadDefaultProgramSources();
|
||||
Instance.UserSetting.Hotkey = "Win + W";
|
||||
}
|
||||
|
||||
|
||||
18
Wox.Infrastructure/UserSettings/ProgramSource.cs
Normal file
18
Wox.Infrastructure/UserSettings/ProgramSource.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Wox.Infrastructure.UserSettings
|
||||
{
|
||||
[Serializable]
|
||||
public class ProgramSource
|
||||
{
|
||||
public string Location { get; set; }
|
||||
public string Assembly { get; set; }
|
||||
public string Type { get; set; }
|
||||
public int BounsPoints { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
public Dictionary<string, string> Meta { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ namespace Wox.Infrastructure.UserSettings
|
||||
public string Theme { get; set; }
|
||||
public bool ReplaceWinR { get; set; }
|
||||
public List<WebSearch> WebSearches { get; set; }
|
||||
public List<ProgramSource> ProgramSources { get; set; }
|
||||
public List<CustomPluginHotkey> CustomPluginHotkeys { get; set; }
|
||||
public bool StartWoxOnSystemStartup { get; set; }
|
||||
|
||||
@@ -39,5 +40,29 @@ namespace Wox.Infrastructure.UserSettings
|
||||
|
||||
return webSearches;
|
||||
}
|
||||
|
||||
public List<ProgramSource> LoadDefaultProgramSources()
|
||||
{
|
||||
var list = new List<ProgramSource>();
|
||||
list.Add(new ProgramSource()
|
||||
{
|
||||
BounsPoints = 0,
|
||||
Enabled = true,
|
||||
Type = "CommonStartMenuProgramSource"
|
||||
});
|
||||
list.Add(new ProgramSource()
|
||||
{
|
||||
BounsPoints = 0,
|
||||
Enabled = true,
|
||||
Type = "UserStartMenuProgramSource"
|
||||
});
|
||||
list.Add(new ProgramSource()
|
||||
{
|
||||
BounsPoints = -10,
|
||||
Enabled = true,
|
||||
Type = "AppPathsProgramSource"
|
||||
});
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
<Compile Include="IniParser.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="UserSettings\PluginHotkey.cs" />
|
||||
<Compile Include="UserSettings\ProgramSource.cs" />
|
||||
<Compile Include="UserSettings\UserSelectedRecords.cs" />
|
||||
<Compile Include="UserSettings\UserSetting.cs" />
|
||||
<Compile Include="UserSettings\WebSearch.cs" />
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Text;
|
||||
|
||||
namespace Wox.Plugin.System
|
||||
{
|
||||
[global::System.ComponentModel.Browsable(false)]
|
||||
public class AppPathsProgramSource: AbstractProgramSource
|
||||
{
|
||||
public AppPathsProgramSource()
|
||||
@@ -12,6 +13,12 @@ namespace Wox.Plugin.System
|
||||
this.BonusPoints = -10;
|
||||
}
|
||||
|
||||
public AppPathsProgramSource(Wox.Infrastructure.UserSettings.ProgramSource source)
|
||||
: this()
|
||||
{
|
||||
this.BonusPoints = source.BounsPoints;
|
||||
}
|
||||
|
||||
public override List<Program> LoadPrograms()
|
||||
{
|
||||
var list = new List<Program>();
|
||||
|
||||
37
Wox.Plugin.System/CommonStartMenuProgramSource.cs
Normal file
37
Wox.Plugin.System/CommonStartMenuProgramSource.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Wox.Plugin.System
|
||||
{
|
||||
[global::System.ComponentModel.Browsable(false)]
|
||||
public class CommonStartMenuProgramSource : FileSystemProgramSource
|
||||
{
|
||||
[DllImport("shell32.dll")]
|
||||
static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner, [Out] StringBuilder lpszPath, int nFolder, bool fCreate);
|
||||
const int CSIDL_COMMON_STARTMENU = 0x16; // \Windows\Start Menu\Programs
|
||||
const int CSIDL_COMMON_PROGRAMS = 0x17;
|
||||
|
||||
private static string getPath()
|
||||
{
|
||||
StringBuilder commonStartMenuPath = new StringBuilder(560);
|
||||
SHGetSpecialFolderPath(IntPtr.Zero, commonStartMenuPath, CSIDL_COMMON_PROGRAMS, false);
|
||||
|
||||
return commonStartMenuPath.ToString();
|
||||
}
|
||||
|
||||
public CommonStartMenuProgramSource()
|
||||
: base(getPath())
|
||||
{
|
||||
}
|
||||
|
||||
public CommonStartMenuProgramSource(Wox.Infrastructure.UserSettings.ProgramSource source)
|
||||
: this()
|
||||
{
|
||||
this.BonusPoints = source.BounsPoints;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,12 @@ namespace Wox.Plugin.System
|
||||
Suffixes = suffixes;
|
||||
}
|
||||
|
||||
public FileSystemProgramSource(Wox.Infrastructure.UserSettings.ProgramSource source)
|
||||
: this(source.Location)
|
||||
{
|
||||
this.BonusPoints = source.BounsPoints;
|
||||
}
|
||||
|
||||
public override List<Program> LoadPrograms()
|
||||
{
|
||||
List<Program> list = new List<Program>();
|
||||
|
||||
@@ -15,6 +15,12 @@ namespace Wox.Plugin.System
|
||||
BaseDirectory = baseDirectory;
|
||||
}
|
||||
|
||||
public PortableAppsProgramSource(Wox.Infrastructure.UserSettings.ProgramSource source)
|
||||
: this(source.Location)
|
||||
{
|
||||
this.BonusPoints = source.BounsPoints;
|
||||
}
|
||||
|
||||
public override List<Program> LoadPrograms()
|
||||
{
|
||||
List<Program> list = new List<Program>();
|
||||
|
||||
@@ -44,11 +44,13 @@ namespace Wox.Plugin.System
|
||||
{
|
||||
List<Program> installedList = new List<Program>();
|
||||
List<IProgramSource> sources = new List<IProgramSource>();
|
||||
|
||||
[DllImport("shell32.dll")]
|
||||
static extern bool SHGetSpecialFolderPath(IntPtr hwndOwner,[Out] StringBuilder lpszPath, int nFolder, bool fCreate);
|
||||
const int CSIDL_COMMON_STARTMENU = 0x16; // \Windows\Start Menu\Programs
|
||||
const int CSIDL_COMMON_PROGRAMS = 0x17;
|
||||
Dictionary<string, Type> sourceTypes = new Dictionary<string, Type>() {
|
||||
{"CommonStartMenuProgramSource", typeof(CommonStartMenuProgramSource)},
|
||||
{"UserStartMenuProgramSource", typeof(UserStartMenuProgramSource)},
|
||||
{"AppPathsProgramSource", typeof(AppPathsProgramSource)},
|
||||
{"PortableAppsProgramSource", typeof(PortableAppsProgramSource)},
|
||||
{"FileSystemProgramSource", typeof(FileSystemProgramSource)},
|
||||
};
|
||||
|
||||
protected override List<Result> QueryInternal(Query query)
|
||||
{
|
||||
@@ -106,13 +108,26 @@ namespace Wox.Plugin.System
|
||||
|
||||
protected override void InitInternal(PluginInitContext context)
|
||||
{
|
||||
sources.Add(new FileSystemProgramSource(Environment.GetFolderPath(Environment.SpecialFolder.Programs)));
|
||||
if (CommonStorage.Instance.UserSetting.ProgramSources == null)
|
||||
CommonStorage.Instance.UserSetting.ProgramSources = CommonStorage.Instance.UserSetting.LoadDefaultProgramSources();
|
||||
|
||||
StringBuilder commonStartMenuPath = new StringBuilder(560);
|
||||
SHGetSpecialFolderPath(IntPtr.Zero, commonStartMenuPath, CSIDL_COMMON_PROGRAMS, false);
|
||||
sources.Add(new FileSystemProgramSource(commonStartMenuPath.ToString()));
|
||||
|
||||
sources.Add(new AppPathsProgramSource());
|
||||
CommonStorage.Instance.UserSetting.ProgramSources.ForEach(source =>
|
||||
{
|
||||
if (source.Enabled)
|
||||
{
|
||||
Type sourceClass;
|
||||
if (sourceTypes.TryGetValue(source.Type, out sourceClass))
|
||||
{
|
||||
sources.Add(sourceClass.GetConstructor(
|
||||
new Type[] { typeof(Wox.Infrastructure.UserSettings.ProgramSource) }
|
||||
).Invoke(new object[] { source }) as IProgramSource);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: invalid class
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
foreach (var source in sources)
|
||||
{
|
||||
|
||||
22
Wox.Plugin.System/UserStartMenuProgramSource.cs
Normal file
22
Wox.Plugin.System/UserStartMenuProgramSource.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Wox.Plugin.System
|
||||
{
|
||||
[global::System.ComponentModel.Browsable(false)]
|
||||
public class UserStartMenuProgramSource : FileSystemProgramSource
|
||||
{
|
||||
public UserStartMenuProgramSource()
|
||||
: base(Environment.GetFolderPath(Environment.SpecialFolder.Programs))
|
||||
{
|
||||
}
|
||||
|
||||
public UserStartMenuProgramSource(Wox.Infrastructure.UserSettings.ProgramSource source)
|
||||
: this()
|
||||
{
|
||||
this.BonusPoints = source.BounsPoints;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,12 +52,14 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AppPathsProgramSource.cs" />
|
||||
<Compile Include="CommonStartMenuProgramSource.cs" />
|
||||
<Compile Include="PortableAppsProgramSource.cs" />
|
||||
<Compile Include="IProgramSource.cs" />
|
||||
<Compile Include="BaseSystemPlugin.cs" />
|
||||
<Compile Include="BrowserBookmarks.cs" />
|
||||
<Compile Include="Calculator.cs" />
|
||||
<Compile Include="FileSystemProgramSource.cs" />
|
||||
<Compile Include="UserStartMenuProgramSource.cs" />
|
||||
<Compile Include="WebSearchPlugin.cs" />
|
||||
<Compile Include="WindowsShellRun.cs" />
|
||||
<Compile Include="CMD.cs" />
|
||||
|
||||
Reference in New Issue
Block a user