Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions ClevoFanControl/ClevoFanControl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Win32.TaskScheduler, Version=2.9.2.0, Culture=neutral, PublicKeyToken=e25603a88b3aa7da, processorArchitecture=MSIL">
<HintPath>..\packages\TaskScheduler.2.9.2\lib\net452\Microsoft.Win32.TaskScheduler.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Management" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand Down Expand Up @@ -83,6 +87,7 @@
<DesignTime>True</DesignTime>
</Compile>
<None Include="app.manifest" />
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down
12 changes: 11 additions & 1 deletion ClevoFanControl/frmMain.Designer.cs

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

84 changes: 78 additions & 6 deletions ClevoFanControl/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Win32.TaskScheduler;
//using OpenHardwareMonitor.Hardware;


Expand Down Expand Up @@ -133,6 +134,7 @@ private void Form1_Load(object sender, EventArgs e) {
gpuFanTable = defaultGpuFanTable;

LoadFanTableAndConfig();
CheckAutoStartState();

SetSliderValuesFromTable();

Expand Down Expand Up @@ -666,6 +668,35 @@ private void LoadFanTableAndConfig() {

}

private void CheckAutoStartState(){
using (TaskService ts = new TaskService())
{
Microsoft.Win32.TaskScheduler.Task task = ts.GetTask("ClevoFanControl");
if (task == null){
mnuAutostart.Checked = false;
return;
}
else
{
if (!task.IsActive){
mnuAutostart.Checked = false;
return;
}
foreach(Microsoft.Win32.TaskScheduler.Action a in task.Definition.Actions){
if(a.ActionType == TaskActionType.Execute){
Microsoft.Win32.TaskScheduler.ExecAction exec = (Microsoft.Win32.TaskScheduler.ExecAction)a;
if (exec.Path == Application.ExecutablePath){
mnuAutostart.Checked = true;
return;
}
}
}
}
mnuAutostart.Checked = false;
return;
}
}

private void SaveFanTableAndConfig() {

var path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\";
Expand Down Expand Up @@ -727,13 +758,49 @@ private void ShowWindow() {
WindowState = FormWindowState.Normal;
ShowInTaskbar = true;
}

private void AutoStartToggle(){
using (TaskService ts = new TaskService())
{
if (mnuAutostart.Checked == false)
{
ts.RootFolder.DeleteTask("ClevoFanControl",false);
// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description = "ClevoFanControl auto start.";

// Create a trigger
td.Triggers.Add(new LogonTrigger());
string exe_path = Application.ExecutablePath;

// Create an action that will launch ClevoFanControl
td.Actions.Add(new ExecAction(exe_path, null));
// Start on battety used
td.Settings.DisallowStartIfOnBatteries = false;

// Run with highest privilege
td.Principal.RunLevel = TaskRunLevel.Highest;


// Register the task in the root folder
ts.RootFolder.RegisterTaskDefinition("ClevoFanControl", td);
mnuAutostart.Checked = true;
}
else
{
ts.RootFolder.DeleteTask("ClevoFanControl", false);
mnuAutostart.Checked = false;
}
}
}

private void ExitApp() {
tmrMain.Enabled = false;
//computer.Close();
//SetFansToMaximum();
fan?.SetFansAuto(0);
fan?.SetFansAuto(1);
fan?.SetFansAuto(2);
fan?.SetFansAuto(255);
//fan?.SetFansAuto(1);
//fan?.SetFansAuto(2);
fan?.Dispose();
SaveFanTableAndConfig();
Close();
Expand Down Expand Up @@ -773,6 +840,10 @@ private void mnuShowWindow_Click(object sender, EventArgs e) {
ShowWindow();
}

private void mnuAutostart_Click(object sender, EventArgs e)
{
AutoStartToggle();
}
private void icoTray_DoubleClick(object sender, EventArgs e) {
ShowWindow();
}
Expand Down Expand Up @@ -888,9 +959,10 @@ private void btnProfileDefault_CheckedChanged(object sender, EventArgs e) {
//gpuFanTable = defaultGpuFanTable;
////tabFanCurves.Enabled = false;
//tmrMain.Enabled = false;
fan?.SetFansAuto(0);
fan?.SetFansAuto(1);
fan?.SetFansAuto(2);
// pass 255 just set all fan auto
fan?.SetFansAuto(255);
//fan?.SetFansAuto(1);
//fan?.SetFansAuto(2);
mnuProfileManual.Checked = false;
mnuProfileDefault.Checked = true;
mnuProfileMax.Checked = false;
Expand Down
3 changes: 0 additions & 3 deletions ClevoFanControl/frmMain.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1916,9 +1916,6 @@
<metadata name="tipTooltip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>301, 17</value>
</metadata>
<metadata name="tipTooltip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>301, 17</value>
</metadata>
<metadata name="tmrGui.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>395, 17</value>
</metadata>
Expand Down
4 changes: 4 additions & 0 deletions ClevoFanControl/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="TaskScheduler" version="2.9.2" targetFramework="net45" />
</packages>