protocols setting

This commit is contained in:
Vic 2022-10-23 20:01:18 +08:00
parent b77a8f755a
commit 1715f8145d
4 changed files with 81 additions and 25 deletions

View file

@ -167,9 +167,9 @@
FontSize="16"
FontWeight="SemiBold"
Text="{DynamicResource flowlauncher_plugin_program_suffixes_excutable_types}" />
<CheckBox Name="apprefMS" Margin="10,0,0,0" IsChecked="{Binding SuffixesStaus[appref-ms]}">appref-ms</CheckBox>
<CheckBox Name="exe" Margin="10,0,0,0" IsChecked="{Binding SuffixesStaus[exe]}">exe</CheckBox>
<CheckBox Name="lnk" Margin="10,0,0,0" IsChecked="{Binding SuffixesStaus[lnk]}">lnk</CheckBox>
<CheckBox Name="apprefMS" Margin="10,0,0,0" IsChecked="{Binding SuffixesStatus[appref-ms]}">appref-ms</CheckBox>
<CheckBox Name="exe" Margin="10,0,0,0" IsChecked="{Binding SuffixesStatus[exe]}">exe</CheckBox>
<CheckBox Name="lnk" Margin="10,0,0,0" IsChecked="{Binding SuffixesStatus[lnk]}">lnk</CheckBox>
<CheckBox
Name="CustomFiles"
Margin="10,0,0,0"
@ -193,9 +193,9 @@
FontSize="16"
FontWeight="SemiBold"
Text="{DynamicResource flowlauncher_plugin_program_suffixes_URL_types}" />
<CheckBox Name="steam" Margin="10,0,0,0">Steam Games</CheckBox>
<CheckBox Name="epic" Margin="10,0,0,0">Epic Games</CheckBox>
<CheckBox Name="http" Margin="10,0,0,0">Http/Https</CheckBox>
<CheckBox Name="steam" Margin="10,0,0,0" IsChecked="{Binding ProtocolsStatus[steam://run/;steam://rungameid/]}">Steam Games</CheckBox>
<CheckBox Name="epic" Margin="10,0,0,0" IsChecked="{Binding ProtocolsStatus[com.epicgames.launcher://apps/]}">Epic Games</CheckBox>
<CheckBox Name="http" Margin="10,0,0,0" IsChecked="{Binding ProtocolsStatus[http://;https://]}">Http/Https</CheckBox>
<CheckBox
Name="CustomProtocol"
Margin="10,0,0,0"

View file

@ -7,8 +7,9 @@ namespace Flow.Launcher.Plugin.Program
public partial class ProgramSuffixes
{
private PluginInitContext context;
private Settings _settings;
public Dictionary<string, bool> SuffixesStaus => _settings.BuiltinSuffixesStatus;
public Settings _settings;
public Dictionary<string, bool> SuffixesStatus => _settings.BuiltinSuffixesStatus;
public Dictionary<string, bool> ProtocolsStatus => _settings.BuiltinProtocolsStatus;
public ProgramSuffixes(PluginInitContext context, Settings settings)
{
@ -16,6 +17,7 @@ namespace Flow.Launcher.Plugin.Program
_settings = settings;
InitializeComponent();
tbSuffixes.Text = string.Join(Settings.SuffixSeperator, _settings.CustomSuffixes);
tbProtocols.Text = string.Join(Settings.SuffixSeperator, _settings.CustomProtocols);
}
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
@ -26,6 +28,7 @@ namespace Flow.Launcher.Plugin.Program
private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
{
var suffixes = tbSuffixes.Text.Split(Settings.SuffixSeperator, StringSplitOptions.RemoveEmptyEntries);
var protocols = tbProtocols.Text.Split(Settings.SuffixSeperator, StringSplitOptions.RemoveEmptyEntries);
if (suffixes.Length == 0 && _settings.UseCustomSuffixes)
{
@ -34,10 +37,15 @@ namespace Flow.Launcher.Plugin.Program
return;
}
_settings.CustomSuffixes = suffixes;
if (protocols.Length == 0 && _settings.UseCustomProtocols)
{
string warning = context.API.GetTranslation("flowlauncher_plugin_program_suffixes_cannot_empty"); // TODO text update
MessageBox.Show(warning);
return;
}
//string msg = context.API.GetTranslation("flowlauncher_plugin_program_update_file_suffixes");
//MessageBox.Show(msg);
_settings.CustomSuffixes = suffixes;
_settings.CustomProtocols = protocols;
DialogResult = true;
}
@ -49,6 +57,10 @@ namespace Flow.Launcher.Plugin.Program
lnk.IsChecked = true;
CustomFiles.IsChecked = false;
steam.IsChecked = true;
epic.IsChecked = true;
http.IsChecked = false;
CustomProtocol.IsChecked = false;
}
}
}

