Skip to content

Commit

Permalink
web: migrate from dart:html to package:web (for wasm support).
Browse files Browse the repository at this point in the history
  • Loading branch information
hpoul committed May 21, 2024
1 parent 904d043 commit a0933ca
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 48 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
## 5.1.0-rc.2
## 5.1.0-rc.3

* Split Split authenticationValidityDurationSeconds between android and iOS
* `darwinTouchIDAuthenticationForceReuseContextDuration`: Basically the equivalent to `androidAuthenticationValidityDuration`
* `darwinTouchIDAuthenticationAllowableReuseDuration`
* android: return correct code if no biometric is enrolled #115 @ThomasLamprecht
* web: migrate from dart:html to package:web (for wasm support).

## 5.0.1

Expand Down
24 changes: 22 additions & 2 deletions example/.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,27 @@
# This file should be version controlled and should not be manually edited.

version:
revision: 4984d1a33dd6de2862578e3f08b4ca7dfce7d54b
channel: dev
revision: "5dcb86f68f239346676ceb1ed1ea385bd215fba1"
channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
- platform: web
create_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1
base_revision: 5dcb86f68f239346676ceb1ed1ea385bd215fba1

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
17 changes: 0 additions & 17 deletions example/lib/generated_plugin_registrant.dart

This file was deleted.

10 changes: 9 additions & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ packages:
path: ".."
relative: true
source: path
version: "5.0.1"
version: "5.1.0-rc.2"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -276,6 +276,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "14.2.1"
web:
dependency: transitive
description:
name: web
sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
win32:
dependency: transitive
description:
Expand Down
Binary file added example/web/icons/Icon-maskable-192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/web/icons/Icon-maskable-512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 20 additions & 15 deletions example/web/index.html
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
<!DOCTYPE html>
<html>
<head>
<!--
If you are serving your web app in a path other than the root, change the
href value below to reflect the base path you are serving from.
The path provided below has to start and end with a slash "/" in order for
it to work correctly.
For more details:
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
This is a placeholder for base href that will be replaced by the value of
the `--base-href` argument provided to `flutter build`.
-->
<base href="$FLUTTER_BASE_HREF">

<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="Demonstrates how to use the biometric_storage plugin.">
<meta name="description" content="A new Flutter project.">

<!-- iOS meta tags & icons -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="biometric_storage_example">
<meta name="apple-mobile-web-app-title" content="example">
<link rel="apple-touch-icon" href="icons/Icon-192.png">

<!-- Favicon -->
<link rel="shortcut icon" type="image/png" href="favicon.png"/>
<link rel="icon" type="image/png" href="favicon.png"/>

<title>biometric_storage_example</title>
<title>example</title>
<link rel="manifest" href="manifest.json">
</head>
<body>
<!-- This script installs service_worker.js to provide PWA functionality to
application. For more information, see:
https://developers.google.com/web/fundamentals/primers/service-workers -->
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('flutter_service_worker.js');
});
}
</script>
<script src="main.dart.js" type="application/javascript"></script>
<script src="flutter_bootstrap.js" async></script>
</body>
</html>
18 changes: 15 additions & 3 deletions example/web/manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "biometric_storage_example",
"short_name": "biometric_storage_example",
"name": "example",
"short_name": "example",
"start_url": ".",
"display": "standalone",
"background_color": "#0175C2",
"theme_color": "#0175C2",
"description": "Demonstrates how to use the biometric_storage plugin.",
"description": "A new Flutter project.",
"orientation": "portrait-primary",
"prefer_related_applications": false,
"icons": [
Expand All @@ -18,6 +18,18 @@
"src": "icons/Icon-512.png",
"sizes": "512x512",
"type": "image/png"
},
{
"src": "icons/Icon-maskable-192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "icons/Icon-maskable-512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
}
]
}
14 changes: 6 additions & 8 deletions lib/src/biometric_storage_web.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import 'dart:async';
// In order to *not* need this ignore, consider extracting the "web" version
// of your plugin as a separate package, instead of inlining it in the same
// package as the core of your plugin.
// ignore: avoid_web_libraries_in_flutter
import 'dart:html' as html show window;
import 'package:web/web.dart' as web show window;

import 'package:biometric_storage/src/biometric_storage.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
Expand Down Expand Up @@ -37,7 +33,9 @@ class BiometricStoragePluginWeb extends BiometricStorage {
String name,
PromptInfo promptInfo,
) async {
return html.window.localStorage.remove(name) != null;
final oldValue = web.window.localStorage.getItem(name);
web.window.localStorage.removeItem(name);
return oldValue != null;
}

@override
Expand All @@ -48,7 +46,7 @@ class BiometricStoragePluginWeb extends BiometricStorage {
String name,
PromptInfo promptInfo,
) async {
return html.window.localStorage[name];
return web.window.localStorage.getItem(name);
}

@override
Expand All @@ -57,6 +55,6 @@ class BiometricStoragePluginWeb extends BiometricStorage {
String content,
PromptInfo promptInfo,
) async {
html.window.localStorage[name] = content;
web.window.localStorage.setItem(name, content);
}
}
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: biometric_storage
description: |
Secure Storage: Encrypted data store optionally secured by biometric lock with support
for iOS, Android, MacOS. Partial support for Linux, Windows and web (localStorage).
version: 5.1.0-rc.2
version: 5.1.0-rc.3
homepage: https://github.com/authpass/biometric_storage/

environment:
Expand All @@ -19,6 +19,7 @@ dependencies:

ffi: '>=1.0.0 <3.0.0'
win32: '>=2.0.0 <6.0.0'
web: ">=0.5.0 <1.0.0"

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit a0933ca

Please sign in to comment.