NW.js Windows Builder
=====================

This is the Windows counterpart to the drag-and-drop Mac builder.

WHAT IT DOES
- Drag/drop an HTML or NW.js project folder.
- Accepts either package.json or plain index.html.
- If package.json is missing, it creates one automatically.
- Lets you set App Name, Version, App/Bundle ID, Icon, and Output folder.
- Downloads the official NW.js Windows x64 runtime on the first build only.
- Builds a portable Windows app folder with a renamed .exe.
- Optionally creates a ZIP for moving the finished app to another PC.

FIRST TIME
1. Double-click BUILD_WINDOWS_EXE.bat
2. It creates "NW.js Windows Builder.exe"
3. The builder opens automatically.
4. Drag your HTML/NW.js project folder onto the top drop area.
5. Click BUILD WINDOWS APP.

NO PYTHON OR NODE.JS IS REQUIRED.

RUNTIME
The builder uses official NW.js v0.114.1 Windows x64.
The runtime is cached under:
%LOCALAPPDATA%\NWjsWindowsBuilder\Runtime

OUTPUT
For an app named "My App", you get:
My App\
  My App.exe
  package.nw\
  nw.dll
  locales\
  ...other NW.js runtime files...

Keep the whole folder together. The .exe uses the runtime files beside it.

ICON NOTE
The selected icon is used as the NW.js application/window icon through package.json.
Changing the Windows Explorer icon embedded inside the final EXE is a separate PE-resource step and is intentionally not done by this first version.

The NW.js runtime is downloaded from:
https://dl.nwjs.io/v0.114.1/nwjs-v0.114.1-win-x64.zip


VERSION 2 - WINDOW FITTING
--------------------------
New Window Settings:
- Auto size to HTML (default)
- Manual Width / Height override
- Resizable on/off
- Center on screen
- Always on top

Auto Size looks for common pixel width/height declarations in index.html and local CSS.
When detected, it adds a small allowance for the Windows frame/title bar to help prevent
scrollbars caused by the desktop window being a few pixels smaller than the HTML design.
If detection is not possible, the builder preserves an existing package.json size or
falls back to 900 x 700.

For unusual responsive HTML, turn Auto Size off and enter the exact Width/Height you want.


VERSION 3 - TRUE RUNTIME AUTO-FIT
---------------------------------
Auto Size no longer guesses dimensions from CSS.

Instead, the generated NW.js app:
1. Loads normally.
2. Measures the rendered HTML/document content.
3. Calls the NW.js native Window.resizeTo(width, height) API.
4. Rechecks a few times while fonts/layout settle.
5. Centers the window.
6. Optionally hides scrollbars after the size stabilizes.

This is much more reliable for real HTML applications containing many controls.

Recommended settings for compact desktop apps:
- Auto size to HTML: ON
- Hide scrollbars after fit: ON
- Center: ON
- Resizable: your preference

If an application intentionally contains a scrollable grid/panel inside the app, that
internal component will still scroll normally. The Hide Scrollbars option targets the
outer document window, not the app's own dedicated scrolling controls.


VERSION 4 - TIGHT SIDE FIT
--------------------------
Auto Fit now treats width differently from height.

The v3 vertical sizing was retained because it was working well.
Horizontal sizing now measures the application's actually occupied controls/content
instead of body/html scrollWidth. This prevents width:100% or responsive wrappers from
holding the NW.js window at the large temporary startup width.

Result: the left and right edges of the Windows app should sit much tighter against
the application's real content.

A 4-pixel safety allowance is retained to prevent edge clipping.


VERSION 5 - LOCK NARROWEST WIDTH
--------------------------------
Fixes a responsive-layout behavior seen in v4:

Some HTML apps briefly report the correct compact width, then a later reflow reports
a much larger width. Previous versions accepted that later measurement and widened
the native NW.js window again.

v5 remembers the narrowest valid width found during startup and never allows a later
auto-fit pass to widen the window. Vertical sizing remains dynamic.

This is specifically intended for compact desktop-style HTML apps.


VERSION 6 - FRAMELESS TEST OPTION
---------------------------------
New checkbox:
- Frameless + Close Button

When checked:
- NW.js window.frame is set to false.
- The normal Windows title bar/border is removed.
- A small fixed X close button is injected into the top-right corner.
- The X turns red on hover and closes the NW.js app.
- The close button is position:fixed, so it is ignored by the auto-size measurement.
- v5's locked tight-width behavior is otherwise unchanged.

This option is OFF by default so existing builds behave exactly as before.


NW.js WINDOWS BUILDER — FINAL
=============================
This Final build keeps the proven v5/v6 tight auto-sizing and frameless behavior
unchanged, and adds optional finishing/distribution features:

