From ff34b197c7ab9b269ebc58901b555815b3a5ee2f Mon Sep 17 00:00:00 2001 From: Simon Siefke Date: Thu, 1 Jun 2023 18:32:35 +0200 Subject: [PATCH] feat: add protocol api example --- src/templates.ts | 1 + static/show-me/protocol/main.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 static/show-me/protocol/main.js diff --git a/src/templates.ts b/src/templates.ts index 5dddad25c8..862d74fef9 100644 --- a/src/templates.ts +++ b/src/templates.ts @@ -21,6 +21,7 @@ export const SHOW_ME_TEMPLATES: Templates = { Notification: 'Notification', PowerMonitor: 'PowerMonitor', PowerSaveBlocker: 'PowerSaveBlocker', + Protocol: 'Protocol', Screen: 'Screen', Session: 'Session', Shell: 'Shell', diff --git a/static/show-me/protocol/main.js b/static/show-me/protocol/main.js new file mode 100644 index 0000000000..3f89c74f06 --- /dev/null +++ b/static/show-me/protocol/main.js @@ -0,0 +1,17 @@ +// Register and handle custom protocol +// +// For more info, see: +// https://www.electronjs.org/docs/latest/api/protocol + +const { app, BrowserWindow, protocol } = require('electron') + +app.whenReady().then(() => { + protocol.handle('some-protocol', () => { + return new Response( + Buffer.from('

Hello from protocol handler

'), // Could also be a string or ReadableStream. + { headers: { 'content-type': 'text/html' } } + ) + }) + const mainWindow = new BrowserWindow({ height: 600, width: 600 }) + mainWindow.loadURL('some-protocol://index.html') +})