diff options
author | Minteck <contact@minteck.org> | 2022-03-27 21:23:27 +0200 |
---|---|---|
committer | Minteck <contact@minteck.org> | 2022-03-27 21:23:27 +0200 |
commit | 9ce177d037d0aec26d51cfcba5a091155aebbfc6 (patch) | |
tree | d3bc54df6ccd675e07713fe37cc641fca427cd69 /sdk/main.js | |
download | alicorn-9ce177d037d0aec26d51cfcba5a091155aebbfc6.tar.gz alicorn-9ce177d037d0aec26d51cfcba5a091155aebbfc6.tar.bz2 alicorn-9ce177d037d0aec26d51cfcba5a091155aebbfc6.zip |
Initial commit
Diffstat (limited to 'sdk/main.js')
-rw-r--r-- | sdk/main.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/sdk/main.js b/sdk/main.js new file mode 100644 index 0000000..e0f571c --- /dev/null +++ b/sdk/main.js @@ -0,0 +1,32 @@ +console.log("Alicorn SDK") +const { contextBridge, ipcRenderer } = require('electron'); +global.windowId = null; + +let host = require('@electron/remote').getCurrentWindow().webContents.executeJavaScript; + +ipcRenderer.on('window-id', (event, data) => { + console.log("[SDK] Alicorn Window ID: " + data); + contextBridge.exposeInMainWorld('AlicornWindowID', data); + global.windowId = data; +}) + +contextBridge.exposeInMainWorld('AlicornRoot', require('path').dirname(__dirname)); +contextBridge.exposeInMainWorld('AlicornKeyboardHandler', require('fs').readFileSync("sdk/keyboard.js").toString()); + +contextBridge.exposeInMainWorld('AlicornSDK', { + init: async () => { + let api = {}; + + console.log("[SDK] Establishing features set... This may take a while."); + let features = await host("Object.keys(AlicornSDK)"); + console.log("[SDK] Established features set"); + + for (let feature of features) { + api[feature] = (options) => { + return host("AlicornSDK[" + JSON.stringify(feature) + "](\"" + windowId + "\", " + JSON.stringify(options) + ");"); + }; + } + + return api; + } +})
\ No newline at end of file |