Skip to content

Commit 750cfa4

Browse files
committed
Support .url file
1 parent caa2c75 commit 750cfa4

File tree

4 files changed

+39
-3
lines changed

4 files changed

+39
-3
lines changed

Flow.Launcher/ViewModel/ResultViewModel.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,17 @@ private async ValueTask LoadImageAsync()
163163
}
164164
}
165165

166+
var loadFullImage = (Path.GetExtension(imagePath) ?? "").Equals(".url", StringComparison.OrdinalIgnoreCase);
167+
166168
if (ImageLoader.CacheContainImage(imagePath))
167169
{
168170
// will get here either when icoPath has value\icon delegate is null\when had exception in delegate
169-
image = ImageLoader.Load(imagePath);
171+
image = ImageLoader.Load(imagePath, loadFullImage);
170172
return;
171173
}
172174

173175
// We need to modify the property not field here to trigger the OnPropertyChanged event
174-
Image = await Task.Run(() => ImageLoader.Load(imagePath)).ConfigureAwait(false);
176+
Image = await Task.Run(() => ImageLoader.Load(imagePath, loadFullImage)).ConfigureAwait(false);
175177
}
176178

177179
public Result Result { get; }

Plugins/Flow.Launcher.Plugin.Program/Flow.Launcher.Plugin.Program.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
</ItemGroup>
5959

6060
<ItemGroup>
61+
<PackageReference Include="ini-parser" Version="2.5.2" />
6162
<PackageReference Include="System.Runtime" Version="4.3.1" />
6263
</ItemGroup>
6364

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
using System.Diagnostics;
1717
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
1818
using System.Diagnostics.CodeAnalysis;
19+
using System.Text.RegularExpressions;
1920
using System.Threading.Channels;
21+
using Flow.Launcher.Infrastructure.Image;
22+
using IniParser;
2023

2124
namespace Flow.Launcher.Plugin.Program.Programs
2225
{
@@ -36,6 +39,7 @@ public class Win32 : IProgram, IEquatable<Win32>
3639
public string Location => ParentDirectory;
3740

3841
private const string ShortcutExtension = "lnk";
42+
private const string UrlExtension = "url";
3943
private const string ExeExtension = "exe";
4044

4145
private static readonly Win32 Default = new Win32()
@@ -287,6 +291,33 @@ private static Win32 LnkProgram(string path)
287291
#endif
288292
}
289293

294+
private static Win32 UrlProgram(string path)
295+
{
296+
var program = Win32Program(path);
297+
298+
var parser = new FileIniDataParser();
299+
var data = parser.ReadFile(path);
300+
301+
try
302+
{
303+
var urlSection = data["InternetShortcut"];
304+
305+
program.LnkResolvedPath = urlSection["URL"];
306+
307+
var iconPath = urlSection["IconFile"];
308+
if (Path.GetExtension(iconPath).Equals(".ico", StringComparison.OrdinalIgnoreCase))
309+
{
310+
program.IcoPath = iconPath;
311+
}
312+
}
313+
catch (Exception e)
314+
{
315+
// Many files do not have the required fields, so no logging is done.
316+
}
317+
318+
return program;
319+
}
320+
290321
private static Win32 ExeProgram(string path)
291322
{
292323
try
@@ -343,6 +374,7 @@ private static IEnumerable<Win32> UnregisteredPrograms(List<Settings.ProgramSour
343374
{
344375
ExeExtension => ExeProgram(x),
345376
ShortcutExtension => LnkProgram(x),
377+
UrlExtension => UrlProgram(x),
346378
_ => Win32Program(x)
347379
});
348380

@@ -365,6 +397,7 @@ private static IEnumerable<Win32> StartMenuPrograms(string[] suffixes)
365397
.Select(x => Extension(x) switch
366398
{
367399
ShortcutExtension => LnkProgram(x),
400+
UrlExtension => UrlProgram(x),
368401
_ => Win32Program(x)
369402
}).Where(x => x.Valid);
370403
return programs;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class Settings
99
public DateTime LastIndexTime { get; set; }
1010
public List<ProgramSource> ProgramSources { get; set; } = new List<ProgramSource>();
1111
public List<DisabledProgramSource> DisabledProgramSources { get; set; } = new List<DisabledProgramSource>();
12-
public string[] ProgramSuffixes { get; set; } = {"appref-ms", "exe", "lnk"};
12+
public string[] ProgramSuffixes { get; set; } = {"appref-ms", "exe", "lnk", "url"};
1313

1414
public bool EnableStartMenuSource { get; set; } = true;
1515

0 commit comments

Comments
 (0)