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
5 changes: 5 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ boot adminer — `api.php`, `Settings/Theme/screenshot.php` — each `require`
(`Env::DataDir->get()`, `Latte::engine()`, `Debug\Tracy::enable()`), so there are no function files
to special-case — PSR-4 covers everything.

**Build tooling in PHP goes to `app/cli/`, as `Desktop\Cli\` classes.** A static method with its
test in `tests/cli/`, added to `make qa`. It is dev-only autoload, and `package-app` removes the
folder, so it never ships. `cli/` still holds the scripts not moved yet.

## The Adminer Desktop theme

`app/src/Settings/Theme/designs/adminer-desktop/` is the app's own default look, not one of
Expand Down Expand Up @@ -226,6 +230,7 @@ run, so an edited seed needs no `make destroy`.
app/adminer-plugins.php the entry adminer includes: boots the autoloader, returns ours + the enabled plugins
app/AdminerDesktop.php the plugin adminer sees (global namespace): hooks and all translations
app/api.php the one URL the page's own scripts post to: ?action= routes to src/Api/
app/cli/ Desktop\Cli\: build tooling, never released
app/src/ the Desktop\ namespace, PSR-4: everything we wrote
app/src/Api/ one class per action; ResizePreference stores a dragged width
app/src/Files.php Desktop\Files - recursive file finding
Expand Down
26 changes: 15 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ else
EXE = .exe
endif

.PHONY: logo-ico help install linux-deps fetch verify qa phpstan dresscode dresscode-hook golangci oxc security check check-app e2e e2e-visual e2e-packaged i18n i18n-check mcp-bridge-data bench build run dev editor debug demo down destroy kill-orphans bundle zip dist tarball windows deb logs serve clean checksums
.PHONY: help install linux-deps fetch verify qa phpstan dresscode dresscode-hook golangci oxc security check check-app e2e e2e-visual e2e-packaged i18n i18n-check mcp-bridge-data bench build run dev editor debug demo down destroy kill-orphans bundle zip dist tarball windows deb logs serve clean checksums

.DEFAULT_GOAL := help

Expand Down Expand Up @@ -197,6 +197,11 @@ $(WIN_INI)/openssl.ini:
@mkdir -p $(dir $@)
printf 'extension_dir=bin/ext\nextension=php_openssl.dll\n' > $@

# The windows frankenphp keeps gd as an extension too, and the icon build resizes with it.
$(WIN_INI)/gd.ini:
@mkdir -p $(dir $@)
printf 'extension_dir=bin/ext\nextension=php_gd.dll\n' > $@

# The app's own PHP deps: latte renders our markup and tracy stands behind -debug. qa
# needs them as much as the app does -- phpstan resolves those classes through vendor/,
# and the template linter is one of the packages. composer.json lives in app/ so vendor/
Expand Down Expand Up @@ -328,6 +333,7 @@ qa: fetch app/vendor i18n mcp-bridge-data ## Run every static check (php, go, j
./bin/frankenphp$(EXE) php-cli tests/i18n/GeneratorTest.php
./bin/frankenphp$(EXE) php-cli tests/version/AppVersionTest.php
./bin/frankenphp$(EXE) php-cli tests/shortcuts/ShortcutsTest.php
./bin/frankenphp$(EXE) php-cli tests/cli/WindowsIcoTest.php
@sh tests/cli/kill-orphans-test.sh
@# The launcher's own download code against the real webview, every way adminer starts one.
@sh tests/launcher/downloads.sh
Expand Down Expand Up @@ -406,19 +412,16 @@ bench: mcp-bridge-data ## Benchmark the MCP bridge's own cost per call
i18n-check: bin/frankenphp$(EXE) app/vendor ## Report native-shell translation coverage (missing strings per locale)
@./bin/frankenphp$(EXE) php-cli cli/i18n.php check

# The exe's icon on Windows. go build links any .syso beside the sources, and windres comes with
# the gcc cgo already needs. The .ico is committed: nothing on a Windows runner can resize a PNG.
# The exe's icon on Windows, from the same logo.png as the mac and linux ones. go build links any
# .syso beside the sources, and windres comes with the gcc cgo already needs.
WIN_ICON = $(if $(EXE),launcher/icon_windows_amd64.syso)

launcher/icon_windows_amd64.syso: launcher/icon.rc assets/logo.ico
launcher/icon_windows_amd64.syso: launcher/icon.rc build.noindex/logo.ico
windres -O coff -i $< -o $@

# macOS only, for sips. After editing the logo: make logo-ico, and commit assets/logo.ico.
logo-ico: bin/frankenphp$(EXE) ## Rebuild assets/logo.ico from assets/logo.png
@mkdir -p build.noindex/ico
@for s in 16 24 32 48 64 128 256; do sips -z $$s $$s assets/logo.png --out build.noindex/ico/$$s.png >/dev/null; done
./bin/frankenphp$(EXE) php-cli cli/windows-ico.php
@rm -rf build.noindex/ico
build.noindex/logo.ico: assets/logo.png app/cli/WindowsIco.php app/vendor $(if $(EXE),$(WIN_INI)/gd.ini)
@mkdir -p $(dir $@)
$(if $(EXE),PHP_INI_SCAN_DIR=$(WIN_INI)) ./bin/frankenphp$(EXE) php-cli -r 'require "app/vendor/autoload.php"; Desktop\Cli\WindowsIco::run();'

build: fetch i18n mcp-bridge-data $(WIN_ICON) ## Build the launcher binary
go build -ldflags "$(LDFLAGS)" -o build.noindex/adminer-desktop$(EXE) ./launcher
Expand Down Expand Up @@ -578,8 +581,9 @@ DIST = build.noindex/pkg/adminer-desktop
# the same tree a release carries. composer strips the dev tooling app/vendor carries for qa
# (dresscode, playwright: nothing the shipped app runs), reconciling the copy down to
# production deps in place. No precompile on windows: Latte locks even a precompiled template
# there, so app/ would have to be writable.
# there, so app/ would have to be writable. app/cli/ is build tooling, so it does not ship.
define package-app
rm -rf $(1)/cli
$(COMPOSER) install --no-dev --no-interaction --working-dir=$(1)
$(if $(EXE),,./bin/frankenphp php-cli cli/latte-precompile.php $(1))
endef
Expand Down
55 changes: 55 additions & 0 deletions app/cli/WindowsIco.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);

namespace Desktop\Cli;

use GdImage;
use RuntimeException;

/** Builds the Windows icon from assets/logo.png, the one source every platform's icon comes from. */
class WindowsIco {
private const array SIZES = [16, 24, 32, 48, 64, 128, 256];

static function run(): void {
$root = dirname(__DIR__, 2);
$logo = imagecreatefrompng("$root/assets/logo.png");
if (!$logo) {
throw new RuntimeException("ico: cannot read assets/logo.png");
}
$images = [];
foreach (self::SIZES as $size) {
$images[$size] = self::resize($logo, $size);
}
file_put_contents("$root/build.noindex/logo.ico", self::pack($images));
}

/** The PNG bytes of a square copy, keeping the transparency around the logo. */
static function resize(GdImage $source, int $size): string {
$target = imagecreatetruecolor($size, $size);
imagealphablending($target, false);
imagesavealpha($target, true);
imagecopyresampled($target, $source, 0, 0, 0, 0, $size, $size, imagesx($source), imagesy($source));
ob_start();
imagepng($target);
return (string) ob_get_clean();
}

/** A directory of sizes, each entry the PNG as it is, which every Windows since Vista reads.
* @param array<int, string> $images PNG bytes by width in pixels; they are square
*/
static function pack(array $images): string {
$directory = pack("vvv", 0, 1, count($images));
$body = "";
$offset = 6 + 16 * count($images);
foreach ($images as $size => $png) {
if (!str_starts_with($png, "\x89PNG")) {
throw new RuntimeException("ico: the $size px image is not a PNG");
}
// A byte each, so 256 is written as 0: the format's own way of saying it.
$directory .= pack("CCCCvvVV", $size % 256, $size % 256, 0, 0, 1, 32, strlen($png), $offset);
$body .= $png;
$offset += strlen($png);
}
return $directory . $body;
}
}
1 change: 1 addition & 0 deletions app/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"autoload-dev": {
"psr-4": {
"Desktop\\Cli\\": "cli/",
"Desktop\\Tests\\": "../tests/e2e/bootstrap/"
}
},
Expand Down
Binary file removed assets/logo.ico
Binary file not shown.
24 changes: 0 additions & 24 deletions cli/windows-ico.php

This file was deleted.

2 changes: 1 addition & 1 deletion launcher/icon.rc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 32512 is IDI_APPLICATION, the id webview loads the window's icon from. Explorer takes the same one.
32512 ICON "../assets/logo.ico"
32512 ICON "../build.noindex/logo.ico"
2 changes: 1 addition & 1 deletion launcher/icon_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ package main
import "unsafe"

// setWindowIcon is the Linux (GTK) path only. macOS ships the .icns in the .app bundle and the
// Windows exe carries assets/logo.ico as a resource (launcher/icon.rc), so there is nothing to set.
// Windows exe carries one built from assets/logo.png (launcher/icon.rc), so there is nothing to set.
func setWindowIcon(window unsafe.Pointer, path string) bool { return true }
38 changes: 38 additions & 0 deletions tests/cli/WindowsIcoTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);

/** Does the .ico say what Windows reads: how many images, how big, and where each one starts? A
* wrong offset still builds, and shows up only as a blank icon on a machine nobody tests on.
*/

use Desktop\Cli\WindowsIco;
use Tester\Assert;

require dirname(__DIR__) . "/bootstrap.php";

$small = "\x89PNG-small";
$large = "\x89PNG-a-larger-one";
$ico = WindowsIco::pack([16 => $small, 256 => $large]);

Assert::same(['reserved' => 0, 'type' => 1, 'count' => 2], unpack("vreserved/vtype/vcount", $ico));

$first = unpack("Cwidth/Cheight/x2/vplanes/vbits/Vlength/Voffset", $ico, 6);
Assert::same(16, $first['width']);
Assert::same(1, $first['planes']);
Assert::same(32, $first['bits']);
Assert::same($small, substr($ico, $first['offset'], $first['length']));

$second = unpack("Cwidth/Cheight/x2/vplanes/vbits/Vlength/Voffset", $ico, 22);
Assert::same(0, $second['width']); // 256 does not fit a byte
Assert::same(0, $second['height']);
Assert::same($large, substr($ico, $second['offset'], $second['length']));

Assert::exception(fn() => WindowsIco::pack([16 => '']), RuntimeException::class, 'ico: the 16 px image is not a PNG');

// A transparent corner stays transparent, or the icon sits on a black square.
$source = imagecreatetruecolor(64, 64);
imagealphablending($source, false);
imagefill($source, 0, 0, imagecolorallocatealpha($source, 0, 0, 0, 127));
$small = imagecreatefromstring(WindowsIco::resize($source, 16));
Assert::same(16, imagesx($small));
Assert::same(127, imagecolorat($small, 0, 0) >> 24);
Loading