aboutsummaryrefslogtreecommitdiffstats
path: root/WarframeClock/Program.cs
diff options
context:
space:
mode:
Diffstat (limited to 'WarframeClock/Program.cs')
-rw-r--r--WarframeClock/Program.cs102
1 files changed, 49 insertions, 53 deletions
diff --git a/WarframeClock/Program.cs b/WarframeClock/Program.cs
index 6378173..f390adc 100644
--- a/WarframeClock/Program.cs
+++ b/WarframeClock/Program.cs
@@ -1,93 +1,89 @@
using System;
using System.Linq;
using System.Threading;
-using System.Windows.Forms;
namespace WarframeClock
{
class Program
{
- public static bool UseWorldStatePhp = true;
- public static string VersionString = "Warframe Clock Overlay 2019-01-16";
- private static Clock clock;
- private static System.Threading.Timer worldStateFetchTimer;
+ public static readonly string VersionString = "Warframe Clock Overlay 2019-01-17";
+ public static readonly bool UseWorldStatePhp = true;
+
+ private static Timer worldStateFetchTimer;
+ private static System.Windows.Forms.NotifyIcon notifyIcon;
+ private static OverlayWindow overlayWindow;
[STAThread]
static void Main(string[] args)
{
try
{
- clock = new Clock();
-
- StartNotifyIcon();
if (UseWorldStatePhp)
StartWorldStateFetch();
+ StartNotifyIcon();
StartOverlay();
}
catch (Exception ex)
{
Console.WriteLine($"Main: Uncaught exception: {ex.Message}");
Console.WriteLine(ex.StackTrace);
- MessageBox.Show($"Main: Uncaught exception: {ex.Message}\n{ex.StackTrace}");
+ System.Windows.Forms.MessageBox.Show($"Main: Uncaught exception: {ex.Message}\n{ex.StackTrace}");
+ Terminate();
}
}
- private static void StartNotifyIcon()
+ private static void StartWorldStateFetch()
{
- var thread = new Thread(delegate ()
+ worldStateFetchTimer = new Timer(state =>
{
- var iconMenu = new ContextMenu();
- var icon = new NotifyIcon()
+ try
{
- Text = "Warframe Clock",
- ContextMenu = iconMenu,
- Icon = Properties.Resources.TrayIcon
- };
-
- iconMenu.MenuItems.Add(new MenuItem(VersionString) { Enabled = false });
- iconMenu.MenuItems.Add(new MenuItem("Quit", (_, __) =>
+ var worldState = WorldState.Fetch();
+ var cetusSyndicate = worldState.SyndicateMissions.FirstOrDefault(mi => mi.Tag == "CetusSyndicate");
+ if (cetusSyndicate == null)
+ {
+ Console.WriteLine("WorldState: CetusSyndicate missions not found");
+ return;
+ }
+ var cetusExpiry = cetusSyndicate.Expiry.Date.NumberLong;
+ Console.WriteLine($"WorldState: CetusSyndicate missions expire at {cetusExpiry}");
+ Clock.CetusExpiry = cetusExpiry;
+ }
+ catch (Exception ex)
{
- icon.Dispose();
- Environment.Exit(0);
- }));
- icon.Visible = true;
-
- Application.Run();
- });
- thread.Start();
+ Console.WriteLine($"WorldState: Failed to fetch or parse worldState.php: {ex.ToString()}");
+ Console.WriteLine(ex.StackTrace);
+ }
+ }, null, 0, 10 * 60 * 1000 /* 10 minutes */);
}
- private static void StartWorldStateFetch()
+ private static void StartNotifyIcon()
{
- worldStateFetchTimer = new System.Threading.Timer(state =>
+ var iconMenu = new System.Windows.Forms.ContextMenu();
+ notifyIcon = new System.Windows.Forms.NotifyIcon()
{
- lock (state)
- {
- try
- {
- var worldState = WorldState.Fetch();
- var cetusSyndicate = worldState.SyndicateMissions.FirstOrDefault(mi => mi.Tag == "CetusSyndicate");
- if (cetusSyndicate == null)
- {
- Console.WriteLine("WorldState: CetusSyndicate missions not found");
- return;
- }
- var cetusExpiry = cetusSyndicate.Expiry.Date.NumberLong;
- Console.WriteLine($"WorldState: CetusSyndicate missions expire at {cetusExpiry}");
- clock.CetusExpiry = cetusExpiry;
- }
- catch (Exception ex)
- {
- Console.WriteLine($"WorldState: Failed to fetch or parse worldState.php: {ex.ToString()}");
- Console.WriteLine(ex.StackTrace);
- }
- }
- }, new object(), 0, 10 * 60 * 1000 /* 10 minutes */);
+ Text = "Warframe Clock",
+ ContextMenu = iconMenu,
+ Icon = Properties.Resources.TrayIcon
+ };
+
+ iconMenu.MenuItems.Add(new System.Windows.Forms.MenuItem(VersionString) { Enabled = false });
+ iconMenu.MenuItems.Add(new System.Windows.Forms.MenuItem("Quit", (_, __) => Terminate()));
+ notifyIcon.Visible = true;
}
private static void StartOverlay()
{
- new ClockOverlay(clock, "Warframe.x64").Start();
+ overlayWindow = new OverlayWindow();
+ overlayWindow.Start();
+ }
+
+ private static void Terminate()
+ {
+ notifyIcon.Dispose();
+ overlayWindow.Close();
+ worldStateFetchTimer.Change(Timeout.Infinite, Timeout.Infinite);
+ Environment.Exit(0);
}
}
}