Skip to content
Open
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
8 changes: 4 additions & 4 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"
url: "https://pub.dev"
source: hosted
version: "1.16.0"
version: "1.17.0"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -280,10 +280,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00"
sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55
url: "https://pub.dev"
source: hosted
version: "0.7.6"
version: "0.7.7"
typed_data:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions lib/cli_commands.dart
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ library;
import 'dart:isolate';

import 'package:ansicolor/ansicolor.dart';
import 'package:html/dom.dart';
import 'package:html/parser.dart' as html_parser;
import 'package:image/image.dart';
import 'package:meta/meta.dart';
Expand Down
11 changes: 5 additions & 6 deletions lib/templates.dart
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ const String _iOSBrandingRightBottomConstraints = '''

/// Web related templates
const String _webCss = '''
<style id="splash-screen-style">
<style id="splash-screen-style">
html {
height: 100%
}
Expand Down Expand Up @@ -478,26 +478,25 @@ const String _webCssDark = '''

// XML's insertBefore can't have a newline at the end:
const String _indexHtmlPicture = '''
<picture id="splash">
<picture id="splash">
<source srcset="splash/img/light-1x.[IMAGEEXTENSION] 1x, splash/img/light-2x.[IMAGEEXTENSION] 2x, splash/img/light-3x.[IMAGEEXTENSION] 3x, splash/img/light-4x.[IMAGEEXTENSION] 4x" media="(prefers-color-scheme: light)">
<source srcset="splash/img/dark-1x.[IMAGEEXTENSION] 1x, splash/img/dark-2x.[IMAGEEXTENSION] 2x, splash/img/dark-3x.[IMAGEEXTENSION] 3x, splash/img/dark-4x.[IMAGEEXTENSION] 4x" media="(prefers-color-scheme: dark)">
<img class="[IMAGEMODE]" aria-hidden="true" src="splash/img/light-1x.[IMAGEEXTENSION]" alt=""/>
</picture>''';

// XML's insertBefore can't have a newline at the end:
const String _indexHtmlBrandingPicture = '''
<picture id="splash-branding">
<picture id="splash-branding">
<source srcset="splash/img/branding-1x.[BRANDINGEXTENSION] 1x, splash/img/branding-2x.[BRANDINGEXTENSION] 2x, splash/img/branding-3x.[BRANDINGEXTENSION] 3x, splash/img/branding-4x.[BRANDINGEXTENSION] 4x" media="(prefers-color-scheme: light)">
<source srcset="splash/img/branding-dark-1x.[BRANDINGEXTENSION] 1x, splash/img/branding-dark-2x.[BRANDINGEXTENSION] 2x, splash/img/branding-dark-3x.[BRANDINGEXTENSION] 3x, splash/img/branding-dark-4x.[BRANDINGEXTENSION] 4x" media="(prefers-color-scheme: dark)">
<img class="[BRANDINGMODE]" aria-hidden="true" src="splash/img/branding-1x.[BRANDINGEXTENSION]" alt=""/>
</picture>''';

const String _webJS = '''
<script id="splash-screen-script">
<script id="splash-screen-script">
function removeSplashFromWeb() {
document.getElementById("splash")?.remove();
document.getElementById("splash-branding")?.remove();
document.body.style.background = "transparent";
}
</script>
''';
</script>''';
122 changes: 80 additions & 42 deletions lib/web.dart
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ void _createWebSplash({
)
?.remove();
document.querySelector('script[src="splash/splash.js"]')?.remove();
document.querySelector('picture#splash')?.remove();
document.querySelector('picture#splash-branding')?.remove();
document.querySelector('div#splash')?.remove();
webIndex.writeAsStringSync(document.outerHtml);
return;
Expand Down Expand Up @@ -296,18 +294,26 @@ void _createSplashCss({
);
}

cssContent += ' </style>\n';
cssContent += ' </style>';

// Add css as an inline style in head tag
final webIndex = File(_webIndex);
final document = html_parser.parse(webIndex.readAsStringSync());

// Update splash css style tag
document.head
?..querySelector('style#splash-screen-style')?.remove()
..append(
html_parser.parseFragment(cssContent, container: ''),
);
Element? splashScreenStyle =
document.querySelector('style#splash-screen-style');
if (splashScreenStyle == null) {
document.head?.append(html_parser.parseFragment(
"\n $cssContent",
container: '',
));
} else {
splashScreenStyle.replaceWith(html_parser.parseFragment(
cssContent,
container: '',
));
}

// Write the updated index.html
webIndex.writeAsStringSync(document.outerHtml);
Expand All @@ -319,11 +325,19 @@ void _createSplashJs() {
final document = html_parser.parse(webIndex.readAsStringSync());

// Update splash js script tag
document.head
?..querySelector('script#splash-screen-script')?.remove()
..append(
html_parser.parseFragment(_webJS, container: ''),
);
Element? splashScreenScript =
document.querySelector('script#splash-screen-script');
if (splashScreenScript == null) {
document.head?.append(html_parser.parseFragment(
"\n\n $_webJS\n",
container: '',
));
} else {
splashScreenScript.replaceWith(html_parser.parseFragment(
_webJS,
container: '',
));
}

// Write the updated index.html
webIndex.writeAsStringSync(document.outerHtml);
Expand Down Expand Up @@ -365,40 +379,64 @@ void _updateHtml({
?.remove();

// Update splash image
document.querySelector('picture#splash')?.remove();
document.querySelector('div#splash')?.remove();
if (imagePath != null) {
document.body?.insertBefore(
html_parser.parseFragment(
'\n${_indexHtmlPicture.replaceAll(
'[IMAGEMODE]',
imageMode,
).replaceAll(
'[IMAGEEXTENSION]',
imagePath.endsWith('.gif') ? 'gif' : 'png',
)}',
Element? splashPicture = document.querySelector('picture#splash');
if (imagePath == null) {
splashPicture?.remove();
} else {
final fragmentContent = _indexHtmlPicture
.replaceAll(
'[IMAGEMODE]',
imageMode,
)
.replaceAll(
'[IMAGEEXTENSION]',
imagePath.endsWith('.gif') ? 'gif' : 'png',
);
if (splashPicture == null) {
document.body?.insertBefore(
html_parser.parseFragment(
"\n $fragmentContent\n",
container: '',
),
document.body?.firstChild,
);
} else {
splashPicture.replaceWith(html_parser.parseFragment(
fragmentContent,
container: '',
),
document.body?.firstChild,
);
));
}
}

// Update branding image
document.querySelector('picture#splash-branding')?.remove();
if (brandingImagePath != null) {
document.body?.insertBefore(
html_parser.parseFragment(
'\n${_indexHtmlBrandingPicture.replaceAll(
'[BRANDINGMODE]',
brandingMode,
).replaceAll(
'[BRANDINGEXTENSION]',
brandingImagePath.endsWith('.gif') ? 'gif' : 'png',
)}',
Element? splashBrandingPicture =
document.querySelector('picture#splash-branding');
if (brandingImagePath == null) {
splashBrandingPicture?.remove();
} else {
final fragmentContent = _indexHtmlBrandingPicture
.replaceAll(
'[BRANDINGMODE]',
brandingMode,
)
.replaceAll(
'[BRANDINGEXTENSION]',
brandingImagePath.endsWith('.gif') ? 'gif' : 'png',
);
if (splashBrandingPicture == null) {
document.body?.insertBefore(
html_parser.parseFragment(
"\n $fragmentContent\n",
container: '',
),
document.body?.firstChild,
);
} else {
splashBrandingPicture.replaceWith(html_parser.parseFragment(
fragmentContent,
container: '',
),
document.body?.firstChild,
);
));
}
}

// Write the updated index.html
Expand Down