Skip to content

Commit

Permalink
Merge pull request #20 from KrystianLesniak/develop
Browse files Browse the repository at this point in the history
Release: 1.4.0
  • Loading branch information
KrystianLesniak authored Sep 13, 2023
2 parents 710251e + 3bd1c6e commit 12567ee
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 7 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ GamesLauncher is a plugin for [Flow launcher](https://github.com/Flow-Launcher/F
* Epic Games Launcher
* Xbox
* Amazon Games
* [Custom Shortcuts](#custom-shortcuts)

## Installation
In Flow Launcher, use the plugin store to find "GamesLauncher" or type:
Expand All @@ -39,6 +40,13 @@ You can disable specific platforms via settings menu.

<img src="docs/settings.png" height="65%" width="65%">

### Custom shortcuts
If you have retail games (or on an unsupported platform) you can add your own shortcuts files (.lnk / .uri) to the plugin games list.

To do this, go to Settings -> Plugins -> GamesLauncher -> Open Custom Shortcuts Directory

Place your shortcut in the opened directory and... That's it! You can now `Reload Plugin Data` to update your library.

### Update library
If you have (un)installed a game, you can update the plugin without restarting Flow Launcher by using the `Reload Plugin Data` command.

Expand Down
Binary file modified docs/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions src/GamesLauncher.Common/Paths.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace GamesLauncher.Common
{
public static class Paths
{
public static string CustomShortcutsDirectory => Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"FlowLauncher", "Settings", "Plugins", "GamesLauncher Custom Shortcuts");
}
}
2 changes: 1 addition & 1 deletion src/GamesLauncher.Platforms/GamesLauncher.Platforms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReference Include="GameFinder.StoreHandlers.Steam" Version="4.0.0" />
<PackageReference Include="GameFinder.StoreHandlers.Xbox" Version="4.0.0" />
<PackageReference Include="Microsoft-WindowsAPICodePack-Shell" Version="1.1.5" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.10" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.11" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion src/GamesLauncher.Platforms/PlatformsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ private IEnumerable<ISyncEngine> InitializeEngines(MainSettings settings)
if (settings.SynchronizeSteam)
engines.Add(new SteamSyncEngine(publicApi));

if(settings.SynchronizeAmazon)
if (settings.SynchronizeAmazon)
engines.Add(new AmazonSyncEngine(publicApi));

engines.Add(new ShortcutsSyncEngine(publicApi));

return engines;
}

Expand Down
71 changes: 71 additions & 0 deletions src/GamesLauncher.Platforms/SyncEngines/ShortcutsSyncEngine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using Flow.Launcher.Plugin;
using GamesLauncher.Common;

namespace GamesLauncher.Platforms.SyncEngines
{
public class ShortcutsSyncEngine : ISyncEngine

{
public string PlatformName => "Shortcut";

private readonly IPublicAPI publicApi;
private readonly DirectoryInfo shortcutsDirectory;

public ShortcutsSyncEngine(IPublicAPI publicApi)
{
this.publicApi = publicApi;
shortcutsDirectory = Directory.CreateDirectory(Paths.CustomShortcutsDirectory);
}

public async IAsyncEnumerable<Game> GetGames()
{
string[] shortcutExtensions = { "*.url", "*.lnk" };

foreach (var shortcutExtension in shortcutExtensions)
{
foreach (var shortcut in shortcutsDirectory.EnumerateFiles(shortcutExtension, SearchOption.AllDirectories))
{
yield return new Game(
Title: Path.GetFileNameWithoutExtension(shortcut.FullName),
RunTask: GetGameRunTask(shortcut.FullName),
IconPath: await GetIconPath(shortcut),
IconDelegate: null,
Platform: PlatformName
);
}
}
}

private Func<ActionContext, ValueTask<bool>> GetGameRunTask(string fullPath)
{
return (context) =>
{
publicApi.ShellRun($"start \"\" \"{fullPath}\"");
return ValueTask.FromResult(true);
};
}

private static async Task<string?> GetIconPath(FileInfo fileInfo)
{
if (fileInfo.Extension == ".lnk")
{
return fileInfo.FullName; //TODO: Take ico location path directly from lnk like it's done for url below. Flow Launcher weridly handles lnk icons
}

if (fileInfo.Extension == ".url")
{
await foreach (var line in File.ReadLinesAsync(fileInfo.FullName))
{
if (line.Trim().StartsWith("IconFile="))
{
return line.Replace("IconFile=", "").Trim();
}
}
}

return null;
}

}
}
7 changes: 6 additions & 1 deletion src/GamesLauncher/GamesLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
<RepositoryUrl>https://github.com/KrystianLesniak/Flow.Launcher.Plugin.GamesLauncher</RepositoryUrl>
<PackageTags>flow-launcher flow-plugin</PackageTags>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<UseWPF>true</UseWPF>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<Nullable>enable</Nullable>
<SelfContained>false</SelfContained>
</PropertyGroup>

