Skip to content

ScriptWidget for Windows (preview) - #76

Merged
everettjf merged 35 commits into
mainfrom
windows
Nov 17, 2026
Merged

everettjf merged 35 commits into
mainfrom
windows

Conversation

@everettjf

@everettjf everettjf commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Outcome

A preview of ScriptWidget for Windows 11: the same Package 2.0 widgets, drawn natively on the desktop.

  • Runtime (Windows/src/ScriptWidget.Core): a C# port of Android/core, file by file: QuickJS-NG engine wrapper, compiler, executor, timeline, packages and archives, $storage, fetch/$http, Data Source Plugins, $weather, and the renderer painted with Win2D. It runs the shared JavaScript from Web/preview-engine.
  • Desktop host (ScriptWidget.exe, native AOT): tray icon, one layered window per widget placed directly above the desktop window, scheduling, clicks on buttons, toggles and links, Show Desktop handling.
  • Management window (ScriptWidgetStudio.exe, WinUI 3): library, templates, component examples and an API reference generated from the editor's completion metadata (a template or example opens with its preview beside its read-only code; it is copied from there), code editor (the shared CodeMirror bundle in a locked-down WebView2) with a live preview drawn by the desktop renderer, settings; English and Simplified Chinese.
  • swcli validates, runs and draws a package from a folder. package.ps1 builds the MSIX in two forms (self-contained for local testing, framework-dependent for the Store). desktop-check.ps1 checks the desktop behavior without needing to look at the screen.

Documentation: docs/windows/README.md (what it does, differences from the other platforms, security), docs/windows/testing.md (what ran, on which machine), docs/windows/TODO.md (what is left), docs/windows/plan.md.

My widgets
Editor

Changes outside Windows/

  • .gitattributes: text is checked out with LF everywhere. A CRLF checkout broke the shared JavaScript build scripts and scriptwidget-preview on Windows.
  • Scripts/lib/shared-js.mjs: the shared-JavaScript build, now used by both Android/scripts/build-shared-js.mjs and Windows/scripts/build-shared-js.mjs. The regenerated Android assets are byte-identical except android-apis.js.
  • Android/core/src/main/js/android-apis.js (and its generated copy): the "not supported on Android" message takes the platform name from the host and still defaults to Android.
  • Scripts/validate-doc-links.mjs: the repository-boundary check no longer assumes / as the separator.
  • .github/workflows/android.yml: a hand-started job that runs the core and app instrumented suites on an emulator.
  • AGENTS.md, CHANGELOG.md, docs/platform-support.md, docs/README.md: Windows entries.

Security and compatibility

  • Package paths, archives, network and storage rules are ported from Android/core with their tests; Windows adds reserved device names, trailing dots and spaces, colons, UNC and drive forms, and reparse points.
  • Requests resolve the host themselves and connect to the address they checked; redirects are re-checked at every hop and do not carry Authorization or Cookie to another origin (the Android transport does; flagged for review there).
  • Package code runs inside the host process in this release, bounded in memory, stack and time, as on iPhone and Android. A restricted process is in the to-do.
  • QuickJS on Windows used today's UTC offset for every date; the Windows build asks ICU for the offset at the date in question. The vendored QuickJS source is unchanged.

What ran

  • dotnet test on Windows 11 x64 and in CI on x64 and ARM64: 238 tests pass, including the 127 parity packages (element tree byte-identical to the JavaScriptCore reference) and the renderer on every parity package at three sizes. The preview engine's own tests pass on Windows (199).
  • The native AOT swcli ran and drew all 140 bundled packages without a crash.
  • desktop-check.ps1 passes on the development PC (debug and native AOT builds) and in CI on Windows Server 2025 (x64) and Windows 11 (ARM64): what each widget window shows, the window order, drag with snapping, a button click running its declared action, the tray and right-click menu actions, display/clock/sleep/lock/theme events, and Show Desktop acted out with a stand-in desktop window.
  • Explorer was restarted for real on the development PC with the native AOT host running: the host kept running, added its tray icon again and kept the widget directly above the new desktop window.
  • The development PC was put to sleep for real (Modern Standby, 107 seconds, ended by a wake timer) with the host running: it redrew on resume and the widget stayed above the desktop window.
  • The management window was driven through UI Automation: new widget, add to desktop, save, use a template, settings.
  • The Store form of the package was registered in Developer Mode and started the way the Start menu starts it: package identity, private data folder, .swt file association, startup task.

On the unlocked desktop

