uptime-kuma/extra/exe-builder/Program.cs

88 lines
2.7 KiB
C#
Raw Normal View History

2022-10-06 04:08:10 +00:00
using System;
using System.Collections.Generic;
2022-10-06 16:16:07 +00:00
using System.Diagnostics;
2022-10-06 04:08:10 +00:00
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;
using UptimeKuma.Properties;
namespace UptimeKuma {
static class Program {
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new UptimeKumaApplicationContext());
}
}
public class UptimeKumaApplicationContext : ApplicationContext
{
private NotifyIcon trayIcon;
2022-10-06 16:16:07 +00:00
private Process process;
2022-10-06 04:08:10 +00:00
public UptimeKumaApplicationContext()
{
// Initialize Tray Icon
trayIcon = new NotifyIcon();
trayIcon.Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
trayIcon.ContextMenu = new ContextMenu(new MenuItem[] {
2022-10-06 16:16:07 +00:00
new MenuItem("Open", Open),
2022-10-06 04:08:10 +00:00
new MenuItem("Check for Update", CheckForUpdate),
new MenuItem("About", About),
new MenuItem("Exit", Exit),
});
trayIcon.Visible = true;
2022-10-06 16:16:07 +00:00
var startInfo = new ProcessStartInfo();
startInfo.FileName = "node/node.exe";
startInfo.Arguments = "server/server.js";
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.WorkingDirectory = "core";
process = new Process();
process.StartInfo = startInfo;
process.EnableRaisingEvents = true;
try {
process.Start();
Open(null, null);
} catch (Exception e) {
MessageBox.Show("Startup failed: " + e.Message, "Uptime Kuma Error");
throw;
}
2022-10-06 04:08:10 +00:00
}
2022-10-06 16:16:07 +00:00
void Open(object sender, EventArgs e) {
Process.Start("http://localhost:3001");
}
void CheckForUpdate(object sender, EventArgs e) {
2022-10-06 04:08:10 +00:00
}
void About(object sender, EventArgs e)
{
MessageBox.Show("Uptime Kuma v1.0.0" + Environment.NewLine + "© 2022 Louis Lam", "Info");
}
2022-10-06 16:16:07 +00:00
void Exit(object sender, EventArgs e)
{
// Hide tray icon, otherwise it will remain shown until user mouses over it
trayIcon.Visible = false;
process.Close();
Application.Exit();
2022-10-06 04:08:10 +00:00
}
}
}