Skip to content

Commit 3b188da

Browse files
committed
update to test new module import
1 parent d6ad3d9 commit 3b188da

File tree

3 files changed

+32
-41
lines changed

3 files changed

+32
-41
lines changed

dargon2_flutter/dargon2_flutter/pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ dependencies:
3232
dargon2_flutter_platform_interface: '^3.1.0'
3333
dargon2_flutter_mobile: '^3.1.0'
3434
dargon2_flutter_desktop: '^3.1.0'
35-
dargon2_flutter_web: '^3.1.0'
35+
dargon2_flutter_web:
36+
path: ../dargon2_flutter_web
3637
dargon2_interface: '^1.1.0'
3738

3839

dargon2_flutter/dargon2_flutter_web/lib/src/argon2.dart

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,12 @@ class DArgon2FlutterWeb extends DArgon2Platform {
2727

2828
/// The static hashwasm URL to use when getting the script.
2929
static const hashwasm =
30-
"https://cdn.jsdelivr.net/npm/hash-wasm@4.8.0/dist/argon2.umd.min";
30+
"https://cdn.jsdelivr.net/npm/hash-wasm@4.9.0/+esm";
3131

3232
/// The [DArgon2FlutterWeb] constructor. Needed to set the global hashwasm
3333
/// variable to the right script.
3434
DArgon2FlutterWeb() {
35-
if (context['require'] != null) {
36-
_registerRequire();
37-
} else {
38-
_registerNormal();
39-
}
35+
_registerDependency();
4036
}
4137

4238
@override
@@ -110,52 +106,46 @@ class DArgon2FlutterWeb extends DArgon2Platform {
110106
return current;
111107
}
112108

113-
/// Registers the hashwasm argon2 implementation in release or script-loaded
114-
/// environments by adding a script tag with the dependency.
115-
void _registerNormal() async {
116-
print("NORMAL");
117-
// Create the script element
118-
ScriptElement script = ScriptElement();
119-
script.type = "text/javascript";
120-
script.charset = "utf-8";
121-
script.async = true;
122-
script.src = "$hashwasm.js";
123-
// Add it to the document head
124-
assert(document.head != null);
125-
document.head!.append(script);
126-
// await its load
127-
await script.onLoad.first;
128-
}
129-
130109
/// Registers the hashwasm argon2 implementation in debug or requirejs loaded
131110
/// environments as adding the script tag would not suffice then.
132111
///
133112
/// Adds it as a require.js dependency and sets the global hashwasm variable
134113
/// to the require app.
135-
void _registerRequire() async {
114+
void _registerDependency() async {
136115
// Make sure it's not already there
137116
if (context['hashwasm'] != null) return;
138-
// Get the require object
139-
JsObject require = JsObject.fromBrowserObject(context['require']);
140-
// Add the script to the config
141-
require.callMethod('config', [
142-
JsObject.jsify({
143-
'paths': {"hashwasm": hashwasm}
144-
})
145-
]);
117+
118+
String windowVar = "hashwasm";
119+
120+
ScriptElement script = ScriptElement();
121+
script.type = 'text/javascript';
122+
script.crossOrigin = 'anonymous';
123+
script.text = '''
124+
window.trigger_$windowVar = async (callback) => {
125+
let {argon2i, argon2d, argon2id} = await import($hashwasm);
126+
callback([argon2i, argon2d, argon2id]);
127+
};
128+
''';
129+
130+
assert(document.head != null);
131+
document.head!.append(script);
146132
Completer completer = Completer();
147-
List<String> services = ['hashwasm'];
148-
// Load the script
149-
context.callMethod('require', [
150-
JsObject.jsify(services),
151-
(app) {
152-
// Set it to the global variable
153-
context['hashwasm'] = app;
133+
134+
context.callMethod('trigger_$windowVar', [
135+
(module) {
136+
context[windowVar] = JsObject.jsify({
137+
"argon2i": module[0],
138+
"argon2d": module[1],
139+
"argon2id": module[2],
140+
});
141+
context.deleteProperty('trigger_$windowVar');
154142
completer.complete();
155143
}
156144
]);
145+
157146
await completer.future;
158147
}
148+
159149
}
160150

161151
/// JS interop binding to call the hashwasm argon2i hash function.

dargon2_flutter/dargon2_flutter_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies:
2020
dev_dependencies:
2121
flutter_test:
2222
sdk: flutter
23-
flutter_lints: ^1.0.0
23+
flutter_lints: ^2.0.1
2424

2525
# For information on the generic Dart part of this file, see the
2626
# following page: https://dart.dev/tools/pub/pubspec

0 commit comments

Comments
 (0)