Keep web Material styling and preserve visible installer access URLs

This commit is contained in:
2026-10-26 18:37:13 +00:00
parent 48c29fd1ff
commit 41a3be8715
13 changed files with 176 additions and 15 deletions
+2 -4
View File
@@ -1,6 +1,6 @@
import '../ui/adaptive/platform.dart';
import '../ui/theme/app_theme.dart'; import '../ui/theme/app_theme.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../shell/adaptive_shell.dart'; import '../shell/adaptive_shell.dart';
@@ -79,7 +79,5 @@ class MyApp extends StatelessWidget {
); );
} }
bool get _platformIsCupertino => bool get _platformIsCupertino => prefersCupertino();
defaultTargetPlatform == TargetPlatform.iOS ||
defaultTargetPlatform == TargetPlatform.macOS;
} }
+2 -3
View File
@@ -1,3 +1,4 @@
import '../ui/adaptive/platform.dart';
import 'dart:async'; import 'dart:async';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
@@ -551,7 +552,5 @@ class _PipelinesAppState extends State<PipelinesApp>
AppDestination.settings => AppRoute.settings, AppDestination.settings => AppRoute.settings,
}; };
bool get _platformIsCupertino => bool get _platformIsCupertino => prefersCupertino();
defaultTargetPlatform == TargetPlatform.iOS ||
defaultTargetPlatform == TargetPlatform.macOS;
} }
+2 -3
View File
@@ -1,3 +1,4 @@
import '../ui/adaptive/platform.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@@ -243,9 +244,7 @@ class _PipelinesRootState extends State<PipelinesRoot> {
super.dispose(); super.dispose();
} }
bool get _cupertino => bool get _cupertino => prefersCupertino();
defaultTargetPlatform == TargetPlatform.iOS ||
defaultTargetPlatform == TargetPlatform.macOS;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -1,5 +1,4 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import '../../../ui/adaptive/host.dart'; import '../../../ui/adaptive/host.dart';
@@ -9,7 +8,8 @@ import '../pipeline_query.dart';
/// The one platform decision for this feature. The screen itself receives no /// The one platform decision for this feature. The screen itself receives no
/// platform flag, so tests and integration obey Flutter's target platform. /// platform flag, so tests and integration obey Flutter's target platform.
bool useCupertinoControls(BuildContext context) => bool useCupertinoControls(BuildContext context) =>
usesCupertinoHost(context) || defaultTargetPlatform == TargetPlatform.iOS; usesCupertinoHost(context) ||
Theme.of(context).platform == TargetPlatform.iOS;
/// Standard platform activity indicator with an accessible status label. /// Standard platform activity indicator with an accessible status label.
class PipelineProgress extends StatelessWidget { class PipelineProgress extends StatelessWidget {
+8
View File
@@ -0,0 +1,8 @@
import 'package:flutter/foundation.dart';
/// Browsers use Material consistently, regardless of their host OS.
bool prefersCupertino({bool web = kIsWeb, TargetPlatform? platform}) {
final target = platform ?? defaultTargetPlatform;
return !web &&
(target == TargetPlatform.iOS || target == TargetPlatform.macOS);
}
+3
View File
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@@ -26,6 +27,7 @@ abstract final class AppColors {
const _seed = Color(0xFF6750A4); const _seed = Color(0xFF6750A4);
ThemeData appLightTheme() => ThemeData( ThemeData appLightTheme() => ThemeData(
platform: kIsWeb ? TargetPlatform.android : null,
colorScheme: ColorScheme.fromSeed(seedColor: _seed), colorScheme: ColorScheme.fromSeed(seedColor: _seed),
pageTransitionsTheme: appPageTransitions, pageTransitionsTheme: appPageTransitions,
); );
@@ -94,6 +96,7 @@ ThemeData appDarkTheme() {
surfaceContainerHighest: const Color(0xFF303136), surfaceContainerHighest: const Color(0xFF303136),
); );
return ThemeData( return ThemeData(
platform: kIsWeb ? TargetPlatform.android : null,
colorScheme: scheme, colorScheme: scheme,
scaffoldBackgroundColor: scheme.surface, scaffoldBackgroundColor: scheme.surface,
pageTransitionsTheme: appPageTransitions, pageTransitionsTheme: appPageTransitions,
+19
View File
@@ -0,0 +1,19 @@
# Material styling in browsers
Web selects the Material app host on every OS. Native iOS/macOS retain
Cupertino. Both Material themes set the web platform to Android so adaptive
feature controls and route transitions cannot switch back to Apple styling
based on the browser's host OS. Pipeline controls now follow the theme too.
Verification: 18 focused native widget tests and 3 Chrome platform tests passed;
Flutter analysis passed; release web build passed. Desktop and phone captures
of Pipelines and Settings were rendered against an isolated fixture under
/tmp/pipelines-material-web. Existing operator data was not used for tests.
The Pipelines capture exercises its error state because the runs fixture does
not implement list_pipelines; Settings renders the populated fixture data.
Published with ./install --web after verifying zero executing runs. Rollback:
/tmp/pipelines-web-before-material.tar.gz. No shared service restart. Authenticated
HTML and main.dart.js returned HTTP 200 on port 8083; served JS matches installed
bundle by SHA-256. Native-device behavior was not tested on a device.
+41
View File
@@ -0,0 +1,41 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/app.dart';
import 'package:pipelines_app/ui/adaptive/platform.dart';
import 'package:pipelines_app/ui/theme/app_theme.dart';
void main() {
test('web uses Material on every host; native Apple uses Cupertino', () {
for (final platform in TargetPlatform.values) {
expect(prefersCupertino(web: true, platform: platform), isFalse);
expect(
prefersCupertino(web: false, platform: platform),
platform == TargetPlatform.iOS || platform == TargetPlatform.macOS,
);
}
});
for (final platform in [TargetPlatform.macOS, TargetPlatform.iOS]) {
testWidgets('app and themes select the right controls on $platform', (
tester,
) async {
debugDefaultTargetPlatformOverride = platform;
addTearDown(() => debugDefaultTargetPlatformOverride = null);
await tester.pumpWidget(const MyApp());
if (kIsWeb) {
expect(find.byType(MaterialApp), findsOneWidget);
expect(find.byType(CupertinoApp), findsNothing);
expect(appLightTheme().platform, TargetPlatform.android);
expect(appDarkTheme().platform, TargetPlatform.android);
} else {
expect(find.byType(CupertinoApp), findsOneWidget);
expect(appLightTheme().platform, platform);
expect(appDarkTheme().platform, platform);
}
await tester.pumpWidget(const SizedBox.shrink());
debugDefaultTargetPlatformOverride = null;
});
}
}
+6
View File
@@ -69,6 +69,12 @@ when present) so each new build installs over the last.
web-app and phone-app status. The default browser URL is web-app and phone-app status. The default browser URL is
`http://localhost:8082/` on this computer, or `http://HOST:8082/` on a trusted `http://localhost:8082/` on this computer, or `http://HOST:8082/` on a trusted
LAN/VPN (`--web-port` / `--web-host` override it). Setup prints the actual URL. LAN/VPN (`--web-port` / `--web-host` override it). Setup prints the actual URL.
Re-running `./install` preserves the saved API, web and ntfy ports and bind
addresses. Explicit flags override those settings, for example
`./install --web-port 8096`. An already-running supervisor retains its current
settings until restarted; restart only when no work is active.
Native installation and web/APK builds finish by printing the browser URLs,
including the saved web port, LAN address and configured public origin.
The unauthenticated Go API defaults to **127.0.0.1:8080**; expose only the web The unauthenticated Go API defaults to **127.0.0.1:8080**; expose only the web
proxy. Use TLS termination or an encrypted VPN for remote access; plain HTTP proxy. Use TLS termination or an encrypted VPN for remote access; plain HTTP
does not encrypt the sign-in password. does not encrypt the sign-in password.
+22
View File
@@ -212,6 +212,26 @@ def build_apk(prefix, server_url=None, notes="", runner=subprocess.run, log=prin
return target / "pipelines.apk" return target / "pipelines.apk"
def print_web_urls(manifest, lan_host=None):
"""Keep browser access details as the final installer output."""
web = manifest.get("web") or {}
if not web.get("port"):
return
host = web.get("host", "0.0.0.0")
local = "localhost" if host in ("0.0.0.0", "127.0.0.1") else host
urls = [f"http://{local}:{web['port']}/"]
if host == "0.0.0.0":
lan_host = lan_host or urlsplit(manifest.get("public_url", "")).hostname
if lan_host and lan_host not in ("localhost", "127.0.0.1", "0.0.0.0"):
urls.append(f"http://{lan_host}:{web['port']}/")
public = manifest.get("opencode_env", {}).get("PIPELINES_WEB_PUBLIC_URL")
if public:
urls.append(public.rstrip("/") + "/")
print("\nOpen Pipelines in your browser:")
for url in dict.fromkeys(urls):
print(" " + url)
def main(argv=None): def main(argv=None):
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
parser.add_argument("kind", choices=("web", "apk")) parser.add_argument("kind", choices=("web", "apk"))
@@ -223,6 +243,7 @@ def main(argv=None):
raise RuntimeError("Docker is required to build the app; start Docker and retry") raise RuntimeError("Docker is required to build the app; start Docker and retry")
if args.kind == "apk": if args.kind == "apk":
build_apk(args.prefix, args.server_url, args.notes) build_apk(args.prefix, args.server_url, args.notes)
print_web_urls(load_manifest(args.prefix))
return return
manifest = load_manifest(args.prefix) manifest = load_manifest(args.prefix)
web = manifest.get("web") or {} web = manifest.get("web") or {}
@@ -230,6 +251,7 @@ def main(argv=None):
raise ValueError("This installation does not serve the app; rerun ./install") raise ValueError("This installation does not serve the app; rerun ./install")
install_tree(build("web"), Path(web["root"])) install_tree(build("web"), Path(web["root"]))
print(f"Web app installed at {web['root']}; reload the page.") print(f"Web app installed at {web['root']}; reload the page.")
print_web_urls(manifest)
if __name__ == "__main__": if __name__ == "__main__":
+21 -1
View File
@@ -293,6 +293,24 @@ class Setup:
raise ValueError("Invalid existing authoring role; no permission changes were made") raise ValueError("Invalid existing authoring role; no permission changes were made")
return existing.get("allow_authoring", False) return existing.get("allow_authoring", False)
def preserve_network_settings(self, prefix, args):
"""A plain reinstall keeps the installed addresses; flags override them."""
path = prefix / MARKER
if not path.exists() and not path.is_symlink():
return
if path.is_symlink() or not path.is_file():
raise ValueError("Refusing to read network settings from a non-regular installation manifest")
existing = json.loads(path.read_text())
web = existing.get("web") or {}
saved = {"port": existing.get("server_port"),
"ntfy_port": existing.get("ntfy_port"),
"bind_address": existing.get("bind_address"),
"web_port": web.get("port"), "web_host": web.get("host")}
supplied = {argument.split("=", 1)[0] for argument in args.argv}
for name, value in saved.items():
if value is not None and "--" + name.replace("_", "-") not in supplied:
setattr(args, name, value)
# --- prefix layout --------------------------------------------------- # --- prefix layout ---------------------------------------------------
def prepare_layout(self, prefix): def prepare_layout(self, prefix):
@@ -704,6 +722,8 @@ class Setup:
python = self.require_tools() python = self.require_tools()
if args.prefix: if args.prefix:
self.prefix_argument = args.prefix self.prefix_argument = args.prefix
prefix = self.resolve_prefix()
self.preserve_network_settings(prefix, args)
if not 1024 <= args.port <= 65535: if not 1024 <= args.port <= 65535:
raise ValueError("Invalid server port; choose a value between 1024 and 65535") raise ValueError("Invalid server port; choose a value between 1024 and 65535")
if not 1024 <= args.ntfy_port <= 65535: if not 1024 <= args.ntfy_port <= 65535:
@@ -717,7 +737,6 @@ class Setup:
ipaddress.IPv4Address(args.web_host) ipaddress.IPv4Address(args.web_host)
except ValueError: except ValueError:
raise ValueError("Invalid API/web bind address; use an IPv4 address such as 0.0.0.0 or 127.0.0.1") from None raise ValueError("Invalid API/web bind address; use an IPv4 address such as 0.0.0.0 or 127.0.0.1") from None
prefix = self.resolve_prefix()
allow_authoring = self.authoring_role(prefix, args.allow_authoring) allow_authoring = self.authoring_role(prefix, args.allow_authoring)
web_public_url = self.environ.get("PIPELINES_WEB_PUBLIC_URL", "") web_public_url = self.environ.get("PIPELINES_WEB_PUBLIC_URL", "")
previous = prefix / MARKER previous = prefix / MARKER
@@ -843,6 +862,7 @@ class Setup:
"(use a workspace path that exists on this server).") "(use a workspace path that exists on this server).")
else: else:
print(f"Unauthenticated API bound to {args.bind_address}:{args.port}; use the authenticated web URL.") print(f"Unauthenticated API bound to {args.bind_address}:{args.port}; use the authenticated web URL.")
app_build.print_web_urls(manifest, lan_host=lan_ip)
def arguments(argv=None): def arguments(argv=None):
+21
View File
@@ -1,5 +1,7 @@
import importlib.util import importlib.util
import io
import json import json
from contextlib import redirect_stdout
from pathlib import Path from pathlib import Path
import subprocess import subprocess
import tempfile import tempfile
@@ -24,6 +26,25 @@ class Runner:
class AppBuildTests(unittest.TestCase): class AppBuildTests(unittest.TestCase):
def test_web_urls_include_saved_port_lan_and_public_origin(self):
manifest = {"web": {"host": "0.0.0.0", "port": 8096},
"public_url": "http://192.168.1.20:8090",
"opencode_env": {"PIPELINES_WEB_PUBLIC_URL": "https://pipelines.example.com"}}
with redirect_stdout(io.StringIO()) as output:
app_build.print_web_urls(manifest)
self.assertEqual(output.getvalue().splitlines()[-3:], [
" http://localhost:8096/", " http://192.168.1.20:8096/",
" https://pipelines.example.com/"])
def test_web_install_ends_with_access_urls(self):
manifest = {"web": {"host": "127.0.0.1", "port": 8083, "root": "/unused"}}
with patch.object(app_build, "docker_available", return_value=True), \
patch.object(app_build, "load_manifest", return_value=manifest), \
patch.object(app_build, "build"), patch.object(app_build, "install_tree"), \
redirect_stdout(io.StringIO()) as output:
app_build.main(["web"])
self.assertEqual(output.getvalue().splitlines()[-1], " http://localhost:8083/")
def setUp(self): def setUp(self):
self.home = tempfile.TemporaryDirectory() self.home = tempfile.TemporaryDirectory()
self.addCleanup(self.home.cleanup) self.addCleanup(self.home.cleanup)
+27 -2
View File
@@ -150,6 +150,27 @@ class SetupNativeTests(unittest.TestCase):
mapping["cc"] = cc mapping["cc"] = cc
return lambda name: mapping.get(name) return lambda name: mapping.get(name)
def test_reinstall_preserves_network_settings_and_explicit_flags_override(self):
with tempfile.TemporaryDirectory() as directory:
installer = self.installer(directory, Recorder())
prefix = installer.resolve_prefix()
prefix.mkdir()
manifest = {"server_port": 8090, "ntfy_port": 8091,
"bind_address": "127.0.0.2",
"web": {"port": 8096, "host": "127.0.0.1"}}
(prefix / setup_native.MARKER).write_text(json.dumps(manifest))
args = setup_native.arguments([])
installer.preserve_network_settings(prefix, args)
self.assertEqual((args.port, args.ntfy_port, args.web_port), (8090, 8091, 8096))
self.assertEqual((args.bind_address, args.web_host), ("127.0.0.2", "127.0.0.1"))
args = setup_native.arguments(["--web-port=8082", "--port", "8080"])
installer.preserve_network_settings(prefix, args)
self.assertEqual((args.port, args.ntfy_port, args.web_port), (8080, 8091, 8082))
(prefix / setup_native.MARKER).unlink()
args = setup_native.arguments([])
installer.preserve_network_settings(prefix, args)
self.assertEqual(args.web_port, 8082)
def test_require_tools_reports_each_missing_tool_without_installing(self): def test_require_tools_reports_each_missing_tool_without_installing(self):
with tempfile.TemporaryDirectory() as directory: with tempfile.TemporaryDirectory() as directory:
recorder = Recorder() recorder = Recorder()
@@ -435,7 +456,7 @@ class SetupNativeTests(unittest.TestCase):
with patch.object(setup_native.shutil, "which", side_effect=self.which_all()), \ with patch.object(setup_native.shutil, "which", side_effect=self.which_all()), \
patch.object(setup_native.lan, "detect_lan", return_value="192.168.1.20"), \ patch.object(setup_native.lan, "detect_lan", return_value="192.168.1.20"), \
patch.object(setup_native.configure, "host_timezone", return_value="Europe/London"): patch.object(setup_native.configure, "host_timezone", return_value="Europe/London"):
installer.run(setup_native.arguments([])) installer.run(setup_native.arguments(["--web-port", "8096"]))
before = (prefix / "secrets/publisher-token").read_text() before = (prefix / "secrets/publisher-token").read_text()
def refuse_resolution(): def refuse_resolution():
@@ -443,8 +464,12 @@ class SetupNativeTests(unittest.TestCase):
installer.resolver = refuse_resolution installer.resolver = refuse_resolution
recorder.calls.clear() recorder.calls.clear()
installer.run(setup_native.arguments([])) with redirect_stdout(io.StringIO()) as output:
installer.run(setup_native.arguments([]))
self.assertEqual((prefix / "secrets/publisher-token").read_text(), before) self.assertEqual((prefix / "secrets/publisher-token").read_text(), before)
self.assertEqual(manage.load(prefix)["web"]["port"], 8096)
self.assertEqual(output.getvalue().splitlines()[-2:], [
" http://localhost:8096/", " http://192.168.1.20:8096/"])
self.assertFalse(any("token" in call for call in recorder.calls), "reinstall re-created the token") self.assertFalse(any("token" in call for call in recorder.calls), "reinstall re-created the token")
def test_ntfy_is_built_from_the_pinned_module(self): def test_ntfy_is_built_from_the_pinned_module(self):