Skip to content

Commit

Permalink
Merge pull request #10 from Leo-Corporation/vNext
Browse files Browse the repository at this point in the history
Version 1.1.0.2308
  • Loading branch information
lpeyr authored Aug 1, 2023
2 parents a239a25 + 4a69bc2 commit b724abc
Show file tree
Hide file tree
Showing 16 changed files with 482 additions and 29 deletions.
4 changes: 2 additions & 2 deletions DayBar.Setup/Setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "DayBar"
#define MyAppVersion "1.0.0.2307"
#define MyAppFullVersion "1.0.0.2307"
#define MyAppVersion "1.1.0.2308"
#define MyAppFullVersion "1.1.0.2308"
#define MyAppPublisher "Léo Corporation"
#define MyAppURL "https://leocorporation.dev/"
#define MyAppExeName "DayBar.exe"
Expand Down
43 changes: 42 additions & 1 deletion DayBar/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,48 @@
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>
<Style x:Key="DayToggleButtonStyle" TargetType="ToggleButton">
<Setter Property="Width" Value="30" />
<Setter Property="Height" Value="30" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Foreground" Value="{DynamicResource Foreground1}"/>
<Setter Property="BorderThickness" Value="2" />
<Setter Property="BorderBrush" Value="{DynamicResource Accent}" />
<Setter Property="Content" Value="Mon" />
<Setter Property="FontSize" Value="11" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToggleButton">
<Grid>
<Ellipse Width="30"
Height="30"
Fill="{TemplateBinding Background}"
Stroke="{TemplateBinding BorderBrush}"
StrokeThickness="{TemplateBinding BorderThickness}" />
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="{TemplateBinding Content}" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Background" Value="{DynamicResource Accent}" />
<Setter Property="Foreground" Value="{DynamicResource WindowButtonsHoverForeground1}"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="{DynamicResource LightAccent}" />
<Setter Property="Foreground" Value="{DynamicResource WindowButtonsHoverForeground1}"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Background" Value="{DynamicResource Accent}" />
<Setter Property="Foreground" Value="{DynamicResource WindowButtonsHoverForeground1}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

</Application.Resources>
</Application>
2 changes: 1 addition & 1 deletion DayBar/Classes/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace DayBar.Classes
{
public static class Global
{
public static string Version => "1.0.0.2307";
public static string Version => "1.1.0.2308";
public static string LastVersionLink => "https://raw.githubusercontent.com/Leo-Corporation/LeoCorp-Docs/master/Liens/Update%20System/DayBar/Version.txt";
public static HomePage HomePage { get; set; }
public static NotificationsPage NotificationsPage { get; set; }
Expand Down
77 changes: 77 additions & 0 deletions DayBar/Classes/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
*/
using DayBar.Enums;
using PeyrSharp.Env;
using System;
using System.IO;
using System.Xml.Serialization;

Expand Down Expand Up @@ -75,18 +76,79 @@ public class Settings
/// </summary>
public bool IsFirstRun { get; set; }

/// <summary>
/// The working hour start minute.
/// </summary>
public int? StartMinute { get; set; }

/// <summary>
/// The working hour end minute.
/// </summary>
public int? EndMinute { get; set; }

/// <summary>
/// True if the app sould show a notification every x%.
/// </summary>
public bool? NotifyPercentage { get; set; }

/// <summary>
/// The value to look when showing a notfication every x%.
/// </summary>
public int? NotifyPercentageValue { get; set; }
public NotificationDays? NotificationDays { get; set; }

public Settings()
{
// Default configuration
StartHour = 0;
StartMinute = 0;
EndHour = 24;
EndMinute = 0;
NotifyUpdate = true;
NotifyHalfDay = false;
LaunchOnStart = true;
UseDarkThemeSystemTray = false;
Theme = Themes.System;
Language = Languages.Default;
IsFirstRun = true;
NotifyPercentage = false;
NotifyPercentageValue = 25;
NotificationDays = new()
{
Monday = true,
Tuesday = true,
Wednesday = true,
Thursday = true,
Friday = true,
Saturday = true,
Sunday = true
};
}
}

public struct NotificationDays
{
public bool Monday { get; set; }
public bool Tuesday { get; set; }
public bool Wednesday { get; set; }
public bool Thursday { get; set; }
public bool Friday { get; set; }
public bool Saturday { get; set; }
public bool Sunday { get; set; }

public bool IsNotificationDay()
{
return DateTime.Now.DayOfWeek switch
{
DayOfWeek.Monday => Monday,
DayOfWeek.Tuesday => Tuesday,
DayOfWeek.Wednesday => Wednesday,
DayOfWeek.Thursday => Thursday,
DayOfWeek.Friday => Friday,
DayOfWeek.Saturday => Saturday,
DayOfWeek.Sunday => Sunday,
_ => true
};
}
}

Expand Down Expand Up @@ -119,6 +181,21 @@ public static Settings Load()
StreamReader streamReader = new(SettingsPath);
var settings = (Settings?)xmlDeserializer.Deserialize(streamReader) ?? new();
streamReader.Dispose();

settings.StartMinute ??= 0;
settings.EndMinute ??= 0;
settings.NotifyPercentage ??= false;
settings.NotifyPercentageValue ??= 25;
settings.NotificationDays ??= new()
{
Monday = true,
Tuesday = true,
Wednesday = true,
Thursday = true,
Friday = true,
Saturday = true,
Sunday = true
};
return settings;
}

