Add direct native-window launch and publish 0.5 beta
Forward a direct LuminaryWindow launch through the bundle launcher so it starts desktop mode instead of showing a signed-out page. Refresh the guide screenshots and version the release as 0.5.0 Beta.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<!--
|
||||
Optional native window for the Windows bundle. The launcher starts it with
|
||||
a url switch pointing at the local server.
|
||||
|
||||
It is a window host only: node.exe stays a child of the launcher, so Stop
|
||||
works the same whether the UI runs here or in an Edge app window. Starting
|
||||
it without a url argument (for example, double-clicking it) forwards to the
|
||||
bundle launcher instead of showing a signed-out page.
|
||||
|
||||
Published self-contained: the customer needs no .NET install. The only
|
||||
runtime requirement is Microsoft Edge WebView2, which ships with Windows
|
||||
10/11 alongside Edge. EnableWindowsTargeting lets this be compiled on a
|
||||
Linux build host; it still only runs on Windows.
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AssemblyName>LuminaryWindow</AssemblyName>
|
||||
<RootNamespace>Luminary</RootNamespace>
|
||||
<ApplicationIcon>../Luminary.ico</ApplicationIcon>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<SelfContained>true</SelfContained>
|
||||
<PublishSingleFile>true</PublishSingleFile>
|
||||
<!-- ~140 MB raw becomes roughly half that in the single file. -->
|
||||
<EnableCompressionInSingleFile>true</EnableCompressionInSingleFile>
|
||||
<AllowedReferenceRelatedFileExtensions>none</AllowedReferenceRelatedFileExtensions>
|
||||
<!-- WebView2Loader.dll is native; single-file must extract it at startup. -->
|
||||
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
|
||||
<EnableWindowsTargeting>true</EnableWindowsTargeting>
|
||||
<Version>0.5.0</Version>
|
||||
<AssemblyTitle>Luminary</AssemblyTitle>
|
||||
<Product>Luminary</Product>
|
||||
<Company>Maple Street</Company>
|
||||
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
||||
<DebugType>none</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.4370.26" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
using Microsoft.Web.WebView2.WinForms;
|
||||
|
||||
namespace Luminary;
|
||||
|
||||
/// <summary>
|
||||
/// The whole app window: WebView2 filling the client area, the Luminary icon in
|
||||
/// the title bar and taskbar, and an explicit message when the WebView2 runtime
|
||||
/// is missing instead of a silent exit.
|
||||
/// </summary>
|
||||
internal sealed class MainForm : Form
|
||||
{
|
||||
private const string RuntimeDownload = "https://go.microsoft.com/fwlink/p/?LinkId=2124703";
|
||||
|
||||
private readonly string _url;
|
||||
private readonly WebView2 _web = new() { Dock = DockStyle.Fill };
|
||||
|
||||
public MainForm(string url)
|
||||
{
|
||||
_url = url;
|
||||
Text = "Luminary";
|
||||
Width = 1500;
|
||||
Height = 950;
|
||||
MinimumSize = new Size(900, 600);
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Icon = LoadIcon();
|
||||
|
||||
Controls.Add(_web);
|
||||
Load += async (_, _) => await InitializeAsync();
|
||||
}
|
||||
|
||||
/// <summary>The exe carries the icon; extracting it avoids shipping a second file.</summary>
|
||||
private static Icon? LoadIcon()
|
||||
{
|
||||
try
|
||||
{
|
||||
var exe = Environment.ProcessPath;
|
||||
if (!string.IsNullOrEmpty(exe))
|
||||
{
|
||||
var icon = Icon.ExtractAssociatedIcon(exe);
|
||||
if (icon != null) return icon;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// A missing icon must never stop the window from opening.
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private async Task InitializeAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Its own profile, next to the catalog, so the app never shares
|
||||
// cookies or storage with the user's normal browsing. LUMINARY_DATA
|
||||
// wins, the same precedence the server and launcher use.
|
||||
var dataRoot = Environment.GetEnvironmentVariable("LUMINARY_DATA");
|
||||
if (string.IsNullOrWhiteSpace(dataRoot))
|
||||
{
|
||||
dataRoot = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
|
||||
"Luminary", "data");
|
||||
}
|
||||
var dataDir = Path.Combine(dataRoot, "webview2");
|
||||
Directory.CreateDirectory(dataDir);
|
||||
|
||||
var environment = await CoreWebView2Environment.CreateAsync(null, dataDir);
|
||||
await _web.EnsureCoreWebView2Async(environment);
|
||||
|
||||
var settings = _web.CoreWebView2.Settings;
|
||||
settings.AreDevToolsEnabled = false;
|
||||
settings.IsStatusBarEnabled = false;
|
||||
settings.AreDefaultContextMenusEnabled = true;
|
||||
|
||||
_web.CoreWebView2.Navigate(_url);
|
||||
}
|
||||
catch (WebView2RuntimeNotFoundException)
|
||||
{
|
||||
Fail(
|
||||
"The Microsoft Edge WebView2 runtime is missing.\n\n" +
|
||||
"Install it from " + RuntimeDownload + " and start Luminary again.",
|
||||
close: true);
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
Fail("Luminary could not open its window.\n\n" + error.Message, close: true);
|
||||
}
|
||||
}
|
||||
|
||||
private void Fail(string message, bool close)
|
||||
{
|
||||
MessageBox.Show(this, message, "Luminary", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
if (close) Close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
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.exe (or Luminary.cmd) 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;
|
||||
foreach (var name in new[] { "Luminary.exe", "Luminary.vbs", "Luminary.cmd" })
|
||||
{
|
||||
var launcher = Path.Combine(root, name);
|
||||
if (!File.Exists(launcher)) continue;
|
||||
|
||||
try
|
||||
{
|
||||
Process.Start(new ProcessStartInfo(launcher)
|
||||
{
|
||||
WorkingDirectory = root,
|
||||
UseShellExecute = true,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Try the next entry point before giving up.
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user