View file

@ -294,17 +294,28 @@ namespace Flow.Launcher.Plugin.Program.Programs
private static Win32 UrlProgram(string path)
{
var program = Win32Program(path);
var parser = new FileIniDataParser();
var data = parser.ReadFile(path);
program.Valid = false;
try
{
var parser = new FileIniDataParser();
var data = parser.ReadFile(path);
var urlSection = data["InternetShortcut"];
if (urlSection != null)
{
var url = urlSection["URL"];
foreach(var protocol in Main._settings.GetProtocols())
{
if(url.StartsWith(protocol))
{
program.LnkResolvedPath = url;
program.Valid = true;
break;
}
}
}
program.LnkResolvedPath = urlSection["URL"];
var iconPath = urlSection["IconFile"];
var iconPath = urlSection["IconFile"];
if (Path.GetExtension(iconPath).Equals(".ico", StringComparison.OrdinalIgnoreCase))
{
program.IcoPath = iconPath;
@ -537,7 +548,7 @@ namespace Flow.Launcher.Plugin.Program.Programs
{
var programs = Enumerable.Empty<Win32>();
var unregistered = UnregisteredPrograms(settings.ProgramSources, settings.GetProgramExtensions());
var unregistered = UnregisteredPrograms(settings.ProgramSources, settings.GetSuffixes());
programs = programs.Concat(unregistered);
@ -545,13 +556,13 @@ namespace Flow.Launcher.Plugin.Program.Programs
if (settings.EnableRegistrySource)
{
var appPaths = AppPathsPrograms(settings.GetProgramExtensions());
var appPaths = AppPathsPrograms(settings.GetSuffixes());
autoIndexPrograms = autoIndexPrograms.Concat(appPaths);
}
if (settings.EnableStartMenuSource)
{
var startMenu = StartMenuPrograms(settings.GetProgramExtensions());
var startMenu = StartMenuPrograms(settings.GetSuffixes());
autoIndexPrograms = autoIndexPrograms.Concat(startMenu);
}

View file

@ -11,17 +11,23 @@ namespace Flow.Launcher.Plugin.Program
public DateTime LastIndexTime { get; set; }
public List<ProgramSource> ProgramSources { get; set; } = new List<ProgramSource>();
public List<DisabledProgramSource> DisabledProgramSources { get; set; } = new List<DisabledProgramSource>();
public string[] CustomSuffixes { get; set; } = { };
public string[] CustomSuffixes { get; set; } = Array.Empty<string>();
public string[] CustomProtocols { get; set; } = Array.Empty<string>();
[JsonIgnore]
public Dictionary<string, bool> BuiltinSuffixesStatus { get; set; } = new Dictionary<string, bool>{
{ "exe", true }, { "appref-ms", true }, { "lnk", true }
};
[JsonIgnore]
public Dictionary<string, bool> BuiltinProtocolsStatus { get; set; } = new Dictionary<string, bool>{
{ $"steam://run/{SuffixSeperator}steam://rungameid/", true }, { "com.epicgames.launcher://apps/", true }, { $"http://{SuffixSeperator}https://", false}
};
public bool UseCustomSuffixes = false;
public bool UseCustomProtocols = false;
public string[] GetProgramExtensions()
public string[] GetSuffixes()
{
List<string> extensions = new List<string>();
foreach(var item in BuiltinSuffixesStatus)
@ -32,7 +38,10 @@ namespace Flow.Launcher.Plugin.Program
}
}
// todo: url
if (BuiltinProtocolsStatus.Values.Any(x => x == true) || UseCustomProtocols)
{
extensions.Add("url");
}
if (UseCustomSuffixes)
{
@ -40,12 +49,36 @@ namespace Flow.Launcher.Plugin.Program
}
else
{
return extensions.ToArray();
return extensions.DistinctBy(x => x.ToLower()).ToArray();
}
}
public string[] GetProtocols()
{
List<string> protocols = new List<string>();
foreach (var item in BuiltinProtocolsStatus)
{
if (item.Value)
{
var tmp = item.Key.Split(SuffixSeperator, StringSplitOptions.RemoveEmptyEntries);
foreach(var p in tmp)
{
protocols.Add(p);
}
}
}
if (UseCustomProtocols)
{
return protocols.Concat(CustomProtocols).DistinctBy(x => x.ToLower()).ToArray();
}
else
{
return protocols.DistinctBy(x => x.ToLower()).ToArray();
}
}
public bool EnableStartMenuSource { get; set; } = true;
public bool EnableDescription { get; set; } = false;
public bool HideAppsPath { get; set; } = true;
public bool EnableRegistrySource { get; set; } = true;