From 643e0a087b220694d877003b3073b3fbd1be6419 Mon Sep 17 00:00:00 2001 From: nyne Date: Sat, 18 Jan 2025 16:55:04 +0800 Subject: [PATCH] Update api --- _template_.js | 6 ++++++ _venera_.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/_template_.js b/_template_.js index f5cd577..bc63228 100644 --- a/_template_.js +++ b/_template_.js @@ -745,6 +745,12 @@ class NewComicSource extends ComicSource { title: "Setting4", type: "callback", buttonText: "Click me", + /** + * callback function + * + * If the callback function returns a Promise, the button will show a loading indicator until the promise is resolved. + * @returns {void | Promise} + */ callback: () => { // do something } diff --git a/_venera_.js b/_venera_.js index 6dc0388..23dda28 100644 --- a/_venera_.js +++ b/_venera_.js @@ -4,6 +4,13 @@ Venera JavaScript Library This library provides a set of APIs for interacting with the Venera app. */ +function setTimeout(callback, delay) { + sendMessage({ + method: 'delay', + time: delay, + }).then(callback); +} + /// encode, decode, hash, decrypt let Convert = { /** @@ -1197,3 +1204,49 @@ class Image { return new Image(key); } } + +/** + * UI related apis + * @since 1.2.0 + */ +let UI = { + /** + * Show a message + * @param message {string} + */ + showMessage: (message) => { + sendMessage({ + method: 'UI', + function: 'showMessage', + message: message, + }) + }, + + /** + * Show a dialog. Any action will close the dialog. + * @param title {string} + * @param content {string} + * @param actions {{text:string, callback: () => void}[]} + */ + showDialog: (title, content, actions) => { + sendMessage({ + method: 'UI', + function: 'showDialog', + title: title, + content: content, + actions: actions, + }) + }, + + /** + * Open [url] in external browser + * @param url {string} + */ + launchUrl: (url) => { + sendMessage({ + method: 'UI', + function: 'launchUrl', + url: url, + }) + }, +} \ No newline at end of file