Skip to content

Separate Renderer from Main Code#2759

Merged
jameskerr merged 76 commits intomainfrom
untangle
May 25, 2023
Merged

Separate Renderer from Main Code#2759
jameskerr merged 76 commits intomainfrom
untangle

Conversation

@jameskerr
Copy link
Contributor

@jameskerr jameskerr commented May 2, 2023

To Do List:

  • Publish relevant Zealot Packages
  • Update this PR to point to updated zealot packages
  • Test about window
  • Test detail window
  • Write migration script for the packet indexes
  • Write migration script for suricata data
  • Spawn suricata updater
  • Test with a packaged app
  • Bring in changes from old zealot that got made since the new zealot repo was created

Things to Test

  1. Import some pcaps into the app before this change
  2. Upgrade to this change, make sure you can still extract those pcaps
  3. All the windows work
  4. The packets button works
  5. Ingesting pcaps works
  6. Ingesting non-pcaps works

Summary

An electron app is composed of a main node process, and one or more chrome renderer processes. Electron makes it possible to use node APIs within the renderer processes. This is done by providing an option to the BrowserWindow constructor called nodeIntegration: true. 5 years ago, this was the default. It was what made electron unique. However, this created big security risks. Since a web browser is built to load remote files. When remote files are loaded, they also have full access to the node apis, and thereby the computer they are running on. (file system, processes, etc...).

It became good practice to turn off nodeIntegration and use interprocess communication to access the powerful node apis. That is now the default in latest electron versions.

Historically, our app has been like a node application that runs in the browser. With this PR, I have turned off nodeIntegration and migrated to ipc for everything that needs node APIs.

Plugins

The biggest place we used the node apis was in the plugins for brimcap, zeek, and suricata. These have been re-arranged to run in the node process. The API they use to interact with the app has been much improved as well in this PR.

Zealot

This PR now uses the built versions of @brimdata/zed-js and @brimdata/zed-node published on NPM and maintained in the brimdata/zealot repo.

Packaged Files

I changed the electron-builder configuration to only include files from dist/, out/, and zdeps/. It was previously including everything. I also notice that we bundle two versions of the zed and zq. We also include some other rather large binaries from the zed repo we don't need. We could reduce the size of the packaged app by 200Mb if we fix this and only include what we need.

Installers

Installers now get put in installers/. They were previously in dist/installers/. But since dist was and is included in the package other versions of the installers could be included in the app package. That's why some builds were many gigabytes large. 🤦

New Tools & Commands

Renderer

We now use nextjs to build the renderer javascript bundle.

yarn start:renderer

This starts a dev server on port 3000 and serves the html the browser window needs. It will perform hot module reloading whenever a file changes. The main process, when in dev mode, will load this url. Changes to files will immediately be reflected in the browser window.

yarn build:renderer

outputs to out/

This will create an folder (/out) of optimized, static files to serve in production mode. This is located in the out/ folder. When the app is in production mode, it will load these files directly from the file system.

Main

We use esbuild to build the main process bundle.

Esbuild bundles all the typescript files used in the main process into one javascript file. This is not required in node, but is convenient as it allows us to keep all our source typescript files (main and renderer) in the same directory. Esbuild works by only including that are imported, not everything in a directory.

yarn start:main

This runs the below command and triggers a rebuild whenever files change.

yarn build:main

outputs to dist/main.js

yarn start:electron

This wraps the electron start script in a tool called nodemon. This will watch a directory and restart the node script on changes. It watches the /dist folder where the main process bundle lives. This is perfect for development.

@philrz
Copy link
Contributor

philrz commented May 9, 2023

Repro is with the build from https://github.com/brimdata/zui/actions/runs/4920574674.

Not a serious bug, but I've noticed that when selecting Show Welcome Page from the Help pull-down menu, nothing happens. The error No command found: tabs.showWelcomePage shows up in DevTools.

Repro.mp4

@philrz
Copy link
Contributor

philrz commented May 9, 2023

I've marked this PR with a "do not merge" label for now since we've discussed holding off on merging it until we put out another GA Zui release. That way we can merge it right after that release and it'll have more soak time through internal testing and Zui Insiders before we put out yet another GA Zui release in the future.

@philrz
Copy link
Contributor

philrz commented May 24, 2023

Now that GA Zui v1.1.0 is out and this branch has been caught up with main, I'm getting back to testing it again, this time with the new Dev build at https://github.com/brimdata/zui/actions/runs/5072267182.

First, I've verified that the three issues I reported in comments above have all been fixed. 👍

Here's a new issue I found, though. While the About window comes up ok now, I can click on the links shown for Website and Source and they come up in my browser as expected. However, clicking on either License or Acknowledgments is a no-op. Doing the same in a GA Zui on my Mac, the relevant files are opened up for view in a text editor.

image

Interestingly, I only had that problem on macOS. On Windows it opened the files in the text editor as expected.

@philrz
Copy link
Contributor

philrz commented May 24, 2023

@philrz
Copy link
Contributor

philrz commented May 24, 2023

When upgrading from an older release and the migrations successfully move brimcap-root and suricata to their new locations, I noticed that the now empty data directory is left behind. Any interest in putting in some extra logic in the last migration to delete data if it's found to be empty? I know it's not hurting anything by just hanging around, but a user that had maybe been accustomed to seeing it populated in the past might be thrown by it now being empty. Having it disappear entirely might inspire them to go check the docs.

Copy link
Contributor

@philrz philrz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a new Dev build in https://github.com/brimdata/zui/actions/runs/5083087906 I've verified the fixes to the last couple issues reported in comments above. I feel like I've done enough testing on this one for it to merge and get some extended soak time in Zui Insiders before the next GA release, so, 👍.

Copy link
Contributor

@philrz philrz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a new Dev build in https://github.com/brimdata/zui/actions/runs/5083087906 I've verified the fixes to the last couple issues reported in comments above. I feel like I've done enough testing on this one for it to merge and get some extended soak time in Zui Insiders before the next GA release, so, 👍.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants