You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
uptime-kuma/extra/exe-builder/Program.cs

136 lines
4.1 KiB

using System;
using System.Collections.Generic;
2 years ago
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
2 years ago
using System.Runtime.InteropServices;
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]
2 years ago
static void Main(string[] args) {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new UptimeKumaApplicationContext());
}
}
public class UptimeKumaApplicationContext : ApplicationContext
{
private NotifyIcon trayIcon;
2 years ago
private Process process;
public UptimeKumaApplicationContext()
{
trayIcon = new NotifyIcon();
trayIcon.Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
trayIcon.ContextMenu = new ContextMenu(new MenuItem[] {
2 years ago
new("Open", Open),
//new("Debug Console", DebugConsole),
new("Check for Update...", CheckForUpdate),
new("Visit GitHub...", VisitGitHub),
new("About", About),
new("Exit", Exit),
});
2 years ago
trayIcon.MouseDoubleClick += new MouseEventHandler(Open);
trayIcon.Visible = true;
2 years ago
if (Directory.Exists("core") && Directory.Exists("node") && Directory.Exists("core/node_modules") && Directory.Exists("core/dist")) {
// Go go go
StartProcess();
} else {
DownloadFiles();
}
}
void DownloadFiles() {
var form = new DownloadForm();
form.Closed += Exit;
form.Show();
}
void StartProcess() {
2 years ago
var startInfo = new ProcessStartInfo {
FileName = "node/node.exe",
Arguments = "server/server.js --data-dir=\"../data/\"",
RedirectStandardOutput = false,
RedirectStandardError = false,
UseShellExecute = false,
CreateNoWindow = true,
WorkingDirectory = "core"
};
2 years ago
process = new Process();
process.StartInfo = startInfo;
process.EnableRaisingEvents = true;
process.Exited += ProcessExited;
2 years ago
2 years ago
try {
process.Start();
2 years ago
//Open(null, null);
2 years ago
} catch (Exception e) {
MessageBox.Show("Startup failed: " + e.Message, "Uptime Kuma Error");
}
}
2 years ago
void Open(object sender, EventArgs e) {
Process.Start("http://localhost:3001");
}
2 years ago
void DebugConsole(object sender, EventArgs e) {
}
2 years ago
void CheckForUpdate(object sender, EventArgs e) {
2 years ago
Process.Start("https://github.com/louislam/uptime-kuma/releases");
}
2 years ago
2 years ago
void VisitGitHub(object sender, EventArgs e)
{
Process.Start("https://github.com/louislam/uptime-kuma");
}
void About(object sender, EventArgs e)
{
MessageBox.Show("Uptime Kuma v1.0.0" + Environment.NewLine + "© 2022 Louis Lam", "Info");
}
2 years ago
void Exit(object sender, EventArgs e)
{
// Hide tray icon, otherwise it will remain shown until user mouses over it
trayIcon.Visible = false;
process?.Kill();
Application.Exit();
2 years ago
}
void ProcessExited(object sender, EventArgs e) {
if (process.ExitCode != 0) {
var line = "";
while (!process.StandardOutput.EndOfStream)
{
line += process.StandardOutput.ReadLine();
}
MessageBox.Show("Uptime Kuma exited unexpectedly. Exit code: " + process.ExitCode + " " + line);
}
trayIcon.Visible = false;
2 years ago
Application.Exit();
}
2 years ago
}
}