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
66 changes: 64 additions & 2 deletions .dart_tool/package_config.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,76 @@
{
"configVersion": 2,
"packages": [
{
"name": "args",
"rootUri": "file:///Users/christianpauly/.pub-cache/hosted/pub.dev/args-2.7.0",
"packageUri": "lib/",
"languageVersion": "3.3"
},
{
"name": "collection",
"rootUri": "file:///Users/christianpauly/.pub-cache/hosted/pub.dev/collection-1.19.1",
"packageUri": "lib/",
"languageVersion": "3.4"
},
{
"name": "import_sorter",
"rootUri": "file:///Users/christianpauly/.pub-cache/hosted/pub.dev/import_sorter-4.6.0",
"packageUri": "lib/",
"languageVersion": "2.12"
},
{
"name": "path",
"rootUri": "file:///Users/christianpauly/.pub-cache/hosted/pub.dev/path-1.9.1",
"packageUri": "lib/",
"languageVersion": "3.4"
},
{
"name": "source_span",
"rootUri": "file:///Users/christianpauly/.pub-cache/hosted/pub.dev/source_span-1.10.1",
"packageUri": "lib/",
"languageVersion": "3.1"
},
{
"name": "string_scanner",
"rootUri": "file:///Users/christianpauly/.pub-cache/hosted/pub.dev/string_scanner-1.4.1",
"packageUri": "lib/",
"languageVersion": "3.1"
},
{
"name": "term_glyph",
"rootUri": "file:///Users/christianpauly/.pub-cache/hosted/pub.dev/term_glyph-1.2.2",
"packageUri": "lib/",
"languageVersion": "3.1"
},
{
"name": "tint",
"rootUri": "file:///Users/christianpauly/.pub-cache/hosted/pub.dev/tint-2.0.1",
"packageUri": "lib/",
"languageVersion": "2.18"
},
{
"name": "web",
"rootUri": "file:///Users/christianpauly/.pub-cache/hosted/pub.dev/web-1.1.1",
"packageUri": "lib/",
"languageVersion": "3.4"
},
{
"name": "yaml",
"rootUri": "file:///Users/christianpauly/.pub-cache/hosted/pub.dev/yaml-3.1.3",
"packageUri": "lib/",
"languageVersion": "3.4"
},
{
"name": "web_multiple_tab_detector",
"rootUri": "../",
"packageUri": "lib/",
"languageVersion": "2.12"
}
],
"generated": "2022-02-16T08:12:09.964550Z",
"generator": "pub",
"generatorVersion": "2.16.1"
"generatorVersion": "3.10.4",
"flutterRoot": "file:///Users/christianpauly/develop/flutter",
"flutterVersion": "3.38.5",
"pubCache": "file:///Users/christianpauly/.pub-cache"
}
82 changes: 82 additions & 0 deletions .dart_tool/package_graph.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"roots": [
"web_multiple_tab_detector"
],
"packages": [
{
"name": "web_multiple_tab_detector",
"version": "0.3.0",
"dependencies": [
"web"
],
"devDependencies": [
"import_sorter"
]
},
{
"name": "import_sorter",
"version": "4.6.0",
"dependencies": [
"args",
"tint",
"yaml"
]
},
{
"name": "web",
"version": "1.1.1",
"dependencies": []
},
{
"name": "tint",
"version": "2.0.1",
"dependencies": []
},
{
"name": "yaml",
"version": "3.1.3",
"dependencies": [
"collection",
"source_span",
"string_scanner"
]
},
{
"name": "string_scanner",
"version": "1.4.1",
"dependencies": [
"source_span"
]
},
{
"name": "source_span",
"version": "1.10.1",
"dependencies": [
"collection",
"path",
"term_glyph"
]
},
{
"name": "term_glyph",
"version": "1.2.2",
"dependencies": []
},
{
"name": "path",
"version": "1.9.1",
"dependencies": []
},
{
"name": "collection",
"version": "1.19.1",
"dependencies": []
},
{
"name": "args",
"version": "2.7.0",
"dependencies": []
}
],
"configVersion": 1
}
Binary file not shown.
27 changes: 27 additions & 0 deletions .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 0 additions & 18 deletions .github/workflows/main.yml

This file was deleted.

1 change: 1 addition & 0 deletions .github/workflows/versions.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dart_version=3.10.4
15 changes: 0 additions & 15 deletions .gitlab-ci.yml

This file was deleted.

28 changes: 17 additions & 11 deletions lib/src/web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

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=';
Expand All @@ -32,15 +34,15 @@ 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;
}
}

void setTabs(String name, int number) {
window.localStorage[name] = number.toString();
web.window.localStorage.setItem(name, number.toString());
}

bool _pongReceived = false;
Expand All @@ -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<bool> isSingleTab(String name) async {
Expand All @@ -74,8 +80,8 @@ Future<bool> 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));
Expand Down
4 changes: 4 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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