@nemigo/electron 0.1.0 → 0.2.0

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.
@@ -5,8 +5,9 @@
5
5
  * @see https://www.electronjs.org/docs/latest/tutorial/security#13-disable-or-limit-navigation
6
6
  */
7
7
  export declare class NetworkSecurity {
8
- #private;
9
- constructor(allowedOrigins?: string[], allowedExternalUrls?: string[]);
8
+ readonly allowedInternal: Set<string>;
9
+ readonly allowedExternal: Set<string>;
10
+ constructor(allowedInternal?: string[], allowedExternal?: string[], init?: boolean);
10
11
  init(): this;
11
12
  private handleNavigation;
12
13
  private handleWindowOpen;
package/dist/security.js CHANGED
@@ -6,11 +6,13 @@ import { app, shell } from "electron";
6
6
  * @see https://www.electronjs.org/docs/latest/tutorial/security#13-disable-or-limit-navigation
7
7
  */
8
8
  export class NetworkSecurity {
9
- #allowedOrigins;
10
- #allowedExternalUrls;
11
- constructor(allowedOrigins = [], allowedExternalUrls = []) {
12
- this.#allowedOrigins = new Set(allowedOrigins);
13
- this.#allowedExternalUrls = new Set(allowedExternalUrls);
9
+ allowedInternal;
10
+ allowedExternal;
11
+ constructor(allowedInternal = [], allowedExternal = [], init = true) {
12
+ this.allowedInternal = new Set(allowedInternal);
13
+ this.allowedExternal = new Set(allowedExternal);
14
+ if (init)
15
+ this.init();
14
16
  }
15
17
  init() {
16
18
  app.on("web-contents-created", (_, contents) => {
@@ -22,7 +24,7 @@ export class NetworkSecurity {
22
24
  handleNavigation(contents) {
23
25
  contents.on("will-navigate", (e, url) => {
24
26
  const { origin } = new URL(url);
25
- if (!this.#allowedOrigins.has(origin)) {
27
+ if (!this.allowedInternal.has(origin)) {
26
28
  e.preventDefault();
27
29
  console.warn(`Blocked navigating to disallowed origin: ${origin}`);
28
30
  }
@@ -32,7 +34,7 @@ export class NetworkSecurity {
32
34
  contents.setWindowOpenHandler(({ url }) => {
33
35
  const { origin } = new URL(url);
34
36
  // Если URL в разрешенном списке — открываем во внешнем браузере
35
- if (this.#allowedExternalUrls.has(origin)) {
37
+ if (this.allowedExternal.has(origin)) {
36
38
  shell.openExternal(url).catch(console.error);
37
39
  }
38
40
  else {
@@ -0,0 +1,7 @@
1
+ import type { AliasOptions } from "vite";
2
+ export interface ElectronViteConfigOptions {
3
+ isDEV: boolean;
4
+ node: number;
5
+ alias?: AliasOptions;
6
+ }
7
+ export declare const defineElectronViteConfig: (options: ElectronViteConfigOptions) => import("vite").UserConfig;
@@ -0,0 +1,27 @@
1
+ import { electronViteHotReboot } from "./hot-reboot.js";
2
+ import { defineConfig } from "vite";
3
+ export const defineElectronViteConfig = (options) => defineConfig({
4
+ resolve: {
5
+ alias: options.alias,
6
+ },
7
+ build: {
8
+ ssr: true,
9
+ minify: options.isDEV ? false : "esbuild",
10
+ sourcemap: options.isDEV ? "inline" : false,
11
+ target: `node${options.node}`,
12
+ lib: {
13
+ entry: [
14
+ "src/index.ts",
15
+ ],
16
+ formats: ["es"],
17
+ },
18
+ rollupOptions: {
19
+ output: {
20
+ entryFileNames: "[name].js",
21
+ },
22
+ },
23
+ emptyOutDir: true,
24
+ reportCompressedSize: false,
25
+ },
26
+ plugins: options.isDEV ? [electronViteHotReboot()] : [],
27
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nemigo/electron",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "private": false,
5
5
  "author": {
6
6
  "name": "Vlad Logvin",
@@ -14,13 +14,17 @@
14
14
  "format": "prettier --write ./"
15
15
  },
16
16
  "exports": {
17
- "./vite/hot-reboot": {
18
- "types": "./dist/vite/hot-reboot.d.ts",
19
- "default": "./dist/vite/hot-reboot.js"
20
- },
21
17
  "./security": {
22
18
  "types": "./dist/security.d.ts",
23
19
  "default": "./dist/security.js"
20
+ },
21
+ "./vite": {
22
+ "types": "./dist/vite/index.d.ts",
23
+ "default": "./dist/vite/index.js"
24
+ },
25
+ "./vite/hot-reboot": {
26
+ "types": "./dist/vite/hot-reboot.d.ts",
27
+ "default": "./dist/vite/hot-reboot.js"
24
28
  }
25
29
  },
26
30
  "peerDependencies": {