Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/desktop-builds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Desktop builds

# EaglePlot desktop app (roadmap D5): Electron + @stlite/desktop, Pyodide and every package
# bundled, fully offline. Builds the installers on each OS; on Linux it also launches the
# built app and runs scripts/desktop/smoke.js. Installers are uploaded as artifacts, and
# attached to the GitHub Release when one is published. Builds are unsigned (see
# packaging/desktop/README.md for what users see on first launch).
on:
release:
types: [published]
pull_request:
paths:
- "packaging/desktop/**"
- "scripts/desktop/**"
- "eagleplot/utils/runtime.py"
- ".github/workflows/desktop-builds.yml"
workflow_dispatch:

permissions:
contents: read

concurrency:
group: desktop-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
build:
name: Desktop app (${{ matrix.os }})
runs-on: ${{ matrix.os }}
timeout-minutes: 45
permissions:
contents: write # attach the installers to a published release
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04
builder_args: "--linux AppImage"
- os: windows-2025
builder_args: "--win nsis"
- os: macos-15
builder_args: "--mac dmg --x64 --arm64"

steps:
- uses: actions/checkout@v7

- uses: actions/setup-python@v7
with:
python-version: "3.12"

- uses: actions/setup-node@v7
with:
node-version: "22"
cache: npm
cache-dependency-path: packaging/desktop/package-lock.json

- name: Build the app
shell: bash
env:
# No signing certificates: don't let electron-builder look for one.
CSC_IDENTITY_AUTO_DISCOVERY: "false"
run: python packaging/desktop/build_desktop.py -- ${{ matrix.builder_args }} --publish never

- name: Installer size
shell: bash
run: ls -la packaging/desktop/dist/ | grep -E 'EaglePlot-.*\.(exe|dmg|AppImage)$'

# Launch the built app and check it works offline, keeps settings and opens links in
# the system browser. Ubuntu 24.04 blocks the unprivileged user namespaces Electron's
# sandbox needs unless this AppArmor restriction is lifted.
- name: Smoke-test the app (Linux)
if: runner.os == 'Linux'
run: |
sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
sudo apt-get update -qq && sudo apt-get install -y -qq xvfb
npm install --no-save --prefix build/desktop-smoke-tools playwright@1
NODE_PATH=build/desktop-smoke-tools/node_modules xvfb-run -a \
node scripts/desktop/smoke.js packaging/desktop/dist/linux-unpacked/eagleplot --out build/desktop-smoke

- uses: actions/upload-artifact@v7
if: always()
with:
name: eagleplot-desktop-${{ runner.os }}
path: |
packaging/desktop/dist/EaglePlot-*
build/desktop-smoke/
if-no-files-found: warn

