Backend API

The Franz Backend API provides a set of helper functions to integrate a recipe into Franz.

Every Franz Recipe requires an index.js which is the main entry point for a Franz Recipe. Most Recipes don't need special handling at the Recipe backend. The usual Franz Recipe looks like this

module.exports = Franz => Franz;

Franz Backend Class Methods

Events

validateUrl(URL)

Validate if the given URL is a valid service instance.

Arguments

  1. string URL

Returns

Promise

Usage

// RocketChat integration
module.exports = Franz => class RocketChat extends Franz {
  async validateUrl(url) {
    try {
      const resp = await window.fetch(`${url}/api/info`, {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json',
        },
      });
      const data = await resp.json();

      return Object.hasOwnProperty.call(data, 'version');
    } catch (err) {
      console.error(err);
    }

    return false;
  }
};

overrideUserAgent()

Validate if the given URL is a valid service instance.

Returns

Boolean

Usage

// Discord integration
module.exports = Franz => class Discord extends Franz {
  overrideUserAgent() {
    const useragent = window.navigator.userAgent;

    // Quick and dirty hackfix
    const parts = useragent.split('(KHTML, like Gecko)');

    return window.navigator.userAgent.replace(/(Franz|Electron)([^\s]+\s)/g, '');
  }
};

Events

Franz recipes can hook into the electron webview events to trigger custom functions.

This is necessary for services like TweetDeck where custom URL forwarding is needed during login.

Usage

module.exports = Franz => class Tweetdeck extends Franz {
  events = {
    'did-get-redirect-request': '_redirectFix',
  }

  _redirectFix(event) {
    if (event.newURL !== undefined && event.oldURL !== undefined && event.isMainFrame) {
      if (event.isMainFrame) {
        setTimeout(() => this.send('redirect-url', event.newURL), 100);
        event.preventDefault();
      }
    }
  }
};