Skip to content

Commit

Permalink
Release 4.16.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
sw3103 committed Jan 26, 2023
1 parent 5f8726e commit 6dbcebf
Show file tree
Hide file tree
Showing 18 changed files with 213 additions and 70 deletions.
44 changes: 44 additions & 0 deletions 4x/Move Mouse/Actions/ActionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public abstract class ActionBase : INotifyPropertyChanged
private bool _isEnabled;
private bool _repeat;
private EventTrigger _trigger;
private IntervalRepeatMode _repeatMode;
private int _intervalThrottle;
private int _intervalExecutionCount;

public enum EventTrigger
{
Expand All @@ -25,6 +28,12 @@ public enum EventTrigger
Stop
}

public enum IntervalRepeatMode
{
Forever,
Throttle
}

public abstract bool IsValid { get; }

public Guid Id { get; set; }
Expand Down Expand Up @@ -74,12 +83,47 @@ public EventTrigger Trigger

public IEnumerable<EventTrigger> EventTriggerValues => Enum.GetValues(typeof(EventTrigger)).Cast<EventTrigger>();

public IntervalRepeatMode RepeatMode
{
get => _repeatMode;
set
{
_repeatMode = value;
OnPropertyChanged();
}
}

public IEnumerable<IntervalRepeatMode> IntervalRepeatModeValues => Enum.GetValues(typeof(IntervalRepeatMode)).Cast<IntervalRepeatMode>();

public int IntervalThrottle
{
get => _intervalThrottle;
set
{
_intervalThrottle = value;
OnPropertyChanged();
}
}

[XmlIgnore]
public int IntervalExecutionCount
{
get => _intervalExecutionCount;
set
{
_intervalExecutionCount = value;
OnPropertyChanged();
}
}

protected ActionBase()
{
Id = Guid.NewGuid();
_isEnabled = true;
_repeat = true;
_trigger = EventTrigger.Interval;
_repeatMode = IntervalRepeatMode.Forever;
_intervalThrottle = 1;
ExecuteCommand = new RelayCommand(param => Execute(), param => CanExecute());
}

Expand Down
2 changes: 1 addition & 1 deletion 4x/Move Mouse/Actions/ActivateApplicationAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private void RefreshApplications()

public override string ToString()
{
return $"Name = {Name} | Mode = {Mode} | Application = {Application} | Trigger = {Trigger} | Repeat = {Repeat}";
return $"{this.GetType().Name} | Name = {Name} | Mode = {Mode} | Application = {Application} | Trigger = {Trigger} | Repeat = {Repeat} | RepeatMode = {RepeatMode} | IntervalThrottle = {IntervalThrottle} | IntervalExecutionCount = {IntervalExecutionCount}";
}
}
}
2 changes: 1 addition & 1 deletion 4x/Move Mouse/Actions/ClickMouseAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public override void Execute()

public override string ToString()
{
return $"Name = {Name} | Button = {Button} | Hold = {Hold} | HoldInterval = {HoldInterval} | Trigger = {Trigger} | Repeat = {Repeat}";
return $"{this.GetType().Name} | Name = {Name} | Button = {Button} | Hold = {Hold} | HoldInterval = {HoldInterval} | Trigger = {Trigger} | Repeat = {Repeat} | RepeatMode = {RepeatMode} | IntervalThrottle = {IntervalThrottle} | IntervalExecutionCount = {IntervalExecutionCount}";
}
}
}
2 changes: 1 addition & 1 deletion 4x/Move Mouse/Actions/CommandAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public override void Execute()

public override string ToString()
{
return $"Name = {Name} | FilePath = {FilePath} | Arguments = {Arguments} | WaitForExit = {WaitForExit} | Hidden = {Hidden} | Trigger = {Trigger} | Repeat = {Repeat}";
return $"{this.GetType().Name} | Name = {Name} | FilePath = {FilePath} | Arguments = {Arguments} | WaitForExit = {WaitForExit} | Hidden = {Hidden} | Trigger = {Trigger} | Repeat = {Repeat} | RepeatMode = {RepeatMode} | IntervalThrottle = {IntervalThrottle} | IntervalExecutionCount = {IntervalExecutionCount}";
}
}
}
3 changes: 2 additions & 1 deletion 4x/Move Mouse/Actions/MoveMouseCursorAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public override void Execute()
{
try
{
IntervalExecutionCount++;
StaticCode.Logger?.Here().Information(ToString());

switch (Direction)
Expand Down Expand Up @@ -236,7 +237,7 @@ public override void Execute()

public override string ToString()
{
return $"Name = {Name} | Distance = {Distance} | Direction = {Direction} | Speed = {Speed} | Delay = {Delay} | Trigger = {Trigger} | Repeat = {Repeat}";
return $"{this.GetType().Name} | Name = {Name} | Distance = {Distance} | Direction = {Direction} | Speed = {Speed} | Delay = {Delay} | Trigger = {Trigger} | Repeat = {Repeat} | RepeatMode = {RepeatMode} | IntervalThrottle = {IntervalThrottle} | IntervalExecutionCount = {IntervalExecutionCount}";
}
}
}
2 changes: 1 addition & 1 deletion 4x/Move Mouse/Actions/PositionMouseCursorAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private void _cursorTrackingTimer_Elapsed(object sender, ElapsedEventArgs e)

