Skip to content

Commit

Permalink
PowerControl: Allow to set Autostart Profile Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ayufan committed Sep 24, 2023
1 parent 3ec48b5 commit 384e3a7
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
4 changes: 2 additions & 2 deletions PowerControl/Helpers/ProfileSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ public static String UserProfilesPath

public String ProfileName { get; }

public ProfileSettings(string profileName) : base("PersistentSettings")
public ProfileSettings(string prefix, string profileName) : base("PersistentSettings")
{
this.ProfileName = profileName;
this.ConfigFile = Path.Combine(UserProfilesPath, String.Format("PowerControl.Process.{0}.ini", profileName));
this.ConfigFile = Path.Combine(UserProfilesPath, String.Format("{0}.{1}.ini", prefix, profileName));

this.SettingChanging += delegate { };
this.SettingChanged += delegate { };
Expand Down
40 changes: 40 additions & 0 deletions PowerControl/Menu/MenuItemWithOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,50 @@ public override void CreateMenu(System.Windows.Forms.ContextMenuStrip contextMen
toolStripItem.DropDownItems.Add(item);
}

AddMenuItemsToModifyProfile(
PowerControl.Options.Profiles.Controller?.AutostartProfileSettings,
toolStripItem.DropDownItems
);

toolStripItem.Visible = Visible && Options.Count > 0;
};
}

private void AddMenuItemsToModifyProfile(Helper.ProfileSettings? profileSettings, ToolStripItemCollection dropDownItems)
{
if (profileSettings is null || PersistentKey is null)
return;

dropDownItems.Add(new ToolStripSeparator());

var headingItem = new ToolStripMenuItem(profileSettings.ProfileName + ": ");
dropDownItems.Add(headingItem);

var persistedValue = profileSettings.GetValue(PersistentKey);

foreach (var option in Options)
{
var item = new ToolStripMenuItem("Set: " + option);
item.Checked = option == persistedValue;
item.Click += delegate { profileSettings.SetValue(PersistentKey, option); };
headingItem.DropDownItems.Add(item);
}

if (persistedValue is not null)
{
headingItem.Text += persistedValue;
headingItem.Checked = true;

headingItem.DropDownItems.Add(new ToolStripSeparator());
var unsetItem = headingItem.DropDownItems.Add("Unset");
unsetItem.Click += delegate { profileSettings.DeleteKey(PersistentKey); };
}
else
{
headingItem.Text += "Not set";
}
}

private void SelectIndex(int index)
{
if (Options.Count == 0)
Expand Down
10 changes: 8 additions & 2 deletions PowerControl/ProfilesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,20 @@ public IEnumerable<String> WatchedProfiles
public ProfileSettings? GameProfileSettings { get; private set; }

public ProfileSettings? SessionProfileSettings { get; private set; }
public ProfileSettings AutostartProfileSettings { get; private set; }

public ProfilesController()
{
PowerControl.Options.Profiles.Controller = this;
MenuStack.Root.ValueChanged += Root_OnOptionValueChange;

AutostartProfileSettings = new ProfileSettings("PowerControl", "Autostart");

timer.Start();
timer.Tick += Timer_Tick;

ProfileChanged(null);
ApplyProfile(AutostartProfileSettings);
}

~ProfilesController()
Expand Down Expand Up @@ -106,13 +112,13 @@ private void AddProcess(int processId, string processName)
{
Log.TraceLine("ProfilesController: New Process: {0}/{1}", processId, processName);

var profileSettings = new ProfileSettings(processName);
var profileSettings = new ProfileSettings("PowerControl.Process", processName);
watchedProcesses.Add(processId, profileSettings);

// Create memory only SessionProfileSettings
if (SessionProfileSettings is null)
{
SessionProfileSettings = new ProfileSettings("Session:" + processName) { UseConfigFile = false };
SessionProfileSettings = new ProfileSettings("PowerControl.Session", "Session." + processName) { UseConfigFile = false };
SaveProfile(SessionProfileSettings);
}

Expand Down
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

## 0.6.16

- PowerControl: Allow to set Autostart Profile Settings
- PowerControl: Show Game Profiles menu item
- PowerControl: Improve handling of restoring DesktopProfile
- All: Support [unofficial APU drivers](https://sourceforge.net/projects/amernimezone/files/Release%20Polaris-Vega-Navi/AMD%20SOC%20Driver%20Variant/) that present themselves as `AMD Radeon 670M`
Expand Down

0 comments on commit 384e3a7

Please sign in to comment.