Skip to content

Commit

Permalink
Release 4.17.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
sw3103 committed Nov 8, 2023
1 parent eb001d5 commit 7ff536f
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 33 deletions.
14 changes: 14 additions & 0 deletions 4x/Move Mouse/Jobs/RefreshSchedulesJob.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
1 change: 1 addition & 0 deletions 4x/Move Mouse/Move Mouse.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@
<Compile Include="Converters\StartupTaskStateToBoolConverter.cs" />
<Compile Include="Converters\StringToFileExistsConverter.cs" />
<Compile Include="Jobs\CheckForUpdateJob.cs" />
<Compile Include="Jobs\RefreshSchedulesJob.cs" />
<Compile Include="Jobs\ResetUpdateStatusJob.cs" />
<Compile Include="Jobs\UpdateThemeJob.cs" />
<Compile Include="Schedules\AdvancedSchedule.cs" />
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.16.3.0")]
[assembly: AssemblyFileVersion("4.16.3.0")]
[assembly: AssemblyVersion("4.17.0.0")]
[assembly: AssemblyFileVersion("4.17.0.0")]
22 changes: 20 additions & 2 deletions 4x/Move Mouse/Schedules/SimpleSchedule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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));
Expand Down
7 changes: 7 additions & 0 deletions 4x/Move Mouse/StaticCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -153,6 +155,11 @@ public static void OnUpdateAvailablityChanged(bool updateAvailable)
{
UpdateAvailablityChanged?.Invoke(updateAvailable);
}

public static void OnRefreshSchedules()
{
RefreshSchedules?.Invoke();
}
}
}

Expand Down
34 changes: 22 additions & 12 deletions 4x/Move Mouse/ViewModels/MouseWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;

namespace ellabi.ViewModels
{
Expand Down Expand Up @@ -146,13 +147,20 @@ 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);
ScheduleJobs();
//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);
Expand Down Expand Up @@ -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))
{
Expand All @@ -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)
//{
Expand Down Expand Up @@ -327,10 +330,10 @@ private async void ScheduleJobsThread(object stateInfo)

if (StaticCode.DownloadSource == StaticCode.MoveMouseSource.GitHub)
{
var resetUpdateStatus = JobBuilder.Create<ResetUpdateStatusJob>()
var resetUpdateStatusJob = JobBuilder.Create<ResetUpdateStatusJob>()
.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<CheckForUpdateJob>()
Expand All @@ -340,6 +343,11 @@ private async void ScheduleJobsThread(object stateInfo)
await _scheduler.TriggerJob(new JobKey("CheckForUpdateJob"));
}

var refreshSchedulesJob = JobBuilder.Create<RefreshSchedulesJob>()
.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();
//}
}
Expand All @@ -355,16 +363,17 @@ private async void ScheduleJobsThread(object stateInfo)
}
}

