[exe] Show server status

pull/2752/head
Louis Lam 2 years ago
parent a80f228136
commit b91c526d2e

@ -5,6 +5,7 @@ using System.Drawing;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Sockets;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -33,19 +34,26 @@ namespace UptimeKuma {
private NotifyIcon trayIcon; private NotifyIcon trayIcon;
private Process process; private Process process;
private MenuItem statusMenuItem;
private MenuItem runWhenStarts; private MenuItem runWhenStarts;
private RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); private RegistryKey registryKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
public UptimeKumaApplicationContext()
{ public UptimeKumaApplicationContext() {
var startingText = "Starting server...";
trayIcon = new NotifyIcon(); trayIcon = new NotifyIcon();
trayIcon.Text = startingText;
runWhenStarts = new MenuItem("Run when system starts", RunWhenStarts); runWhenStarts = new MenuItem("Run when system starts", RunWhenStarts);
runWhenStarts.Checked = registryKey.GetValue(appName) != null; runWhenStarts.Checked = registryKey.GetValue(appName) != null;
statusMenuItem = new MenuItem(startingText);
statusMenuItem.Enabled = false;
trayIcon.Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location); trayIcon.Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
trayIcon.ContextMenu = new ContextMenu(new MenuItem[] { trayIcon.ContextMenu = new ContextMenu(new MenuItem[] {
statusMenuItem,
new("Open", Open), new("Open", Open),
//new("Debug Console", DebugConsole), //new("Debug Console", DebugConsole),
runWhenStarts, runWhenStarts,
@ -109,6 +117,22 @@ namespace UptimeKuma {
process.Start(); process.Start();
//Open(null, null); //Open(null, null);
// Async task to check if the server is ready
Task.Run(() => {
var runningText = "Server is running";
using TcpClient tcpClient = new TcpClient();
while (true) {
try {
tcpClient.Connect("127.0.0.1", 3001);
statusMenuItem.Text = runningText;
trayIcon.Text = runningText;
break;
} catch (Exception) {
System.Threading.Thread.Sleep(2000);
}
}
});
} catch (Exception e) { } catch (Exception e) {
MessageBox.Show("Startup failed: " + e.Message, "Uptime Kuma Error"); MessageBox.Show("Startup failed: " + e.Message, "Uptime Kuma Error");
} }

@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Uptime Kuma")] [assembly: AssemblyProduct("Uptime Kuma")]
[assembly: AssemblyCopyright("Copyright © 2022 Louis Lam")] [assembly: AssemblyCopyright("Copyright © 2023 Louis Lam")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]

Loading…
Cancel
Save