sonnyp / Junction

Application/browser chooser
https://flathub.org/apps/re.sonny.Junction
GNU General Public License v3.0
458 stars 29 forks source link

[RFC] Support for custom rules and user script #16

Closed sonnyp closed 2 years ago

sonnyp commented 2 years ago

Feedback and comments welcome.

This is a WIP to implement custom rules and user script.

The userscript runs in strict mode and in the same process as the rest of the application

  1. User shouldn't copy paste stuff from the Internet without understanding
  2. The script has access to gi bindings and as such can do a bunch of cool stuff like triggering notifications and whatnot
  3. Async is not allowed for now
  4. It's not a ESModule, no import / export for now

Here is an example

// resource is an object containing
// `URI` https://docs.gtk.org/glib/struct.Uri.html
// `content_type` String
// `file` https://docs.gtk.org/gio/iface.File.html

// Always open `*github.com*` URLs with Firefox Developer Edition
if (resource.URI.get_host() === "github.com") {
  return {
    app: "firefox-developer-edition.desktop",
  };
}

// Open Jitsi and 8x8 URLs in the desktop app
if (
  resource.URI.get_host() === "meet.jit.si" ||
  resource.URI.get_host() === "8x8.vc"
) {
  return {
    app: "org.jitsi.jitsi-meet.desktop",
    // https://github.com/jitsi/jitsi-meet-electron/issues/509
    uri: `jitsi-meet://${resource.file.get_uri()}`,
  };
}

// Open Youtube URLs in FreeTube
if (resource.URI.get_host() === "www.youtube.com") {
  return {
    app: "io.freetubeapp.FreeTube.desktop",
  };
}
sonnyp commented 2 years ago

I'm gonna close this for now due to a lack of interest from users (and myself);

There 2 main cases are already covered by

  1. https://github.com/sonnyp/Junction/issues/5
  2. https://github.com/sonnyp/Junction/issues/75