- name: Attach to the release
if: github.event_name == 'release'
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
shopt -s nullglob
files=(packaging/desktop/dist/EaglePlot-*.exe packaging/desktop/dist/EaglePlot-*.dmg packaging/desktop/dist/EaglePlot-*.AppImage)
gh release upload "${{ github.event.release.tag_name }}" "${files[@]}" --clobber
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,10 @@ tests/*.json

# Generated documentation site (build_docs.py)
docs/_site/

# Desktop app build (packaging/desktop/build_desktop.py): staged app copy, npm and outputs
packaging/desktop/eagleplot/
packaging/desktop/.streamlit/
packaging/desktop/node_modules/
packaging/desktop/build/
packaging/desktop/dist/
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## [Unreleased]

### Added

- **A desktop app for Windows, macOS and Linux** (`packaging/desktop/`): the same app
in its own window, with Python and every package included, so it needs no Python
install and no network. Installers are built for every release and need no admin
rights. Settings are kept between sessions. Links open in your web browser. They are
not code-signed yet: the first launch shows a warning (see `packaging/desktop/README.md`).
Loading whole folders is not available in the desktop app yet.

### Changed

- **The EaglePlot logo is now in NCCU maroon and gray** (it was blue): the same disc, bars
Expand Down
4 changes: 3 additions & 1 deletion eagleplot/utils/figures.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ def lazy_download_supported(version: Optional[str] = None) -> bool:
return (major, minor) >= (1, 52)


LAZY_DOWNLOAD = lazy_download_supported()
#: Downloads are built on click: Streamlit supports it, and so does this runtime (not the
#: desktop build; see ``Capabilities.on_click_downloads``).
LAZY_DOWNLOAD = lazy_download_supported() and capabilities().on_click_downloads


def figure_bytes(fig: Any, fmt: str, dpi: Optional[int] = None) -> bytes:
Expand Down
45 changes: 40 additions & 5 deletions eagleplot/utils/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,31 @@
#: to a folder it mounts on browser storage (IndexedDB), so settings survive a reload.
CONFIG_DIR_ENV = "EAGLEPLOT_CONFIG_DIR"

#: Where the desktop build (packaging/desktop) mounts the user's app-data folder
#: (Electron's ``userData``): ``config.json`` goes there and survives restarts.
DESKTOP_CONFIG_DIR = "/home/pyodide/.eagleplot"


def _running_in_electron() -> bool:
"""Under Pyodide in the desktop build: Python runs in a Node.js worker inside Electron.

@stlite/desktop can't pass environment variables to Python, so the desktop build is
recognised from Node's ``process.versions.electron``.
"""
if sys.platform != "emscripten":
return False
try:
import js # type: ignore[import-not-found] # only exists under Pyodide

return bool(getattr(js.process.versions, "electron", None))
except Exception: # noqa: BLE001 - a browser has no ``process``
return False


#: Running under Pyodide (stlite, in a browser or in Electron).
IS_PYODIDE = sys.platform == "emscripten"
#: Running in the Electron desktop build (always Pyodide as well).
IS_DESKTOP = IS_PYODIDE and os.environ.get(DESKTOP_ENV) == "1"
IS_DESKTOP = IS_PYODIDE and (os.environ.get(DESKTOP_ENV) == "1" or _running_in_electron())


@dataclass(frozen=True)
Expand All @@ -53,6 +74,11 @@ class Capabilities:
#: The user can add a missing optional package with ``pip install``. Not in the
#: browser or desktop builds, whose packages are fixed when the site is built.
pip_install: bool = True
#: ``st.download_button(data=callable)`` works (the file is built on click). Under
#: stlite these requests go to the placeholder origin https://stlite.invalid; the
#: browser build routes them to Python (packaging/web/index.html), but the desktop
#: build uses stlite's own page, where they fail, so files are prepared in advance.
on_click_downloads: bool = True


def _browser_storage_is_persistent(environ: Mapping[str, str]) -> bool:
Expand All @@ -78,12 +104,17 @@ def compute_capabilities(platform: str, environ: Mapping[str, str]) -> Capabilit
)
if desktop:
return Capabilities(
local_folders=True,
outbound_http=True,
# Folder import needs the user's typed paths (C:\Users\…) mapped onto the
# folders the desktop build mounts: roadmap D5.2. Off until then.
local_folders=False,
# Python runs in a Node.js worker, where Pyodide's requests support (built on
# the browser's XMLHttpRequest) doesn't work; NIST links out instead.
outbound_http=False,
persistent_storage=True,
native_speed=False,
app_config_file=False,
pip_install=False,
on_click_downloads=False,
)
return Capabilities( # browser
local_folders=False,
Expand All @@ -98,7 +129,10 @@ def compute_capabilities(platform: str, environ: Mapping[str, str]) -> Capabilit
@lru_cache(maxsize=1)
def capabilities() -> Capabilities:
"""The capabilities of this process (computed once)."""
return compute_capabilities(sys.platform, os.environ)
environ: Mapping[str, str] = os.environ
if IS_DESKTOP:
environ = {**os.environ, DESKTOP_ENV: "1"}
return compute_capabilities(sys.platform, environ)


_PIP_HINT = re.compile(
Expand Down Expand Up @@ -155,7 +189,8 @@ def start_deferred_loads(packages: tuple = DEFERRED_PACKAGES) -> bool:
server every package is installed already.
"""
global _deferred_load_started
if not IS_PYODIDE or _deferred_load_started:
# The desktop build bundles every package (nothing to fetch, and no network needed).
if not IS_PYODIDE or IS_DESKTOP or _deferred_load_started:
return False
import pyodide_js # type: ignore[import-not-found] # only exists under Pyodide
from pyodide.ffi import create_once_callable # type: ignore[import-not-found]
Expand Down
16 changes: 9 additions & 7 deletions eagleplot/utils/user_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,20 @@
from pathlib import Path
from typing import Dict, List

from eagleplot.utils.runtime import CONFIG_DIR_ENV
from eagleplot.utils.runtime import CONFIG_DIR_ENV, DESKTOP_CONFIG_DIR, IS_DESKTOP

# ── Location ──────────────────────────────────────────────────────────────
# Stored in the repository root (two directories up from this file), unless
# EAGLEPLOT_CONFIG_DIR names another folder. The browser build sets it to a folder kept
# in browser storage, so settings survive a reload (roadmap D2.2).
# in browser storage, so settings survive a reload (roadmap D2.2). The desktop build
# mounts the user's app-data folder at DESKTOP_CONFIG_DIR (roadmap D5).
_APP_ROOT = Path(__file__).parent.parent.parent
_CONFIG_PATH = (
Path(os.environ[CONFIG_DIR_ENV]) / "config.json"
if os.environ.get(CONFIG_DIR_ENV)
else _APP_ROOT / "config.json"
)
if os.environ.get(CONFIG_DIR_ENV):
_CONFIG_PATH = Path(os.environ[CONFIG_DIR_ENV]) / "config.json"
elif IS_DESKTOP:
_CONFIG_PATH = Path(DESKTOP_CONFIG_DIR) / "config.json"
else:
_CONFIG_PATH = _APP_ROOT / "config.json"

_EMPTY: Dict = {
"version": "1.0",
Expand Down
90 changes: 90 additions & 0 deletions packaging/desktop/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# EaglePlot desktop app

The Streamlit GUI as a desktop program for Windows, macOS and Linux (roadmap D5). It is
the same app as the [browser version](../web/README.md), packaged with
[`@stlite/desktop`](https://github.com/whitphx/stlite/tree/main/packages/desktop) into
Electron: Python (Pyodide) and every package are bundled, so it needs **no Python install
and no network**.

## Build

Needs Node.js 22 and Python.

```bash
python packaging/desktop/build_desktop.py # installer for this OS, in packaging/desktop/dist/
python packaging/desktop/build_desktop.py --dir # unpacked app only (faster, for testing)
python packaging/desktop/build_desktop.py -- --mac dmg --x64 --arm64 # extra electron-builder arguments
```

`build_desktop.py` copies `eagleplot/` and `.streamlit/config.toml` into this folder, runs
`npm ci`, dumps the Pyodide runtime and packages into `build/` (`--pyodide-source DIR`
uses a local Pyodide distribution instead of jsDelivr), lets https links open in the
system browser, and runs electron-builder. The version is EaglePlot's own.

[`.github/workflows/desktop-builds.yml`](../../.github/workflows/desktop-builds.yml) builds
all three on every published release and attaches them to it, and can be started by hand
(Actions → Desktop builds → Run workflow). On Linux it also launches the app and runs
[`scripts/desktop/smoke.js`](../../scripts/desktop/smoke.js).

| OS | File | Admin rights |
| --- | --- | --- |
| Windows | `EaglePlot-<version>-win-x64.exe` (per-user install) | No |
| macOS | `EaglePlot-<version>-mac-arm64.dmg` (Apple Silicon), `-mac-x64.dmg` (Intel) | No |
| Linux | `EaglePlot-<version>-linux-x86_64.AppImage` (make it executable, run it) | No |

## Pins

| Package | Version |
| --- | --- |
| `@stlite/desktop` | 0.105.1 (Streamlit 1.65, Pyodide 314.0.3: the same as the browser build) |
| Electron | 45.0.0 |
| electron-builder | 26.18.0 |

## What the desktop app does differently

The app recognises the desktop build from Electron (`eagleplot.utils.runtime`), because
@stlite/desktop can't pass environment variables to Python.

- **Settings persist:** `config.json` (defaults, presets, workflows) is in the user's app
data folder (Electron's `userData`, e.g. `%APPDATA%\EaglePlot` on Windows), mounted into
the app at `/home/pyodide/.eagleplot`.
- **Links** (Help, NIST, GitHub) open in the system browser. @stlite/desktop blocks all
navigation; `build_desktop.py` patches its Electron main process so that http(s) links
go to `shell.openExternal` and everything else stays blocked. If a new @stlite/desktop
changes that code, the build stops with a message saying so.
- **Downloads are prepared in advance** (`Capabilities.on_click_downloads` is off):
stlite's own page sends Streamlit's on-click downloads to the placeholder origin
`https://stlite.invalid`, where they fail. Prepared downloads go through Python and work.
Streamlit still checks each download button's URL at that origin once; the request
can't resolve (`.invalid` is reserved) and nothing depends on it.
- **Python runs in a Node.js worker** (`nodeJsWorker`), which is needed to mount host
folders. It runs only EaglePlot's own code; keep it that way (no pickle loading, no
user-supplied Python).
- **Not yet:** loading a whole folder (Batch Import, Batch Analysis) needs the paths users
type (`C:\Users\…`) mapped onto mounted folders: roadmap D5.2. Fetching from NIST is off
(Pyodide's `requests` support needs the browser's XMLHttpRequest, which Node lacks); the
page links to NIST instead.

## Unsigned builds: what users see the first time

The installers are not code-signed yet (roadmap D5.4).

- **Windows:** SmartScreen says "Windows protected your PC". Click **More info → Run
anyway**. Some managed laptops block unsigned programs entirely: use the
[browser version](https://the-schultz-lab.github.io/eagleplot/app/), which can also be
installed from Chrome or Edge.
- **macOS:** "EaglePlot can't be opened because Apple cannot check it for malicious
software". Open **System Settings → Privacy & Security**, scroll down and click **Open
Anyway** (once). The app is ad-hoc signed, so it runs on Apple Silicon.
- **Linux:** `chmod +x EaglePlot-*.AppImage`, then run it.

## Testing

```bash
python packaging/desktop/build_desktop.py --dir
xvfb-run -a node scripts/desktop/smoke.js packaging/desktop/dist/linux-unpacked/eagleplot
```

The app calls `app.enableSandbox()`, and Chromium refuses to run sandboxed as root: run it
as a normal user. On Ubuntu 24.04 the sandbox also needs
`sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0`.
Binary file added packaging/desktop/assets/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading