1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 21:38:38 +00:00

Implemented auto-run, this resolves #15

This commit is contained in:
SpoinkyNL 2016-02-21 00:12:48 +01:00
parent d6ff4a0551
commit fbad2a450f
16 changed files with 307 additions and 89 deletions

View File

@ -2,44 +2,19 @@
<configuration>
<configSections>
<sectionGroup name="userSettings"
type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Artemis.Modules.Games.RocketLeague.RocketLeague"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.Offsets"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Modules.Games.Witcher3.Witcher3"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Modules.Effects.AudioVisualizer.AudioVisualization"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Modules.Games.CounterStrike.CounterStrike"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.CounterStrike"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.VolumeDisplay"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.AudioVisualization"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.RocketLeague"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.TypeWave"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.General"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Artemis.Modules.Games.RocketLeague.RocketLeague" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.Offsets" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Modules.Games.Witcher3.Witcher3" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Modules.Effects.AudioVisualizer.AudioVisualization" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Modules.Games.CounterStrike.CounterStrike" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.CounterStrike" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.VolumeDisplay" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.AudioVisualization" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.RocketLeague" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.TypeWave" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="Artemis.Settings.General" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<connectionStrings />
@ -229,6 +204,9 @@
<setting name="GamestatePort" serializeAs="String">
<value>51364</value>
</setting>
<setting name="Autorun" serializeAs="String">
<value>True</value>
</setting>
</Artemis.Settings.General>
</userSettings>
<runtime>

View File

@ -151,13 +151,10 @@
<HintPath>..\packages\log4net.2.0.5\lib\net45-full\log4net.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MahApps.Metro, Version=1.3.0.17, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.1.3.0-ALPHA017\lib\net45\MahApps.Metro.dll</HintPath>
<Reference Include="MahApps.Metro, Version=1.2.4.0, Culture=neutral, PublicKeyToken=f4fb5a3c4d1e5b4f, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.1.2.4.0\lib\net45\MahApps.Metro.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MemorySharp">
<HintPath>E:\Downloads\Chome Downloads\MemorySharp-master\MemorySharp-master\MemorySharp\bin\Release\MemorySharp.dll</HintPath>
</Reference>
<Reference Include="Microsoft.QualityTools.Testing.Fakes, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
@ -175,7 +172,10 @@
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Web" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.1.2.4.0\lib\net45\System.Windows.Interactivity.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
@ -227,6 +227,7 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="ArtemisBootstrapper.cs" />
<Compile Include="Events\ToggleEnabled.cs" />
<Compile Include="Events\ChangeActiveEffect.cs" />
<Compile Include="Events\ChangeBitmap.cs" />
<Compile Include="KeyboardProviders\Corsair\K70.cs" />
@ -303,6 +304,7 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>General.settings</DependentUpon>
</Compile>
<Compile Include="Settings\GeneralSettings.cs" />
<Compile Include="Settings\Offsets.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
@ -320,6 +322,7 @@
<Compile Include="Utilities\Memory\Win32.cs" />
<Compile Include="Utilities\Keyboard\Key.cs" />
<Compile Include="Utilities\Keyboard\KeyboardRectangle.cs" />
<Compile Include="Utilities\ShellLink.cs" />
<Compile Include="ViewModels\EffectsViewModel.cs" />
<Compile Include="Modules\Effects\AudioVisualizer\AudioVisualizerViewModel.cs" />
<Compile Include="Modules\Effects\Debug\DebugEffectViewModel.cs" />
@ -417,14 +420,16 @@
<None Include="packages.config" />
<AppDesigner Include="Properties\" />
<Resource Include="Resources\bow.png" />
<Resource Include="Resources\WindowsIcons-license.txt" />
<Resource Include="Resources\Entypo-license.txt" />
<Content Include="Resources\Witcher3\playerWitcher.txt" />
<Content Include="Resources\Witcher3\artemis.txt" />
<Resource Include="logo-disabled.ico" />
<Resource Include="Resources\Entypo.ttf" />
<None Include="Settings\Offsets.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Offsets.Designer.cs</LastGenOutput>
</None>
<Resource Include="Resources\Entypo.ttf" />
<None Include="Settings\General.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>General.Designer.cs</LastGenOutput>
@ -499,7 +504,6 @@
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Content Include="LogitechLedEnginesWrapper.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@ -511,8 +515,6 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Resource>
<Content Include="Resources\CounterStrike\gamestateConfiguration.txt" />
<Resource Include="Resources\Entypo-license.txt" />
<Resource Include="Resources\WindowsIcons-license.txt" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5.2">

