diff options
author | Kristóf Marussy <kristof@marussy.com> | 2021-09-19 00:41:52 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2021-09-19 00:57:47 +0200 |
commit | c5d2a889d4cb44f995d74051f83628b505383093 (patch) | |
tree | b1bab2b6d7f99ab00b0ca9860079f71472ac79ae /recipes/rocketchat | |
parent | Fix images opening in browser instead of in Discord (#712) (diff) | |
download | ferdium-recipes-c5d2a889d4cb44f995d74051f83628b505383093.tar.gz ferdium-recipes-c5d2a889d4cb44f995d74051f83628b505383093.tar.zst ferdium-recipes-c5d2a889d4cb44f995d74051f83628b505383093.zip |
fix: privileged API access
Privileged browser APIs should be accessed from webview.js via the Ferdi
parameter to the exported function.
If any service is broken (e.g., screen sharing), then most likely we
have to fix recipe.js or screenshare.js
Diffstat (limited to 'recipes/rocketchat')
-rw-r--r-- | recipes/rocketchat/package.json | 2 | ||||
-rw-r--r-- | recipes/rocketchat/webview.js | 67 |
2 files changed, 35 insertions, 34 deletions
diff --git a/recipes/rocketchat/package.json b/recipes/rocketchat/package.json index 3b807bf..f2c6374 100644 --- a/recipes/rocketchat/package.json +++ b/recipes/rocketchat/package.json | |||
@@ -1,7 +1,7 @@ | |||
1 | { | 1 | { |
2 | "id": "rocketchat", | 2 | "id": "rocketchat", |
3 | "name": "Rocket.Chat", | 3 | "name": "Rocket.Chat", |
4 | "version": "1.2.0", | 4 | "version": "1.2.1", |
5 | "license": "MIT", | 5 | "license": "MIT", |
6 | "config": { | 6 | "config": { |
7 | "serviceURL": "https://{teamId}.rocket.chat", | 7 | "serviceURL": "https://{teamId}.rocket.chat", |
diff --git a/recipes/rocketchat/webview.js b/recipes/rocketchat/webview.js index 4240935..159adea 100644 --- a/recipes/rocketchat/webview.js +++ b/recipes/rocketchat/webview.js | |||
@@ -1,36 +1,3 @@ | |||
1 | const getTeamIcon = function getTeamIcon() { | ||
2 | const manifestElement = document.querySelector('link[rel="manifest"]'); | ||
3 | |||
4 | if (manifestElement == null) { | ||
5 | return; | ||
6 | } | ||
7 | |||
8 | const manifestUrl = manifestElement.getAttribute('href'); | ||
9 | |||
10 | if (manifestUrl == null) { | ||
11 | return; | ||
12 | } | ||
13 | |||
14 | const xmlhttp = new XMLHttpRequest(); | ||
15 | |||
16 | xmlhttp.onreadystatechange = function () { | ||
17 | if (this.readyState != 4 || this.status != 200) { | ||
18 | return; | ||
19 | } | ||
20 | |||
21 | const response = JSON.parse(this.responseText); | ||
22 | |||
23 | if (response.icons.length >= 1) { | ||
24 | Ferdi.ipcRenderer.sendToHost( | ||
25 | 'avatar', | ||
26 | `${window.location.protocol}//${window.location.host}${response.icons[0].src}`, | ||
27 | ); | ||
28 | } | ||
29 | }; | ||
30 | |||
31 | xmlhttp.open('GET', manifestUrl, true); | ||
32 | xmlhttp.send(); | ||
33 | }; | ||
34 | 1 | ||
35 | module.exports = Ferdi => { | 2 | module.exports = Ferdi => { |
36 | const getMessages = function getMessages() { | 3 | const getMessages = function getMessages() { |
@@ -51,6 +18,40 @@ module.exports = Ferdi => { | |||
51 | 18 | ||
52 | Ferdi.loop(getMessages); | 19 | Ferdi.loop(getMessages); |
53 | 20 | ||
21 | const getTeamIcon = function getTeamIcon() { | ||
22 | const manifestElement = document.querySelector('link[rel="manifest"]'); | ||
23 | |||
24 | if (manifestElement == null) { | ||
25 | return; | ||
26 | } | ||
27 | |||
28 | const manifestUrl = manifestElement.getAttribute('href'); | ||
29 | |||
30 | if (manifestUrl == null) { | ||
31 | return; | ||
32 | } | ||
33 | |||
34 | const xmlhttp = new XMLHttpRequest(); | ||
35 | |||
36 | xmlhttp.onreadystatechange = function () { | ||
37 | if (this.readyState != 4 || this.status != 200) { | ||
38 | return; | ||
39 | } | ||
40 | |||
41 | const response = JSON.parse(this.responseText); | ||
42 | |||
43 | if (response.icons.length >= 1) { | ||
44 | Ferdi.ipcRenderer.sendToHost( | ||
45 | 'avatar', | ||
46 | `${window.location.protocol}//${window.location.host}${response.icons[0].src}`, | ||
47 | ); | ||
48 | } | ||
49 | }; | ||
50 | |||
51 | xmlhttp.open('GET', manifestUrl, true); | ||
52 | xmlhttp.send(); | ||
53 | }; | ||
54 | |||
54 | setTimeout(() => { | 55 | setTimeout(() => { |
55 | getTeamIcon(); | 56 | getTeamIcon(); |
56 | }, 4000); | 57 | }, 4000); |