public override string ToString()
{
return $"Name = {Name} | X = {X} | Y = {Y} | Trigger = {Trigger} | Repeat = {Repeat}";
return $"{this.GetType().Name} | Name = {Name} | X = {X} | Y = {Y} | Trigger = {Trigger} | Repeat = {Repeat} | RepeatMode = {RepeatMode} | IntervalThrottle = {IntervalThrottle} | IntervalExecutionCount = {IntervalExecutionCount}";
}
}
}
2 changes: 1 addition & 1 deletion 4x/Move Mouse/Actions/ScriptAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public override void Execute()

public override string ToString()
{
return $"Name = {Name} | ScriptPath = {ScriptPath} | WaitForExit = {WaitForExit} | Hidden = {Hidden} | Trigger = {Trigger} | Repeat = {Repeat}";
return $"{this.GetType().Name} | Name = {Name} | ScriptPath = {ScriptPath} | WaitForExit = {WaitForExit} | Hidden = {Hidden} | Trigger = {Trigger} | Repeat = {Repeat} | RepeatMode = {RepeatMode} | IntervalThrottle = {IntervalThrottle} | IntervalExecutionCount = {IntervalExecutionCount}";
}
}
}
2 changes: 1 addition & 1 deletion 4x/Move Mouse/Actions/ScrollMouseAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public override void Execute()

public override string ToString()
{
return $"Name = {Name} | Distance = {Distance} | Direction = {Direction} | Trigger = {Trigger} | Repeat = {Repeat}";
return $"{this.GetType().Name} | Name = {Name} | Distance = {Distance} | Direction = {Direction} | Trigger = {Trigger} | Repeat = {Repeat} | RepeatMode = {RepeatMode} | IntervalThrottle = {IntervalThrottle} | IntervalExecutionCount = {IntervalExecutionCount}";
}
}
}
2 changes: 1 addition & 1 deletion 4x/Move Mouse/Actions/SleepAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public override void Execute()

public override string ToString()
{
return $"Name = {Name} | Random = {Random} | Seconds = {Seconds} | UpperSeconds = {UpperSeconds} | Trigger = {Trigger} | Repeat = {Repeat}";
return $"{this.GetType().Name} | Name = {Name} | Random = {Random} | Seconds = {Seconds} | UpperSeconds = {UpperSeconds} | Trigger = {Trigger} | Repeat = {Repeat} | RepeatMode = {RepeatMode} | IntervalThrottle = {IntervalThrottle} | IntervalExecutionCount = {IntervalExecutionCount}";
}
}
}
15 changes: 15 additions & 0 deletions 4x/Move Mouse/Classes/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class Settings : INotifyPropertyChanged
private bool? _pauseOnBattery;
private LogEventLevel? _logLevel;
private bool? _showSystemTrayNotifications;
//private bool? _reactivatePreviousWindow;

public int LowerInterval
{
Expand Down Expand Up @@ -535,6 +536,20 @@ public bool ShowSystemTrayNotifications
}
}

//public bool ReactivatePreviousWindow
//{
// get
// {
// if (_reactivatePreviousWindow == null) _reactivatePreviousWindow = false;
// return _reactivatePreviousWindow.Value;
// }
// set
// {
// _reactivatePreviousWindow = value;
// OnPropertyChanged();
// }
//}

[XmlArrayItem(Type = typeof(ActionBase)),
XmlArrayItem(Type = typeof(MoveMouseCursorAction)),
XmlArrayItem(Type = typeof(ClickMouseAction)),
Expand Down
4 changes: 2 additions & 2 deletions 4x/Move Mouse/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("4.15.1.0")]
[assembly: AssemblyFileVersion("4.15.1.0")]
[assembly: AssemblyVersion("4.16.0.0")]
[assembly: AssemblyFileVersion("4.16.0.0")]
3 changes: 2 additions & 1 deletion 4x/Move Mouse/StaticCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ public static class StaticCode

