diff options
author | Stephan Bergmann <stephan.bergmann@allotropia.de> | 2024-07-18 11:44:45 +0200 |
---|---|---|
committer | Stephan Bergmann <stephan.bergmann@allotropia.de> | 2024-07-18 15:55:12 +0200 |
commit | 91bedcab61424cdfb2f3ba9e48481406fe141ceb (patch) | |
tree | 67c15068c4c1b46ea83c5f138ac9ebc776a79aea /static | |
parent | a7c1163684fa5c0376efebe8dc6225a7dfb8e700 (diff) |
Change from Module.intiUno() to Module.uno_init promise
...that is resolved from within C++ Desktop::InitApplicationServiceManager once
UNO is fully initialized, so client code can trigger on
Module.uno_init.then(...)
Change-Id: I2d4c542d9729d09f434502e3f966e9ee474e926c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170683
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <stephan.bergmann@allotropia.de>
Diffstat (limited to 'static')
-rw-r--r-- | static/README.wasm.md | 49 | ||||
-rw-r--r-- | static/emscripten/uno.js | 11 |
2 files changed, 32 insertions, 28 deletions
diff --git a/static/README.wasm.md b/static/README.wasm.md index 7d69716e7173..523658868e58 100644 --- a/static/README.wasm.md +++ b/static/README.wasm.md @@ -210,33 +210,36 @@ improvement! ;) Some usage examples through javascript of the current implementation: ```js // inserts a string at the start of the Writer document. -Module.initUno(); -const css = Module.uno.com.sun.star; -const xModel = Module.getCurrentModelFromViewSh(); -const xTextDocument = css.text.XTextDocument.query(xModel); -const xText = xTextDocument.getText(); -const xTextCursor = xText.createTextCursor(); -xTextCursor.setString("string here!"); +Module.uno_init.then(function() { + const css = Module.uno.com.sun.star; + const xModel = Module.getCurrentModelFromViewSh(); + const xTextDocument = css.text.XTextDocument.query(xModel); + const xText = xTextDocument.getText(); + const xTextCursor = xText.createTextCursor(); + xTextCursor.setString("string here!"); +}); ``` ```js // changes each paragraph of the Writer document to a random color. -Module.initUno(); -const css = Module.uno.com.sun.star; -const xModel = Module.getCurrentModelFromViewSh(); -const xTextDocument = css.text.XTextDocument.query(xModel); -const xText = xTextDocument.getText(); -const xEnumAccess = css.container.XEnumerationAccess.query(xText); -const xParaEnumeration = xEnumAccess.createEnumeration(); -while (xParaEnumeration.hasMoreElements()) { - const next = xParaEnumeration.nextElement(); - const xParagraph = css.text.XTextRange.query(next.get()); - const xParaProps = css.beans.XPropertySet.query(xParagraph); - const color = new Module.uno_Any(Module.uno_Type.Long(), Math.floor(Math.random() * 0xFFFFFF)); - xParaProps.setPropertyValue("CharColor", color); - next.delete(); - color.delete(); -} +Module.uno_init.then(function() { + const css = Module.uno.com.sun.star; + const xModel = Module.getCurrentModelFromViewSh(); + const xTextDocument = css.text.XTextDocument.query(xModel); + const xText = xTextDocument.getText(); + const xEnumAccess = css.container.XEnumerationAccess.query(xText); + const xParaEnumeration = xEnumAccess.createEnumeration(); + while (xParaEnumeration.hasMoreElements()) { + const next = xParaEnumeration.nextElement(); + const xParagraph = css.text.XTextRange.query(next.get()); + const xParaProps = css.beans.XPropertySet.query(xParagraph); + const color = new Module.uno_Any( + Module.uno_Type.Long(), Math.floor(Math.random() * 0xFFFFFF)); + xParaProps.setPropertyValue("CharColor", color); + next.delete(); + color.delete(); + } +}); ``` diff --git a/static/emscripten/uno.js b/static/emscripten/uno.js index 6a9c4cd5cb6e..7d051a24a84b 100644 --- a/static/emscripten/uno.js +++ b/static/emscripten/uno.js @@ -11,11 +11,13 @@ Module.unoTagSymbol = Symbol('unoTag'); -Module.initUno = function() { - if (Module.uno === undefined) { +Module.uno_init = new Promise(function (resolve, reject) { + Module.uno_init$resolve = function() { Module.uno = init_unoembind_uno(Module, Module.unoTagSymbol); - } -}; + resolve(); + }; + Module.uno_init$reject = reject; +}); Module.catchUnoException = function(exception) { // Rethrow non-C++ exceptions (non-UNO C++ exceptions are mapped to css.uno.RuntimeException in @@ -30,7 +32,6 @@ Module.catchUnoException = function(exception) { } Module.unoObject = function(interfaces, obj) { - Module.initUno(); interfaces = ['com.sun.star.lang.XTypeProvider'].concat(interfaces); obj.impl_refcount = 0; obj.queryInterface = function(type) { |