Skip to content

Commit b657648

Browse files
committed
Updated high priority feature
1 parent e3eeca2 commit b657648

File tree

8 files changed

+84
-155
lines changed

8 files changed

+84
-155
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,8 @@ MigrationBackup/
348348

349349
# Ionide (cross platform F# VS Code tools) working folder
350350
.ionide/
351+
Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorPage.xaml.cs
352+
Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorPage.xaml
353+
Bloxstrap/UI/Elements/Dialogs/FlagWindow.xaml
354+
Bloxstrap/UI/Elements/Dialogs/FlagWindow.xaml.cs
355+
Bloxstrap/UI/Elements/Settings/Pages/FastFlagEditorPage.xaml

Bloxstrap/Bootstrapper.cs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -624,20 +624,33 @@ private void StartRoblox()
624624
{
625625
using var process = Process.Start(startInfo)!;
626626

627-
// Apply High CPU Priority if enabled in settings
628-
if (App.Settings.Prop.HighPriority)
627+
// Apply CPU Priority based on user selection in settings
628+
try
629629
{
630-
try
631-
{
632-
process.PriorityClass = ProcessPriorityClass.High;
633-
App.Logger.WriteLine(LOG_IDENT, "Set Roblox process priority to High.");
634-
}
635-
catch (Exception ex)
630+
var selectedPriority = App.Settings.Prop.SelectedProcessPriority;
631+
632+
if (selectedPriority != ProcessPriorityOption.Normal)
636633
{
637-
App.Logger.WriteLine(LOG_IDENT, $"Failed to set process priority: {ex}");
638-
System.Windows.MessageBox.Show($"Failed to set High CPU Priority:\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
634+
ProcessPriorityClass priorityClass = selectedPriority switch
635+
{
636+
ProcessPriorityOption.Low => ProcessPriorityClass.Idle,
637+
ProcessPriorityOption.BelowNormal => ProcessPriorityClass.BelowNormal,
638+
ProcessPriorityOption.Normal => ProcessPriorityClass.Normal,
639+
ProcessPriorityOption.AboveNormal => ProcessPriorityClass.AboveNormal,
640+
ProcessPriorityOption.High => ProcessPriorityClass.High,
641+
_ => ProcessPriorityClass.Normal
642+
};
643+
644+
Process currentProcess = Process.GetCurrentProcess();
645+
currentProcess.PriorityClass = priorityClass;
639646
}
640647
}
648+
catch (Exception ex)
649+
{
650+
App.Logger.WriteLine(LOG_IDENT, $"Failed to set process priority: {ex}");
651+
System.Windows.MessageBox.Show($"Failed to set CPU Priority:\n{ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
652+
}
653+
641654

642655
_appPid = process.Id;
643656

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Bloxstrap.Enums
2+
{
3+
public enum ProcessPriorityOption
4+
{
5+
Low,
6+
BelowNormal,
7+
Normal,
8+
AboveNormal,
9+
High,
10+
RealTime
11+
}
12+
}

Bloxstrap/Models/Persistable/Settings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class Settings
2828
public bool WPFSoftwareRender { get; set; } = false;
2929
public bool DisableAnimations { get; set; } = false;
3030
public bool DisableHardwareAcceleration { get; set; } = false;
31-
public bool HighPriority { get; set; } = false;
31+
public ProcessPriorityOption SelectedProcessPriority { get; set; } = ProcessPriorityOption.Normal;
3232
public string? CustomFontPath { get; set; } = null;
3333
public bool EnableAnalytics { get; set; } = false;
3434
public bool UpdateRoblox { get; set; } = true;

Bloxstrap/UI/Elements/Dialogs/InvalidFlagsWindow.xaml

Lines changed: 0 additions & 79 deletions
This file was deleted.

Bloxstrap/UI/Elements/Dialogs/InvalidFlagsWindow.xaml.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.

Bloxstrap/UI/Elements/Settings/Pages/ChannelPage.xaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,18 @@
7070
</controls:OptionControl>
7171

7272
<controls:OptionControl
73-
Header="High Priority"
74-
Description="Runs Roblox with high CPU priority using Task Manager.">
75-
<ui:ToggleSwitch IsChecked="{Binding HighPriority, Mode=TwoWay}" />
73+
Header="Roblox Process Priority"
74+
Description="Select the CPU priority for the Roblox process.">
75+
<ComboBox
76+
Width="200"
77+
Margin="5,0,0,0"
78+
Padding="10,5,10,5"
79+
ItemsSource="{Binding ProcessPriorityOptions, Mode=OneTime}"
80+
SelectedItem="{Binding SelectedPriority, Mode=TwoWay}" />
7681
</controls:OptionControl>
7782

7883

84+
7985
<controls:OptionControl
8086
x:Name="FlagStateOption"
8187
Header="{x:Static resources:Strings.Menu_Channel_VersionHash_Title}"

Bloxstrap/UI/ViewModels/Settings/ChannelViewModel.cs

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
using System.ComponentModel;
2-
using System.Windows;
3-
using System.Windows.Interop;
4-
using System.Windows.Media;
5-
using Bloxstrap.AppData;
6-
using Bloxstrap.Integrations;
72
using Bloxstrap.RobloxInterfaces;
8-
using Wpf.Ui.Hardware;
93

104
namespace Bloxstrap.UI.ViewModels.Settings
115
{
6+
127
public class ChannelViewModel : NotifyPropertyChangedViewModel
138
{
149
public ChannelViewModel()
1510
{
1611
Task.Run(() => LoadChannelDeployInfo(App.Settings.Prop.Channel));
12+
13+
// Initialize SelectedPriority from settings
14+
_selectedPriority = App.Settings.Prop.SelectedProcessPriority;
1715
}
1816

1917
public new event PropertyChangedEventHandler? PropertyChanged;
@@ -25,14 +23,6 @@ public bool UpdateCheckingEnabled
2523
get => App.Settings.Prop.CheckForUpdates;
2624
set => App.Settings.Prop.CheckForUpdates = value;
2725
}
28-
29-
public bool HighPriority
30-
{
31-
get => App.Settings.Prop.HighPriority;
32-
set => App.Settings.Prop.HighPriority = value;
33-
}
34-
35-
3626
public bool DisableAnimations
3727
{
3828
get => App.Settings.Prop.DisableAnimations;
@@ -45,6 +35,26 @@ public bool HardwareAcceleration
4535
set => App.Settings.Prop.WPFSoftwareRender = value;
4636
}
4737

38+
39+
private ProcessPriorityOption _selectedPriority;
40+
41+
public IReadOnlyList<ProcessPriorityOption> ProcessPriorityOptions { get; } =
42+
Enum.GetValues(typeof(ProcessPriorityOption)).Cast<ProcessPriorityOption>().ToList();
43+
44+
public ProcessPriorityOption SelectedPriority
45+
{
46+
get => _selectedPriority;
47+
set
48+
{
49+
if (_selectedPriority != value)
50+
{
51+
_selectedPriority = value;
52+
App.Settings.Prop.SelectedProcessPriority = value;
53+
OnPropertyChanged(nameof(SelectedPriority));
54+
}
55+
}
56+
}
57+
4858
private async Task LoadChannelDeployInfo(string channel)
4959
{
5060
ShowLoadingError = false;
@@ -78,17 +88,17 @@ private async Task LoadChannelDeployInfo(string channel)
7888
ShowLoadingError = true;
7989
OnPropertyChanged(nameof(ShowLoadingError));
8090

81-
// channels that dont exist also throw HttpStatusCode.Unauthorized
8291
if (ex.StatusCode == HttpStatusCode.Unauthorized)
8392
ChannelInfoLoadingText = Strings.Menu_Channel_Switcher_Unauthorized;
8493
else
85-
ChannelInfoLoadingText = $"An http error has occured ({ex.StatusCode})"; // i dont think we need strings for errors
94+
ChannelInfoLoadingText = $"An http error has occured ({ex.StatusCode})";
8695

8796
OnPropertyChanged(nameof(ChannelInfoLoadingText));
8897
}
8998
}
9099

91-
public bool IsRobloxInstallationMissing => String.IsNullOrEmpty(App.RobloxState.Prop.Player.VersionGuid) && String.IsNullOrEmpty(App.RobloxState.Prop.Studio.VersionGuid);
100+
public bool IsRobloxInstallationMissing => string.IsNullOrEmpty(App.RobloxState.Prop.Player.VersionGuid) &&
101+
string.IsNullOrEmpty(App.RobloxState.Prop.Studio.VersionGuid);
92102

93103
public bool ShowLoadingError { get; set; } = false;
94104
public bool ShowChannelWarning { get; set; } = false;
@@ -115,7 +125,7 @@ public string ChannelHash
115125
{
116126
const string VersionHashFormat = "version-(.*)";
117127
Match match = Regex.Match(value, VersionHashFormat);
118-
if (match.Success || String.IsNullOrEmpty(value))
128+
if (match.Success || string.IsNullOrEmpty(value))
119129
{
120130
App.Settings.Prop.ChannelHash = value;
121131
}
@@ -129,11 +139,11 @@ public bool UpdateRoblox
129139
}
130140

131141
public IReadOnlyDictionary<string, ChannelChangeMode> ChannelChangeModes => new Dictionary<string, ChannelChangeMode>
132-
{
133-
{ Strings.Menu_Channel_ChangeAction_Automatic, ChannelChangeMode.Automatic },
134-
{ Strings.Menu_Channel_ChangeAction_Prompt, ChannelChangeMode.Prompt },
135-
{ Strings.Menu_Channel_ChangeAction_Ignore, ChannelChangeMode.Ignore },
136-
};
142+
{
143+
{ Strings.Menu_Channel_ChangeAction_Automatic, ChannelChangeMode.Automatic },
144+
{ Strings.Menu_Channel_ChangeAction_Prompt, ChannelChangeMode.Prompt },
145+
{ Strings.Menu_Channel_ChangeAction_Ignore, ChannelChangeMode.Ignore },
146+
};
137147

138148
public string SelectedChannelChangeMode
139149
{
@@ -147,4 +157,4 @@ public bool ForceRobloxReinstallation
147157
set => App.State.Prop.ForceReinstall = value;
148158
}
149159
}
150-
}
160+
}

0 commit comments

Comments
 (0)