public const string PayPalUrl = "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QZTWHD9CRW5XN";
public const string HomePageUrl = "http://www.movemouse.co.uk";
public const string HelpPageUrl = "https://sites.google.com/a/windandkite.co.uk/movemouse/help";
public const string HelpPageUrl = "https://github.com/sw3103/movemouse/wiki";
public const string TwitterUrl = "https://twitter.com/movemouse";
public const string GitHubUrl = "https://github.com/sw3103/movemouse";
public const string CronHelpUrl = "http://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.html";
public const string TroubleshootingUrl = "https://github.com/sw3103/movemouse/wiki/Troubleshooting";
//public const string CronHelpUrl = "https://crontab.guru/examples.html";
//public const string ThemesXmlUrl = "https://raw.githubusercontent.com/sw3103/movemouse/master/Themes/Themes.xml";
//public const string ThemesXmlUrl = "C:\\Users\\steve\\source\\repos\\movemouse\\Themes\\Themes_Test.xml";
Expand Down
57 changes: 46 additions & 11 deletions 4x/Move Mouse/ViewModels/MouseWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
using ellabi.Jobs;
using ellabi.Schedules;
using ellabi.Utilities;
using ellabi.Wrappers;
using Microsoft.VisualBasic;
using Microsoft.Win32;
using Quartz;
using Quartz.Impl;
using Quartz.Impl.Triggers;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;

namespace ellabi.ViewModels
Expand Down Expand Up @@ -61,6 +65,7 @@ internal class MouseWindowViewModel : INotifyPropertyChanged, IDisposable
private object _lock = new object();
private bool _updateAvailable;
//private DateTime _startTime;
//private string _previousActiveWindowTitle;

public enum MouseState
{
Expand Down Expand Up @@ -491,7 +496,7 @@ public void Start()
_activeExecutionId = Guid.NewGuid();
_lastStopStartToggleTime = DateTime.Now;
PerformActions(ActionBase.EventTrigger.Start);
double interval = SettingsVm.Settings.RandomInterval ? new Random().Next((SettingsVm.Settings.LowerInterval * 1000), (SettingsVm.Settings.UpperInterval * 1000)) : (SettingsVm.Settings.LowerInterval * 1000);
double interval = SettingsVm.Settings.RandomInterval ? new Random().Next(SettingsVm.Settings.LowerInterval * 1000, SettingsVm.Settings.UpperInterval * 1000) : (SettingsVm.Settings.LowerInterval * 1000);
interval = interval > 0 ? interval : 1;
ExecutionTime = DateTime.Now.AddMilliseconds(interval);
CurrentState = MouseState.Running;
Expand All @@ -515,6 +520,26 @@ public void Start()
}
}

//private void GetActiveWindow()
//{
// try
// {
// var handle = NativeMethods.GetForegroundWindow();
// const int nChar = 256;
// var sb = new StringBuilder(nChar);
// _previousActiveWindowTitle = null;

// if (NativeMethods.GetWindowText(handle, sb, nChar) > 0)
// {
// _previousActiveWindowTitle = sb.ToString();
// }
// }
// catch (Exception ex)
// {
// StaticCode.Logger?.Here().Error(ex.Message);
// }
//}

