Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Steam Desktop profile overwrite toggle in settings menu #1082

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions HandheldCompanion/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@
<setting name="LegionBatteryChargeLimit" serializeAs="String">
<value>False</value>
</setting>
<setting name="OverrideSteamProfileOnStart" serializeAs="String">
<value>True</value>
</setting>
</HandheldCompanion.Properties.Settings>
</userSettings>
</configuration>
33 changes: 31 additions & 2 deletions HandheldCompanion/Controls/Hints/Hint_SteamNeptuneDesktop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public Hint_SteamNeptuneDesktop() : base()
{
PlatformManager.Steam.Updated += Steam_Updated;
PlatformManager.Initialized += PlatformManager_Initialized;
SettingsManager.SettingValueChanged += SettingsManager_SettingValueChanged;

// default state
this.HintActionButton.Visibility = Visibility.Visible;
Expand All @@ -24,7 +25,8 @@ public Hint_SteamNeptuneDesktop() : base()
}

private void Steam_Updated(PlatformStatus status)
{
{
bool OverrideSteamProfileOnStart = SettingsManager.GetBoolean("OverrideSteamProfileOnStart");
bool DesktopProfileApplied = PlatformManager.Steam.HasDesktopProfileApplied();

// UI thread (async)
Expand All @@ -38,7 +40,24 @@ private void Steam_Updated(PlatformStatus status)
this.Visibility = Visibility.Collapsed;
break;
case PlatformStatus.Started:
this.Visibility = DesktopProfileApplied ? Visibility.Visible : Visibility.Collapsed;

if (OverrideSteamProfileOnStart)
{
this.HintTitle.Text = Properties.Resources.Hint_SteamNeptuneDesktop;
this.HintDescription.Text = Properties.Resources.Hint_SteamNeptuneDesktopDesc;
this.HintReadMe.Text = Properties.Resources.Hint_SteamNeptuneReadme;

this.Visibility = DesktopProfileApplied ? Visibility.Visible : Visibility.Collapsed;
}
else
{
this.HintTitle.Text = Properties.Resources.Hint_SteamNeptuneDesktopOverridden;
this.HintDescription.Text = Properties.Resources.Hint_SteamNeptuneDesktopOverriddenDesc;
this.HintReadMe.Text = Properties.Resources.Hint_SteamNeptuneReadmeOverridden;

this.Visibility = !DesktopProfileApplied ? Visibility.Visible : Visibility.Collapsed;
}

break;
}
});
Expand All @@ -49,6 +68,16 @@ private void PlatformManager_Initialized()
Steam_Updated(PlatformManager.Steam.Status);
}

private void SettingsManager_SettingValueChanged(string name, object value)
{
switch (name)
{
case "OverrideSteamProfileOnStart":
Steam_Updated(PlatformManager.Steam.Status);
break;
}
}

