Skip to content

Commit 1715f81

Browse files
protocols setting
1 parent b77a8f7 commit 1715f81

File tree

4 files changed

+81
-25
lines changed

4 files changed

+81
-25
lines changed

Plugins/Flow.Launcher.Plugin.Program/ProgramSuffixes.xaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@
167167
FontSize="16"
168168
FontWeight="SemiBold"
169169
Text="{DynamicResource flowlauncher_plugin_program_suffixes_excutable_types}" />
170-
<CheckBox Name="apprefMS" Margin="10,0,0,0" IsChecked="{Binding SuffixesStaus[appref-ms]}">appref-ms</CheckBox>
171-
<CheckBox Name="exe" Margin="10,0,0,0" IsChecked="{Binding SuffixesStaus[exe]}">exe</CheckBox>
172-
<CheckBox Name="lnk" Margin="10,0,0,0" IsChecked="{Binding SuffixesStaus[lnk]}">lnk</CheckBox>
170+
<CheckBox Name="apprefMS" Margin="10,0,0,0" IsChecked="{Binding SuffixesStatus[appref-ms]}">appref-ms</CheckBox>
171+
<CheckBox Name="exe" Margin="10,0,0,0" IsChecked="{Binding SuffixesStatus[exe]}">exe</CheckBox>
172+
<CheckBox Name="lnk" Margin="10,0,0,0" IsChecked="{Binding SuffixesStatus[lnk]}">lnk</CheckBox>
173173
<CheckBox
174174
Name="CustomFiles"
175175
Margin="10,0,0,0"
@@ -193,9 +193,9 @@
193193
FontSize="16"
194194
FontWeight="SemiBold"
195195
Text="{DynamicResource flowlauncher_plugin_program_suffixes_URL_types}" />
196-
<CheckBox Name="steam" Margin="10,0,0,0">Steam Games</CheckBox>
197-
<CheckBox Name="epic" Margin="10,0,0,0">Epic Games</CheckBox>
198-
<CheckBox Name="http" Margin="10,0,0,0">Http/Https</CheckBox>
196+
<CheckBox Name="steam" Margin="10,0,0,0" IsChecked="{Binding ProtocolsStatus[steam://run/;steam://rungameid/]}">Steam Games</CheckBox>
197+
<CheckBox Name="epic" Margin="10,0,0,0" IsChecked="{Binding ProtocolsStatus[com.epicgames.launcher://apps/]}">Epic Games</CheckBox>
198+
<CheckBox Name="http" Margin="10,0,0,0" IsChecked="{Binding ProtocolsStatus[http://;https://]}">Http/Https</CheckBox>
199199
<CheckBox
200200
Name="CustomProtocol"
201201
Margin="10,0,0,0"

