Browse Source

Add some notes

The helpful snippet about the purpose of install-app-deps taken from
https://webpack.electron.build/dependency-management
Manav Rathi 1 year ago
parent
commit
0e861d5c48
3 changed files with 28 additions and 0 deletions
  1. 5 0
      desktop/docs/dependencies.md
  2. 8 0
      desktop/docs/dev.md
  3. 15 0
      desktop/src/preload.ts

+ 5 - 0
desktop/docs/dependencies.md

@@ -22,6 +22,11 @@ a _renderer_ process.
     export of the [Photos web app](../web/README.md) in the generated app. This
     export of the [Photos web app](../web/README.md) in the generated app. This
     gets loaded by the embedded Chromium at runtime, acting as the app's UI.
     gets loaded by the embedded Chromium at runtime, acting as the app's UI.
 
 
+There is also a third environment that gets temporarily created:
+
+-   The [preload script](../src/preload.ts) acts as a gateway between the _main_
+    and the _renderer_ process. It runs in its own isolated environment.
+
 ### electron-builder
 ### electron-builder
 
 
 [Electron Builder](https://www.electron.build) is used for packaging the app for
 [Electron Builder](https://www.electron.build) is used for packaging the app for

+ 8 - 0
desktop/docs/dev.md

@@ -2,3 +2,11 @@
 
 
 -   `yarn build:quick` is a variant of `yarn build` that uses the
 -   `yarn build:quick` is a variant of `yarn build` that uses the
     `--config.compression=store` flag to (slightly) speed up electron-builder.
     `--config.compression=store` flag to (slightly) speed up electron-builder.
+
+## Notes
+
+-   When using native node modules (those written in C/C++), we need to ensure
+    they are built against `electron`'s packaged `node` version. We use
+    [electron-builder](https://www.electron.build/cli)'s `install-app-deps`
+    command to rebuild those modules automatically after each `yarn install` by
+    invoking it in as the `preinstall` step in our package.json.

+ 15 - 0
desktop/src/preload.ts

@@ -1,3 +1,18 @@
+/**
+ * @file The preload script
+ *
+ * The preload script runs in an isolated environment. It has access to some of
+ * the Node imports. Its task is to expose these imports and other functions as
+ * an object on the DOM, so that the renderer process can invoke functions that
+ * live in the main (Node.js) process.
+ *
+ * Note that this script cannot import other code from `src/`. This is not an
+ * inherent limitation, just that we'll need to transpile our TypeScript and
+ * bundle it such that it can be imported from here at runtime, when this
+ * preload script is run by Electron inside its half-node half-DOM isolated
+ * environment.
+ */
+
 import { contextBridge } from "electron";
 import { contextBridge } from "electron";
 import {
 import {
     deleteDiskCache,
     deleteDiskCache,