Skip to content

Commit

Permalink
Merge pull request #134 from PhantomGamers/dev
Browse files Browse the repository at this point in the history
  • Loading branch information
PhantomGamers committed Jun 23, 2023
2 parents 644485d + 0462d7a commit 470938c
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 25 deletions.
52 changes: 40 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
# SFP (Formerly SteamFriendsPatcher)

This utility allows you to apply themes and scripts to the new Steam beta client.
This utility allows you to apply skins and scripts to the new Steam client.

- [SFP (Formerly SteamFriendsPatcher)](#sfp--formerly-steamfriendspatcher-)
* [Instructions](#instructions)
* [Features](#features)
+ [Steam Skinning](#steam-skinning)
+ [Scripting](#scripting)
+ [Skins and Scripts in Separate Folders](#skins-and-scripts-in-separate-folders)
+ [Enable JavaScript Injection](#enable-javascript-injection)
* [Skin Authors](#skin-authors)
+ [Matching against pages with variable titles](#matching-against-pages-with-variable-titles)
+ [Finding Steam Page Titles](#finding-steam-page-titles)
* [Todo](#todo)
* [Known Issues](#known-issues)
* [Dependencies](#dependencies)
+ [All](#all)
+ [Linux](#linux)
* [Credits](#credits)

<small><i><a href='http://ecotrust-canada.github.io/markdown-toc/'>Table of contents generated with markdown-toc</a></i></small>

## Instructions

Expand All @@ -16,6 +35,8 @@ This utility allows you to apply themes and scripts to the new Steam beta client
- This setting is enabled by default
6. Use the "Open File" button in SFP to access the files where your custom skins and scripts are applied from.

For more information and links to existing skins see [Steam Skins Wiki](https://steamskins.pages.dev/)

## Features

### Steam Skinning
Expand Down Expand Up @@ -68,11 +89,6 @@ Default `skin.json`:
"TargetCss": "webkit.css",
"TargetJs": "webkit.js"
},
{
"MatchRegexString": ".friendsui-container",
"TargetCss": "friends.custom.css",
"TargetJs": "friends.custom.js"
},
{
"MatchRegexString": "^Steam$",
"TargetCss": "libraryroot.custom.css",
Expand All @@ -88,11 +104,6 @@ Default `skin.json`:
"TargetCss": "libraryroot.custom.css",
"TargetJs": "libraryroot.custom.js"
},
{
"MatchRegexString": "Menu$",
"TargetCss": "libraryroot.custom.css",
"TargetJs": "libraryroot.custom.js"
},
{
"MatchRegexString": "Supernav$",
"TargetCss": "libraryroot.custom.css",
Expand Down Expand Up @@ -128,6 +139,16 @@ Default `skin.json`:
"TargetCss": "bigpicture.custom.css",
"TargetJs": "bigpicture.custom.js"
},
{
"MatchRegexString": ".friendsui-container",
"TargetCss": "friends.custom.css",
"TargetJs": "friends.custom.js"
},
{
"MatchRegexString": "Menu$",
"TargetCss": "libraryroot.custom.css",
"TargetJs": "libraryroot.custom.js"
},
{
"MatchRegexString": ".ModalDialogPopup",
"TargetCss": "libraryroot.custom.css",
Expand Down Expand Up @@ -186,16 +207,23 @@ visit <http://localhost:8080> in your web browser.

## Todo

- Add ability to install and customize themes directly from SFP
- Add ability to install and customize skins directly from SFP

## Known Issues

- None currently

## Dependencies

### All

- [.NET 7.0](https://dotnet.microsoft.com/en-us/download/dotnet/7.0) (Only if not using self contained version)

### Linux

- ttf-ms-fonts
- run `fc-cache --force` after installing

## Credits

- Darth from the Steam community forums for the method.
Expand Down
3 changes: 3 additions & 0 deletions SFP/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
<setting name="DumpPages" serializeAs="String">
<value>False</value>
</setting>
<setting name="UseAppTheme" serializeAs="String">
<value>True</value>
</setting>
</SFP.Properties.Settings>
</userSettings>
</configuration>
12 changes: 6 additions & 6 deletions SFP/Models/Injection/Config/SfpConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ public class SfpConfig
MatchRegexString = "https://store.steampowered.com", TargetCss = "webkit.css", TargetJs = "webkit.js"
},
new PatchEntry { MatchRegexString = "https://steamcommunity.com", TargetCss = "webkit.css", TargetJs = "webkit.js" },
// Friends List and Chat
new PatchEntry
{
MatchRegexString = @".friendsui-container", TargetCss = "friends.custom.css", TargetJs = "friends.custom.js"
},
new PatchEntry
{
MatchRegexString = "^Steam$", TargetCss = "libraryroot.custom.css", TargetJs = "libraryroot.custom.js"
Expand All @@ -69,7 +64,6 @@ public class SfpConfig
{
MatchRegexString = "^SP Overlay:", TargetCss = "libraryroot.custom.css", TargetJs = "libraryroot.custom.js"
},
new PatchEntry { MatchRegexString = "Menu$", TargetCss = "libraryroot.custom.css", TargetJs = "libraryroot.custom.js" },
new PatchEntry
{
MatchRegexString = @"Supernav$", TargetCss = "libraryroot.custom.css", TargetJs = "libraryroot.custom.js"
Expand Down Expand Up @@ -106,6 +100,12 @@ public class SfpConfig
{
MatchRegexString = "^MainMenu_", TargetCss = "bigpicture.custom.css", TargetJs = "bigpicture.custom.js"
},
// Friends List and Chat
new PatchEntry
{
MatchRegexString = @".friendsui-container", TargetCss = "friends.custom.css", TargetJs = "friends.custom.js"
},
new PatchEntry { MatchRegexString = "Menu$", TargetCss = "libraryroot.custom.css", TargetJs = "libraryroot.custom.js" },
new PatchEntry
{
// Steam Dialog popups (Settings, Game Properties, etc)
Expand Down
47 changes: 47 additions & 0 deletions SFP/Models/Injection/Injector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public static partial class Injector

public static event EventHandler? InjectionStateChanged;

private static string PreferredColorScheme { get; set; } = "light";

public static async Task StartInjectionAsync(bool noError = false)
{
if (s_browser is { IsConnected: true })
Expand Down Expand Up @@ -93,6 +95,7 @@ private static async Task InjectAsync()
var pages = await s_browser.PagesAsync();
Log.Logger.Info("Found " + pages.Length + " pages");

_ = SfpConfig.GetConfig();
var processTasks = pages.Select(ProcessPage);

await Task.WhenAll(processTasks);
Expand Down Expand Up @@ -185,6 +188,11 @@ private static async Task ProcessPage(Page? page)
return;
}

if (Settings.Default.UseAppTheme)
{
await UpdateColorInPage(page);
}

page.FrameNavigated -= Frame_Navigate;
page.FrameNavigated += Frame_Navigate;

Expand Down Expand Up @@ -415,6 +423,45 @@ private static bool IsFrameWebkit(Frame frame)
return !frame.Url.StartsWith("https://steamloopback.host");
}

private static async Task UpdateColorInPage(Page page)
{
try
{
await page.EmulateMediaFeaturesAsync(new[]
{ new MediaFeatureValue { MediaFeature = MediaFeature.PrefersColorScheme, Value = PreferredColorScheme } });
}
catch (PuppeteerException e)
{
Log.Logger.Error(e);
}
}

public static async void UpdateColorScheme(string? colorScheme = null)
{
if (s_browser == null || !Settings.Default.UseAppTheme && colorScheme == null)
{
return;
}

var tmpColorScheme = PreferredColorScheme;
PreferredColorScheme = colorScheme ?? PreferredColorScheme;

var pages = await s_browser.PagesAsync();
var processTasks = pages.Select(UpdateColorInPage);
await Task.WhenAll(processTasks);

PreferredColorScheme = tmpColorScheme;
}

public static void SetColorScheme(string themeVariant)
{
PreferredColorScheme = themeVariant.ToLower() switch
{
"dark" => "dark",
_ => "light"
};
}

[GeneratedRegex(@"^(?:https?:\/\/)?(?:[^@\/\n]+@)?(?:www\.)?([^:\/?\n]+)")]
private static partial Regex GetDomainRegex();
}
5 changes: 2 additions & 3 deletions SFP/Models/Steam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,6 @@ public static async Task TryInject()
var argumentsMissing = await CheckForMissingArgumentsAsync();
if (argumentsMissing)
{
s_injectOnce = true;
Log.Logger.Warn("Steam is missing arguments, restarting Steam to fix...");
return;
}
}
Expand Down Expand Up @@ -383,7 +381,7 @@ private static async Task<bool> CheckForMissingArgumentsAsync()

var args = Settings.Default.SteamLaunchArgs.Trim().ToLower();
const string DebuggingString = @"-cef-enable-debugging";
if (!args.Contains(DebuggingString))
if (!args.Split(' ', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries).Contains(DebuggingString))
{
args += $" {DebuggingString}";
args = args.Trim();
Expand All @@ -397,6 +395,7 @@ private static async Task<bool> CheckForMissingArgumentsAsync()
return false;
}

s_injectOnce = true;
Log.Logger.Info("Steam process detected with missing launch arguments, restarting...");
await RestartSteam();
return true;
Expand Down
13 changes: 13 additions & 0 deletions SFP/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions SFP/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,8 @@
<Setting Name="DumpPages" Roaming="true" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="UseAppTheme" Roaming="true" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
17 changes: 14 additions & 3 deletions SFP_UI/App.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#region

using System.Diagnostics.CodeAnalysis;
using System.Reactive;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Avalonia.Styling;
using Avalonia.Threading;
using FluentAvalonia.Styling;
using ReactiveUI;
using SFP.Models;
using SFP.Models.Injection;
using SFP.Properties;
using SFP_UI.Models;
using SFP_UI.ViewModels;
Expand Down Expand Up @@ -41,8 +40,20 @@ public override async void OnFrameworkInitializationCompleted()

base.OnFrameworkInitializationCompleted();

if (Design.IsDesignMode)
{
return;
}

SetIconsState(Settings.Default.ShowTrayIcon);

Injector.SetColorScheme(ActualThemeVariant.ToString());
ActualThemeVariantChanged += (_, _) =>
{
Injector.SetColorScheme(ActualThemeVariant.ToString());
Injector.UpdateColorScheme();
};

await HandleStartupTasks();

if (Settings.Default.CheckForUpdates)
Expand All @@ -66,7 +77,7 @@ private static async Task HandleStartupTasks()
}
}

private static void SetIconsState(bool state)
public static void SetIconsState(bool state)
{
var icons = TrayIcon.GetIcons(Current!);
if (icons == null)
Expand Down
1 change: 1 addition & 0 deletions SFP_UI/Pages/SettingsPage.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<CheckBox IsChecked="{Binding ForceSteamArgs}">Force Steam arguments</CheckBox>
<CheckBox IsChecked="{Binding InjectCss}">Inject CSS</CheckBox>
<CheckBox IsChecked="{Binding InjectJs}">Inject JavaScript</CheckBox>
<CheckBox IsChecked="{Binding UseAppTheme}">Use App Theme</CheckBox>
<CheckBox IsChecked="{Binding DumpPages}">For Skin Authors: Dump Pages</CheckBox>
<Separator Margin="0,10" />

Expand Down
6 changes: 5 additions & 1 deletion SFP_UI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Runtime.InteropServices;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
using Avalonia.ReactiveUI;
using Avalonia.Threading;
using Bluegrams.Application;
Expand All @@ -14,6 +15,7 @@
using SFP_UI.Models;
using SFP_UI.Targets;
using SFP_UI.Views;
using SkiaSharp;

#endregion

Expand Down Expand Up @@ -118,7 +120,9 @@ private static AppBuilder BuildAvaloniaApp()
return AppBuilder.Configure<App>()
.UsePlatformDetect()
.LogToTrace()
.UseReactiveUI();
.UseReactiveUI()
.With(new Win32PlatformOptions { OverlayPopups = true })
.With(new FontManagerOptions { DefaultFamilyName = SKTypeface.Default.FamilyName ?? "Century Schoolbook" });
}

private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
Expand Down
Loading

0 comments on commit 470938c

Please sign in to comment.