Expand Down
6 changes: 3 additions & 3 deletions DayBar/DayBar.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
Expand All @@ -8,7 +8,7 @@
<ApplicationIcon>DayBar.ico</ApplicationIcon>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Title>DayBar</Title>
<Version>1.0.0.2307</Version>
<Version>1.1.0.2308</Version>
<Authors>Léo Corporation</Authors>
<Company>Léo Corporation</Company>
<Copyright>© 2023</Copyright>
Expand Down Expand Up @@ -238,7 +238,7 @@

<ItemGroup>
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" />
<PackageReference Include="PeyrSharp.Env" Version="1.7.0.2307" />
<PackageReference Include="PeyrSharp.Env" Version="1.8.0.2308" />
</ItemGroup>

<ItemGroup>
Expand Down
95 changes: 81 additions & 14 deletions DayBar/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
using DayBar.Classes;
using PeyrSharp.Env;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows;
using System.Windows.Controls;
Expand All @@ -42,10 +43,28 @@ public MainWindow()
InitializeComponent();

Global.MainWindow = this;
InitTimer(Global.Settings.StartHour * 3600, Global.Settings.EndHour * 3600);
RefreshNotifications();
InitTimer(new(Global.Settings.StartHour, Global.Settings.StartMinute ?? 0, 0), new(Global.Settings.EndHour, Global.Settings.EndMinute ?? 0, 0));
InitUI();
Hide();
}
List<int> percentages = new List<int>();
List<bool> shown = new List<bool>();
internal void RefreshNotifications()
{
percentages.Clear();
shown.Clear();
// Calculate the total number of notifications required (100 / NotifyPercentageValue)
int totalNotifications = 100 / Global.Settings.NotifyPercentageValue.GetValueOrDefault(25);

// Fill the percentages list with the desired percentages for notifications
for (int i = 0; i < totalNotifications; i++)
{
int percentage = (i + 1) * Global.Settings.NotifyPercentageValue.GetValueOrDefault(25);
percentages.Add(percentage);
shown.Add(false);
}
}

string lastVersion = "";
private async void InitUI()
Expand All @@ -68,33 +87,61 @@ private async void InitUI()

DispatcherTimer dispatcherTimer = new();
bool halfShown = false;
internal void InitTimer(int startHour, int endHour)

internal void InitTimer(TimeSpan startWorkHour, TimeSpan endWorkHour)
{
dispatcherTimer.Stop();
int c = CalculatePercentage(startHour, endHour);
dispatcherTimer = new();
int c = CalculatePercentage(DateTime.Now, startWorkHour, endWorkHour);

dispatcherTimer.Interval = TimeSpan.FromMinutes(1);
dispatcherTimer.Tick += (o, e) =>
{
c = CalculatePercentage(startHour, endHour);
c = CalculatePercentage(DateTime.Now, startWorkHour, endWorkHour);
SetNotifyIcon(ref c);
};

SetNotifyIcon(ref c);
dispatcherTimer.Start();
}

private int CalculatePercentage(int startHour, int endHour)
private int CalculatePercentage(DateTime currentTime, TimeSpan startWorkHour, TimeSpan endWorkHour)
{
// Get the current time
DateTime now = DateTime.Now;
// Get the start of the day
DateTime startOfDay = new(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, startHour / 3600, 0, 0);
// Get the difference as a TimeSpan
TimeSpan elapsed = now - startOfDay;
// Get the total number of seconds
int seconds = (int)elapsed.TotalSeconds;
return seconds * 100 / (endHour - startHour);
// Get the current date and time
DateTime currentDate = DateTime.Now;

// Create DateTime objects for the start and end work hours
DateTime startDateTime = currentDate.Date.Add(startWorkHour);
DateTime endDateTime = currentDate.Date.Add(endWorkHour);

// If end work hour is before the start work hour, adjust it to the next day
if (endDateTime < startDateTime)
{
endDateTime = endDateTime.AddDays(1);
}

// Check if the current time is within the range of the previous day
if (currentTime < startDateTime)
{
startDateTime = startDateTime.AddDays(-1);
endDateTime = endDateTime.AddDays(-1);
}

// Calculate the total number of minutes between start and end work hours
TimeSpan totalWorkHours = endDateTime - startDateTime;
int totalWorkMinutes = (int)totalWorkHours.TotalMinutes;

// Calculate the number of minutes passed since the start of the workday
TimeSpan timePassed = currentTime - startDateTime;
int minutesPassed = (int)timePassed.TotalMinutes;

// Calculate the percentage of time passed (rounded down to the nearest integer)
int percentagePassed = (int)((double)minutesPassed / totalWorkMinutes * 100);

// Make sure the percentage is within the range of 0 to 100
percentagePassed = Math.Max(0, Math.Min(100, percentagePassed));

return percentagePassed;
}

