Skip to content

Commit 4b5d3c8

Browse files
devilAPIclaude
andcommitted
Advanced settings, plus downloads, file uploads and fullscreen video
The generated app ignored downloads and <input type=file>, and video could not go fullscreen. All three work now: http(s) downloads go through DownloadManager with the page's cookies, blob: and data: downloads are saved from the page and keep their download attribute's name, and the file chooser supports picking several files. New Advanced settings page: orientation, dark mode, hide system bars, keep screen on, loading color, external links, loading bar, offline page with Retry, reload button, pinch zoom, desktop mode, user agent and app version. Options are stored with saved apps; older apps get the defaults. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015N24yBvRNRonkZRTorXZTq
1 parent a85c120 commit 4b5d3c8

18 files changed

Lines changed: 1306 additions & 58 deletions

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Fill in the form and tap **Generate**:
2929
- **Color** - title-bar color
3030
- **Icon** - an image from your gallery/files (center-cropped to a square); without one the app gets the web2apk globe icon
3131
- **Fullscreen** - hides only the title bar; the Android status bar stays visible
32+
- **Advanced settings** - screen orientation, dark mode for websites (Android 13+), hide the status and navigation bars, keep the screen on, app color while loading, open other sites in the browser, loading bar, offline page with Retry, reload button, pinch to zoom, desktop mode, custom user agent and app version
3233
- **Preview** - a live sketch of the app screen and home-screen icon (beside the form on wide screens)
3334
- **Package** - shown as "Package: ... - tap to change". It is derived from the domain (`https://example.org` -> `org.example.web2apk`). Every app needs its own ID: two apps with the same ID replace each other, so change it if you build several apps for one domain.
3435