private void CleanupJobs()
private async Task CleanupJobs()
{
StaticCode.Logger?.Here().Debug(String.Empty);

try
{
if ((_scheduler != null) && !_scheduler.IsShutdown)
{
_scheduler?.Clear();
_scheduler?.Shutdown();
await _scheduler?.Clear();
await _scheduler?.Shutdown();

}
}
catch (Exception ex)
Expand Down Expand Up @@ -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;
}
Expand Down
57 changes: 40 additions & 17 deletions 4x/Move Mouse/Views/SettingsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2075,13 +2075,16 @@
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="70"/>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="70"/>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="5"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="Auto"/>
Expand All @@ -2096,16 +2099,36 @@
</Grid.RowDefinitions>
<TextBlock Grid.Column="1" Grid.Row="1" Text="Action" Style="{StaticResource LabelTextBlockStyle}"/>
<ComboBox Grid.Column="3" Grid.Row="1" SelectedItem="{Binding Path=Action, NotifyOnTargetUpdated=True}" ItemsSource="{Binding Path=ScheduleActionValues}" HorizontalAlignment="Stretch"/>
<TextBlock Grid.Column="1" Grid.Row="3" Text="Time" Style="{StaticResource LabelTextBlockStyle}"/>
<xctk:TimeSpanUpDown Grid.Column="3" Grid.Row="3" Value="{Binding Path=Time, NotifyOnTargetUpdated=True, UpdateSourceTrigger=LostFocus}" Minimum="0:0:0" Maximum="23:59:59" HorizontalAlignment="Stretch"/>
<toggleSwitch:HorizontalToggleSwitch Grid.Column="5" Grid.Row="1" IsChecked="{Binding Path=Monday, NotifyOnTargetUpdated=True, Mode=TwoWay}" UncheckedContent="Mon" CheckedContent="Mon"/>
<toggleSwitch:HorizontalToggleSwitch Grid.Column="7" Grid.Row="1" IsChecked="{Binding Path=Tuesday, NotifyOnTargetUpdated=True, Mode=TwoWay}" UncheckedContent="Tue" CheckedContent="Tue"/>
<toggleSwitch:HorizontalToggleSwitch Grid.Column="9" Grid.Row="1" IsChecked="{Binding Path=Wednesday, NotifyOnTargetUpdated=True, Mode=TwoWay}" UncheckedContent="Wed" CheckedContent="Wed"/>
<toggleSwitch:HorizontalToggleSwitch Grid.Column="11" Grid.Row="1" IsChecked="{Binding Path=Thursday, NotifyOnTargetUpdated=True, Mode=TwoWay}" UncheckedContent="Thu" CheckedContent="Thu"/>
<toggleSwitch:HorizontalToggleSwitch Grid.Column="5" Grid.Row="3" IsChecked="{Binding Path=Friday, NotifyOnTargetUpdated=True, Mode=TwoWay}" UncheckedContent="Fri" CheckedContent="Fri"/>
<toggleSwitch:HorizontalToggleSwitch Grid.Column="7" Grid.Row="3" IsChecked="{Binding Path=Saturday, NotifyOnTargetUpdated=True, Mode=TwoWay}" UncheckedContent="Sat" CheckedContent="Sat"/>
<toggleSwitch:HorizontalToggleSwitch Grid.Column="9" Grid.Row="3" IsChecked="{Binding Path=Sunday, NotifyOnTargetUpdated=True, Mode=TwoWay}" UncheckedContent="Sun" CheckedContent="Sun"/>
<Button Grid.Column="13" Grid.Row="1" Grid.RowSpan="3" Style="{StaticResource TaskActionButtonStyle}" Command="{Binding ElementName=ScheduleItemsControl, Path=DataContext.RemoveSelectedScheduleCommand, NotifyOnTargetUpdated=True}" CommandParameter="{Binding Path=Id}" Margin="0">
<TextBlock Grid.Column="5" Grid.Row="1" Text="Time" Style="{StaticResource LabelTextBlockStyle}"/>
<xctk:TimeSpanUpDown Grid.Column="7" Grid.Row="1" Value="{Binding Path=Time, NotifyOnTargetUpdated=True, UpdateSourceTrigger=LostFocus}" Minimum="0:0:0" Maximum="23:59:59" HorizontalAlignment="Stretch"/>
<TextBlock Grid.Column="9" Grid.Row="1" Text="Delay" Style="{StaticResource LabelTextBlockStyle}"/>
<xctk:IntegerUpDown Grid.Column="11" Grid.Row="1" Value="{Binding Path=Delay, NotifyOnTargetUpdated=True}" Increment="1" Minimum="0" Maximum="99999"/>
<TextBlock Grid.Column="13" Grid.Row="1" Text="seconds" Style="{StaticResource LabelTextBlockStyle}"/>
<Grid Grid.Column="1" Grid.Row="3" Grid.ColumnSpan="14">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<toggleSwitch:HorizontalToggleSwitch Grid.Column="0" IsChecked="{Binding Path=Monday, NotifyOnTargetUpdated=True, Mode=TwoWay}" UncheckedContent="Mon" CheckedContent="Mon"/>
<toggleSwitch:HorizontalToggleSwitch Grid.Column="2" IsChecked="{Binding Path=Tuesday, NotifyOnTargetUpdated=True, Mode=TwoWay}" UncheckedContent="Tue" CheckedContent="Tue"/>
<toggleSwitch:HorizontalToggleSwitch Grid.Column="4" IsChecked="{Binding Path=Wednesday, NotifyOnTargetUpdated=True, Mode=TwoWay}" UncheckedContent="Wed" CheckedContent="Wed"/>
<toggleSwitch:HorizontalToggleSwitch Grid.Column="6" IsChecked="{Binding Path=Thursday, NotifyOnTargetUpdated=True, Mode=TwoWay}" UncheckedContent="Thu" CheckedContent="Thu"/>
<toggleSwitch:HorizontalToggleSwitch Grid.Column="8" IsChecked="{Binding Path=Friday, NotifyOnTargetUpdated=True, Mode=TwoWay}" UncheckedContent="Fri" CheckedContent="Fri"/>
<toggleSwitch:HorizontalToggleSwitch Grid.Column="10" IsChecked="{Binding Path=Saturday, NotifyOnTargetUpdated=True, Mode=TwoWay}" UncheckedContent="Sat" CheckedContent="Sat"/>
<toggleSwitch:HorizontalToggleSwitch Grid.Column="12" IsChecked="{Binding Path=Sunday, NotifyOnTargetUpdated=True, Mode=TwoWay}" UncheckedContent="Sun" CheckedContent="Sun"/>
</Grid>
<Button Grid.Column="16" Grid.Row="1" Grid.RowSpan="3" Style="{StaticResource TaskActionButtonStyle}" Command="{Binding ElementName=ScheduleItemsControl, Path=DataContext.RemoveSelectedScheduleCommand, NotifyOnTargetUpdated=True}" CommandParameter="{Binding Path=Id}" Margin="0">
<Image>
<Image.Style>
<Style TargetType="Image" BasedOn="{StaticResource TaskActionButtonImageStyle}">
Expand All @@ -2119,7 +2142,7 @@
</Image.Style>
</Image>
</Button>
<Border Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="15" Grid.RowSpan="5" BorderThickness="1" BorderBrush="{StaticResource StandardBorderBrush}"/>
<Border Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="18" Grid.RowSpan="5" BorderThickness="1" BorderBrush="{StaticResource StandardBorderBrush}"/>
</Grid>
</DataTemplate>
<DataTemplate DataType="{x:Type schedules:AdvancedSchedule}">
Expand All @@ -2129,7 +2152,7 @@
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="70"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
Expand Down

0 comments on commit 7ff536f

Please sign in to comment.