After the first night the desktop was unlocked, so the host ran on the real desktop with nine widgets, the real Win+D key and real mouse input. Details are in docs/windows/testing.md.

Widgets on the desktop

  • Win+D failed twice and is fixed: the widgets disappeared while the desktop was shown (Windows raises the desktop window later than it makes it the foreground window), and after leaving they were left above ordinary windows. The self-test has cases for both; the first fails on the old code.
  • Copying a bundled network template without widget.json (Daily Quote and eight more) failed with "Network host is not declared"; the copy now declares the hosts the template names. The Android app installs bundled templates the same way and probably has the same failure; noted in docs/android/TODO.md, not reproduced.
  • Passed: the look against the wallpaper, staying behind ordinary windows, dragging, the right-click menu at the pointer, the hand pointer over a button, a button click running its action.

Not covered

  • Not tried: signing out and in with the app installed, a second display, a scale change, a full-screen program in front, the tray icon's own menu on screen, a link opening the browser.
  • ARM64 passes the tests and the desktop check on the CI ARM64 machine; nobody has run it on an ARM64 PC.
  • Android after the shared-JavaScript build refactor and the android-apis.js change: the JVM tests pass in CI and the core (30 of 30) and app (63 of 63) instrumented suites pass on a CI emulator (new hand-started job in android.yml). They were not re-run on a phone.
  • The Microsoft Store submission needs the owner's Partner Center identity; the packages are unsigned and use a placeholder identity.

🤖 Generated with Claude Code

everettjf and others added 30 commits November 17, 2026 00:30
The widgets are drawn natively with Win2D instead of a C++ Direct2D
painter or a WebView. The plan now ports Android/core file by file,
records what was measured on a Windows 11 machine, and lists the
phases, risks and fallbacks.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The shared JavaScript build scripts strip import lines with a "\n"
pattern and the parity trees are compared byte for byte. A Windows
checkout with core.autocrlf turned them into CRLF, so
scriptwidget-preview and build-shared-js.mjs failed there.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…parity

Windows/native builds swcore.dll from the QuickJS-NG sources the Android
app uses, with a C binding that mirrors scriptwidget_jni.c. QuickJS on
Windows used today's UTC offset for every date; the build now asks ICU
for the offset at the date in question.

ScriptWidget.Core ports the engine wrapper, shared script loading, the
package compiler, the script executor, the timeline planner, the XML
bridge, Intl over the system ICU, $storage and the runtime policy.

The shared JavaScript build moves into Scripts/lib/shared-js.mjs so the
Android and Windows scripts produce their assets from the same code. The
Android assets are byte-identical except android-apis.js, whose
"not supported on Android" message now takes the platform name from the
host and still defaults to Android.

All 127 corpus packages produce the same canonical tree as JavaScriptCore.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
ScriptWidget.App has the layered widget window (per-pixel transparency,
never activated, dragged with snapping to the work area), the layer that
keeps widgets at the bottom of the window order and raises them while
Windows shows the desktop, monitor enumeration, the tray icon and popup
menus, and a window self-test for checks on a real desktop.

ScriptWidget.Core gains the declared actions and controls with the
action planner (ported from Android), $device and $system for Windows,
the saved widget placements and settings, and the current-user pipe
between the host and the programs that drive it.

The workflow builds swcore for x64 and ARM64, runs the preview engine
tests on Windows and the .NET tests, and runs them again with
AddressSanitizer in swcore.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Ports core/pkg (archive preflight, hardened .swt import and export, the
package store, atomic file writes, tree verification, name and path
rules) from Kotlin to ScriptWidget.Core.Packages, one file per Kotlin
file, with the same limits, error codes and messages, and ports its
tests to xUnit.

Windows additions: path components and package names refuse reserved
device names, trailing dots and spaces, colons, < > " | ? *, control
characters, drive and UNC forms and overlong segments or paths; disk
access refuses every reparse point, opens files without following
links, counts hard links, and requires each path to be its own
Path.GetFullPath form below the root.

ZipArchive stops inflating at the declared size, so an entry that
under-declares its size fails its CRC (archive_corrupt) instead of
archive_size_mismatch; the three affected tests accept either code.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Adds ScriptWidget.Core.Render: Css, DomPainter, SvgPainter, TextEngine,
FontRegistry, GifFrames and WidgetRenderer, one file per Kotlin file.
Layout runs in the shared render.js on one large-stack worker thread with
the 8-second deadline; the recorded elements are painted with Win2D into
premultiplied BGRA bytes, with hit regions and date, GIF, motion and list
slots, bitmap budget scaling and a managed PNG encoder.