View File

@ -0,0 +1,12 @@
namespace Artemis.Events
{
public class ToggleEnabled
{
public bool Enabled { get; set; }
public ToggleEnabled(bool enabled)
{
Enabled = enabled;
}
}
}

View File

@ -24,7 +24,12 @@ namespace Artemis.KeyboardProviders.Logitech
// Initialize the SDK
LogitechGSDK.LogiLedInit();
Thread.Sleep(200);
LogitechGSDK.LogiLedSaveCurrentLighting();
LogitechGSDK.LogiLedSetTargetDevice(LogitechGSDK.LOGI_DEVICETYPE_PERKEY_RGB);
// Disable keys we can't color
LogitechGSDK.LogiLedSetLighting(0, 0, 0);
}
public override void Disable()

View File

@ -52,6 +52,14 @@ namespace Artemis.Models
public void StartEffects()
{
if (Enabled)
return;
if (_updateWorker.IsBusy || _processWorker.IsBusy)
{
Events.PublishOnUIThread(new ToggleEnabled(Enabled));
return;
}
LoadLastKeyboard();
// If no keyboard was loaded, don't enable effects.
if (ActiveKeyboard == null)
@ -66,10 +74,16 @@ namespace Artemis.Models
// Start the Background Workers
_updateWorker.RunWorkerAsync();
_processWorker.RunWorkerAsync();
Enabled = true;
Events.PublishOnUIThread(new ToggleEnabled(Enabled));
}
public void ShutdownEffects()
{
if (!Enabled)
return;
// Stop the Background Worker
_updateWorker.CancelAsync();
_processWorker.CancelAsync();
@ -80,6 +94,9 @@ namespace Artemis.Models
ActiveKeyboard?.Disable();
ActiveKeyboard = null;
Enabled = false;
Events.PublishOnUIThread(new ToggleEnabled(Enabled));
}
private void LoadLastKeyboard()
@ -176,6 +193,12 @@ namespace Artemis.Models
var sw = new Stopwatch();
while (!_updateWorker.CancellationPending)
{
if (ActiveKeyboard == null)
{
Thread.Sleep(1000 / Fps);
continue;
}
sw.Start();
// Update the current effect
@ -186,7 +209,8 @@ namespace Artemis.Models
// Draw enabled overlays on top
foreach (
var overlayModel in EffectModels.OfType<OverlayModel>().Where(overlayModel => overlayModel.Enabled))
var overlayModel in
EffectModels.OfType<OverlayModel>().Where(overlayModel => overlayModel.Enabled))
{
overlayModel.Update();
bitmap = bitmap != null ? overlayModel.GenerateBitmap(bitmap) : overlayModel.GenerateBitmap();
@ -197,12 +221,12 @@ namespace Artemis.Models
{
ActiveKeyboard.DrawBitmap(bitmap);
// debugging
// debugging TODO: Disable when window isn't shown
Events.PublishOnUIThread(new ChangeBitmap(bitmap));
}
// Sleep according to time left this frame
var sleep = (int) (1000/Fps - sw.ElapsedMilliseconds);
var sleep = (int)(1000 / Fps - sw.ElapsedMilliseconds);
if (sleep > 0)
Thread.Sleep(sleep);
sw.Reset();

View File

@ -74,9 +74,7 @@ namespace Artemis.Modules.Overlays.VolumeDisplay
return bitmap;
using (var g = Graphics.FromImage(bitmap))
{
VolumeDisplay.Draw(g);
}
return bitmap;
}

View File

@ -70,5 +70,17 @@ namespace Artemis.Settings {
this["GamestatePort"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool Autorun {
get {
return ((bool)(this["Autorun"]));
}
set {
this["Autorun"] = value;
}
}
}
}

View File

