diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json
deleted file mode 100644
index 367ed03..0000000
--- a/.dart_tool/package_config.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "configVersion": 2,
- "packages": [
- {
- "name": "web_multiple_tab_detector",
- "rootUri": "../",
- "packageUri": "lib/",
- "languageVersion": "2.12"
- }
- ],
- "generated": "2022-02-16T08:12:09.964550Z",
- "generator": "pub",
- "generatorVersion": "2.16.1"
-}
diff --git a/.github/workflows/integrate.yml b/.github/workflows/integrate.yml
new file mode 100644
index 0000000..a3e84f8
--- /dev/null
+++ b/.github/workflows/integrate.yml
@@ -0,0 +1,27 @@
+name: Continious Integration
+
+on:
+ push:
+ branches:
+ - main
+ pull_request:
+ merge_group:
+
+concurrency:
+ group: ${{ github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ dart:
+ permissions:
+ contents: read
+ uses: famedly/frontend-ci-templates/.github/workflows/dart.yml@main
+ with:
+ env_file: ".github/workflows/versions.env"
+ secrets:
+ ssh_key: "${{ secrets.CI_SSH_PRIVATE_KEY }}"
+
+ general:
+ permissions:
+ contents: read
+ uses: famedly/frontend-ci-templates/.github/workflows/general.yml@main
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
deleted file mode 100644
index 92a7abd..0000000
--- a/.github/workflows/main.yml
+++ /dev/null
@@ -1,18 +0,0 @@
-name: Add issues to Product Management Project.
-
-on:
- issues:
- types:
- - opened
-
-jobs:
- add-to-project:
- name: Add issue to project
- runs-on: ubuntu-latest
- steps:
- - uses: actions/add-to-project@v0.5.0
- with:
- # You can target a repository in a different organization
- # to the issue
- project-url: https://github.com/orgs/famedly/projects/4
- github-token: ${{ secrets.ADD_ISSUE_TO_PROJECT_PAT }}
diff --git a/.github/workflows/versions.env b/.github/workflows/versions.env
new file mode 100644
index 0000000..c65fc3a
--- /dev/null
+++ b/.github/workflows/versions.env
@@ -0,0 +1 @@
+dart_version=3.10.4
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 93d2a1e..2ded13c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
.packages
pubspec.lock
+.dart_tool/
\ No newline at end of file
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
deleted file mode 100644
index 688dab7..0000000
--- a/.gitlab-ci.yml
+++ /dev/null
@@ -1,15 +0,0 @@
-image:
- name: registry.gitlab.com/famedly/containers/flutter-dockerimages:stable
-
-variables:
- GIT_SUBMODULE_STRATEGY: recursive
-
-stages:
-- coverage
-- publish
-
-code_analyze:
- stage: coverage
- script:
- - flutter format lib/ --set-exit-if-changed
- - flutter analyze
diff --git a/lib/src/web.dart b/lib/src/web.dart
index b92b033..a827fa2 100644
--- a/lib/src/web.dart
+++ b/lib/src/web.dart
@@ -16,9 +16,11 @@
* along with this program. If not, see .
*/
-import 'dart:html';
+import 'dart:js_interop';
import 'dart:math';
+import 'package:web/web.dart' as web;
+
String randomString([int length = 50]) {
var result = '';
final chars = 'abcdefghijklmnopqrstuvwxyz-_1234567890=';
@@ -32,7 +34,7 @@ String randomString([int length = 50]) {
int getTabs(String name) {
try {
- final n = int.parse(window.localStorage[name]!);
+ final n = int.parse(web.window.localStorage.getItem(name)!);
return n < 0 ? 0 : n;
} catch (_) {
return 0;
@@ -40,7 +42,7 @@ int getTabs(String name) {
}
void setTabs(String name, int number) {
- window.localStorage[name] = number.toString();
+ web.window.localStorage.setItem(name, number.toString());
}
bool _pongReceived = false;
@@ -50,22 +52,26 @@ void register(String name) {
_instanceId = randomString();
setTabs(name, getTabs(name) + 1);
- window.onUnload.listen((_) {
+ void onUnloadCallback(web.Event event) {
setTabs(name, getTabs(name) - 1);
- });
+ }
+
+ web.window.onunload = onUnloadCallback.toJS;
- window.onStorage.listen((evt) {
+ void onStorageCallback(web.StorageEvent evt) {
if (evt.key == '$name-ping') {
final val = evt.newValue!;
if (val.split('|')[0] != _instanceId) {
- window.localStorage['$name-pong'] =
- _instanceId + '|' + DateTime.now().toString();
+ web.window.localStorage.setItem(
+ '$name-pong', _instanceId + '|' + DateTime.now().toString());
}
}
if (evt.key == '$name-pong') {
_pongReceived = true;
}
- });
+ }
+
+ web.window.onstorage = onStorageCallback.toJS;
}
Future isSingleTab(String name) async {
@@ -74,8 +80,8 @@ Future isSingleTab(String name) async {
return true;
}
// send ping to other tabs
- window.localStorage['$name-ping'] =
- _instanceId + '|' + DateTime.now().toString();
+ web.window.localStorage
+ .setItem('$name-ping', _instanceId + '|' + DateTime.now().toString());
int counter = 100;
while (!_pongReceived && counter > 0) {
await Future.delayed(Duration(milliseconds: 50));
diff --git a/pubspec.yaml b/pubspec.yaml
index 019d3d3..a406033 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -6,3 +6,7 @@ repository: https://gitlab.com/famedly/libraries/web_multiple_tab_detector
environment:
sdk: ">=2.12.0 <3.0.0"
+dependencies:
+ web: ^1.1.1
+dev_dependencies:
+ import_sorter: ^4.6.0