Skip to content

Commit 1afaa15

Browse files
committed
v8.5.0
1 parent dbcedf8 commit 1afaa15

File tree

12 files changed

+183
-19
lines changed

12 files changed

+183
-19
lines changed

build/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/fav.png

21.9 KB
Loading

demo/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,300;0,500;0,700;0,800;1,400&display=swap"
1111
rel="stylesheet"
1212
/>
13+
<link rel="icon" type="image/x-icon" href="fav.png">
1314
<script
1415
src="https://kit.fontawesome.com/0a1af2edbf.js"
1516
crossorigin="anonymous"

demo/main.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const Gleap = window.Gleap;
22

3-
// Gleap.setFrameUrl("http://0.0.0.0:3001");
4-
// Gleap.setApiUrl("http://0.0.0.0:9000");
5-
Gleap.initialize("ogWhNhuiZcGWrva5nlDS8l7a78OfaLlV");
3+
Gleap.setFrameUrl("http://0.0.0.0:3001");
4+
Gleap.setApiUrl("http://0.0.0.0:9000");
5+
Gleap.initialize("DUPaIr7s689BBblcFI4pc5aBgYJTm7Sc");
66
//Gleap.setEnvironment("dev");
77

88
Gleap.attachCustomData({
@@ -14,6 +14,8 @@ Gleap.attachCustomData({
1414
},
1515
});
1616

17+
Gleap.showTabNotificationBadge(true);
18+
1719
Gleap.log("Test log");
1820
Gleap.log("Test log info", "INFO");
1921
Gleap.log("Test log warn", "WARNING");

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export namespace Gleap {
6161
function enableShortcuts(enabled: boolean): void;
6262
function setLanguage(language: string): void;
6363
function preFillForm(data: object): void;
64+
function showTabNotificationBadge(showNotificationBadge: boolean): void;
6465
function attachNetworkLogs(networkLogs: string): void;
6566
function clearIdentity(): void;
6667
function identify(

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gleap",
3-
"version": "8.4.7",
3+
"version": "8.5.0",
44
"main": "build/index.js",
55
"scripts": {
66
"start": "webpack serve",

published/8.5.0/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

published/latest/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Gleap.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,17 @@ class Gleap {
388388
GleapCustomDataManager.getInstance().clearCustomData();
389389
}
390390

391+
/**
392+
* Show or hide the notification badge count.
393+
* @param {boolean} showNotificationBadge show or hide the notification badge
394+
*
395+
*/
396+
static showTabNotificationBadge(showNotificationBadge) {
397+
const notificationInstance = GleapNotificationManager.getInstance();
398+
notificationInstance.showNotificationBadge = showNotificationBadge;
399+
notificationInstance.updateTabBarNotificationCount();
400+
}
401+
391402
/**
392403
* Override the browser language.
393404
* @param {string} language country code with two letters

src/GleapNotificationBadge.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/**
2+
* Add notification badge (pill) to favicon in browser tab
3+
* @url stackoverflow.com/questions/65719387/
4+
*/
5+
export default class GleapNotificationBadge {
6+
constructor(options) {
7+
Object.assign(
8+
this, {
9+
backgroundColor: "#f00",
10+
color: "#fff",
11+
size: 0.6,
12+
position: "se",
13+
radius: 8,
14+
src: "",
15+
onChange() { },
16+
},
17+
options
18+
);
19+
this.canvas = document.createElement("canvas");
20+
this.src = this.src || this.faviconEL.getAttribute("href");
21+
this.ctx = this.canvas.getContext("2d");
22+
}
23+
24+
faviconEL = document.querySelector("link[rel$=icon]");
25+
26+
_drawIcon() {
27+
this.ctx.clearRect(0, 0, this.faviconSize, this.faviconSize);
28+
this.ctx.drawImage(this.img, 0, 0, this.faviconSize, this.faviconSize);
29+
}
30+
31+
_drawShape() {
32+
const r = this.radius;
33+
const xa = this.offset.x;
34+
const ya = this.offset.y;
35+
const xb = this.offset.x + this.badgeSize;
36+
const yb = this.offset.y + this.badgeSize;
37+
this.ctx.beginPath();
38+
this.ctx.moveTo(xb - r, ya);
39+
this.ctx.quadraticCurveTo(xb, ya, xb, ya + r);
40+
this.ctx.lineTo(xb, yb - r);
41+
this.ctx.quadraticCurveTo(xb, yb, xb - r, yb);
42+
this.ctx.lineTo(xa + r, yb);
43+
this.ctx.quadraticCurveTo(xa, yb, xa, yb - r);
44+
this.ctx.lineTo(xa, ya + r);
45+
this.ctx.quadraticCurveTo(xa, ya, xa + r, ya);
46+
this.ctx.fillStyle = this.backgroundColor;
47+
this.ctx.fill();
48+
this.ctx.closePath();
49+
}
50+
51+
_drawVal() {
52+
const margin = (this.badgeSize * 0.18) / 2;
53+
this.ctx.beginPath();
54+
this.ctx.textBaseline = "middle";
55+
this.ctx.textAlign = "center";
56+
this.ctx.font = `bold ${this.badgeSize * 0.82}px Arial`;
57+
this.ctx.fillStyle = this.color;
58+
this.ctx.fillText(this.value, this.badgeSize / 2 + this.offset.x, this.badgeSize / 2 + this.offset.y + margin);
59+
this.ctx.closePath();
60+
}
61+
62+
_drawFavicon() {
63+
this.faviconEL.setAttribute("href", this.dataURL);
64+
}
65+
66+
_draw() {
67+
this._drawIcon();
68+
if (this.value) this._drawShape();
69+
if (this.value) this._drawVal();
70+
this._drawFavicon();
71+
}
72+
73+
_setup() {
74+
this.faviconSize = this.img.naturalWidth;
75+
this.badgeSize = this.faviconSize * this.size;
76+
this.canvas.width = this.faviconSize;
77+
this.canvas.height = this.faviconSize;
78+
const sd = this.faviconSize - this.badgeSize;
79+
const sd2 = sd / 2;
80+
this.offset = {
81+
n: { x: sd2, y: 0 },
82+
e: { x: sd, y: sd2 },
83+
s: { x: sd2, y: sd },
84+
w: { x: 0, y: sd2 },
85+
nw: { x: 0, y: 0 },
86+
ne: { x: sd, y: 0 },
87+
sw: { x: 0, y: sd },
88+
se: { x: sd, y: sd },
89+
}[this.position];
90+
}
91+
92+
// Public functions / methods:
93+
94+
update() {
95+
this._value = Math.min(99, parseInt(this._value, 10));
96+
if (this.img) {
97+
this._draw();
98+
if (this.onChange) this.onChange.call(this);
99+
} else {
100+
this.img = new Image();
101+
this.img.addEventListener("load", () => {
102+
this._setup();
103+
this._draw();
104+
if (this.onChange) this.onChange.call(this);
105+
});
106+
this.img.src = this.src;
107+
}
108+
}
109+
110+
get dataURL() {
111+
return this.canvas.toDataURL();
112+
}
113+
114+
get value() {
115+
return this._value;
116+
}
117+
118+
set value(val) {
119+
this._value = val;
120+
this.update();
121+
}
122+
}

0 commit comments

Comments
 (0)