- Remembers last-used settings automatically.
- Create ZIP package.
- Create a Desktop shortcut.
- Embed the selected icon directly into the generated EXE.
- Build a normal Setup.exe with Inno Setup 6 when Inno Setup is installed.
- Optional Authenticode code signing from a selected PFX/P12 certificate when
  Windows SignTool is installed.
- Certificate passwords are NEVER stored in the settings file.
- NW.js runtime remains cached under LocalAppData for faster repeat builds.
- Frameless + Close Button remains optional.
- Auto Size / tight-width lock remains the same proven logic from v5/v6.

NOTES
-----
Installer:
The builder automatically detects Inno Setup 6. If Build Setup.exe is checked and
Inno Setup is missing, the builder still writes the .iss installer script and tells
you what is missing.

Code Signing:
Requires your own PFX/P12 code-signing certificate and Microsoft's SignTool
(typically installed with the Windows SDK). This is intentionally OFF by default.

EXE Icon:
Embed icon is ON by default. ICO is preferred. PNG/JPG is converted automatically
for the EXE resource and is also still used by NW.js for the app/window icon.

Settings:
Saved to LocalAppData\NWjsWindowsBuilder\settings.json.
The PFX password is deliberately not saved.

This package is the FINAL baseline. Keep a backup copy before making future changes.


FINAL v2 — SEPARATE FRAMELESS OPTIONS
=====================================
The Window Settings section now has TWO independent frameless choices:

1. Frameless
   - Removes the normal Windows title bar/frame.
   - Does NOT inject any close button.
   - Intended for apps that already contain their own close/minimize controls.

2. Frameless + Close Button
   - Removes the normal Windows title bar/frame.
   - Injects the small fixed X close button used in the previous test.

The two checkboxes are mutually exclusive so only one frameless mode can be active
at a time.

All FINAL features remain unchanged:
- proven tight auto-sizing
- remembered settings
- ZIP output
- Desktop shortcut
- EXE icon embedding
- optional Inno Setup installer
- optional code signing
- NW.js runtime cache


FINAL v3 — INSTALLER FIX
========================
Fixed the Build Setup.exe option.

The previous installer generator accidentally wrote the characters \r\n into the
Inno Setup script instead of real line breaks. FINAL v3 generates a proper .iss
file using StringBuilder.AppendLine(), then runs the Inno Setup compiler.

When Build Setup.exe is checked:
- The normal NW.js app is built first.
- A valid <AppName>_installer.iss file is created.
- If Inno Setup 6 is installed, <AppName>_Setup.exe is compiled automatically.
- If Inno Setup 6 is not installed, the app build still succeeds and the builder
  clearly tells you that Inno Setup 6 is the only missing piece.


FINAL v4 — INSTALLER COMPILER DIAGNOSTICS
=========================================
- Simplified the generated Inno Setup script to a standard per-user install.
- Installs to LocalAppData\Programs\AppName, so no administrator rights are required.
- Creates Start Menu and Desktop shortcuts.
- Uses OutputDir=. so Setup.exe is created next to the .iss script.
- Captures ISCC.exe stdout/stderr.
- If compilation fails, the builder now displays the actual Inno Setup compiler
  error and line number instead of only "exit code 2".


FINAL v5 — MAC PARITY / STABILITY UPDATE
========================================
This update ports the proven behavior from Mac Builder v4.6 while retaining all
Windows FINAL v4 distribution features.

- Tightens auto-centered left/right gutters.
- Removes bottom gutters from 100%-height wrappers.
- Excludes content hidden inside internal scrolling panels.
- Runs one startup fitting sequence, centers once, then stops completely.
- Button clicks and Angular/React updates cannot resize or move the app.
- Keeps the narrowest valid startup width and 4-pixel clipping allowance.
- Makes only the copied package.nw writable; the source project is unchanged.
- Preserves an existing inject_js_end script inside the project.
- Keeps framed, Frameless, Frameless + Close Button, remembered settings,
  runtime cache, ZIP, shortcut, EXE icon, Inno Setup, and signing features.
- Signing passwords are still never saved.

BUILD ON WINDOWS
1. Unzip this package.
2. Double-click BUILD_WINDOWS_EXE.bat.
3. It creates NW.js Windows Builder.exe and opens it.
4. Rebuild old apps; generated apps do not update automatically.


FINAL v5 ICON FIX
=================
- PNG, JPG, JPEG, and BMP artwork is converted to a true multi-resolution ICO
  containing 16, 24, 32, 48, 64, 128, and 256 pixel images.
- Transparent PNG backgrounds are preserved and non-square artwork is centered.
- Existing ICO files are validated before EXE resources are changed.
- Invalid or truncated icon files now show a useful error instead of crashing in
  Buffer.BlockCopy.

This Mac has no Windows/.NET compiler. The C# structure and embedded JavaScript
were checked here, including focused gutter, scrolling, and interaction-lock
tests. Compile and perform the final native test on Windows. No older EXE is
included, preventing accidental use of FINAL v4.