public void Stop(MouseState state)
{
StaticCode.Logger?.Here().Information(state.ToString());
Expand Down Expand Up @@ -543,6 +568,11 @@ public void Stop(MouseState state)
if (CurrentState.Equals(MouseState.Paused))
{
StartAutoResumeTimer();

//if (SettingsVm.Settings.ReactivatePreviousWindow && !String.IsNullOrWhiteSpace(_previousActiveWindowTitle))
//{
// Interaction.AppActivate(_previousActiveWindowTitle);
//}
}
}
}
Expand Down Expand Up @@ -613,6 +643,14 @@ private void PerformActions(ActionBase.EventTrigger trigger)
{
var executionId = _activeExecutionId;

if (_firstPass)
{
for (int i = 0; i < SettingsVm.Settings.Actions.Length; i++)
{
SettingsVm.Settings.Actions[i].IntervalExecutionCount = 0;
}
}

switch (trigger)
{
case ActionBase.EventTrigger.Start:
Expand Down Expand Up @@ -643,7 +681,7 @@ private void PerformActions(ActionBase.EventTrigger trigger)

if (SettingsVm.Settings.Actions.Any(action => action.IsValid && action.IsEnabled && action.Trigger.Equals(trigger)))
{
var actions = _firstPass ? SettingsVm.Settings.Actions.Where(action => action.IsValid && action.IsEnabled && action.Trigger.Equals(trigger)) : SettingsVm.Settings.Actions.Where(action => action.IsValid && action.IsEnabled && action.Trigger.Equals(trigger) && action.Repeat);
var actions = _firstPass ? SettingsVm.Settings.Actions.Where(action => action.IsValid && action.IsEnabled && action.Trigger.Equals(trigger)) : SettingsVm.Settings.Actions.Where(action => action.IsValid && action.IsEnabled && action.Trigger.Equals(trigger) && action.Repeat && ((action.RepeatMode == ActionBase.IntervalRepeatMode.Forever) || ((action.RepeatMode == ActionBase.IntervalRepeatMode.Throttle) && (action.IntervalExecutionCount < action.IntervalThrottle))));

foreach (var action in actions)
{
Expand All @@ -666,19 +704,14 @@ private void PerformActions(ActionBase.EventTrigger trigger)
CurrentState = MouseState.Locked;
}

if (_activeExecutionId.Equals(executionId) && (CurrentState.Equals(MouseState.Sleeping) || (!_firstPass && SettingsVm.Settings.Actions.Any(action => action.IsValid && action.IsEnabled && action.Trigger.Equals(trigger) && action.Repeat))))
if (_activeExecutionId.Equals(executionId) && (CurrentState.Equals(MouseState.Locked) || CurrentState.Equals(MouseState.Sleeping) || (!_firstPass && SettingsVm.Settings.Actions.Any(action => action.IsValid && action.IsEnabled && action.Trigger.Equals(trigger) && action.Repeat && ((action.RepeatMode == ActionBase.IntervalRepeatMode.Forever) || ((action.RepeatMode == ActionBase.IntervalRepeatMode.Throttle) && (action.IntervalExecutionCount < action.IntervalThrottle)))))))
{
Start();

if (CurrentState.Equals(MouseState.Sleeping))
{
ShowNotification("Automatically resuming after blackout expired.");
}
}
else
{
Stop(MouseState.Idle);
ShowNotification("Automatically stopping as there are no actions that are configured to repeat at each interval.");
ShowNotification("Automatically stopping as there are no actions that are configured to repeat forever at each interval.");
}

break;
Expand Down Expand Up @@ -805,6 +838,7 @@ private void _autoResumeTimer_Elapsed(object sender, System.Timers.ElapsedEventA
if (StaticCode.GetLastInputTime().TotalSeconds > SettingsVm.Settings.AutoResumeSeconds)
{
Start();
//GetActiveWindow();
ShowNotification($"Automatically resuming after {SettingsVm.Settings.AutoResumeSeconds} seconds of inactivity.");
}
}
Expand All @@ -821,6 +855,7 @@ private void StartBlackoutTimer()
try
{
StopBlackoutTimer();
ShowNotification("Going to sleep whilst blackout in effect.");

if (_blackoutTimer == null)
{
Expand Down Expand Up @@ -862,7 +897,7 @@ private void _blackoutTimer_Elapsed(object sender, System.Timers.ElapsedEventArg
if (!BlackoutIsActive())
{
Start();
ShowNotification("Resuming now blackout is over.");
ShowNotification("Resuming now blackout has expired.");
}
}
catch (Exception ex)
Expand Down Expand Up @@ -914,7 +949,7 @@ public void ShowNotification(string message)

public void ShowNotification(string title, string message, Hardcodet.Wpf.TaskbarNotification.BalloonIcon symbol)
{
if (!SettingsVm.Settings.HideSystemTrayIcon && SettingsVm.Settings.ShowSystemTrayNotifications)
if (!SettingsVm.Settings.HideSystemTrayIcon && SettingsVm.Settings.ShowSystemTrayNotifications && !_workstationLocked)
{
OnRequestNotification(this, title, message, symbol);
}
Expand Down
4 changes: 2 additions & 2 deletions 4x/Move Mouse/Views/MouseWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
</MultiDataTrigger.Conditions>
<Setter Property="Visibility" Value="Hidden"/>
</MultiDataTrigger>
<DataTrigger Binding="{Binding Path=CurrentState, NotifyOnTargetUpdated=True}" Value="Running">
<!--<DataTrigger Binding="{Binding Path=CurrentState, NotifyOnTargetUpdated=True}" Value="Running">
<Setter Property="IconSource" Value="/Resources/Mouse-SystemTray-Active.ico"/>
</DataTrigger>
<DataTrigger Binding="{Binding Path=CurrentState, NotifyOnTargetUpdated=True}" Value="Executing">
Expand All @@ -321,7 +321,7 @@
</DataTrigger>
<DataTrigger Binding="{Binding Path=CurrentState, NotifyOnTargetUpdated=True}" Value="OnBattery">
<Setter Property="IconSource" Value="/Resources/Mouse-SystemTray-Battery.ico"/>
</DataTrigger>
</DataTrigger>-->
</Style.Triggers>
</Style>
</tb:TaskbarIcon.Style>
Expand Down
Loading

0 comments on commit 6dbcebf

Please sign in to comment.