Skip to content

Commit

Permalink
Implementing AutoStart on Windows Startup
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianLima committed Aug 10, 2017
1 parent a4bd63f commit a5955af
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 44 deletions.
11 changes: 11 additions & 0 deletions HueHue/HueHue.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@
<ItemGroup>
<None Include="Resources\BlackTransparent.png" />
</ItemGroup>
<ItemGroup>
<COMReference Include="IWshRuntimeLibrary">
<Guid>{F935DC20-1CF0-11D0-ADB9-00C04FD58A0B}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>0</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
30 changes: 27 additions & 3 deletions HueHue/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using HueHue.Helpers;
using HueHue.Views;
using System;
using System.Windows;

namespace HueHue
Expand Down Expand Up @@ -30,21 +31,45 @@ public MainWindow()
}

icon = new TrayIcon();

//The app was auto started by windows from the user's startup folder
if (settings.AutoStart && Environment.GetCommandLineArgs() != null)
{
this.Minimize();
StartStop();
}
}

private void Button_Click(object sender, RoutedEventArgs e)
{
StartStop();
}

private void StartStop()
{
if (!isRunning)
{
isRunning = true;
buttonStart.Content = "Stop";
stream.Start();
try
{
stream.Start();
}
catch (Exception)
{
}
}
else
{
isRunning = false;
buttonStart.Content = "Start";
stream.Stop();
try
{
stream.Stop();
}
catch (Exception)
{
}
}
}

Expand All @@ -69,7 +94,6 @@ private void comboBox_SelectionChanged(object sender, System.Windows.Controls.Se
break;

default:

break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion HueHue/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<ToggleButton x:Name="language_toggle" Style="{StaticResource MaterialDesignSwitchToggleButton}" VerticalAlignment="Top" Margin="0,36,0,0" ToolTip="MaterialDesignSwitchToggleButton" IsChecked="{Binding AutoStart}" Height="18" HorizontalAlignment="Right" Width="46" />
<ToggleButton x:Name="language_toggle" Style="{StaticResource MaterialDesignSwitchToggleButton}" VerticalAlignment="Top" Margin="0,36,0,0" ToolTip="MaterialDesignSwitchToggleButton" IsChecked="{Binding AutoStart}" Height="18" HorizontalAlignment="Right" Width="46" Checked="language_toggle_Checked" Unchecked="language_toggle_Unchecked" />
<Label Content="Auto start with Windows" HorizontalAlignment="Left" Margin="0,32,0,0" VerticalAlignment="Top"/>
<ToggleButton x:Name="language_toggle_Copy" Style="{StaticResource MaterialDesignSwitchToggleButton}" VerticalAlignment="Top" Margin="0,68,0,0" ToolTip="MaterialDesignSwitchToggleButton" IsChecked="{Binding Minimize}" Height="18" HorizontalAlignment="Right" Width="46" />
<Label Content="Minimize on close" HorizontalAlignment="Left" Margin="0,64,0,0" VerticalAlignment="Top"/>
Expand Down
51 changes: 39 additions & 12 deletions HueHue/SettingsWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
using HueHue.Helpers;
using IWshRuntimeLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace HueHue
{
Expand Down Expand Up @@ -46,5 +35,43 @@ private void Chip2_Click(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process.Start("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9YPV3FHEFRAUQ");
}

private void SetAutoStart()
{
try
{
string currentApp = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "HueHue" + ".exe");
WshShell shell = new WshShell();
WshShortcut shortcut = (WshShortcut)shell.CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\HueHue.lnk");
shortcut.TargetPath = currentApp;
shortcut.IconLocation = currentApp + ",0";
shortcut.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
shortcut.Arguments = "autostart";
shortcut.Save();
}
catch (Exception e)
{
throw new Exception("Error setting to auto start" + Environment.NewLine + e.Message);
}
}

private void language_toggle_Checked(object sender, RoutedEventArgs e)
{
//When checked, let's create a .lnk on the user's Windows startup folder
if (!System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\HueHue.lnk"))
{
SetAutoStart();
}
}

private void language_toggle_Unchecked(object sender, RoutedEventArgs e)
{
//If the shortcut exists, delete it
var shortcut = Environment.GetFolderPath(Environment.SpecialFolder.Startup) + @"\HueHue.lnk";
if (System.IO.File.Exists(shortcut))
{
System.IO.File.Delete(shortcut);
}
}
}
}
4 changes: 2 additions & 2 deletions HueHueClient/HueHueClient.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<AdditionalIncludeDirectories>$(ProjectDir)..\..\..\Arduino\libraries\FastLED-3.1.3;C:\Program Files (x86)\Arduino\libraries;C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries;$(ProjectDir)..\..\..\Arduino\libraries;C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino;C:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\eightanaloginputs;$(ProjectDir)..\HueHueClient;C:\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\;C:\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\avr\;C:\Program Files (x86)\Arduino\hardware\tools\avr\lib\gcc\avr\4.8.1\include;C:\Program Files (x86)\Arduino\hardware\tools\avr\lib\gcc\avr\4.9.2\include;C:\Program Files (x86)\Arduino\hardware\tools\avr\lib\gcc\avr\4.9.3\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ProjectDir)..\..\..\Arduino\libraries\FastLED;$(ProjectDir)..\..\..\..\..\..\Program Files (x86)\Arduino\libraries;$(ProjectDir)..\..\..\..\AppData\Local\arduino15\packages\arduino\hardware\avr\1.6.17\libraries;$(ProjectDir)..\..\..\Arduino\libraries;$(ProjectDir)..\..\..\..\AppData\Local\arduino15\packages\arduino\hardware\avr\1.6.17\cores\arduino;$(ProjectDir)..\..\..\..\AppData\Local\arduino15\packages\arduino\hardware\avr\1.6.17\variants\eightanaloginputs;$(ProjectDir)..\HueHueClient;$(ProjectDir)..\..\..\..\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.3-arduino2\avr\include\;$(ProjectDir)..\..\..\..\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.3-arduino2\avr\include\avr\;$(ProjectDir)..\..\..\..\AppData\Local\arduino15\packages\arduino\tools\avr-gcc\4.9.2-atmel3.5.3-arduino2\lib\gcc\avr\4.8.1\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<ForcedIncludeFiles>$(ProjectDir)__vm\.HueHueClient.vsarduino.h;%(ForcedIncludeFiles)</ForcedIncludeFiles>
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
<PreprocessorDefinitions>__AVR_ATmega32u4__;__AVR_ATmega32U4__;_VMDEBUG=1;F_CPU=16000000L;ARDUINO=10803;ARDUINO_AVR_YUN;ARDUINO_ARCH_AVR;USB_VID=0x2341;USB_PID=0x8041;__cplusplus=201103L;_VMICRO_INTELLISENSE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>__AVR_ATmega328p__;__AVR_ATmega328P__;_VMDEBUG=1;F_CPU=16000000L;ARDUINO=10802;ARDUINO_AVR_NANO;ARDUINO_ARCH_AVR;__cplusplus=201103L;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<GenerateDebugInformation>true</GenerateDebugInformation>
Expand Down
39 changes: 13 additions & 26 deletions HueHueClient/__vm/.HueHueClient.vsarduino.h
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
/*
Editor: http://www.visualmicro.com
visual micro and the arduino ide ignore this code during compilation. this code is automatically maintained by visualmicro, manual changes to this file will be overwritten
the contents of the Visual Micro sketch sub folder can be deleted prior to publishing a project
all non-arduino files created by visual micro and all visual studio project or solution files can be freely deleted and are not required to compile a sketch (do not delete your own code!).
note: debugger breakpoints are stored in '.sln' or '.asln' files, knowledge of last uploaded breakpoints is stored in the upload.vmps.xml file. Both files are required to continue a previous debug session without needing to compile and upload again
visual micro and the arduino ide ignore this code during compilation. this code is automatically maintained by visualmicro, manual changes to this file will be overwritten
the contents of the Visual Micro sketch sub folder can be deleted prior to publishing a project
all non-arduino files created by visual micro and all visual studio project or solution files can be freely deleted and are not required to compile a sketch (do not delete your own code!).
note: debugger breakpoints are stored in '.sln' or '.asln' files, knowledge of last uploaded breakpoints is stored in the upload.vmps.xml file. Both files are required to continue a previous debug session without needing to compile and upload again
Hardware: Arduino Yún, Platform=avr, Package=arduino
Hardware: Arduino Nano w/ ATmega328, Platform=avr, Package=arduino
*/