@ -1,7 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)"
GeneratedClassNamespace="Artemis.Settings" GeneratedClassName="General">
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="Artemis.Settings" GeneratedClassName="General">
<Profiles />
<Settings>
<Setting Name="LastEffect" Type="System.String" Scope="User">
@ -16,5 +14,8 @@
<Setting Name="GamestatePort" Type="System.Int32" Scope="User">
<Value Profile="(Default)">51364</Value>
</Setting>
<Setting Name="Autorun" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@ -0,0 +1,66 @@
using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices.ComTypes;
using Artemis.Utilities;
namespace Artemis.Settings
{
public class GeneralSettings
{
public int GamestatePort
{
get { return General.Default.GamestatePort; }
set
{
if (General.Default.GamestatePort == value) return;
General.Default.GamestatePort = value;
ApplyGamestatePort();
General.Default.Save();
}
}
public bool EnablePointersUpdate
{
get { return General.Default.EnablePointersUpdate; }
set
{
if (General.Default.EnablePointersUpdate == value) return;
General.Default.EnablePointersUpdate = value;
General.Default.Save();
}
}
public bool Autorun
{
get { return General.Default.Autorun; }
set
{
if (General.Default.Autorun == value) return;
General.Default.Autorun = value;
ApplyAutorun();
General.Default.Save();
}
}
private void ApplyGamestatePort()
{
// TODO: Restart Gamestate server
}
private void ApplyAutorun()
{
var startupFolder = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
if (Autorun)
{
var link = (IShellLink) new ShellLink();
link.SetPath(Assembly.GetExecutingAssembly().Location);
var file = (IPersistFile) link;
file.Save(startupFolder + @"\Artemis.lnk", false);
}
else if (File.Exists(startupFolder + @"\Artemis.lnk"))
File.Delete(startupFolder + @"\Artemis.lnk");
}
}
}

View File

