Skip to content

Commit

Permalink
Implemented auto-start with windows boot, and start-in-background fea…
Browse files Browse the repository at this point in the history
…ture.
  • Loading branch information
coreyshuman committed May 30, 2019
1 parent b32248b commit 5f393cd
Show file tree
Hide file tree
Showing 9 changed files with 1,351 additions and 1,743 deletions.
8 changes: 5 additions & 3 deletions ArchonLightingSystem.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<GenerateManifests>false</GenerateManifests>
<ExcludedPermissions>
</ExcludedPermissions>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
Expand Down Expand Up @@ -88,6 +88,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
Expand Down Expand Up @@ -161,13 +162,14 @@
<Compile Include="Models\FrameInfo.cs" />
<Compile Include="Models\LightingModes.cs" />
<Compile Include="Models\UserSettings.cs" />
<Compile Include="Models\StartupService.cs" />
<Compile Include="OpenHardware\HardwareManager.cs" />
<Compile Include="OpenHardware\HardwareNode.cs" />
<Compile Include="OpenHardware\HardwareSettings.cs" />
<Compile Include="OpenHardware\HardwareTypeImage.cs" />
<Compile Include="OpenHardware\Node.cs" />
<Compile Include="OpenHardware\SensorNode.cs" />
<Compile Include="OpenHardware\Startup\StartupManager.cs" />
<Compile Include="OpenHardware\Startup\TaskScheduler.cs" />
<Compile Include="OpenHardware\TypeNode.cs" />
<Compile Include="OpenHardware\UnitManager.cs" />
<Compile Include="OpenHardware\UpdateVisitor.cs" />
Expand Down Expand Up @@ -217,6 +219,7 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include=".gitignore" />
<None Include="app.config" />
<BaseApplicationManifest Include="Properties\app.manifest" />
<None Include="Firmware\latest.hex">
Expand All @@ -240,7 +243,6 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Folder Include="OpenHardware\Startup\" />
<Folder Include="Properties\DataSources\" />
</ItemGroup>
<ItemGroup>
Expand Down
72 changes: 59 additions & 13 deletions Forms/AppForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using ArchonLightingSystem.OpenHardware;
using ArchonLightingSystem.Services;
using ArchonLightingSystem.Forms;
using ArchonLightingSystem.OpenHardware.Startup;

namespace ArchonLightingSystem
{
Expand All @@ -25,7 +26,7 @@ public partial class AppForm : Form
private FirmwareUpdateForm firmwareForm = null;
private HardwareManager hardwareManager = null;
private SequencerForm sequencerForm = null;
private StartupService startupService = new StartupService();
private StartupManager startupManager = new StartupManager();
private FanControllerService fanControllerService = new FanControllerService();

private List<ComboBoxItem> deviceAddressList = new List<ComboBoxItem>();
Expand All @@ -36,11 +37,14 @@ public partial class AppForm : Form
private DragWindowSupport dragSupport = new DragWindowSupport();
private UserSettingsManager settingsManager = new UserSettingsManager();
private UserSettings userSettings = null;
private bool isHidden = false;
private bool allowVisible = false;
private bool allowClose = false;

public unsafe AppForm()
public unsafe AppForm(bool startInBackground)
{
InitializeComponent();
InitializeComponent();

dragSupport.Initialize(this, menuStrip1);
dragSupport.DragWindowEvent += new DragWindowEventDelegate(DragWindowEventHandler);

Expand All @@ -59,7 +63,8 @@ public unsafe AppForm()

FormUpdateTimer.Enabled = true;

startWithWindowsToolStripMenuItem.Checked = startupService.Enabled;
startWithWindowsToolStripMenuItem.Enabled = startupManager.IsAvailable;
startWithWindowsToolStripMenuItem.Checked = startupManager.Startup;

// Handle cleanup when the user logs off
Microsoft.Win32.SystemEvents.SessionEnded += delegate {
Expand All @@ -68,6 +73,31 @@ public unsafe AppForm()
};

fanControllerService.BeginService(userSettings, usbApp, hardwareManager);

allowVisible = !startInBackground;
isHidden = startInBackground;
}



protected override void SetVisibleCore(bool value)
{
if (!allowVisible)
{
value = false;
if (!this.IsHandleCreated) CreateHandle();
}
base.SetVisibleCore(value);
}

protected override void OnFormClosing(FormClosingEventArgs e)
{
if (!allowClose)
{
HideForm();
e.Cancel = true;
}
base.OnFormClosing(e);
}

void DragWindowEventHandler(object sender, DragWindowEventArgs args)
Expand Down Expand Up @@ -305,18 +335,35 @@ private void cbo_DeviceAddress_SelectedIndexChanged(object sender, EventArgs e)

private void closeToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Hide();
FormUpdateTimer.Enabled = false;
HideForm();
}

private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
{
Show();
FormUpdateTimer.Enabled = true;
ShowForm();
}

public void HideForm()
{
Hide();
FormUpdateTimer.Enabled = false;
isHidden = true;
}

public void ShowForm()
{
if (isHidden)
{
allowVisible = true;
Show();
FormUpdateTimer.Enabled = true;
isHidden = false;
}
}

private void closeToolStripMenuItem1_Click(object sender, EventArgs e)
{
allowClose = true;
this.Close();
}

Expand All @@ -327,15 +374,14 @@ private void txt_ControllerName_Leave(object sender, EventArgs e)

private void startWithWindowsToolStripMenuItem_Click(object sender, EventArgs e)
{
if(!startupService.Available)
if(!startupManager.IsAvailable)
{
MessageBox.Show("The startup service is not available.");
return;
}

startupService.Enabled = !startupService.Enabled;

startWithWindowsToolStripMenuItem.Checked = startupService.Enabled;
startupManager.Startup = !startupManager.Startup;
startWithWindowsToolStripMenuItem.Checked = startupManager.Startup;
}

private void sequencerToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down
76 changes: 0 additions & 76 deletions Models/StartupService.cs

This file was deleted.

Loading

0 comments on commit 5f393cd

Please sign in to comment.