From 9ce177d037d0aec26d51cfcba5a091155aebbfc6 Mon Sep 17 00:00:00 2001 From: Minteck Date: Sun, 27 Mar 2022 21:23:27 +0200 Subject: Initial commit --- sdk/host.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 sdk/host.js (limited to 'sdk/host.js') diff --git a/sdk/host.js b/sdk/host.js new file mode 100644 index 0000000..4d76832 --- /dev/null +++ b/sdk/host.js @@ -0,0 +1,42 @@ +AlicornSDK = {}; +AlicornSDKInternal = {}; + +class AlicornSDKError extends Error { + constructor(props) { + super(props); + } +} + +AlicornSDKInternal["checkWindow"] = (w) => { + if (w === null) { + throw new AlicornSDKError("Cannot make SDK call before window is initialized"); + } +} + +AlicornSDKInternal["resolveWindow"] = (w) => { + let wr = null + wr = WindowManager.stack.filter(i => i.id.substring(7).split("-app-")[0] === w)[0] + + return wr; +} + +AlicornSDK["close"] = (_window) => { + AlicornSDKInternal.checkWindow(_window); + let w = AlicornSDKInternal.resolveWindow(_window); + + WindowManager.queueClose(w); +} + +AlicornSDK["ready"] = (_window) => { + AlicornSDKInternal.checkWindow(_window); + let w = AlicornSDKInternal.resolveWindow(_window); + + w.classList.remove("loading"); +} + +AlicornSDK["keyboard"] = (_window, data) => { + AlicornSDKInternal.checkWindow(_window); + let w = AlicornSDKInternal.resolveWindow(_window); + + KeyboardShortcutHandler(data); +} \ No newline at end of file -- cgit