Skip to content

Commit

Permalink
Merge pull request #34 from KrystianLesniak/develop
Browse files Browse the repository at this point in the history
Release: 1.5.0
  • Loading branch information
KrystianLesniak authored Oct 21, 2023
2 parents d6dadb5 + eb2882a commit fa2d514
Show file tree
Hide file tree
Showing 14 changed files with 186 additions and 26 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ You can disable specific platforms via settings menu.
### 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
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.

![Reload](docs/reload.png)

### Hide an item
You can hide a specific game from the plugin list by accessing the context menu (`right arrow`) and using the `Hide` command.

![Hide Game](docs/hide.png)

The game can be unhidden later from the settings menu.
Binary file added docs/hide.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
46 changes: 46 additions & 0 deletions src/GamesLauncher.Common/Settings/HiddenGames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace GamesLauncher.Common.Settings
{
public class HiddenGames
{
public List<HiddenGame> Items { get; set; } = new List<HiddenGame>() //This property and class needs to be public to be retrieved by FL Settings
{
new HiddenGame
{
InternalGameId = "Steam_Steamworks Common Redistributables",
Platform = "Steam",
Title = "Steamworks Common Redistributables"
}
};

public void Hide(string title, string platform, string internalGameId)
{
if (!Items.Any(x => x.InternalGameId == internalGameId))
{
Items.Add(new HiddenGame
{
InternalGameId = internalGameId,
Platform = platform,
Title = title
});
}
}

public void Unhide(HiddenGame hiddenGame)
{
Items.Remove(hiddenGame);
}

public bool IsHidden(string internalGameId)
{
return Items.Any(x => x.InternalGameId == internalGameId);
}
}

public class HiddenGame
{
public string Title { get; set; } = string.Empty;
public string Platform { get; set; } = string.Empty;
public string InternalGameId { get; set; } = string.Empty;
}

}
5 changes: 5 additions & 0 deletions src/GamesLauncher.Platforms/PlatformsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public IEnumerable<Game> GetSynchronizedGames()
return Games;
}

public Game? GetGame(string title, string platform)
{
return Games.FirstOrDefault(x=> x.Title == title && x.Platform == platform);
}