<PropertyGroup>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<OutputPath>$([System.Environment]::GetFolderPath(SpecialFolder.ApplicationData))\FlowLauncher\Plugins\$(AssemblyName)</OutputPath>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugSymbols>false</DebugSymbols>
<DebugType>None</DebugType>
Expand Down
2 changes: 1 addition & 1 deletion src/GamesLauncher/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Task<List<Result>> QueryAsync(Query query, CancellationToken token)

public Control CreateSettingPanel()
{
return new SettingsView(_settings);
return new SettingsView(_settings, _publicApi);
}

private Result CreateResultFromGame(Game game, string search)
Expand Down
12 changes: 12 additions & 0 deletions src/GamesLauncher/Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
Expand Down Expand Up @@ -45,5 +46,16 @@
Margin="10,5,5,5"
HorizontalAlignment="Left"
Content="Amazon Games" />
<Button
Click="BtnOpenCustomShortcutsDirectory_Click"
Grid.Row="5"
Margin="10,5,5,5"
Padding="20,10,20,10"
HorizontalAlignment="Left"
Content="Open Custom Shortcuts Directory">
<Button.ToolTip>
<TextBlock>Place shortcuts (.lnk/.url) in this directory. They will be available in the games list.</TextBlock>
</Button.ToolTip>
</Button>
</Grid>
</UserControl>
13 changes: 11 additions & 2 deletions src/GamesLauncher/Views/SettingsView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using GamesLauncher.Common.Settings;
using Flow.Launcher.Plugin;
using GamesLauncher.Common;
using GamesLauncher.Common.Settings;
using System.Windows;
using System.Windows.Controls;

Expand All @@ -7,11 +9,13 @@ namespace GamesLauncher.Views
public partial class SettingsView : UserControl
{
private readonly MainSettings _settings;
private readonly IPublicAPI _publicAPI;

public SettingsView(MainSettings settings)
public SettingsView(MainSettings settings, IPublicAPI publicAPI)
{
InitializeComponent();
_settings = settings;
_publicAPI = publicAPI;
}

private void SettingsView_OnLoaded(object sender, RoutedEventArgs re)
Expand Down Expand Up @@ -57,5 +61,10 @@ private void SettingsView_OnLoaded(object sender, RoutedEventArgs re)
_settings.SynchronizeAmazon = false;
};
}

private void BtnOpenCustomShortcutsDirectory_Click(object sender, RoutedEventArgs e)
{
_publicAPI.ShellRun(Paths.CustomShortcutsDirectory, "explorer.exe");
}
}
}
2 changes: 1 addition & 1 deletion src/GamesLauncher/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Name": "GamesLauncher",
"Description": "Search and launch games from multiple platforms like Steam, Epic Games, Xbox etc.",
"Author": "KrystianLesniak",
"Version": "1.3.0",
"Version": "1.4.0",
"Language": "csharp",
"Website": "https://github.com/KrystianLesniak/Flow.Launcher.Plugin.GamesLauncher",
"IcoPath": "icon.png",
Expand Down

0 comments on commit 12567ee

Please sign in to comment.