diff --git a/src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek.sln b/src/Nager.WindowsCalendarWeek.sln similarity index 68% rename from src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek.sln rename to src/Nager.WindowsCalendarWeek.sln index 41cf136..8e65c50 100644 --- a/src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek.sln +++ b/src/Nager.WindowsCalendarWeek.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.8.34309.116 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nager.WindowsCalendarWeek", "Nager.WindowsCalendarWeek\Nager.WindowsCalendarWeek.csproj", "{1077449C-969D-4055-B767-990893D4D462}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nager.WindowsCalendarWeekNet4", "Nager.WindowsCalendarWeekNet4\Nager.WindowsCalendarWeekNet4.csproj", "{2FE40F04-C6C4-447D-AF43-3866D2935441}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {1077449C-969D-4055-B767-990893D4D462}.Debug|Any CPU.Build.0 = Debug|Any CPU {1077449C-969D-4055-B767-990893D4D462}.Release|Any CPU.ActiveCfg = Release|Any CPU {1077449C-969D-4055-B767-990893D4D462}.Release|Any CPU.Build.0 = Release|Any CPU + {2FE40F04-C6C4-447D-AF43-3866D2935441}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2FE40F04-C6C4-447D-AF43-3866D2935441}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2FE40F04-C6C4-447D-AF43-3866D2935441}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2FE40F04-C6C4-447D-AF43-3866D2935441}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek.csproj b/src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek.csproj new file mode 100644 index 0000000..be606bd --- /dev/null +++ b/src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek.csproj @@ -0,0 +1,16 @@ + + + + WinExe + net8.0-windows + enable + true + enable + nagerdate.ico + + + + + + + \ No newline at end of file diff --git a/src/Nager.WindowsCalendarWeek/Program.cs b/src/Nager.WindowsCalendarWeek/Program.cs new file mode 100644 index 0000000..e28fcac --- /dev/null +++ b/src/Nager.WindowsCalendarWeek/Program.cs @@ -0,0 +1,143 @@ +using System.Diagnostics; +using System.Globalization; + +namespace Nager.WindowsCalendarWeek; + +static class Program +{ + private static System.Windows.Forms.Timer RefreshIconTimer; + private static NotifyIcon CalendarWeekNotifyIcon; + private static int OneDayMilliseconds = 86400000; + + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + var firstRefreshInterval = (int)(OneDayMilliseconds - Math.Floor(DateTime.Now.TimeOfDay.TotalMilliseconds)); + + RefreshIconTimer = new System.Windows.Forms.Timer(); + RefreshIconTimer.Interval = firstRefreshInterval; + RefreshIconTimer.Tick += new EventHandler(RefreshIconTimer_Tick); + RefreshIconTimer.Start(); + + var bmp = GetBitmapOfCurrentCalendarWeek(); + + CalendarWeekNotifyIcon = new NotifyIcon + { + Icon = Icon.FromHandle(bmp.GetHicon()), + ContextMenuStrip = new ContextMenuStrip + { + Items = + { + new ToolStripMenuItem("Online Kalender", null, new EventHandler(OnlineCalendarItemClickEvent), "ToolStripMenuItem_OnlineCalendar"), + new ToolStripMenuItem("Feiertage", null, new EventHandler(HolidayItemClickEvent), "ToolStripMenuItem_Holiday"), + new ToolStripMenuItem("Quit", null, new EventHandler(QuitItemClickEvent), "ToolStripMenuItem_Quit") + } + }, + Visible = true + }; + + CalendarWeekNotifyIcon.MouseClick += TrayIcon_Click; + + Application.Run(); + } + + private static void RefreshIconTimer_Tick(object sender, EventArgs e) + { + RefreshIconTimer.Interval = OneDayMilliseconds; + + var oldIcon = CalendarWeekNotifyIcon.Icon; + if (oldIcon != null) + { + oldIcon.Dispose(); + } + + var bmp = GetBitmapOfCurrentCalendarWeek(); + CalendarWeekNotifyIcon.Icon = Icon.FromHandle(bmp.GetHicon()); + } + + private static void TrayIcon_Click(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.Left) + { + OpenOnlineCalendar(); + } + } + + private static void OnlineCalendarItemClickEvent(object sender, EventArgs e) + { + OpenOnlineCalendar(); + } + + private static void HolidayItemClickEvent(object sender, EventArgs e) + { + OpenHoliday(); + } + + private static void OpenOnlineCalendar() + { + // show first or second half of the year + var ext = DateTime.Today.Month > 6 ? "-2" : ""; + + var target = $"https://kalenderwoche.at/kalender/{DateTime.Today.Year}{ext}"; + + OpenBrowser(target); + } + + private static void OpenHoliday() + { + OpenBrowser("https://date.nager.at"); + } + + private static void OpenBrowser(string url) + { + var processStartInfo = new ProcessStartInfo("cmd", $"/c start {url}") + { + CreateNoWindow = true + }; + + Process.Start(processStartInfo); + } + + private static Bitmap GetBitmapOfCurrentCalendarWeek() + { + var width = 16; + var height = 16; + var text = GetWeekNumber().ToString(); + + var bitmap = new Bitmap(width, height); + using (var font = new Font("Arial", 8, FontStyle.Bold, GraphicsUnit.Point)) + { + using (var drawBrush = new SolidBrush(Color.White)) + { + using (var stringFormat = new StringFormat()) + { + stringFormat.Alignment = StringAlignment.Center; + stringFormat.LineAlignment = StringAlignment.Center; + + using (var graphics = Graphics.FromImage(bitmap)) + { + var drawingArea = new Rectangle(0, 0, width, height); + + graphics.FillRectangle(Brushes.Black, 0, 0, width, height); + graphics.DrawString(text, font, drawBrush, drawingArea, stringFormat); + } + } + } + } + + return bitmap; + } + + private static int GetWeekNumber() + { + return CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday); + } + + private static void QuitItemClickEvent(object sender, EventArgs e) + { + Application.Exit(); + } +} \ No newline at end of file diff --git a/src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek/nagerdate.ico b/src/Nager.WindowsCalendarWeek/nagerdate.ico similarity index 100% rename from src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek/nagerdate.ico rename to src/Nager.WindowsCalendarWeek/nagerdate.ico diff --git a/src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek/App.config b/src/Nager.WindowsCalendarWeekNet4/App.config similarity index 100% rename from src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek/App.config rename to src/Nager.WindowsCalendarWeekNet4/App.config diff --git a/src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek.csproj b/src/Nager.WindowsCalendarWeekNet4/Nager.WindowsCalendarWeekNet4.csproj similarity index 98% rename from src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek.csproj rename to src/Nager.WindowsCalendarWeekNet4/Nager.WindowsCalendarWeekNet4.csproj index 4362b07..a14d489 100644 --- a/src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek.csproj +++ b/src/Nager.WindowsCalendarWeekNet4/Nager.WindowsCalendarWeekNet4.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - {1077449C-969D-4055-B767-990893D4D462} + {2FE40F04-C6C4-447D-AF43-3866D2935441} WinExe Nager.WindowsCalendarWeek Nager.WindowsCalendarWeek diff --git a/src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek/Program.cs b/src/Nager.WindowsCalendarWeekNet4/Program.cs similarity index 92% rename from src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek/Program.cs rename to src/Nager.WindowsCalendarWeekNet4/Program.cs index 85b2e19..1ac3673 100644 --- a/src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek/Program.cs +++ b/src/Nager.WindowsCalendarWeekNet4/Program.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.Drawing; using System.Globalization; using System.Windows.Forms; @@ -84,13 +85,23 @@ private static void OpenOnlineCalendar() var ext = DateTime.Today.Month > 6 ? "-2" : ""; var target = $"https://kalenderwoche.at/kalender/{DateTime.Today.Year}{ext}"; - System.Diagnostics.Process.Start(target); + + OpenBrowser(target); } private static void OpenHoliday() { - var target = $"https://date.nager.at/"; - System.Diagnostics.Process.Start(target); + OpenBrowser("https://date.nager.at"); + } + + private static void OpenBrowser(string url) + { + var processStartInfo = new ProcessStartInfo("cmd", $"/c start {url}") + { + CreateNoWindow = true + }; + + Process.Start(processStartInfo); } private static Bitmap GetBitmapOfCurrentCalendarWeek() diff --git a/src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek/Properties/AssemblyInfo.cs b/src/Nager.WindowsCalendarWeekNet4/Properties/AssemblyInfo.cs similarity index 100% rename from src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek/Properties/AssemblyInfo.cs rename to src/Nager.WindowsCalendarWeekNet4/Properties/AssemblyInfo.cs diff --git a/src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek/Properties/Resources.Designer.cs b/src/Nager.WindowsCalendarWeekNet4/Properties/Resources.Designer.cs similarity index 100% rename from src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek/Properties/Resources.Designer.cs rename to src/Nager.WindowsCalendarWeekNet4/Properties/Resources.Designer.cs diff --git a/src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek/Properties/Resources.resx b/src/Nager.WindowsCalendarWeekNet4/Properties/Resources.resx similarity index 100% rename from src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek/Properties/Resources.resx rename to src/Nager.WindowsCalendarWeekNet4/Properties/Resources.resx diff --git a/src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek/Properties/Settings.Designer.cs b/src/Nager.WindowsCalendarWeekNet4/Properties/Settings.Designer.cs similarity index 100% rename from src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek/Properties/Settings.Designer.cs rename to src/Nager.WindowsCalendarWeekNet4/Properties/Settings.Designer.cs diff --git a/src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek/Properties/Settings.settings b/src/Nager.WindowsCalendarWeekNet4/Properties/Settings.settings similarity index 100% rename from src/Nager.WindowsCalendarWeek/Nager.WindowsCalendarWeek/Properties/Settings.settings rename to src/Nager.WindowsCalendarWeekNet4/Properties/Settings.settings diff --git a/src/Nager.WindowsCalendarWeekNet4/nagerdate.ico b/src/Nager.WindowsCalendarWeekNet4/nagerdate.ico new file mode 100644 index 0000000..bdadf13 Binary files /dev/null and b/src/Nager.WindowsCalendarWeekNet4/nagerdate.ico differ