Plugins/Flow.Launcher.Plugin.Program/ProgramSuffixes.xaml.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@ namespace Flow.Launcher.Plugin.Program
77
public partial class ProgramSuffixes
88
{
99
private PluginInitContext context;
10-
private Settings _settings;
11-
public Dictionary<string, bool> SuffixesStaus => _settings.BuiltinSuffixesStatus;
10+
public Settings _settings;
11+
public Dictionary<string, bool> SuffixesStatus => _settings.BuiltinSuffixesStatus;
12+
public Dictionary<string, bool> ProtocolsStatus => _settings.BuiltinProtocolsStatus;
1213

1314
public ProgramSuffixes(PluginInitContext context, Settings settings)
1415
{
1516
this.context = context;
1617
_settings = settings;
1718
InitializeComponent();
1819
tbSuffixes.Text = string.Join(Settings.SuffixSeperator, _settings.CustomSuffixes);
20+
tbProtocols.Text = string.Join(Settings.SuffixSeperator, _settings.CustomProtocols);
1921
}
2022

2123
private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
@@ -26,6 +28,7 @@ private void BtnCancel_OnClick(object sender, RoutedEventArgs e)
2628
private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
2729
{
2830
var suffixes = tbSuffixes.Text.Split(Settings.SuffixSeperator, StringSplitOptions.RemoveEmptyEntries);
31+
var protocols = tbProtocols.Text.Split(Settings.SuffixSeperator, StringSplitOptions.RemoveEmptyEntries);
2932

3033
if (suffixes.Length == 0 && _settings.UseCustomSuffixes)
3134
{
@@ -34,10 +37,15 @@ private void BtnAdd_OnClick(object sender, RoutedEventArgs e)
3437
return;
3538
}
3639

37-
_settings.CustomSuffixes = suffixes;
40+
if (protocols.Length == 0 && _settings.UseCustomProtocols)
41+
{
42+
string warning = context.API.GetTranslation("flowlauncher_plugin_program_suffixes_cannot_empty"); // TODO text update
43+
MessageBox.Show(warning);
44+
return;
45+
}
3846

39-
//string msg = context.API.GetTranslation("flowlauncher_plugin_program_update_file_suffixes");
40-
//MessageBox.Show(msg);
47+
_settings.CustomSuffixes = suffixes;
48+
_settings.CustomProtocols = protocols;
4149

4250
DialogResult = true;
4351
}
@@ -49,6 +57,10 @@ private void BtnReset_OnClick(object sender, RoutedEventArgs e)
4957
lnk.IsChecked = true;
5058
CustomFiles.IsChecked = false;
5159

60+
steam.IsChecked = true;
61+
epic.IsChecked = true;
62+
http.IsChecked = false;
63+
CustomProtocol.IsChecked = false;
5264
}
5365
}
5466
}

Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,17 +294,28 @@ private static Win32 LnkProgram(string path)
294294
private static Win32 UrlProgram(string path)
295295
{
296296
var program = Win32Program(path);
297-
298-
var parser = new FileIniDataParser();
299-
var data = parser.ReadFile(path);
297+
program.Valid = false;
300298

301299
try
302300
{
301+
var parser = new FileIniDataParser();
302+
var data = parser.ReadFile(path);
303303
var urlSection = data["InternetShortcut"];
304+
if (urlSection != null)
305+
{
306+
var url = urlSection["URL"];
307+
foreach(var protocol in Main._settings.GetProtocols())
308+
{
309+
if(url.StartsWith(protocol))
310+
{
311+
program.LnkResolvedPath = url;
312+
program.Valid = true;
313+
break;
314+
}
315+
}
316+
}
304317

305-
program.LnkResolvedPath = urlSection["URL"];
306-
307-
var iconPath = urlSection["IconFile"];
318+
var iconPath = urlSection["IconFile"];
308319
if (Path.GetExtension(iconPath).Equals(".ico", StringComparison.OrdinalIgnoreCase))
309320
{
310321
program.IcoPath = iconPath;
@@ -537,21 +548,21 @@ public static Win32[] All(Settings settings)
537548
{
538549
var programs = Enumerable.Empty<Win32>();
539550

540-
var unregistered = UnregisteredPrograms(settings.ProgramSources, settings.GetProgramExtensions());
551+
var unregistered = UnregisteredPrograms(settings.ProgramSources, settings.GetSuffixes());
541552

542553
programs = programs.Concat(unregistered);
543554

544555
var autoIndexPrograms = Enumerable.Empty<Win32>();
545556

546557
if (settings.EnableRegistrySource)
547558
{
548-
var appPaths = AppPathsPrograms(settings.GetProgramExtensions());
559+
var appPaths = AppPathsPrograms(settings.GetSuffixes());
549560
autoIndexPrograms = autoIndexPrograms.Concat(appPaths);
550561
}
551562

552563
if (settings.EnableStartMenuSource)
553564
{
554-
var startMenu = StartMenuPrograms(settings.GetProgramExtensions());
565+
var startMenu = StartMenuPrograms(settings.GetSuffixes());
555566
autoIndexPrograms = autoIndexPrograms.Concat(startMenu);
556567
}
557568

Plugins/Flow.Launcher.Plugin.Program/Settings.cs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,23 @@ public class Settings
1111
public DateTime LastIndexTime { get; set; }
1212
public List<ProgramSource> ProgramSources { get; set; } = new List<ProgramSource>();
1313
public List<DisabledProgramSource> DisabledProgramSources { get; set; } = new List<DisabledProgramSource>();
14-
public string[] CustomSuffixes { get; set; } = { };
14+
public string[] CustomSuffixes { get; set; } = Array.Empty<string>();
15+
public string[] CustomProtocols { get; set; } = Array.Empty<string>();
1516

1617
[JsonIgnore]
1718
public Dictionary<string, bool> BuiltinSuffixesStatus { get; set; } = new Dictionary<string, bool>{
1819
{ "exe", true }, { "appref-ms", true }, { "lnk", true }
1920
};
2021

22+
[JsonIgnore]
23+
public Dictionary<string, bool> BuiltinProtocolsStatus { get; set; } = new Dictionary<string, bool>{
24+
{ $"steam://run/{SuffixSeperator}steam://rungameid/", true }, { "com.epicgames.launcher://apps/", true }, { $"http://{SuffixSeperator}https://", false}
25+
};
26+
2127
public bool UseCustomSuffixes = false;
2228
public bool UseCustomProtocols = false;
2329

24-
public string[] GetProgramExtensions()
30+
public string[] GetSuffixes()
2531
{
2632
List<string> extensions = new List<string>();
2733
foreach(var item in BuiltinSuffixesStatus)
@@ -32,20 +38,47 @@ public string[] GetProgramExtensions()
3238
}
3339
}
3440

35-
// todo: url
41+
if (BuiltinProtocolsStatus.Values.Any(x => x == true) || UseCustomProtocols)
42+
{
43+
extensions.Add("url");
44+
}
3645

3746
if (UseCustomSuffixes)
3847
{
3948
return extensions.Concat(CustomSuffixes).DistinctBy(x => x.ToLower()).ToArray();
4049
}
4150
else
4251
{
43-
return extensions.ToArray();
52+
return extensions.DistinctBy(x => x.ToLower()).ToArray();
4453
}
4554
}
4655

47-
public bool EnableStartMenuSource { get; set; } = true;
56+
public string[] GetProtocols()
57+
{
58+
List<string> protocols = new List<string>();
59+
foreach (var item in BuiltinProtocolsStatus)
60+
{
61+
if (item.Value)
62+
{
63+
var tmp = item.Key.Split(SuffixSeperator, StringSplitOptions.RemoveEmptyEntries);
64+
foreach(var p in tmp)
65+
{
66+
protocols.Add(p);
67+
}
68+
}
69+
}
70+
71+
if (UseCustomProtocols)
72+
{
73+
return protocols.Concat(CustomProtocols).DistinctBy(x => x.ToLower()).ToArray();
74+
}
75+
else
76+
{
77+
return protocols.DistinctBy(x => x.ToLower()).ToArray();
78+
}
79+
}
4880

81+
public bool EnableStartMenuSource { get; set; } = true;
4982
public bool EnableDescription { get; set; } = false;
5083
public bool HideAppsPath { get; set; } = true;
5184
public bool EnableRegistrySource { get; set; } = true;

0 commit comments

Comments
 (0)