diff --git a/Artemis/Artemis/App.xaml b/Artemis/Artemis/App.xaml index d19aed2d9..110eccc23 100644 --- a/Artemis/Artemis/App.xaml +++ b/Artemis/Artemis/App.xaml @@ -1,14 +1,14 @@  - + diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 688c9aad9..a0ba8b1df 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -301,6 +301,8 @@ True Resources.resx + + True True diff --git a/Artemis/Artemis/KeyboardProviders/Corsair/CorsairRGB.cs b/Artemis/Artemis/KeyboardProviders/Corsair/CorsairRGB.cs index 71bc748c2..4b4cf04b1 100644 --- a/Artemis/Artemis/KeyboardProviders/Corsair/CorsairRGB.cs +++ b/Artemis/Artemis/KeyboardProviders/Corsair/CorsairRGB.cs @@ -16,8 +16,8 @@ namespace Artemis.KeyboardProviders.Corsair public CorsairRGB() { Name = "Corsair RGB Keyboards"; - CantEnableText = "Couldn't connect to your Corsair keyboard.\n " + - "Please check your cables and/or drivers (could be outdated) and that Corsair Utility Engine is running.\n\n " + + CantEnableText = "Couldn't connect to your Corsair keyboard.\n" + + "Please check your cables and/or drivers (could be outdated) and that Corsair Utility Engine is running.\n\n" + "If needed, you can select a different keyboard in Artemis under settings."; KeyboardRegions = new List(); } diff --git a/Artemis/Artemis/Managers/EffectManager.cs b/Artemis/Artemis/Managers/EffectManager.cs index 6f899fdda..5ae38a048 100644 --- a/Artemis/Artemis/Managers/EffectManager.cs +++ b/Artemis/Artemis/Managers/EffectManager.cs @@ -143,6 +143,8 @@ namespace Artemis.Managers General.Default.LastEffect = null; General.Default.Save(); + _events.PublishOnUIThread(new ActiveEffectChanged("")); + _clearing = false; _mainManager.Unpause(); } diff --git a/Artemis/Artemis/Managers/KeyboardManager.cs b/Artemis/Artemis/Managers/KeyboardManager.cs index 3097b4c05..4bf566a55 100644 --- a/Artemis/Artemis/Managers/KeyboardManager.cs +++ b/Artemis/Artemis/Managers/KeyboardManager.cs @@ -9,7 +9,6 @@ namespace Artemis.Managers public class KeyboardManager { private readonly MainManager _mainManager; - private KeyboardProvider _pauseKeyboard; public KeyboardManager(MainManager mainManager) { @@ -52,8 +51,9 @@ namespace Artemis.Managers // Disable everything if there's no active keyboard found if (!keyboardProvider.CanEnable()) { - MessageBox.Show(keyboardProvider.CantEnableText, "Artemis (╯°□°)╯︵ ┻━┻", MessageBoxButtons.OK, - MessageBoxIcon.Warning); + _mainManager.DialogService.ShowErrorMessageBox(keyboardProvider.CantEnableText); + //MessageBox.Show(keyboardProvider.CantEnableText, "Artemis (╯°□°)╯︵ ┻━┻", MessageBoxButtons.OK, + // MessageBoxIcon.Warning); return; } diff --git a/Artemis/Artemis/Managers/MainManager.cs b/Artemis/Artemis/Managers/MainManager.cs index 762a8823e..444aa2c88 100644 --- a/Artemis/Artemis/Managers/MainManager.cs +++ b/Artemis/Artemis/Managers/MainManager.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading; using Artemis.Events; using Artemis.Models; +using Artemis.Services; using Artemis.Utilities.GameState; using Artemis.Utilities.Keyboard; using Caliburn.Micro; @@ -18,9 +19,10 @@ namespace Artemis.Managers private bool _paused; private bool _restarting; - public MainManager(IEventAggregator events) + public MainManager(IEventAggregator events, MetroDialogService dialogService) { Events = events; + DialogService = dialogService; KeyboardManager = new KeyboardManager(this); EffectManager = new EffectManager(this, Events); @@ -57,6 +59,7 @@ namespace Artemis.Managers public GameStateWebServer GameStateWebServer { get; set; } public IEventAggregator Events { get; set; } + public MetroDialogService DialogService { get; set; } public bool ProgramEnabled { get; private set; } public bool Suspended { get; set; } diff --git a/Artemis/Artemis/Services/DialogService.cs b/Artemis/Artemis/Services/DialogService.cs new file mode 100644 index 000000000..b5a312a7d --- /dev/null +++ b/Artemis/Artemis/Services/DialogService.cs @@ -0,0 +1,48 @@ +//The MIT License(MIT) + +//Copyright(c) 2015 ihtfw + +//Permission is hereby granted, free of charge, to any person obtaining a copy +//of this software and associated documentation files (the "Software"), to deal +//in the Software without restriction, including without limitation the rights +//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +//copies of the Software, and to permit persons to whom the Software is +//furnished to do so, subject to the following conditions: + +//The above copyright notice and this permission notice shall be included in all +//copies or substantial portions of the Software. + +//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +//SOFTWARE. + +using System; +using System.Threading.Tasks; + +namespace Artemis.Services +{ + public abstract class DialogService + { + public void ShowErrorMessageBox(Exception e) + { + ShowErrorMessageBox(e.Message); + } + + public void ShowErrorMessageBox(string message) + { + ShowMessageBox("Error", message); + } + + public abstract void ShowMessageBox(string title, string message); + + public abstract bool ShowOpenDialog(out string path, string defaultExt, string filter, string initialDir = null); + + public abstract Task ShowInputDialog(string title, string message); + + public abstract Task ShowQuestionMessageBox(string title, string message); + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Services/MetroDialogService.cs b/Artemis/Artemis/Services/MetroDialogService.cs new file mode 100644 index 000000000..e8ef0b398 --- /dev/null +++ b/Artemis/Artemis/Services/MetroDialogService.cs @@ -0,0 +1,143 @@ +//The MIT License(MIT) + +//Copyright(c) 2015 ihtfw + +//Permission is hereby granted, free of charge, to any person obtaining a copy +//of this software and associated documentation files (the "Software"), to deal +//in the Software without restriction, including without limitation the rights +//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +//copies of the Software, and to permit persons to whom the Software is +//furnished to do so, subject to the following conditions: + +//The above copyright notice and this permission notice shall be included in all +//copies or substantial portions of the Software. + +//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +//SOFTWARE. + +using System.Linq; +using System.Threading.Tasks; +using System.Windows; +using Artemis.ViewModels; +using Caliburn.Micro; +using MahApps.Metro.Controls; +using MahApps.Metro.Controls.Dialogs; +using Microsoft.Win32; + +namespace Artemis.Services +{ + public class MetroDialogService : DialogService + { + private readonly ShellViewModel _shellViewModel; + + public MetroDialogService(ShellViewModel shellViewModel) + { + _shellViewModel = shellViewModel; + } + + private MetroWindow GetActiveWindow() + { + MetroWindow window = null; + + Execute.OnUIThread(() => + { + window = Application.Current.Windows.OfType().FirstOrDefault(w => w.IsActive); + if (window == null) + { + window = Application.Current.Windows.OfType().FirstOrDefault(); + } + }); + + return window; + } + + public override void ShowMessageBox(string title, string message) + { + if (_shellViewModel.IsActive == false) + return; + + Execute.OnUIThread(() => GetActiveWindow().ShowMessageAsync(title, message)); + } + + public override async Task ShowQuestionMessageBox(string title, string message) + { + if (_shellViewModel.IsActive == false) + return null; + + var metroDialogSettings = new MetroDialogSettings {AffirmativeButtonText = "Yes", NegativeButtonText = "No"}; + var result = + await + GetActiveWindow() + .ShowMessageAsync(title, message, MessageDialogStyle.AffirmativeAndNegative, metroDialogSettings); + switch (result) + { + case MessageDialogResult.Negative: + return false; + case MessageDialogResult.Affirmative: + return true; + default: + return null; + } + } + + public override Task ShowInputDialog(string title, string message) + { + if (_shellViewModel.IsActive == false) + return null; + + return GetActiveWindow().ShowInputAsync(title, message); + } + + public override bool ShowOpenDialog(out string path, string defaultExt, string filter, string initialDir = null) + { + if (_shellViewModel.IsActive == false) + { + path = null; + return false; + } + + bool? res = null; + string lPath = null; + + Execute.OnUIThread(() => + { + var ofd = new OpenFileDialog + { + DefaultExt = defaultExt, + Filter = filter + }; + + if (initialDir != null) + { + ofd.InitialDirectory = initialDir; + } + + if (Application.Current.MainWindow != null) + { + res = ofd.ShowDialog(Application.Current.MainWindow); + } + else + { + res = ofd.ShowDialog(); + } + if (res == true) + { + lPath = ofd.FileName; + } + else + { + res = false; + } + }); + + path = lPath; + + return res.Value; + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Utilities/Updater.cs b/Artemis/Artemis/Utilities/Updater.cs index ba1585175..9264d3aac 100644 --- a/Artemis/Artemis/Utilities/Updater.cs +++ b/Artemis/Artemis/Utilities/Updater.cs @@ -3,8 +3,9 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Net; -using System.Windows.Forms; +using System.Threading.Tasks; using Artemis.Models; +using Artemis.Services; using Artemis.Settings; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -15,20 +16,25 @@ namespace Artemis.Utilities { public static int CurrentVersion = 100; - public static void CheckForUpdate() + public static async Task CheckForUpdate(MetroDialogService dialogService) { + if (!General.Default.CheckForUpdates) + return null; + var newRelease = IsUpdateAvailable(); if (newRelease == null) - return; + return null; - var viewUpdate = - MessageBox.Show( + var viewUpdate = await + dialogService.ShowQuestionMessageBox("Update available", $"A new version of Artemis is available, version {newRelease["tag_name"].Value()}.\n" + "Do you wish to view the update on GitHub now?\n\n" + - "Note: You can disable update notifications in the settings menu", "Artemis - Update available", - MessageBoxButtons.YesNo, MessageBoxIcon.Information); - if (viewUpdate == DialogResult.Yes) + "Note: You can disable update notifications in the settings menu"); + + if (viewUpdate.Value) Process.Start(new ProcessStartInfo(newRelease["html_url"].Value())); + + return null; } public static JObject IsUpdateAvailable() diff --git a/Artemis/Artemis/ViewModels/Flyouts/FlyoutSettingsViewModel.cs b/Artemis/Artemis/ViewModels/Flyouts/FlyoutSettingsViewModel.cs index cd55b25e8..192b1f0a3 100644 --- a/Artemis/Artemis/ViewModels/Flyouts/FlyoutSettingsViewModel.cs +++ b/Artemis/Artemis/ViewModels/Flyouts/FlyoutSettingsViewModel.cs @@ -8,8 +8,9 @@ using MahApps.Metro.Controls; namespace Artemis.ViewModels.Flyouts { - public class FlyoutSettingsViewModel : FlyoutBaseViewModel, IHandle + public class FlyoutSettingsViewModel : FlyoutBaseViewModel, IHandle, IHandle { + private string _activeEffectName; private bool _enabled; private GeneralSettings _generalSettings; private string _selectedKeyboardProvider; @@ -77,6 +78,23 @@ namespace Artemis.ViewModels.Flyouts } } + public string ActiveEffectName + { + get { return _activeEffectName; } + set + { + if (value == _activeEffectName) return; + _activeEffectName = value; + NotifyOfPropertyChange(() => ActiveEffectName); + } + } + + public void Handle(ActiveEffectChanged message) + { + var effectDisplay = message.ActiveEffect.Length > 0 ? message.ActiveEffect : "none"; + ActiveEffectName = $"Active effect: {effectDisplay}"; + } + public void Handle(ToggleEnabled message) { NotifyOfPropertyChange(() => Enabled); @@ -108,8 +126,8 @@ namespace Artemis.ViewModels.Flyouts protected override void HandleOpen() { - SelectedKeyboardProvider = MainManager.KeyboardManager.ActiveKeyboard != null - ? MainManager.KeyboardManager.ActiveKeyboard.Name + SelectedKeyboardProvider = General.Default.LastKeyboard.Length > 0 + ? General.Default.LastKeyboard : "None"; } } diff --git a/Artemis/Artemis/ViewModels/ShellViewModel.cs b/Artemis/Artemis/ViewModels/ShellViewModel.cs index 3f0a2602b..37cb3bc0b 100644 --- a/Artemis/Artemis/ViewModels/ShellViewModel.cs +++ b/Artemis/Artemis/ViewModels/ShellViewModel.cs @@ -1,5 +1,6 @@ using System.Linq; using Artemis.Managers; +using Artemis.Services; using Artemis.ViewModels.Flyouts; using Caliburn.Micro; @@ -14,8 +15,10 @@ namespace Artemis.ViewModels public ShellViewModel() { + var dialogService = new MetroDialogService(this); IEventAggregator events = new EventAggregator(); - MainManager = new MainManager(events); + + MainManager = new MainManager(events, dialogService); DisplayName = "Artemis"; _welcomeVm = new WelcomeViewModel {DisplayName = "Welcome"}; diff --git a/Artemis/Artemis/ViewModels/SystemTrayViewModel.cs b/Artemis/Artemis/ViewModels/SystemTrayViewModel.cs index b951d5a46..415c579a9 100644 --- a/Artemis/Artemis/ViewModels/SystemTrayViewModel.cs +++ b/Artemis/Artemis/ViewModels/SystemTrayViewModel.cs @@ -1,7 +1,7 @@ using System; -using System.Threading.Tasks; using System.Windows; using Artemis.Events; +using Artemis.Settings; using Artemis.Utilities; using Caliburn.Micro; @@ -15,14 +15,6 @@ namespace Artemis.ViewModels private bool _checkedForUpdate; 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'. - * Thus no property notification is invoked, and system tray context-menu appears - * out of sync, still allowing 'Hide' and disabling 'Show'. - * Given the purpose of the sample - integrating Caliburn.Micro with WPF NotifyIcon - - * syncing the two view-models is not of interest here. - * */ public SystemTrayViewModel(IWindowManager windowManager, ShellViewModel shellViewModel) { @@ -32,7 +24,8 @@ namespace Artemis.ViewModels _shellViewModel.MainManager.EnableProgram(); _checkedForUpdate = false; - // TODO: Check if show on startup is enabled, if so, show window. + if (General.Default.ShowOnStartup) + ShowWindow(); } public bool CanShowWindow => !_shellViewModel.IsActive; @@ -89,18 +82,17 @@ namespace Artemis.ViewModels if (!CanShowWindow) return; - if (!_checkedForUpdate) - { - _checkedForUpdate = true; - var updateTask = new Task(Updater.CheckForUpdate); - updateTask.Start(); - } - // manually show the next window view-model _windowManager.ShowWindow(_shellViewModel); NotifyOfPropertyChange(() => CanShowWindow); NotifyOfPropertyChange(() => CanHideWindow); + + if (_checkedForUpdate) + return; + + _checkedForUpdate = true; + Updater.CheckForUpdate(_shellViewModel.MainManager.DialogService); } diff --git a/Artemis/Artemis/Views/Flyouts/FlyoutSettingsView.xaml b/Artemis/Artemis/Views/Flyouts/FlyoutSettingsView.xaml index 1ce4d86da..55c42ae56 100644 --- a/Artemis/Artemis/Views/Flyouts/FlyoutSettingsView.xaml +++ b/Artemis/Artemis/Views/Flyouts/FlyoutSettingsView.xaml @@ -6,7 +6,7 @@ xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls" xmlns:cal="http://www.caliburnproject.org" mc:Ignorable="d" - d:DesignHeight="300" d:DesignWidth="300" + d:DesignHeight="600" d:DesignWidth="300" Width="300"> @@ -24,6 +24,8 @@ + + @@ -41,38 +43,52 @@ IsChecked="{Binding Path=GeneralSettings.Autorun, Mode=TwoWay}" VerticalAlignment="Center" HorizontalAlignment="Right" Width="125" /> - +