@@ -69,6 +70,8 @@ flutter test
6970
flutter run # or: flutter build apk / ios / linux / windows / macos / web
7071
```
7172

73+
The template build needs JDK 21 (`JAVA_HOME=/usr/lib/jvm/java-21-openjdk scripts/build_template.sh`); newer JDKs fail in the Android build tools.
74+
7275
Tests that verify generated APKs use `apksigner`, `aapt2` and `zipalign` from the newest build-tools under `$ANDROID_HOME`; `flutter test --platform chrome` runs the browser-compatible tests. The icons are drawn by `tool/make_icons.py` (Pillow); rerun it and `scripts/build_template.sh` after changing the icon.
7376

7477
## Maintainer: releases and CI

‎lib/src/apk/apk_builder.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ Uint8List buildUnsignedApk({
4444
final mi = indexOf(kManifestPath);
4545
if (mi < 0) throw const FormatException('Template has no manifest');
4646
final manifest = entries[mi];
47+
final version = spec.options.versionName.trim();
4748
final patched = replaceXmlStrings(manifest.data, {
4849
kTemplatePackage: spec.packageId,
4950
kTemplateLabel: name,
51+
if (version.isNotEmpty) kTemplateVersionName: version,
5052
});
5153
entries[mi] = manifest.method == 0
5254
? ZipEntry.stored(manifest.name, patched)

‎lib/src/apk/app_options.dart‎

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/// Screen orientation of the generated app.
2+
enum AppOrientation {
3+
auto('Automatic'),
4+
portrait('Portrait'),
5+
landscape('Landscape');
6+
7+
const AppOrientation(this.label);
8+
final String label;
9+
}
10+
11+
/// When the generated app shows websites dark (Android 13 and newer).
12+
enum AppDarkMode {
13+
off('Off'),
14+
system('Follow the system'),
15+
always('Always');
16+
17+
const AppDarkMode(this.label);
18+
final String label;
19+
}
20+
21+
/// The advanced settings of a generated app. Everything but [versionName]
22+
/// goes to the template through `assets/config.json`.
23+
class AppOptions {
24+
final AppOrientation orientation;
25+
final AppDarkMode darkMode;
26+
27+
/// Links to other sites open in the browser instead of the app.
28+
final bool externalLinks;
29+
final bool progressBar;
30+
31+
/// Show a page with a Retry button when a page cannot be loaded.
32+
final bool offlinePage;
33+
34+
/// A reload button in the title bar, so it needs the title bar.
35+
final bool reloadButton;
36+
final bool hideSystemBars;
37+
final bool keepScreenOn;
38+
final bool pinchZoom;
39+
40+
/// Show the app color instead of white until the first page is drawn.
41+
final bool loadingColor;
42+
final bool desktopMode;
43+
44+
/// Replaces the WebView's user agent; empty keeps it.
45+
final String userAgent;
46+
47+
/// Version name shown in Android's app info; empty keeps the template's.
48+
final String versionName;
49+
50+
const AppOptions({
51+
this.orientation = AppOrientation.auto,
52+
this.darkMode = AppDarkMode.off,
53+
this.externalLinks = false,
54+
this.progressBar = false,
55+
this.offlinePage = true,
56+
this.reloadButton = false,
57+
this.hideSystemBars = false,
58+
this.keepScreenOn = false,
59+
this.pinchZoom = false,
60+
this.loadingColor = false,
61+
this.desktopMode = false,
62+
this.userAgent = '',
63+
this.versionName = '',
64+
});
65+
66+
AppOptions copyWith({
67+
AppOrientation? orientation,
68+
AppDarkMode? darkMode,
69+
bool? externalLinks,
70+
bool? progressBar,
71+
bool? offlinePage,
72+
bool? reloadButton,
73+
bool? hideSystemBars,
74+
bool? keepScreenOn,
75+
bool? pinchZoom,
76+
bool? loadingColor,
77+
bool? desktopMode,
78+
String? userAgent,
79+
String? versionName,
80+
}) => AppOptions(
81+
orientation: orientation ?? this.orientation,
82+
darkMode: darkMode ?? this.darkMode,
83+
externalLinks: externalLinks ?? this.externalLinks,
84+
progressBar: progressBar ?? this.progressBar,
85+
offlinePage: offlinePage ?? this.offlinePage,
86+
reloadButton: reloadButton ?? this.reloadButton,
87+
hideSystemBars: hideSystemBars ?? this.hideSystemBars,
88+
keepScreenOn: keepScreenOn ?? this.keepScreenOn,
89+
pinchZoom: pinchZoom ?? this.pinchZoom,
90+
loadingColor: loadingColor ?? this.loadingColor,
91+
desktopMode: desktopMode ?? this.desktopMode,
92+
userAgent: userAgent ?? this.userAgent,
93+
versionName: versionName ?? this.versionName,
94+
);
95+
96+
/// Reads [toJson]'s output. Missing keys, as in apps saved by older
97+
/// versions, and unknown enum values fall back to the defaults.
98+
factory AppOptions.fromJson(Map<String, dynamic> json) {
99+
const d = AppOptions();
100+
T pick<T extends Enum>(List<T> values, String key, T fallback) =>
101+
values.asNameMap()[json[key]] ?? fallback;
102+
return AppOptions(
103+
orientation: pick(AppOrientation.values, 'orientation', d.orientation),
104+
darkMode: pick(AppDarkMode.values, 'darkMode', d.darkMode),
105+
externalLinks: json['externalLinks'] as bool? ?? d.externalLinks,
106+
progressBar: json['progressBar'] as bool? ?? d.progressBar,
107+
offlinePage: json['offlinePage'] as bool? ?? d.offlinePage,
108+
reloadButton: json['reloadButton'] as bool? ?? d.reloadButton,
109+
hideSystemBars: json['hideSystemBars'] as bool? ?? d.hideSystemBars,
110+
keepScreenOn: json['keepScreenOn'] as bool? ?? d.keepScreenOn,
111+
pinchZoom: json['pinchZoom'] as bool? ?? d.pinchZoom,
112+
loadingColor: json['loadingColor'] as bool? ?? d.loadingColor,
113+
desktopMode: json['desktopMode'] as bool? ?? d.desktopMode,
114+
userAgent: json['userAgent'] as String? ?? d.userAgent,
115+
versionName: json['versionName'] as String? ?? d.versionName,
116+
);
117+
}
118+
119+
Map<String, dynamic> toJson() => {
120+
'orientation': orientation.name,
121+
'darkMode': darkMode.name,
122+
'externalLinks': externalLinks,
123+
'progressBar': progressBar,
124+
'offlinePage': offlinePage,
125+
'reloadButton': reloadButton,
126+
'hideSystemBars': hideSystemBars,
127+
'keepScreenOn': keepScreenOn,
128+
'pinchZoom': pinchZoom,
129+
'loadingColor': loadingColor,
130+
'desktopMode': desktopMode,
131+
'userAgent': userAgent.trim(),
132+
'versionName': versionName.trim(),
133+
};
134+
}

‎lib/src/apk/app_spec.dart‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import 'dart:convert';
22
import 'dart:typed_data';
33

4+
import 'app_options.dart';
5+
46
/// Form data for one generated app, plus URL / package-id rules.
57
class AppSpec {
68
final String name;
@@ -11,6 +13,7 @@ class AppSpec {
1113
final bool fullscreen;
1214
final String packageId;
1315
final Uint8List? icon;
16+
final AppOptions options;
1417

1518
const AppSpec({
1619
required this.name,
@@ -19,6 +22,7 @@ class AppSpec {
1922
required this.fullscreen,
2023
required this.packageId,
2124
this.icon,
25+
this.options = const AppOptions(),
2226
});
2327

2428
/// Contents of `assets/config.json` in the generated APK.
@@ -29,6 +33,7 @@ class AppSpec {
2933
'title': name,
3034
'color': '#${rgb.toUpperCase()}',
3135
'fullscreen': fullscreen,
36+
...options.toJson(),
3237
});
3338
}
3439
}

‎lib/src/apk/template_contract.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// Constants shared between the template APK and the patcher.
22
const kTemplatePackage = 'de.devilapi.web2apk.template';
33
const kTemplateLabel = 'WEB2APK_TEMPLATE_LABEL';
4+
const kTemplateVersionName = '1.0';
45
const kConfigPath = 'assets/config.json';
56
const kManifestPath = 'AndroidManifest.xml';
67
final kIconPath = RegExp(

‎lib/src/saved_apps.dart‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:typed_data';
33

44
import 'package:shared_preferences/shared_preferences.dart';
55

6+
import 'apk/app_options.dart';
67
import 'apk/app_spec.dart';
78
import 'apk/icons.dart';
89

@@ -23,6 +24,7 @@ class SavedApp {
2324

2425
/// 192x192 PNG, or null when the app has no custom icon.
2526
final Uint8List? icon;
27+
final AppOptions options;
2628
final DateTime updatedAt;
2729

2830
const SavedApp({
@@ -33,6 +35,7 @@ class SavedApp {
3335
required this.packageId,
3436
required this.updatedAt,
3537
this.icon,
38+
this.options = const AppOptions(),
3639
});
3740

3841
/// The stored icon for [icon]: center-cropped and downscaled to 192x192.
@@ -53,19 +56,24 @@ class SavedApp {
5356
fullscreen: spec.fullscreen,
5457
packageId: spec.packageId,
5558
icon: spec.icon == null ? null : (icon192 ?? storedIcon(spec.icon!)),
59+
options: spec.options,
5660
updatedAt: (now ?? DateTime.now()).toUtc(),
5761
);
5862

5963
factory SavedApp.fromJson(Map<String, dynamic> json) {
6064
try {
6165
final icon = json['icon'];
66+
final options = json['options'];
6267
return SavedApp(
6368
name: json['name'] as String,
6469
url: json['url'] as String,
6570
color: json['color'] as int,
6671
fullscreen: json['fullscreen'] as bool,
6772
packageId: json['packageId'] as String,
6873
icon: icon == null ? null : base64Decode(icon as String),
74+
options: options == null
75+
? const AppOptions()
76+
: AppOptions.fromJson(options as Map<String, dynamic>),
6977
updatedAt: DateTime.parse(json['updatedAt'] as String),
7078
);
7179
} on FormatException {
@@ -82,6 +90,7 @@ class SavedApp {
8290
'fullscreen': fullscreen,
8391
'packageId': packageId,
8492
'icon': icon == null ? null : base64Encode(icon!),
93+
'options': options.toJson(),
8594
'updatedAt': updatedAt.toUtc().toIso8601String(),
8695
};
8796
}

0 commit comments

Comments
 (0)