protected override void HintActionButton_Click(object sender, RoutedEventArgs e)
{
Task.Run(async () =>
Expand Down
48 changes: 43 additions & 5 deletions HandheldCompanion/Platforms/Steam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,24 @@ public override bool Stop(bool kill = false)
{
ProcessManager.ProcessStarted -= ProcessManager_ProcessStarted;

// restore files even if Steam is still running
RestoreFiles();
if (HasDesktopProfileApplied())
{
// restore files even if Steam is still running
RestoreFiles();
}

return base.Stop();
}

protected override void Process_Exited(object? sender, EventArgs e)
{
LogManager.LogDebug("Steam stopped, restoring files");
RestoreFiles();
SettingsManager.SettingValueChanged -= SettingsManager_SettingValueChanged;

if (HasDesktopProfileApplied())
{
LogManager.LogDebug("Steam stopped, restoring files");
RestoreFiles();
}
}

public bool HasXboxDriversInstalled()
Expand Down Expand Up @@ -140,14 +148,44 @@ private async void ProcessManager_ProcessStarted(ProcessEx processEx, bool OnSta
if (!OnStartup && processEx.Executable == RunningName)
{
await Task.Delay(3000);
ReplaceFiles();

// Overwrite files only if setting is enabled.
if (SettingsManager.GetBoolean("OverrideSteamProfileOnStart"))
{
ReplaceFiles();
}

SettingsManager.SettingValueChanged += SettingsManager_SettingValueChanged;

// hook into current process
if (Process is not null && !Process.HasExited)
Process.Exited += Process_Exited;
}
}

private void SettingsManager_SettingValueChanged(string name, object value)
{
switch (name)
{
case "OverrideSteamProfileOnStart":

if (Convert.ToBoolean(value))
{
if (HasDesktopProfileApplied())
{
// Steam profile applied, overwrite enabled
ReplaceFiles();
}
}
else if (!HasDesktopProfileApplied())
{
// Steam profile overwritten, overwrite disabled
RestoreFiles();
}
break;
}
}

public HashSet<string>? GetControllerBlacklist()
{
try
Expand Down
45 changes: 45 additions & 0 deletions HandheldCompanion/Properties/Resources.Designer.cs

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

15 changes: 15 additions & 0 deletions HandheldCompanion/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3012,4 +3012,19 @@ Motion input toggle: press selected button(s) to switch motion state.</value>
<data name="DevicePage_LegionBatteryChargeLimit_Desc" xml:space="preserve">
<value>Sets the maximum charge level of the battery to 80%</value>
</data>
<data name="SettingsPage_OverrideSteamProfileOnStart" xml:space="preserve">
<value>Override Steam profiles at startup</value>
</data>
<data name="SettingsPage_OverrideSteamProfileOnStartDesc" xml:space="preserve">
<value>Default Steam desktop and chord input profiles will be swapped for empty ones on application start</value>
</data>
<data name="Hint_SteamNeptuneDesktopOverridden" xml:space="preserve">
<value>Steam Desktop Layout is overwritten</value>
</data>
<data name="Hint_SteamNeptuneDesktopOverriddenDesc" xml:space="preserve">
<value>Steam is already running and Steam Desktop Layout is overwritten by Handheld Companion, but this setting was disabled by the user</value>
</data>
<data name="Hint_SteamNeptuneReadmeOverridden" xml:space="preserve">
<value>You should restart Steam, so that Steam Desktop Layout can be reset to defaults</value>
</data>
</root>
24 changes: 18 additions & 6 deletions HandheldCompanion/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 HandheldCompanion/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -275,5 +275,8 @@
<Setting Name="LegionBatteryChargeLimit" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="OverrideSteamProfileOnStart" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
38 changes: 38 additions & 0 deletions HandheldCompanion/Views/Pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,44 @@
</Grid>
</Border>

<!-- Override default Steam desktop and chord profiles on start -->
<Border
Padding="15,12,12,12"
Background="{DynamicResource ExpanderHeaderBackground}"
CornerRadius="{DynamicResource ControlCornerRadius}">

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5*" MinWidth="200" />
<ColumnDefinition Width="5*" MinWidth="200" />
</Grid.ColumnDefinitions>

<DockPanel>
<ui:FontIcon
Height="40"
HorizontalAlignment="Center"
FontFamily="{DynamicResource SymbolThemeFontFamily}"
Glyph="&#xEA6C;" />

<ui:SimpleStackPanel Margin="12,0,0,0" VerticalAlignment="Center">
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Text="{l:Static resx:Resources.SettingsPage_OverrideSteamProfileOnStart}" />
<TextBlock
Foreground="{DynamicResource SystemControlForegroundBaseMediumBrush}"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{l:Static resx:Resources.SettingsPage_OverrideSteamProfileOnStartDesc}"
TextWrapping="Wrap" />
</ui:SimpleStackPanel>
</DockPanel>

<ui:ToggleSwitch
Name="Toggle_OverrideSteamProfileOnStart"
Grid.Column="1"
HorizontalAlignment="Right"
Style="{DynamicResource InvertedToggleSwitchStyle}"
Toggled="Toggle_OverrideSteamProfileOnStart_Toggled" />
</Grid>
</Border>

<!-- Native display orientation -->
<Border
Padding="15,12,12,12"
Expand Down
11 changes: 11 additions & 0 deletions HandheldCompanion/Views/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ private void SettingsManager_SettingValueChanged(string? name, object value)
case "DesktopProfileOnStart":
Toggle_DesktopProfileOnStart.IsOn = Convert.ToBoolean(value);
break;
case "OverrideSteamProfileOnStart":
Toggle_OverrideSteamProfileOnStart.IsOn = Convert.ToBoolean(value);
break;
case "NativeDisplayOrientation":
var nativeOrientation = (ScreenRotation.Rotations)Convert.ToInt32(value);

Expand Down Expand Up @@ -207,6 +210,14 @@ private void Toggle_DesktopProfileOnStart_Toggled(object? sender, RoutedEventArg
SettingsManager.SetProperty("DesktopProfileOnStart", Toggle_DesktopProfileOnStart.IsOn);
}

private void Toggle_OverrideSteamProfileOnStart_Toggled(object? sender, RoutedEventArgs? e)
{
if (!IsLoaded)
return;

SettingsManager.SetProperty("OverrideSteamProfileOnStart", Toggle_OverrideSteamProfileOnStart.IsOn);
}

private void Button_DetectNativeDisplayOrientation_Click(object sender, RoutedEventArgs? e)
{
if (!IsLoaded)
Expand Down