@cordy/electro 1.2.13 → 1.2.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.mjs +24 -1
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  import { createRequire } from "node:module";
2
+ import { existsSync } from "node:fs";
2
3
  import { join } from "node:path";
3
4
  import { Cron } from "croner";
4
5
 
@@ -980,7 +981,12 @@ var View = class {
980
981
  create() {
981
982
  if (this._view && !this._view.webContents.isDestroyed()) return this._view;
982
983
  const { WebContentsView: WCV } = __require("electron");
983
- const view = new WCV({ webPreferences: { ...this.entry.webPreferences ?? {} } });
984
+ const webPreferences = { ...this.entry.webPreferences ?? {} };
985
+ if (this.entry.hasRenderer && typeof webPreferences.preload !== "string") {
986
+ const preloadPath = resolveDefaultPreloadPath(this.entry.id);
987
+ if (preloadPath) webPreferences.preload = preloadPath;
988
+ }
989
+ const view = new WCV({ webPreferences });
984
990
  if (this.entry.hasRenderer) {
985
991
  const viewId = this.entry.id;
986
992
  view.load = async () => {
@@ -1005,6 +1011,23 @@ var View = class {
1005
1011
  this._view = null;
1006
1012
  }
1007
1013
  };
1014
+ const PRELOAD_EXTENSIONS = [
1015
+ "mjs",
1016
+ "cjs",
1017
+ "js"
1018
+ ];
1019
+ function resolveDefaultPreloadPath(viewId) {
1020
+ const preloadDir = join(import.meta.dirname, "..", "preload");
1021
+ for (const ext of PRELOAD_EXTENSIONS) {
1022
+ const byViewId = join(preloadDir, `${viewId}.${ext}`);
1023
+ if (existsSync(byViewId)) return byViewId;
1024
+ }
1025
+ for (const ext of PRELOAD_EXTENSIONS) {
1026
+ const singleEntryFallback = join(preloadDir, `index.${ext}`);
1027
+ if (existsSync(singleEntryFallback)) return singleEntryFallback;
1028
+ }
1029
+ return null;
1030
+ }
1008
1031
 
1009
1032
  //#endregion
1010
1033
  //#region src/core/window/manager.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cordy/electro",
3
- "version": "1.2.13",
3
+ "version": "1.2.16",
4
4
  "description": "Electron framework — feature-first runtime, codegen, and Vite-based build system",
5
5
  "license": "MIT",
6
6
  "type": "module",