Skip to content

Moving web view to KotlinJS

Ivan Posti edited this page Mar 23, 2021 · 2 revisions

PDF Viewer plugin code is divided into two main parts:

  • Actual plugin code that runs in the IDE process
  • web-view code that runs in the JCEF browser and does actual rendering of the PDFs

The actual PDF rendering component is provided by ng2-pdfjs-viewer. As the ng2-pdfjs-viewer runs PDF.js viewer in an iframe, it introduces a lot of issues, such as slow reloads and losing scroll/zoom states between updates. To fix these issues, I decided to use a custom build of PDF.js and run it on the actual webpage instead of an iframe. Because of that, web-view code can now be written without Angular.

Both parts use a lot of the same code (internal state representation and messaging infrastructure). To minimize code duplication, both parts are now written in Kotlin and use shared code from mpi module.

In summary:

  • Most of the code is now written in Kotlin
  • Shared logic is moved to the mpi module (compiles to JVM bytecode and JS)
  • web-view is split into two modules:
    • bootstrap (initial setups for the PDF.js)
    • viewer (actual viewer logic)

You can check the kotlinjs-migrate branch if you are interested.

Clone this wiki locally