Text is measured and drawn through the same DirectWrite layout (natural
advances, no trimming, no pixel snapping). Inter and the display fonts are
linked from the Android assets into assets\fonts and loaded as
"<absolute path>#<family>"; Noto Sans SC is left out, so Chinese falls
back to the system font.

Where Direct2D has no counterpart: conic gradients are filled per pixel
into an image brush, perspective goes through a 3D transform effect using
the CSS rotate3d matrix, and drop shadows, box shadows and SVG masks are
recorded into command lists and composed with effects.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Ports FetchModule, the plugin layer (manifest validator, strict JSON,
store, request builder, $dataSource module) and WeatherModule from the
Android Kotlin sources to C#, with their unit tests and the network
cases of NativeApiTest that need no device.

The HTTP transport resolves each host itself, refuses private, loopback
and link-local addresses, and connects to the address it checked, so a
DNS answer that changes between the check and the connect cannot be
used. Redirects are followed by hand with the same rules on every hop.
No proxy, cookies or credentials are used. Bodies are counted while
they are read.

The plugin store carries its own archive preflight and link-refusing
file helpers so it does not depend on the package layer.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…kaging

ScriptWidget.Core: the runtime facade (compile, run, render with rounded
corners, remote images under the fetch policy), the package library with
the bundled templates that can run on Windows, startup registration, and
a JSON number accessor that reads values built in memory.

ScriptWidget.App: the host that owns the widget windows, runs packages
on a schedule and at timeline transitions, redraws running timers and
clocks, handles buttons, toggles and links (http, https and mailto only),
pauses while the session is locked or a full-screen program is in front,
and serves the management window over the current-user pipe.

ScriptWidget.Studio: the WinUI 3 management window with the library, the
templates, the code editor (the shared CodeMirror bundle in a locked-down
WebView2) with a live preview drawn by the desktop renderer, and settings.

swcli validates, runs and draws a package from a folder. package.ps1
builds the MSIX. A package whose manifest name Windows cannot store as a
directory ("Ratio 16:9") is installed under a safe directory name.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
supportedFamilies in widget.json uses the WidgetKit names (systemMedium);
they are mapped to the sizes Windows has. The host logs which kind of
action ran and why one was refused (never its content), and a click no
longer depends on mouse capture surviving. swcli render prints the hit
regions. The solution maps its x64 and ARM64 platforms to the projects,
so a solution build and a project build use the same output folder.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The editor bundle decides between an embedding app and the public Web
Studio site by a marker object; the Windows bridge now provides it, so
the editor opens the document instead of asking to pair with a phone.
ScriptWidgetStudio.exe --screenshot <png> [--page ...] saves pictures of
the window and of the code editor, used for the checks in testing.md.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…trim when idle

Win2D's line-metrics array cannot be marshalled under native AOT, so the
published host failed every layout. The text engine now lays lines out
in a fixed line box and finds line starts by hit-testing, which needs no
metrics array and gives the same lines and baseline.

Requests carry a default User-Agent (ScriptWidget-Windows/<version>) when
the script sets none: HttpClient sends nothing, and services such as the
GitHub API refuse that. The host frees the layout engine 20 seconds after
the last render when nothing is due for two minutes. The package script
keeps the management window's resources.pri and publishes the Windows App
SDK files once.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Adds docs/windows/README.md (what the app does, how it runs a widget,
differences from the other platforms, security notes, build commands),
testing.md with everything that ran on 2026-11-17 and everything that
could not (the development PC was locked all session), and TODO.md.
platform-support.md gains a Windows column and AGENTS.md the Windows
folders and commands.

Installed as a package, the data now lives in the package's own local
folder: Windows redirects %LOCALAPPDATA% for packaged programs and that
redirection cannot move a directory, which a transactional package
install does. Show-desktop detection only treats a raised WorkerW that
is the foreground window as "desktop shown", so a click on the
wallpaper can never raise widgets over ordinary windows. CI runs the
engine binding tests, not the whole suite, under AddressSanitizer. The
documentation link check no longer assumes "/" as the path separator.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Reading the window order showed the widget windows underneath Progman:
on Windows 11 build 26200 HWND_BOTTOM puts a window below the desktop
window, where it is neither seen nor clicked. Widgets and the probe are
now inserted after the window just above the desktop. With two widgets
placed they sit directly above Progman and below every other visible
window, and a window opened later goes above them.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…view

