Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions apps.json
Original file line number Diff line number Diff line change
Expand Up @@ -5062,5 +5062,70 @@
{"name":"ltherm.app.js","url":"app.js"},
{"name":"ltherm.img","url":"icon.js","evaluate":true}
]
},
{
"id": "omgbc",
"name": "Oh My Gadget Bridge Core",
"icon": "omgbc.png",
"version": "0.02",
"description": "A custom implementation of gadget bridge, expose an API for other app",
"type": "bootloader",
"tags": "tools, system",
"supports": ["BANGLEJS"],
"readme": "README.md",
"storage": [
{"name":"omgbc.boot.js","url":"boot.js"},
{"name":"omgbc.img","url":"icon.js","evaluate":true},
{"name":"omgbc.settings.js","url":"settings.js"}
]
},
{
"id": "omgbhbf",
"name": "Oh My Gadget Bridge (Health, Battery, Find)",
"version": "0.02",
"description": "Implement Health, Battery, Find",
"icon": "omgbhbf.png",
"type": "bootloader",
"tags": "tools, system",
"supports": ["BANGLEJS"],
"dependencies": {"omgbc":"app"},
"readme": "README.md",
"storage": [
{"name":"omgbhbf.boot.js","url":"boot.js"},
{"name":"omgbhbf.img","url":"icon.js","evaluate":true},
{"name":"omgbhbf.settings.js","url":"settings.js"}
]
},
{
"id": "simplyclock",
"name": "Simply Clock",
"version": "1.01",
"description": "Just simply clock",
"icon": "icon.png",
"type": "clock",
"tags": "clock",
"allow_emulator": true,
"supports": ["BANGLEJS"],
"dependencies": {"omgbc":"app"},
"storage": [
{"name":"simplyclock.app.js","url":"app.js"},
{"name":"simplyclock.img","url":"icon.js","evaluate":true}
]
},
{
"id": "swipeclock",
"name": "Swipe Clock",
"version": "1.00",
"description": "Swipe clock",
"icon": "icon.png",
"type": "clock",
"tags": "clock",
"allow_emulator": true,
"supports": ["BANGLEJS"],
"dependencies": {"omgbc":"app"},
"storage": [
{"name":"swipeclock.app.js","url":"app.js"},
{"name":"swipeclock.img","url":"icon.js","evaluate":true}
]
}
]
1 change: 1 addition & 0 deletions apps/omgbc/ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.01: New App!
132 changes: 132 additions & 0 deletions apps/omgbc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Oh My Gadget Bridge Core

Manage event of gadget bridge (alternative to Android bangle app).
Dispatch many event in bangle and another app can listen here events

## How to install in my app
```js
// apps.json
{
"id": "myapp",
"name": "My app",
"shortName": "app",
"version": "0.01",
"description": "bip bip",
"dependencies": { "omgbc": "app" },
}

// myapp/app.js
global.GadgetBridge.onEvent("notify", (event) => {
// Your code
});
```

## Features

### Api describe
```ts
global.GadgetBridge: {
onEvent(eventName: EventName, callback: Callback, option?: Option)
removeEventListener(eventName: EventName, callback: Callback)
sendEvent(message: string)
musicControl(command: string) // play/pause/next/previous/volumeup/volumedown
messageResponse(msg: Object, opened: boolean) // opened true or false, msg is the message to which you wish to reply
callResponse(call: Object, accepted: boolean) // accepted true or false, call is the call to which you wish to reply
}

type EventName = String; // See list of events
interface Callback {
(event: any, stopPropagation: () => void): void
}
interface Option {
layer: number // default Infinity
}
```

List of events:
- notify
- find
- musicstate
- musicinfo
- call
- connect
- disconnect

## Exemples

For listen a gadgetbridge event :
```js
// file boot.js
function boot() {
global.GadgetBridge.onEvent("notify", (event) => {
// Your code
});
}
setTimeout(boot, 1000); // Necessary to make sure that all are well loaded
```

For stop listening

```js
// file boot.js
function boot() {
var onNotify = (event) => {
// Your code
};
global.GadgetBridge.onEvent("notify", onNotify);
global.GadgetBridge.removeEventListener("notify", onNotify);
}
setTimeout(boot, 1000);
```

### To Know

Event manager sort callback by layer. If you want start your callback behind another you must add lower layer.

For exemple:
```js
// file boot.js
function boot() {
global.GadgetBridge.onEvent("notify", (event) => {
console.log("from boot.js");
}, { layer: 2 });
}
setTimeout(boot, 1000);

// file another.boot.js
function boot() {
global.GadgetBridge.onEvent("notify", (event) => {
console.log("from another.boot.js");
}, { layer: 1 });
}
setTimeout(boot, 1000);

// logs
// -> "from another.boot.js"
// -> "from boot.js"
```

Event manager also proposes to stop the propagation (callbacks with a higher layer will not be called). This is useful if you want to disable another behavior

For exemple:
```js
// file boot.js
function boot() {
global.GadgetBridge.onEvent("notify", (event) => {
console.log("It's never call");
}, { layer: 2 });
}
setTimeout(boot, 1000);

// file another.boot.js
function boot() {
global.GadgetBridge.onEvent("notify", (event, stopPropagation) => {
console.log("from another.boot.js");
stopPropagation();
}, { layer: 1 });
}
setTimeout(boot, 1000);

// logs
// -> "from another.boot.js"
```
Loading