@ -0,0 +1,46 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace Artemis.Utilities
{
/// <summary>
/// Creates a shortcut (.lnk) file.
/// Source: http://stackoverflow.com/a/14632782/5015269
/// </summary>
[ComImport]
[Guid("00021401-0000-0000-C000-000000000046")]
internal class ShellLink
{
}
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("000214F9-0000-0000-C000-000000000046")]
internal interface IShellLink
{
void GetPath([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszFile, int cchMaxPath, out IntPtr pfd,
int fFlags);
void GetIDList(out IntPtr ppidl);
void SetIDList(IntPtr pidl);
void GetDescription([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszName, int cchMaxName);
void SetDescription([MarshalAs(UnmanagedType.LPWStr)] string pszName);
void GetWorkingDirectory([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszDir, int cchMaxPath);
void SetWorkingDirectory([MarshalAs(UnmanagedType.LPWStr)] string pszDir);
void GetArguments([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszArgs, int cchMaxPath);
void SetArguments([MarshalAs(UnmanagedType.LPWStr)] string pszArgs);
void GetHotkey(out short pwHotkey);
void SetHotkey(short wHotkey);
void GetShowCmd(out int piShowCmd);
void SetShowCmd(int iShowCmd);
void GetIconLocation([Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder pszIconPath, int cchIconPath,
out int piIcon);
void SetIconLocation([MarshalAs(UnmanagedType.LPWStr)] string pszIconPath, int iIcon);
void SetRelativePath([MarshalAs(UnmanagedType.LPWStr)] string pszPathRel, int dwReserved);
void Resolve(IntPtr hwnd, int fFlags);
void SetPath([MarshalAs(UnmanagedType.LPWStr)] string pszFile);
}
}

View File

@ -1,24 +1,42 @@
using System.Diagnostics;
using System.Linq;
using System.Windows.Forms;
using Artemis.Events;
using Artemis.Models;
using Artemis.Settings;
using Caliburn.Micro;
using MahApps.Metro.Controls;
namespace Artemis.ViewModels.Flyouts
{
public class FlyoutSettingsViewModel : FlyoutBaseViewModel
public class FlyoutSettingsViewModel : FlyoutBaseViewModel, IHandle<ToggleEnabled>
{
private bool _enabled;
private GeneralSettings _generalSettings;
private string _selectedKeyboardProvider;
public MainModel MainModel { get; set; }
public FlyoutSettingsViewModel(MainModel mainModel)
{
MainModel = mainModel;
Header = "settings";
Position = Position.Right;
GeneralSettings = new GeneralSettings();
MainModel.Events.Subscribe(this);
}
public GeneralSettings GeneralSettings
{
get { return _generalSettings; }
set
{
if (Equals(value, _generalSettings)) return;
_generalSettings = value;
NotifyOfPropertyChange(() => GeneralSettings);
}
}
public MainModel MainModel { get; set; }
public BindableCollection<string> KeyboardProviders
=> new BindableCollection<string>(MainModel.KeyboardProviders.Select(k => k.Name));
@ -30,11 +48,38 @@ namespace Artemis.ViewModels.Flyouts
if (value == _selectedKeyboardProvider) return;
_selectedKeyboardProvider = value;
NotifyOfPropertyChange(() => SelectedKeyboardProvider);
if (value == null)
return;
MainModel.ChangeKeyboard(MainModel.KeyboardProviders.First(k => k.Name == _selectedKeyboardProvider));
}
}
public bool Enabled
{
get { return _enabled; }
set
{
if (value == _enabled) return;
_enabled = value;
NotifyOfPropertyChange(() => Enabled);
}
}
public void Handle(ToggleEnabled message)
{
Enabled = message.Enabled;
}
public void ToggleEnabled()
{
if (Enabled)
MainModel.ShutdownEffects();
else
MainModel.StartEffects();
}
public void NavigateTo(string url)
{
Process.Start(new ProcessStartInfo(url));

View File

@ -24,24 +24,11 @@ namespace Artemis.ViewModels
_overlaysVm = new OverlaysViewModel(MainModel) {DisplayName = "Overlays"};
Flyouts.Add(new FlyoutSettingsViewModel(MainModel));
// By now Effects are added to the MainModel so we can savely start one
ToggleEffects();
}
public IObservableCollection<FlyoutBaseViewModel> Flyouts { get; set; } =
new BindableCollection<FlyoutBaseViewModel>();
public bool EffectsEnabled
{
get { return MainModel.Enabled; }
private set
{
MainModel.Enabled = value;
NotifyOfPropertyChange(() => EffectsEnabled);
}
}
public MainModel MainModel { get; set; }
protected override void OnActivate()
@ -53,16 +40,6 @@ namespace Artemis.ViewModels
ActivateItem(_overlaysVm);
}
public void ToggleEffects()
{
if (EffectsEnabled)
MainModel.ShutdownEffects();
else
MainModel.StartEffects();
EffectsEnabled = !EffectsEnabled;
}
public void OnClose(EventArgs e)
{
MainModel.ShutdownEffects();

View File

@ -1,13 +1,16 @@
using System.Windows;
using Artemis.Events;
using Caliburn.Micro;
namespace Artemis.ViewModels
{
public class SystemTrayViewModel : Screen
public class SystemTrayViewModel : Screen, IHandle<ToggleEnabled>
{
private readonly ShellViewModel _shellViewModel;
private readonly IWindowManager _windowManager;
private bool _enabled;
private string _toggleText;
/*
* NOTE: In this sample the system tray view-model doesn't receive any notification
* when the other window gets closed by pressing the top right 'x'.
@ -21,6 +24,14 @@ namespace Artemis.ViewModels
{
_windowManager = windowManager;
_shellViewModel = shellViewModel;
_shellViewModel.MainModel.Events.Subscribe(this);
/*
* By now Effects are added to the MainModel so we can savely start
* This is done from here to make sure all UI elements listening to
* events will receive the first ToggleEnabled event
* */
_shellViewModel.MainModel.StartEffects();
// TODO: Check if show on startup is enabled, if so, show window.
}
@ -29,6 +40,43 @@ namespace Artemis.ViewModels
public bool CanHideWindow => _shellViewModel.IsActive;
public bool Enabled
{
get { return _enabled; }
set
{
if (value == _enabled) return;
_enabled = value;
ToggleText = _enabled ? "Disable Artemis" : "Enable Artemis";
NotifyOfPropertyChange(() => Enabled);
}
}
public string ToggleText
{
get { return _toggleText; }
set
{
if (value == _toggleText) return;
_toggleText = value;
NotifyOfPropertyChange(() => ToggleText);
}
}
public void Handle(ToggleEnabled message)
{
Enabled = message.Enabled;
}
public void ToggleEnabled()
{
if (Enabled)
_shellViewModel.MainModel.ShutdownEffects();
else
_shellViewModel.MainModel.StartEffects();
}
protected override void OnActivate()
{
base.OnActivate();

View File

@ -31,12 +31,15 @@
<Label Grid.Row="0" Grid.Column="0" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left"
Content="Enable Artemis:" />
<controls:ToggleSwitch Grid.Row="0" Grid.Column="1" Margin="5" OnLabel="Yes" OffLabel="No"
VerticalAlignment="Center" HorizontalAlignment="Right" Width="125" />
VerticalAlignment="Center" HorizontalAlignment="Right" Width="125"
IsChecked="{Binding Path=Enabled, Mode=OneWay}"
cal:Message.Attach="[Event Unchecked] = [Action ToggleEnabled]; [Event Checked] = [Action ToggleEnabled]"/>
<!-- Startup with Windows -->
<Label Grid.Row="1" Grid.Column="0" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left"
Content="Startup with Windows:" />
<controls:ToggleSwitch Grid.Row="1" Grid.Column="1" Margin="5" OnLabel="Yes" OffLabel="No"
IsChecked="{Binding Path=GeneralSettings.Autorun, Mode=TwoWay}"
VerticalAlignment="Center" HorizontalAlignment="Right" Width="125" />
<!-- Keyboard selection -->
@ -50,13 +53,15 @@
<Label Grid.Row="3" Grid.Column="0" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left"
Content="Gamestate server port:" />
<controls:NumericUpDown Grid.Row="3" Grid.Column="1" Margin="10" VerticalAlignment="Center"
HorizontalAlignment="Right" Width="120" />
HorizontalAlignment="Right" Width="120"
Value="{Binding Path=GeneralSettings.GamestatePort, Mode=TwoWay}"/>
<!-- Update pointers -->
<Label Grid.Row="4" Grid.Column="0" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left"
Content="Download pointers:" />
<controls:ToggleSwitch Grid.Row="4" Grid.Column="1" Margin="5" OnLabel="Yes" OffLabel="No"
VerticalAlignment="Center" HorizontalAlignment="Right" Width="125" />
VerticalAlignment="Center" HorizontalAlignment="Right" Width="125"
IsChecked="{Binding Path=GeneralSettings.EnablePointersUpdate, Mode=TwoWay}"/>
<!-- Buttons -->
<Button Grid.Row="5" Grid.Column="0" Margin="10" x:Name="ResetSettings" Content="Reset settings"

View File

@ -17,7 +17,7 @@
<MenuItem Header="Show Artemis" cal:Message.Attach="ShowWindow" />
<MenuItem Header="Hide Artemis" cal:Message.Attach="HideWindow" />
<Separator />
<MenuItem Header="Disable all effects" cal:Message.Attach="DisableEffects" />
<MenuItem Header="{Binding Path=ToggleText, Mode=OneWay}" cal:Message.Attach="ToggleEnabled" />
<MenuItem Header="Exit" cal:Message.Attach="ExitApplication" />
</ContextMenu>

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Autofac" version="3.5.2" targetFramework="net452" />
<package id="Caliburn.Micro" version="2.0.2" targetFramework="net452" />
@ -10,7 +9,7 @@
<package id="Extended.Wpf.Toolkit" version="2.6" targetFramework="net452" />
<package id="Hardcodet.NotifyIcon.Wpf" version="1.0.5" targetFramework="net452" />
<package id="log4net" version="2.0.5" targetFramework="net452" />
<package id="MahApps.Metro" version="1.3.0-ALPHA017" targetFramework="net452" />
<package id="MahApps.Metro" version="1.2.4.0" targetFramework="net452" />
<package id="MahApps.Metro.Resources" version="0.4.0.0" targetFramework="net452" />
<package id="MouseKeyHook" version="5.4.0" targetFramework="net452" />
<package id="NAudio" version="1.7.3" targetFramework="net452" />