private void SetNotifyIcon(ref int progress)
Expand All @@ -112,11 +159,31 @@ private void SetNotifyIcon(ref int progress)
Global.ThemePage.LightProgressTxt.Text = $"{progress}%";
Global.ThemePage.DarkProgressTxt.Text = $"{progress}%";

// Notifications
if (!Global.Settings.NotificationDays.Value.IsNotificationDay()) return;
if (!halfShown && Global.Settings.NotifyHalfDay && progress >= 50)
{
halfShown = true;
myNotifyIcon.ShowBalloonTip(Properties.Resources.DayBar, Properties.Resources.HalfPassed, Hardcodet.Wpf.TaskbarNotification.BalloonIcon.Info);
}

if (Global.Settings.NotifyPercentage ?? false)
{
// Show notifications when progress reaches the specified percentages
for (int i = percentages.Count - 1; i >= 0; i--)
{
if (progress >= percentages[i] && !shown[i] && !shown[^1])
{
shown[i] = true;
for (int j = i - 1; j >= 0; j--)
{
shown[j] = true;
}
myNotifyIcon.ShowBalloonTip(Properties.Resources.DayBar, string.Format(Properties.Resources.XDayHasPassed, progress), Hardcodet.Wpf.TaskbarNotification.BalloonIcon.Info);
break; // To show only one notification per loop
}
}
}
}

internal void UpdatesAvailable()
Expand Down
2 changes: 1 addition & 1 deletion DayBar/Pages/FirstRun/CustomizePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private void RadioButton_Checked(object sender, RoutedEventArgs e)
try
{
Global.Settings.UseDarkThemeSystemTray = DarkRadio.IsChecked ?? false;
Global.MainWindow.InitTimer(Global.Settings.StartHour * 3600, Global.Settings.EndHour * 3600);
Global.MainWindow.InitTimer(new(Global.Settings.StartHour, 0, 0), new(Global.Settings.EndHour, 0, 0));
SettingsManager.Save();
}
catch { }
Expand Down
5 changes: 5 additions & 0 deletions DayBar/Pages/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@
<StackPanel Orientation="Horizontal" Grid.Column="2" VerticalAlignment="Center">
<TextBlock Text="{x:Static lang:Resources.From}" FontWeight="Bold" Margin="2 0" VerticalAlignment="Center"/>
<TextBox Foreground="{DynamicResource Foreground1}" PreviewTextInput="FromTxt_PreviewTextInput" x:Name="FromTxt" Style="{DynamicResource RegularTextBoxStyle}" d:Text="0" TextAlignment="Center" Width="25" Padding="1 0" Background="Transparent" BorderBrush="Transparent" MaxLength="2"/>
<TextBlock Text=":" FontWeight="Bold" Margin="0" VerticalAlignment="Center"/>
<TextBox Foreground="{DynamicResource Foreground1}" PreviewTextInput="FromTxt_PreviewTextInput" x:Name="MinFromTxt" Style="{DynamicResource RegularTextBoxStyle}" d:Text="0" TextAlignment="Center" Width="25" Padding="1 0" Background="Transparent" BorderBrush="Transparent" MaxLength="2"/>

<TextBlock Text="{x:Static lang:Resources.To}" FontWeight="Bold" Margin="2 0" VerticalAlignment="Center"/>
<TextBox Foreground="{DynamicResource Foreground1}" PreviewTextInput="FromTxt_PreviewTextInput" x:Name="ToTxt" Style="{DynamicResource RegularTextBoxStyle}" d:Text="24" TextAlignment="Center" Width="25" Padding="1 0" Background="Transparent" BorderBrush="Transparent" MaxLength="2"/>
<TextBlock Text=":" FontWeight="Bold" Margin="0" VerticalAlignment="Center"/>
<TextBox Foreground="{DynamicResource Foreground1}" PreviewTextInput="FromTxt_PreviewTextInput" x:Name="MinToTxt" Style="{DynamicResource RegularTextBoxStyle}" d:Text="24" TextAlignment="Center" Width="25" Padding="1 0" Background="Transparent" BorderBrush="Transparent" MaxLength="2"/>
<Button x:Name="ValidateTxt" Style="{DynamicResource ButtonMenu}" BorderThickness="0" FontFamily="..\Fonts\#FluentSystemIcons-Regular" Cursor="Hand" FontSize="12" Content="&#xF295;" Padding="4 0" Click="ValidateTxt_Click" Foreground="{DynamicResource Foreground1}" Background="{DynamicResource Background3}"/>
</StackPanel>
</Grid>
Expand Down
Loading

0 comments on commit b724abc

Please sign in to comment.