#if defined(_VMICRO_INTELLISENSE)

#ifndef _VSARDUINO_H_
#define _VSARDUINO_H_
#define __AVR_ATmega32u4__
#define __AVR_ATmega32U4__
#define __AVR_ATmega328p__
#define __AVR_ATmega328P__
#define _VMDEBUG 1
#define F_CPU 16000000L
#define ARDUINO 10803
#define ARDUINO_AVR_YUN
#define ARDUINO 10802
#define ARDUINO_AVR_NANO
#define ARDUINO_ARCH_AVR
#define USB_VID 0x2341
#define USB_PID 0x8041
#define __cplusplus 201103L
#define __AVR__
#define __inline__
#define __asm__(...)
#define __asm__(x)
#define __extension__
#define __inline__
#define __volatile__
Expand All @@ -37,7 +34,7 @@
#define _CONST
#define __builtin_va_start
#define __builtin_va_end
#define __attribute__(...)
#define __attribute__(x)
#define NOINLINE __attribute__((noinline))
#define prog_void
#define PGM_VOID_P int
Expand All @@ -50,7 +47,6 @@
#define __builtin_strlen __attribute__((__const__))
#endif


#define NEW_H
typedef void *__builtin_va_list;
//extern "C" void __cxa_pure_virtual() {;}
Expand All @@ -64,20 +60,11 @@ typedef void *__builtin_va_list;



#include <Arduino.h>
#include <arduino.h>
#include <pins_arduino.h>
#undef F
#define F(string_literal) ((const PROGMEM char *)(string_literal))
#undef PSTR
#define PSTR(string_literal) ((const PROGMEM char *)(string_literal))


#define pgm_read_byte(address_short) uint8_t()
#define pgm_read_word(address_short) uint16_t()
#define pgm_read_dword(address_short) uint32_t()
#define pgm_read_float(address_short) float()
#define pgm_read_ptr(address_short) short()

#include "HueHueClient.ino"
#endif
#endif

0 comments on commit a5955af

Please sign in to comment.