summaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/static/platform.js
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static/platform.js')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/static/platform.js19
1 files changed, 17 insertions, 2 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/platform.js b/packages/meshbay-hub/src/meshbay_hub/static/platform.js
index ae04e53..994f558 100644
--- a/packages/meshbay-hub/src/meshbay_hub/static/platform.js
+++ b/packages/meshbay-hub/src/meshbay_hub/static/platform.js
@@ -103,6 +103,20 @@ export const secrets = {
* keypair bundle on each node is what a second browser recovers — which is
* finding C4, and the reason the application exists.
*/
+/**
+ * The sentence out of a bridge error.
+ *
+ * Electron wraps anything thrown in the main process as
+ * "Error invoking remote method 'hub:set': Error: …", which puts plumbing in
+ * front of a message written for a person. The message is the part that was
+ * written for them.
+ */
+export function bridgeMessage(err) {
+ const raw = (err && err.message) || String(err);
+ const m = raw.match(/^Error invoking remote method '[^']*':\s*(?:\w*Error:\s*)?(.*)$/s);
+ return m ? m[1] : raw;
+}
+
export const device = {
available: Boolean(bridge && bridge.device),
async ensure() {
@@ -168,7 +182,7 @@ export async function nativeSave(suggestedName, size) {
}
export default { isNative, hubBase, capabilities, secrets, nativeSave,
- apiFetch, device };
+ apiFetch, device, bridgeMessage };
// Also a global, because `transport.js` is loaded as a classic script — it
// predates the module graph and exposes `MeshBayTransport` the same way. The
@@ -176,5 +190,6 @@ export default { isNative, hubBase, capabilities, secrets, nativeSave,
// hub end up disagreeing about how to reach it.
if (typeof window !== 'undefined') {
window.MeshBayPlatform = { isNative, hubBase, capabilities, secrets,
- nativeSave, apiFetch, device };
+ nativeSave, apiFetch, device,
+ bridgeMessage };
}