Skip to content

Commit

Permalink
Add an example plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Axel Boberg <[email protected]>
  • Loading branch information
axelboberg committed May 16, 2024
1 parent a5be1db commit 4f154ee
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/plugin-hello-world/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Hello World example plugin
This is an example plugin registering a 'Hello World widget' in the Bridge UI
Copy the entire directory to Bridge's plugin path and restart Bridge to make it appear in the widget selection menu in the edit mode.

**Tip: find the plugin path via the application's menu bar after you've started Bridge. Plugins > Manage Plugins...**
44 changes: 44 additions & 0 deletions examples/plugin-hello-world/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const bridge = require('bridge')

/*
The exported 'activate' function is the plugin's initialization function,
it will be called when the plugin is loaded and every time a workspace
is opened
*/
exports.activate = async () => {
/*
Create a new widget by serving either a file
or a string through Bridge's web server,
this way Bridge will ensure that it's reachable
within the desktop app as well as in browsers
Use the stylesheet provided by Bridge
to match the interface and automatically
apply the current theme
*/
const htmlPath = await bridge.server.serveString(`
<html>
<head>
<title>My widget</title>
<base href="/"></base>
<link rel="stylesheet" href="${bridge.server.uris.STYLE_RESET}" />
</head>
<body>
Hello World
</body>
</html>
`)

/*
Next, register a new widget
This will make the widget appear
in the Bridge interface
*/
bridge.widgets.registerWidget({
id: 'bridge.plugins.helloWorld',
name: 'Hello World',
uri: htmlPath,
description: 'Hello World widget'
})
}
14 changes: 14 additions & 0 deletions examples/plugin-hello-world/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "plugin-hello-world",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"engines": {
"bridge": "^0.0.1"
},
"author": "",
"license": "ISC"
}

0 comments on commit 4f154ee

Please sign in to comment.