726a5b922b
The window now starts Luminary.ps1 through a hidden PowerShell process instead of relying on the VBS entry point, and the installer defaults to Luminary.cmd. Bump the beta to 0.5.1.
132 lines
4.5 KiB
C#
132 lines
4.5 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Luminary;
|
|
|
|
internal static class Program
|
|
{
|
|
[STAThread]
|
|
private static void Main(string[] args)
|
|
{
|
|
var url = "http://127.0.0.1:8787";
|
|
var urlProvided = false;
|
|
for (var i = 0; i < args.Length; i++)
|
|
{
|
|
var arg = args[i];
|
|
if (arg is "--url" or "-url")
|
|
{
|
|
if (i + 1 < args.Length) url = args[i + 1];
|
|
urlProvided = true;
|
|
break;
|
|
}
|
|
if (arg.StartsWith("--url=", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
url = arg[6..];
|
|
urlProvided = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// This exe is the window the launcher opens. If someone double-clicks it
|
|
// directly there is no server in desktop mode, or port 8787 may belong
|
|
// to a full sign-in server. Start the real launcher and let it choose the
|
|
// port, set LUMINARY_LOCAL=1 and open this window with --url.
|
|
if (!urlProvided)
|
|
{
|
|
if (StartBundleLauncher()) return;
|
|
|
|
MessageBox.Show(
|
|
"LuminaryWindow.exe is only the app window.\n\n" +
|
|
"Start Luminary.cmd (or Luminary.vbs) from the Luminary folder instead.",
|
|
"Luminary",
|
|
MessageBoxButtons.OK,
|
|
MessageBoxIcon.Information);
|
|
return;
|
|
}
|
|
|
|
Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
|
|
Application.EnableVisualStyles();
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
|
Application.Run(new MainForm(url));
|
|
}
|
|
|
|
/// <summary>
|
|
/// A direct window launch forwards to the bundle launcher. That launcher
|
|
/// starts the local server with the correct desktop-mode environment and
|
|
/// then reopens this window with --url. Returns false when this file is not
|
|
/// inside a complete bundle.
|
|
/// </summary>
|
|
private static bool StartBundleLauncher()
|
|
{
|
|
// Environment.ProcessPath is the exe itself even in a single-file publish;
|
|
// AppContext.BaseDirectory is only a fallback.
|
|
var root = Path.GetDirectoryName(Environment.ProcessPath) ?? AppContext.BaseDirectory;
|
|
|
|
// A Go build has one native launcher; use it when present.
|
|
var native = Path.Combine(root, "Luminary.exe");
|
|
if (File.Exists(native) && TryStart(native, root)) return true;
|
|
|
|
// Do not go through Luminary.vbs here. Windows Script Host can be
|
|
// disabled by policy, which makes the window fail even though the
|
|
// bundle is healthy. Run the PowerShell launcher hidden instead; it is
|
|
// the same code Luminary.cmd uses and needs no console or .vbs handler.
|
|
var script = Path.Combine(root, "Luminary.ps1");
|
|
if (File.Exists(script))
|
|
{
|
|
var powershell = Path.Combine(
|
|
Environment.SystemDirectory, "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
if (!File.Exists(powershell)) powershell = "powershell.exe";
|
|
|
|
try
|
|
{
|
|
var start = new ProcessStartInfo(powershell)
|
|
{
|
|
WorkingDirectory = root,
|
|
UseShellExecute = false,
|
|
CreateNoWindow = true,
|
|
WindowStyle = ProcessWindowStyle.Hidden,
|
|
};
|
|
start.ArgumentList.Add("-NoProfile");
|
|
start.ArgumentList.Add("-ExecutionPolicy");
|
|
start.ArgumentList.Add("Bypass");
|
|
start.ArgumentList.Add("-WindowStyle");
|
|
start.ArgumentList.Add("Hidden");
|
|
start.ArgumentList.Add("-File");
|
|
start.ArgumentList.Add(script);
|
|
Process.Start(start);
|
|
return true;
|
|
}
|
|
catch
|
|
{
|
|
// Fall through to the command entry point.
|
|
}
|
|
}
|
|
|
|
foreach (var name in new[] { "Luminary.cmd", "Luminary.vbs" })
|
|
{
|
|
var launcher = Path.Combine(root, name);
|
|
if (File.Exists(launcher) && TryStart(launcher, root)) return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private static bool TryStart(string launcher, string workingDirectory)
|
|
{
|
|
try
|
|
{
|
|
Process.Start(new ProcessStartInfo(launcher)
|
|
{
|
|
WorkingDirectory = workingDirectory,
|
|
UseShellExecute = true,
|
|
});
|
|
return true;
|
|
}
|
|
catch
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|