aboutsummaryrefslogtreecommitdiffstats
path: root/docs/integration.md
diff options
context:
space:
mode:
authorLibravatar vantezzen <hello@vantezzen.io>2020-03-08 11:10:17 +0100
committerLibravatar vantezzen <hello@vantezzen.io>2020-03-08 11:10:17 +0100
commit9d715597a600710c20f75412d3dcd8cdb7b3c39e (patch)
tree65ab812834d486aaccf35e2a31a7a628a7100422 /docs/integration.md
parentRevert to using the standart file comparison function (diff)
downloadferdium-recipes-9d715597a600710c20f75412d3dcd8cdb7b3c39e.tar.gz
ferdium-recipes-9d715597a600710c20f75412d3dcd8cdb7b3c39e.tar.zst
ferdium-recipes-9d715597a600710c20f75412d3dcd8cdb7b3c39e.zip
Add documentation
Diffstat (limited to 'docs/integration.md')
-rw-r--r--docs/integration.md148
1 files changed, 148 insertions, 0 deletions
diff --git a/docs/integration.md b/docs/integration.md
new file mode 100644
index 0000000..ddfc35c
--- /dev/null
+++ b/docs/integration.md
@@ -0,0 +1,148 @@
1# Ferdi Recipe Documentation / Overview
2
3A Ferdi recipe is basically nothing else than a node module and is currently initialized on `dom-ready`. You access all of the [electron](http://electron.atom.io) modules as well.
4
5Recipes are responsible for providing the connection between the service itself (e.g. WhatsApp) and Ferdi, providing information like the number of current notifications or handling dark mode.
6
7## Table of Contents
8* [Installation](#user-content-installation)
9* [Plugin structure](#user-content-recipe-structure)
10* [Configuration (package.json)](#user-content-packagejson)
11* [Backend (index.js)](#user-content-indexjs)
12* [Frontend (webview.js)](#user-content-webviewjs)
13* [Icons](#user-content-icons)
14* [Dark Mode](#user-content-dark-mode)
15* [Debugging](#user-content-debugging)
16* [Deployment](#user-content-deployment)
17
18## Installation
191. To install a new recipe for testing, download the recipe folder e.g `whatsapp` or simply create an empty one with the name of your new recipe (we recommend using a recipe like `whatsapp` as a template though).
202. Open the development Ferdi Plugins folder on your machine (note that the `dev` directory may not exist yet, and you must create it):
21 * Mac: `~/Library/Application Support/Ferdi/recipes/dev/`
22 * Windows: `%appdata%/Ferdi/recipes/dev/`
23 * Linux: `~/.config/Ferdi/recipes/dev`
243. Copy the recipe folder into this folder
254. Reload Ferdi (`CMD/CTRL + SHIFT + R`)
26
27## Recipe structure
28Every recipe needs a specific file structure in order to work as a Ferdi recipe
29
30* icon.svg - Icon for the service in SVG form
31* icon.png - Icon for the service in PNG form (1024x1024px)
32* index.js - Backend script, this script is NOT included in the service webview but only in Ferdi itself
33* package.json - Information about the recipe
34* webview.js - Frontend script, this script is injected into the service itself but still has access to all NodeJS APIs
35* darkmode.css - CSS File that gets included when dark mode is activated
36
37### package.json
38The package.json is structured like any other node module and allows to completely configure the service.
39
40```json
41{
42 "id": "tweetdeck",
43 "name": "Tweetdeck",
44 "version": "1.0.1",
45 "description": "Tweetdeck",
46 "main": "index.js",
47 "author": "Stefan Malzner <stefan@adlk.io>",
48 "license": "MIT",
49 "repository": "https://github.com/meetfranz/recipe-tweetdeck",
50 "config": {
51 "serviceURL": "https://tweetdeck.twitter.com/"
52 }
53}
54```
55
56To get more information about all the provided configuration flags, check the [config docs](configuration.md).
57
58Please note that the fields `id`, `name`, `version` and `config` and required.
59
60
61### index.js
62This is your "backend" code. Right now the options are very limited and most of the services don't need a custom handling here. If your service is relatively straight forward and has a static URL eg. _messenger.com_, _`[TEAMID]`.slack.com_ or _web.skype.com_ all you need to do to return the Ferdi Class:
63
64```js
65module.exports = Ferdi => Ferdi;
66```
67
68If your service can be hosted on custom servers, you can validate the given URL to detect if it's your server and not e.g. google.com. To enable validation you can override the function `validateServer`
69```js
70// RocketChat integration
71module.exports = Ferdi => class RocketChat extends Ferdi {
72 async validateUrl(url) {
73 try {
74 const resp = await window.fetch(`${url}/api/info`, {
75 method: 'GET',
76 headers: {
77 'Content-Type': 'application/json',
78 },
79 });
80 const data = await resp.json();
81
82 return Object.hasOwnProperty.call(data, 'version');
83 } catch (err) {
84 console.error(err);
85 }
86
87 return false;
88 }
89};
90```
91
92`validateServer` needs to return a [`Promise`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise), otherwise validation will fail.
93
94### webview.js
95The webview.js is the actual script that will be loaded into the webview. Here you can do whatever you want to do in order perfectly integrate the service into Ferdi. For convenience, we have provided a very simple set of functions to set unread message badges (`Ferdi.setBadge()`) and inject CSS files (`Ferdi.injectCSS()`).
96
97
98```js
99// orat.io integration
100module.exports = (Ferdi) => {
101 function getMessages() {
102 let direct = 0;
103 let indirect = 0;
104 const FerdiData = document.querySelector('#FerdiMessages').dataset;
105 if (FerdiData) {
106 direct = FerdiData.direct;
107 indirect = FerdiData.indirect;
108 }
109
110 Ferdi.setBadge(direct, indirect);
111 }
112
113 Ferdi.loop(getMessages);
114}
115```
116
117To get more information about the provided functions, check the [API docs](frontend_api.md).
118
119### Icons
120In order to show every service icon crystal clear within the Ferdi UI, we require a .svg and .png in 1024x1024px.
121
122### Dark Mode
123You can provide a custom Dark Mode Theme for your recipes just by putting the `darkmode.css` into your recipe folder. Once the `darkmode.css` exists, you can enable the Dark Mode in your service settings.
124
125Recipe Dark Mode is only supported by Ferdi 5.0.0-beta.19+
126
127### Debugging
128In order to debug your service integration, open Ferdi and use the shortcut `Cmd/Ctrl+Alt+Shift+i` to open the recipes developer tools.
129
130### Publishing
131Ferdi uses its recipe repository at <https://github.com/getferdi/recipes> to publish recipes to all clients.
132
133To add your own recipe to the repository:
134- If you already uploaded the recipe to GitHub:
135 1. Fork https://github.com/getferdi/recipes and clone it to your computer
136 2. Open a terminal in the `scripts/` folder of that repository
137 3. Run `yarn install` to install all dependencies
138 4. Run `yarn github [GitHub URL]`, e.g. `yarn github https://github.com/vantezzen/franz-recipe-standardnotes`, to add your new recipe
139 5. Create a PR to <https://github.com/getferdi/recipes> with your new changes
140
141- If you don't have it uploaded it GitHub:
142 ℹ️ We recommend uploading your recipes to GitHub before adding them to provide a platform for users to report issues.
143 1. Fork https://github.com/getferdi/recipes and clone it to your computer
144 2. Copy your recipe files into `scripts/recipe_src`
145 3. Open a terminal at `scripts/`
146 4. Run `yarn install` to install all dependencies
147 5. Run `yarn package` to package your new recipe
148 6. Create a PR to <https://github.com/getferdi/recipes> with your new changes