A redirect to another origin no longer receives the Authorization,
Proxy-Authorization or Cookie header the script set. The changelog and
the Windows README describe the preview and this difference from the
Android transport.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Windows/scripts/desktop-check.ps1 starts the host with a scratch data
folder and checks what can be checked on a locked or unattended desktop:
what each widget window shows (captured from the window), the window
order, a drag with snapping, a button click running its declared action,
and the display, clock, sleep, lock and theme events. 22 checks pass with
the debug build and with the native AOT build.

Found on the way:
- The Store form of the package showed "could not be started": the
  bootstrapper for unpackaged programs ran inside the package. It is off
  for that form, and the two forms build into separate folders.
- A new widget landed exactly on top of one at the default place.
- Pointer positions come from the messages instead of the cursor.
- Icon-only buttons, switches and inputs of the management window had
  no accessible names.

The Store form was registered and started the way the Start menu starts
it: package identity, private data folder, .swt file association and the
startup task all work. The test notes say which checks used posted
messages or UI Automation and which were never run.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Since Windows 11 24H2 the desktop icons live in Progman, and showing the
desktop raises Progman itself and makes it the foreground window; before,
a WorkerW takes over the icons (documented in Rainmeter's System.cpp).
The layer only recognized the WorkerW form, so on this PC the widgets
would have been covered by Win+D. It now watches whichever window hosts
the icons, and still needs both conditions (foreground and raised above
the probe), so a click on the wallpaper is not mistaken for it.

ScriptWidget.exe --selftest-showdesktop acts the sequence out with a
stand-in for the desktop window and checks that the widget is raised and
then returns to its place: 14 checks, part of desktop-check.ps1, which
now also waits for a new widget to be shown before looking at it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The Windows workflow now runs desktop-check.ps1 on the build agent's
desktop and uploads the pictures of the widget windows. The check
reports whether Windows accepted the tray icon (skipped where there is
no taskbar). SCRIPTWIDGET_LANGUAGE chooses English or Chinese for one
run, which is how the Chinese interface was captured and checked.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
desktop-check.ps1 now runs every action of the tray menu and of a
widget's right-click menu through debugging requests the host accepts
only with SCRIPTWIDGET_VERBOSE=1: size, lock positions (a drag is
refused), add, refresh all, remove, and quit, which must end the host
with exit code 0. swcli gains a host command that sends one request.

The ARM64 job on windows-11-arm built natively, passed all 235 tests
and the desktop check; the notes and the to-do say so, and that no
person has run it on an ARM64 PC.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…an emulator

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…refactor

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ed them

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
everettjf and others added 5 commits November 17, 2026 08:40
…mplates

Found on the unlocked desktop with the real Win+D key and mouse:
- Windows raises the desktop window later than it makes it the foreground window, so the widgets were covered while the desktop was shown. The window order is now looked at for as long as the desktop is in front.
- When the desktop is left the desktop window is still raised for a moment, so the widgets were left above ordinary windows. The placing is repeated until it has settled.
- A bundled template without widget.json got a manifest with no network permission when copied into the library. The copy now declares the hosts the template names.
The show-desktop self-test covers both timing cases; the late raise fails on the old code.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
A card on the templates page now opens the template: its preview, its read-only code and the hosts its copy will declare. "Use this template" is on that page only. The component and API examples move from tabs of the templates page to an Examples entry in the sidebar; an example opens the same way and offers "Open a copy in the editor" and "Copy code". An example that draws nothing shows what it printed instead of "#UI Not Found#".

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The Examples entry with its two tabs becomes two sidebar entries. Components stays a grid of previews. APIs is a list to look a name up in: each row shows the API and the line of its example that uses it, and the search also matches that line.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
APIs lists the globals a widget's code can use on the left and the functions of the chosen one on the right, with arguments, return type and a sentence each. The data is generated by build-shared-js.mjs from the metadata the code editor completes from. A global with a bundled example offers "View example"; one Windows does not implement is listed last and says so. The search looks through every function.

Components shows small tiles instead of cards the size of a widget, and a component's page shows its properties before its example's code.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The package held one plain image per logo, so the taskbar drew the icon on its plate in the user's accent color, visible around the rounded corners. The images are now content of the management window's project and are indexed in its resources.pri with their scale, target-size and unplated qualifiers.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@everettjf
everettjf merged commit 24ab958 into main Nov 17, 2026
8 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant