namirasoft-site-react 1.4.329 → 1.4.331
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { NSBarNotificationProps } from "../components/NSBarNotification";
|
|
2
2
|
import { IStorage } from "namirasoft-core";
|
|
3
3
|
export declare class NSNotifier {
|
|
4
|
+
private static mutex_mofify;
|
|
5
|
+
private static mutex_set;
|
|
4
6
|
private storage;
|
|
5
7
|
private setState;
|
|
6
8
|
timeout: number;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import { NSBarNotificationColor, NotificationType } from "../components/NSBarNotification";
|
|
3
3
|
import { BaseUUID, TimeOperation } from "namirasoft-core";
|
|
4
|
+
import { Mutex } from 'async-mutex';
|
|
4
5
|
export class NSNotifier {
|
|
5
6
|
constructor(storage, setState) {
|
|
6
7
|
this.timeout = 5000;
|
|
@@ -20,6 +21,7 @@ export class NSNotifier {
|
|
|
20
21
|
let value = this.storage.get("ns-notifications", "");
|
|
21
22
|
if (value)
|
|
22
23
|
ans = JSON.parse(value);
|
|
24
|
+
console.log("getNotification-Before", ans);
|
|
23
25
|
let now = new Date();
|
|
24
26
|
ans = ans.filter(x => {
|
|
25
27
|
if (x.expired_at) {
|
|
@@ -28,25 +30,36 @@ export class NSNotifier {
|
|
|
28
30
|
}
|
|
29
31
|
return false;
|
|
30
32
|
});
|
|
33
|
+
console.log("getNotification-After", ans);
|
|
31
34
|
return ans;
|
|
32
35
|
}
|
|
33
36
|
setNotifications(notifications) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
n.expired_at
|
|
37
|
+
NSNotifier.mutex_set.runExclusive(() => {
|
|
38
|
+
notifications.forEach(n => {
|
|
39
|
+
if (!n.expired_at)
|
|
40
|
+
n.expired_at = TimeOperation.millisecondsLater(this.timeout, new Date());
|
|
41
|
+
});
|
|
42
|
+
this.storage.set("ns-notifications", JSON.stringify(notifications));
|
|
43
|
+
this.setState();
|
|
37
44
|
});
|
|
38
|
-
this.storage.set("ns-notifications", JSON.stringify(notifications));
|
|
39
|
-
this.setState();
|
|
40
45
|
}
|
|
41
46
|
delNotification(id) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
NSNotifier.mutex_mofify.runExclusive(() => {
|
|
48
|
+
console.log("delNotification-Before", id);
|
|
49
|
+
let notifications = this.getNotifications();
|
|
50
|
+
let tobedeleted = notifications.filter(x => x.id === id);
|
|
51
|
+
notifications = notifications.filter(x => x.id !== id);
|
|
52
|
+
this.setNotifications(notifications);
|
|
53
|
+
console.log("delNotification-After", tobedeleted);
|
|
54
|
+
});
|
|
45
55
|
}
|
|
46
56
|
notify(message) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
57
|
+
NSNotifier.mutex_mofify.runExclusive(() => {
|
|
58
|
+
console.log("notify", message);
|
|
59
|
+
let notifications = this.getNotifications();
|
|
60
|
+
notifications.push(message);
|
|
61
|
+
this.setNotifications(notifications);
|
|
62
|
+
});
|
|
50
63
|
setTimeout(() => {
|
|
51
64
|
this.delNotification(message.id);
|
|
52
65
|
}, this.timeout);
|
|
@@ -79,4 +92,6 @@ export class NSNotifier {
|
|
|
79
92
|
this.notify({ id, text, type: NotificationType.Error, color: NSBarNotificationColor.RED });
|
|
80
93
|
}
|
|
81
94
|
}
|
|
95
|
+
NSNotifier.mutex_mofify = new Mutex();
|
|
96
|
+
NSNotifier.mutex_set = new Mutex();
|
|
82
97
|
//# sourceMappingURL=NSNotifier.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NSNotifier.js","sourceRoot":"","sources":["../../src/routing/NSNotifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,sBAAsB,EAA0B,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnH,OAAO,EAAE,QAAQ,EAAY,aAAa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,KAAK,EAAE,AAArB,CAAsB"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import { NSBarNotificationColor, NSBarNotificationProps, NotificationType } from "../components/NSBarNotification";
|
|
3
3
|
import { BaseUUID, IStorage, TimeOperation } from "namirasoft-core";
|
|
4
|
+
import { Mutex } from 'async-mutex';
|
|
4
5
|
|
|
5
6
|
export class NSNotifier
|
|
6
7
|
{
|
|
8
|
+
private static mutex_mofify: Mutex = new Mutex();
|
|
9
|
+
private static mutex_set: Mutex = new Mutex();
|
|
7
10
|
private storage: IStorage;
|
|
8
11
|
private setState: () => void;
|
|
9
12
|
public timeout: number = 5000;
|
|
@@ -26,6 +29,8 @@ export class NSNotifier
|
|
|
26
29
|
let value = this.storage.get("ns-notifications", "");
|
|
27
30
|
if (value)
|
|
28
31
|
ans = JSON.parse(value);
|
|
32
|
+
|
|
33
|
+
console.log("getNotification-Before", ans);
|
|
29
34
|
let now = new Date();
|
|
30
35
|
ans = ans.filter(x =>
|
|
31
36
|
{
|
|
@@ -36,29 +41,43 @@ export class NSNotifier
|
|
|
36
41
|
}
|
|
37
42
|
return false;
|
|
38
43
|
})
|
|
44
|
+
console.log("getNotification-After", ans);
|
|
39
45
|
return ans;
|
|
40
46
|
}
|
|
41
47
|
setNotifications(notifications: NSBarNotificationProps[]): void
|
|
42
48
|
{
|
|
43
|
-
|
|
49
|
+
NSNotifier.mutex_set.runExclusive(() =>
|
|
44
50
|
{
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
notifications.forEach(n =>
|
|
52
|
+
{
|
|
53
|
+
if (!n.expired_at)
|
|
54
|
+
n.expired_at = TimeOperation.millisecondsLater(this.timeout, new Date());
|
|
55
|
+
});
|
|
56
|
+
this.storage.set("ns-notifications", JSON.stringify(notifications));
|
|
57
|
+
this.setState();
|
|
47
58
|
});
|
|
48
|
-
this.storage.set("ns-notifications", JSON.stringify(notifications));
|
|
49
|
-
this.setState();
|
|
50
59
|
}
|
|
51
60
|
delNotification(id: string): void
|
|
52
61
|
{
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
NSNotifier.mutex_mofify.runExclusive(() =>
|
|
63
|
+
{
|
|
64
|
+
console.log("delNotification-Before", id);
|
|
65
|
+
let notifications: NSBarNotificationProps[] = this.getNotifications();
|
|
66
|
+
let tobedeleted = notifications.filter(x => x.id === id);
|
|
67
|
+
notifications = notifications.filter(x => x.id !== id);
|
|
68
|
+
this.setNotifications(notifications);
|
|
69
|
+
console.log("delNotification-After", tobedeleted);
|
|
70
|
+
});
|
|
56
71
|
}
|
|
57
72
|
private notify(message: NSBarNotificationProps)
|
|
58
73
|
{
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
74
|
+
NSNotifier.mutex_mofify.runExclusive(() =>
|
|
75
|
+
{
|
|
76
|
+
console.log("notify", message);
|
|
77
|
+
let notifications: NSBarNotificationProps[] = this.getNotifications();
|
|
78
|
+
notifications.push(message);
|
|
79
|
+
this.setNotifications(notifications);
|
|
80
|
+
});
|
|
62
81
|
setTimeout(() =>
|
|
63
82
|
{
|
|
64
83
|
this.delNotification(message.id);
|