feat: browser navigation moves into a menu, and a note on the network

- back, forward, open in the system browser and history now live in the
  address bar's three-dot menu; history is a submenu (last 20 URLs, or a
  disabled "no history" row), leaving the URL field wide enough on a phone
- the browser runs on the phone's network: localhost is the phone, not the
  OpenChamber host; the empty state says so and points at the host's LAN
  address for server-side dev servers
- version 0.7.0+700
This commit is contained in:
blumia committed 2026-12-04 09:29:02 +08:00
1 parent ce944751b4
commit 318276d3b9
5 files changed
+66 -51

No files matched your search

+52 -49
View File
@@ -19,12 +19,6 @@ class BrowserPanel extends StatefulWidget {
class _BrowserPanelState extends State<BrowserPanel> {
static const MethodChannel _channel = MethodChannel('openchamber/browser');
static const _quickLinks = [
'http://localhost:3000',
'http://localhost:5173',
'http://localhost:8080',
];
final TextEditingController _url = TextEditingController();
final List<String> _history = [];
WebViewController? _web;
@@ -212,16 +206,6 @@ class _BrowserPanelState extends State<BrowserPanel> {
padding: const EdgeInsets.fromLTRB(4, 6, 4, 6),
child: Row(
children: [
IconButton(
icon: const Icon(Icons.arrow_back, size: 20),
tooltip: tr('Back'),
onPressed: _canBack ? () => web?.goBack() : null,
),
IconButton(
icon: const Icon(Icons.arrow_forward, size: 20),
tooltip: tr('Forward'),
onPressed: _canForward ? () => web?.goForward() : null,
),
Expanded(
child: TextField(
controller: _url,
@@ -249,29 +233,55 @@ class _BrowserPanelState extends State<BrowserPanel> {
? () => web?.runJavaScript('window.stop()')
: web?.reload,
),
if (Platform.isAndroid)
IconButton(
icon: const Icon(Icons.open_in_browser, size: 20),
tooltip: tr('Open in system browser'),
onPressed: _openExternal,
),
if (_history.isNotEmpty)
PopupMenuButton<String>(
icon: const Icon(Icons.history, size: 20),
tooltip: tr('History'),
onSelected: (url) {
_setUrl(url);
_navigate(url);
},
itemBuilder: (_) => [
for (final url in _history)
PopupMenuItem(
value: url,
child: Text(url,
maxLines: 1, overflow: TextOverflow.ellipsis),
),
],
MenuAnchor(
builder: (context, controller, child) => IconButton(
icon: const Icon(Icons.more_vert, size: 20),
tooltip: tr('More'),
onPressed: () =>
controller.isOpen ? controller.close() : controller.open(),
),
menuChildren: [
MenuItemButton(
leadingIcon: const Icon(Icons.arrow_back, size: 18),
onPressed: _canBack ? () => web?.goBack() : null,
child: const AppText('Back'),
),
MenuItemButton(
leadingIcon: const Icon(Icons.arrow_forward, size: 18),
onPressed: _canForward ? () => web?.goForward() : null,
child: const AppText('Forward'),
),
if (Platform.isAndroid)
MenuItemButton(
leadingIcon: const Icon(Icons.open_in_browser, size: 18),
onPressed: _openExternal,
child: const AppText('Open in system browser'),
),
SubmenuButton(
leadingIcon: const Icon(Icons.history, size: 18),
menuChildren: _history.isEmpty
? [
const MenuItemButton(
onPressed: null,
child: AppText('No history'),
),
]
: [
for (final url in _history)
MenuItemButton(
onPressed: () {
_setUrl(url);
_navigate(url);
},
child: Text(url,
maxLines: 1,
overflow: TextOverflow.ellipsis),
),
],
child: const AppText('History'),
),
],
),
],
),
);
@@ -323,17 +333,10 @@ class _BrowserPanelState extends State<BrowserPanel> {
style: TextStyle(fontSize: 12.5),
),
const SizedBox(height: 16),
Wrap(
spacing: 8,
runSpacing: 8,
alignment: WrapAlignment.center,
children: [
for (final url in _quickLinks)
ActionChip(
label: Text(url),
onPressed: () => _navigate(url),
),
],
AppText(
'The browser runs on this device; for a dev server on the OpenChamber host, enter the host\'s LAN address.',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 11.5, color: theme.hintColor),
),
],
),