From 7ff536f40ad2b2d1b28bedd1d938804aa34fd0da Mon Sep 17 00:00:00 2001 From: Steve Williams Date: Wed, 8 Nov 2023 20:34:11 +0000 Subject: [PATCH] Release 4.17.0. --- 4x/Move Mouse/Jobs/RefreshSchedulesJob.cs | 14 +++++ 4x/Move Mouse/Move Mouse.csproj | 1 + 4x/Move Mouse/Properties/AssemblyInfo.cs | 4 +- 4x/Move Mouse/Schedules/SimpleSchedule.cs | 22 ++++++- 4x/Move Mouse/StaticCode.cs | 7 +++ .../ViewModels/MouseWindowViewModel.cs | 34 +++++++---- 4x/Move Mouse/Views/SettingsWindow.xaml | 57 +++++++++++++------ 7 files changed, 106 insertions(+), 33 deletions(-) create mode 100644 4x/Move Mouse/Jobs/RefreshSchedulesJob.cs diff --git a/4x/Move Mouse/Jobs/RefreshSchedulesJob.cs b/4x/Move Mouse/Jobs/RefreshSchedulesJob.cs new file mode 100644 index 0000000..6d49ebf --- /dev/null +++ b/4x/Move Mouse/Jobs/RefreshSchedulesJob.cs @@ -0,0 +1,14 @@ +using Quartz; +using System.Threading.Tasks; + +namespace ellabi.Jobs +{ + public class RefreshSchedulesJob : IJob + { + public async Task Execute(IJobExecutionContext context) + { + StaticCode.OnRefreshSchedules(); + await Task.CompletedTask; + } + } +} \ No newline at end of file diff --git a/4x/Move Mouse/Move Mouse.csproj b/4x/Move Mouse/Move Mouse.csproj index f80286f..c94bb60 100644 --- a/4x/Move Mouse/Move Mouse.csproj +++ b/4x/Move Mouse/Move Mouse.csproj @@ -272,6 +272,7 @@ + diff --git a/4x/Move Mouse/Properties/AssemblyInfo.cs b/4x/Move Mouse/Properties/AssemblyInfo.cs index 574354c..07edea9 100644 --- a/4x/Move Mouse/Properties/AssemblyInfo.cs +++ b/4x/Move Mouse/Properties/AssemblyInfo.cs @@ -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.16.3.0")] -[assembly: AssemblyFileVersion("4.16.3.0")] +[assembly: AssemblyVersion("4.17.0.0")] +[assembly: AssemblyFileVersion("4.17.0.0")] diff --git a/4x/Move Mouse/Schedules/SimpleSchedule.cs b/4x/Move Mouse/Schedules/SimpleSchedule.cs index f27973a..4cf800e 100644 --- a/4x/Move Mouse/Schedules/SimpleSchedule.cs +++ b/4x/Move Mouse/Schedules/SimpleSchedule.cs @@ -14,10 +14,18 @@ public class SimpleSchedule : ScheduleBase private bool _saturday; private bool _sunday; private TimeSpan _time; - + private int _delay; public override bool IsValid => (Monday || Tuesday || Wednesday || Thursday || Friday || Saturday || Sunday) && (Time < TimeSpan.FromHours(24)); - public override string CronExpression => String.Format("{0} {1} {2} ? * {3}", Time.Seconds, Time.Minutes, Time.Hours, BuildDayOfWeekPart()); + public override string CronExpression + { + get + { + var time = Delay == 0 ? Time : Time.Add(TimeSpan.FromSeconds(new Random().Next(0, Delay))); + if (time.TotalDays >= 1) time = new TimeSpan(23, 59, 59); + return String.Format("{0} {1} {2} ? * {3}", time.Seconds, time.Minutes, time.Hours, BuildDayOfWeekPart()); + } + } public bool Monday { @@ -157,6 +165,16 @@ public string TimeString set => _time = String.IsNullOrEmpty(value) ? TimeSpan.Zero : TimeSpan.Parse(value); } + public int Delay + { + get => _delay; + set + { + _delay = value; + OnPropertyChanged(); + } + } + public SimpleSchedule() { Time = DateTime.Now.TimeOfDay.Add(TimeSpan.FromSeconds(-1)); diff --git a/4x/Move Mouse/StaticCode.cs b/4x/Move Mouse/StaticCode.cs index 4dda8dc..12a416a 100644 --- a/4x/Move Mouse/StaticCode.cs +++ b/4x/Move Mouse/StaticCode.cs @@ -16,10 +16,12 @@ public static class StaticCode public delegate void ScheduleArrivedHandler(ScheduleBase.ScheduleAction action); //public delegate void ThemeUpdatedHandler(Theme theme); public delegate void UpdateAvailablityChangedHandler(bool updateAvailable); + public delegate void RefreshSchedulesHandler(); public static event ScheduleArrivedHandler ScheduleArrived; //public static event ThemeUpdatedHandler ThemeUpdated; public static event UpdateAvailablityChangedHandler UpdateAvailablityChanged; + public static event RefreshSchedulesHandler RefreshSchedules; 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"; @@ -153,6 +155,11 @@ public static void OnUpdateAvailablityChanged(bool updateAvailable) { UpdateAvailablityChanged?.Invoke(updateAvailable); } + + public static void OnRefreshSchedules() + { + RefreshSchedules?.Invoke(); + } } } diff --git a/4x/Move Mouse/ViewModels/MouseWindowViewModel.cs b/4x/Move Mouse/ViewModels/MouseWindowViewModel.cs index fe7393f..b46d59a 100644 --- a/4x/Move Mouse/ViewModels/MouseWindowViewModel.cs +++ b/4x/Move Mouse/ViewModels/MouseWindowViewModel.cs @@ -15,6 +15,7 @@ using System.Linq; using System.Runtime.CompilerServices; using System.Threading; +using System.Threading.Tasks; namespace ellabi.ViewModels { @@ -146,6 +147,7 @@ public MouseWindowViewModel() StaticCode.ScheduleArrived += StaticCode_ScheduleArrived; //StaticCode.ThemeUpdated += StaticCode_ThemeUpdated; if (StaticCode.DownloadSource == StaticCode.MoveMouseSource.GitHub) StaticCode.UpdateAvailablityChanged += StaticCode_UpdateAvailablityChanged; + StaticCode.RefreshSchedules += StaticCode_RefreshSchedules; SystemEvents.SessionSwitch += SystemEvents_SessionSwitch; SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; ThreadPool.QueueUserWorkItem(ForceSystrayIconVisibilityAtLaunch); @@ -153,6 +155,12 @@ public MouseWindowViewModel() //Debug.WriteLine(SystemInformation.PowerStatus.BatteryChargeStatus); } + private void StaticCode_RefreshSchedules() + { + Debug.WriteLine("StaticCode_RefreshSchedules()"); + ScheduleJobs(); + } + private void ForceSystrayIconVisibilityAtLaunch(object stateInfo) { StaticCode.Logger?.Here().Debug(String.Empty); @@ -268,12 +276,7 @@ private void StaticCode_ScheduleArrived(ScheduleBase.ScheduleAction action) } } - private void ScheduleJobs() - { - ThreadPool.QueueUserWorkItem(ScheduleJobsThread); - } - - private async void ScheduleJobsThread(object stateInfo) + private async void ScheduleJobs() { using (Mutex myMutex = new Mutex(false, "ScheduleJobsThread", out var owned)) { @@ -285,7 +288,7 @@ private async void ScheduleJobsThread(object stateInfo) //if (_lastSchedulesUpdateTime.Add(_schedulesUpdateDelay) > DateTime.Now) //{ - CleanupJobs(); + await CleanupJobs(); //while (_lastSchedulesUpdateTime.Add(_schedulesUpdateDelay) > DateTime.Now) //{ @@ -327,10 +330,10 @@ private async void ScheduleJobsThread(object stateInfo) if (StaticCode.DownloadSource == StaticCode.MoveMouseSource.GitHub) { - var resetUpdateStatus = JobBuilder.Create() + var resetUpdateStatusJob = JobBuilder.Create() .WithIdentity("ResetUpdateStatusJob") .Build(); - await _scheduler.ScheduleJob(resetUpdateStatus, new CronTriggerImpl("ResetUpdateStatusJob", null, "0 0 0 ? * *")); + await _scheduler.ScheduleJob(resetUpdateStatusJob, new CronTriggerImpl("ResetUpdateStatusJob", null, "0 1 0 ? * *")); await _scheduler.TriggerJob(new JobKey("ResetUpdateStatusJob")); var checkForUpdateTime = TimeSpan.FromHours(10).Add(TimeSpan.FromSeconds(new Random().Next(0, 21600))); var checkForUpdateJob = JobBuilder.Create() @@ -340,6 +343,11 @@ private async void ScheduleJobsThread(object stateInfo) await _scheduler.TriggerJob(new JobKey("CheckForUpdateJob")); } + var refreshSchedulesJob = JobBuilder.Create() + .WithIdentity("RefreshSchedulesJob") + .Build(); + var refreshSchedulesTime = DateTime.Now.AddSeconds(-1).TimeOfDay; + await _scheduler.ScheduleJob(refreshSchedulesJob, new CronTriggerImpl("RefreshSchedulesJob", null, $"{refreshSchedulesTime.Seconds} {refreshSchedulesTime.Minutes} {refreshSchedulesTime.Hours} ? * *")); await _scheduler.Start(); //} } @@ -355,7 +363,7 @@ private async void ScheduleJobsThread(object stateInfo) } } - private void CleanupJobs() + private async Task CleanupJobs() { StaticCode.Logger?.Here().Debug(String.Empty); @@ -363,8 +371,9 @@ private void CleanupJobs() { if ((_scheduler != null) && !_scheduler.IsShutdown) { - _scheduler?.Clear(); - _scheduler?.Shutdown(); + await _scheduler?.Clear(); + await _scheduler?.Shutdown(); + } } catch (Exception ex) @@ -1057,6 +1066,7 @@ public void Dispose() StaticCode.ScheduleArrived -= StaticCode_ScheduleArrived; //StaticCode.ThemeUpdated -= StaticCode_ThemeUpdated; StaticCode.UpdateAvailablityChanged -= StaticCode_UpdateAvailablityChanged; + StaticCode.RefreshSchedules -= StaticCode_RefreshSchedules; SystemEvents.SessionSwitch -= SystemEvents_SessionSwitch; SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged; } diff --git a/4x/Move Mouse/Views/SettingsWindow.xaml b/4x/Move Mouse/Views/SettingsWindow.xaml index 310de4b..ee7bd7b 100644 --- a/4x/Move Mouse/Views/SettingsWindow.xaml +++ b/4x/Move Mouse/Views/SettingsWindow.xaml @@ -2075,13 +2075,16 @@ + + - - - - - + + + + + + @@ -2096,16 +2099,36 @@ - - - - - - - - - -