private IEnumerable<ISyncEngine> InitializeEngines(MainSettings settings)
{
var engines = new List<ISyncEngine>();
Expand Down
14 changes: 0 additions & 14 deletions src/GamesLauncher.Platforms/SyncEngines/Steam/SteamGamesConsts.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ public SteamSyncEngine(IPublicAPI publicApi)
public async IAsyncEnumerable<Game> GetGames()
{
var result = handler.FindAllGames();
var games = result.Where(x => x.IsGame()).Select(x => x.AsGame())
.Where(x => SteamGamesConsts.AppIdsToIgnore.Contains(x.AppId.Value) == false);
var games = result.Where(x => x.IsGame()).Select(x => x.AsGame());

foreach (var game in games)
{
Expand Down
2 changes: 1 addition & 1 deletion src/GamesLauncher.Platforms/SyncEngines/XboxSyncEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private Func<ActionContext, ValueTask<bool>> GetGameRunTask(string cmd)
if (bitmapSource == null || bitmapSource.CanFreeze == false)
return null;

bitmapSource.Freeze();
bitmapSource.Freeze(); //This is needed. Otherwise FL throws exception for some users.

return delegate ()
{
Expand Down
7 changes: 7 additions & 0 deletions src/GamesLauncher/GamesLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
<None Update="icon.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Images\excludeindexpath.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<Folder Include="Images\" />
</ItemGroup>

</Project>
Binary file added src/GamesLauncher/Images/excludeindexpath.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 38 additions & 6 deletions src/GamesLauncher/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@

namespace GamesLauncher
{
public class Main : IAsyncPlugin, ISettingProvider, IAsyncReloadable
public class Main : IAsyncPlugin, ISettingProvider, IAsyncReloadable, IContextMenu
{
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
private IPublicAPI _publicApi;
private MainSettings _settings;
private LastPlayedGames _lastPlayedGames;
private HiddenGames _hiddenGames;

private IPublicAPI _publicApi;
private PlatformsManager _platformsManager;
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.

Expand All @@ -28,6 +29,7 @@ public async Task InitAsync(PluginInitContext context)
_publicApi = context.API;
_settings = _publicApi.LoadSettingJsonStorage<MainSettings>();
_lastPlayedGames = _publicApi.LoadSettingJsonStorage<LastPlayedGames>();
_hiddenGames = _publicApi.LoadSettingJsonStorage<HiddenGames>();

_platformsManager = new PlatformsManager(context.API);

Expand All @@ -45,16 +47,47 @@ public Task<List<Result>> QueryAsync(Query query, CancellationToken token)

var search = query.Search.Trim();

return Task.FromResult(gamesQuery.Select(x => CreateResultFromGame(x, search)).ToList());
return Task.FromResult(
gamesQuery.Select(x =>
CreateQueryResultFromGame(x, search))
.Where(x => x != null).Select(x => x!).ToList());
}

public List<Result> LoadContextMenus(Result selectedResult)
{
var results = new List<Result>();

var game = _platformsManager.GetGame(selectedResult.Title, selectedResult.SubTitle);

if (game is null)
return results;

results.Add(new Result
{
Title = "Hide",
SubTitle = "The game can be unhidden in settings panel",
IcoPath = @"Images\excludeindexpath.png",
Glyph = new GlyphInfo(FontFamily: "/Resources/#Segoe Fluent Icons", Glyph: "\ued1a"),
AsyncAction = (context) =>
{
_hiddenGames.Hide(game.Title, game.Platform, game.InternalGameId);
return ValueTask.FromResult(false);
}
});

return results;
}

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

private Result CreateResultFromGame(Game game, string search)
private Result? CreateQueryResultFromGame(Game game, string search)
{
if (_hiddenGames.IsHidden(game.InternalGameId))
return null;

var result = new Result
{
Title = game.Title,
Expand Down Expand Up @@ -84,6 +117,5 @@ private Result CreateResultFromGame(Game game, string search)

return result;
}

}
}
57 changes: 57 additions & 0 deletions src/GamesLauncher/Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
d:DesignHeight="300"
d:DesignWidth="300"
Loaded="SettingsView_OnLoaded"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
mc:Ignorable="d">
<Grid Margin="60,10,10,20" VerticalAlignment="Top">
<Grid.RowDefinitions>
Expand All @@ -16,6 +17,8 @@
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
Expand Down Expand Up @@ -57,5 +60,59 @@
<TextBlock>Place shortcuts (.lnk/.url) in this directory. They will be available in the games list.</TextBlock>
</Button.ToolTip>
</Button>
<Button
Click="BtnShowHiddenGames_Click"
Grid.Row="6"
Margin="10,5,5,5"
Padding="20,10,20,10"
HorizontalAlignment="Left"
Content="Hidden Games">
</Button>
<StackPanel
Name="HiddenGamesStackPanel"
Visibility="Collapsed"
Grid.Row="7">
<ListView
Name="HiddenGames"
Height="auto"
Margin="10"
BorderBrush="DarkGray"
BorderThickness="1"
ItemsSource="{Binding _hiddenGames.Items}" VerticalAlignment="Center">
<ListView.View>
<GridView>
<GridViewColumn Header="Title">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="0 10 0 0" Text="{Binding Title}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Platform" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="0 10 0 0" Text="{Binding Platform}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button
Click="BtnUnhideGame_Click"
CommandParameter="{Binding .}"
Margin="5,5,5,5"
Content="Unhide" VerticalAlignment="Center">
<Button.ToolTip>
<TextBlock>Unhide this item from plugin list</TextBlock>
</Button.ToolTip>
</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</StackPanel>
</Grid>
</UserControl>
23 changes: 22 additions & 1 deletion src/GamesLauncher/Views/SettingsView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Flow.Launcher.Plugin;
using GamesLauncher.Common;
using GamesLauncher.Common.Settings;
using System;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;

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

private readonly IPublicAPI _publicAPI;

public SettingsView(MainSettings settings, IPublicAPI publicAPI)
public SettingsView(MainSettings settings, HiddenGames hiddenGames, IPublicAPI publicAPI)
{
InitializeComponent();
_settings = settings;
_hiddenGames = hiddenGames;
_publicAPI = publicAPI;

HiddenGames.ItemsSource = new ObservableCollection<HiddenGame>(_hiddenGames.Items);
}

private void SettingsView_OnLoaded(object sender, RoutedEventArgs re)
Expand Down Expand Up @@ -66,5 +73,19 @@ private void BtnOpenCustomShortcutsDirectory_Click(object sender, RoutedEventArg
{
_publicAPI.ShellRun(Paths.CustomShortcutsDirectory, "explorer.exe");
}

private void BtnShowHiddenGames_Click(object sender, RoutedEventArgs e)
{
HiddenGamesStackPanel.Visibility = HiddenGamesStackPanel.Visibility == Visibility.Collapsed ? Visibility.Visible : Visibility.Collapsed;
}

private void BtnUnhideGame_Click(object sender, EventArgs e)
{
if ((sender as Button)?.CommandParameter is not HiddenGame gameToUnhide)
return;

_hiddenGames.Unhide(gameToUnhide);
HiddenGames.ItemsSource = new ObservableCollection<HiddenGame>(_hiddenGames.Items);
}
}
}
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.4.5",
"Version": "1.5.0",
"Language": "csharp",
"Website": "https://github.com/KrystianLesniak/Flow.Launcher.Plugin.GamesLauncher",
"IcoPath": "icon.png",
Expand Down

0 comments on commit fa2d514

Please sign in to comment.