@bouko/electron 1.1.7 → 1.1.9

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.
@@ -1,7 +1,2 @@
1
- export declare class IpcManager {
2
- id: string;
3
- constructor(id: string);
4
- on<T, K>(channel: string, cb: (params?: T) => Promise<K>): void;
5
- }
6
1
  export declare function setupAppIpc(): void;
7
2
  export * from "./manager";
@@ -1,14 +1,5 @@
1
1
  import { ipcMain, BrowserWindow, shell } from "electron";
2
2
  import { choosePath } from "../files/dialog";
3
- export class IpcManager {
4
- id;
5
- constructor(id) {
6
- this.id = id;
7
- }
8
- on(channel, cb) {
9
- ipcMain.handle(`${this.id}:${channel}`, (_, params) => cb(params));
10
- }
11
- }
12
3
  export function setupAppIpc() {
13
4
  ipcMain.on("app:minimize", (event) => {
14
5
  const window = BrowserWindow.fromWebContents(event.sender);
@@ -1,6 +1,6 @@
1
1
  export type IpcSchema = Record<string, Record<string, {
2
- input?: string | object;
3
- result: any;
2
+ input?: unknown;
3
+ result: unknown;
4
4
  }>>;
5
5
  type Input<S extends IpcSchema, N extends keyof S, K extends keyof S[N]> = S[N][K] extends {
6
6
  input: infer I;
@@ -8,37 +8,16 @@ type Input<S extends IpcSchema, N extends keyof S, K extends keyof S[N]> = S[N][
8
8
  type Result<S extends IpcSchema, N extends keyof S, K extends keyof S[N]> = S[N][K] extends {
9
9
  result: infer R;
10
10
  } ? R : never;
11
- export type MainAdapter = {
12
- handle: (channel: string, handler: (input: any) => any) => void;
13
- };
14
- export type RendererAdapter = {
15
- invoke: (channel: string, input?: any) => Promise<any>;
16
- };
17
- type NamespaceMain<S extends IpcSchema, N extends keyof S> = {
11
+ type Namespace<S extends IpcSchema, N extends keyof S> = {
18
12
  on<K extends keyof S[N] & string>(key: K, handler: (input: Input<S, N, K>) => Result<S, N, K> | Promise<Result<S, N, K>>): void;
19
13
  };
20
- type NamespaceRenderer<S extends IpcSchema, N extends keyof S> = {
21
- call<K extends keyof S[N] & string>(key: K, input: Input<S, N, K>): Promise<Result<S, N, K>>;
22
- call0<K extends keyof S[N] & string>(key: K): Input<S, N, K> extends undefined ? Promise<Result<S, N, K>> : never;
23
- };
24
- type MainClient<S extends IpcSchema> = {
25
- [N in keyof S]: NamespaceMain<S, N>;
26
- };
27
- type RendererClient<S extends IpcSchema> = {
28
- [N in keyof S]: NamespaceRenderer<S, N>;
14
+ type Client<S extends IpcSchema> = {
15
+ [N in keyof S]: Namespace<S, N>;
29
16
  };
30
- export declare class IpcMainManager<S extends IpcSchema> {
31
- private adapter;
32
- private delimiter;
33
- readonly ipc: MainClient<S>;
34
- constructor(adapter: MainAdapter, delimiter?: string);
35
- private makeNamespace;
36
- }
37
- export declare class IpcRendererManager<S extends IpcSchema> {
38
- private adapter;
17
+ export declare class IpcManager<S extends IpcSchema> {
39
18
  private delimiter;
40
- readonly ipc: RendererClient<S>;
41
- constructor(adapter: RendererAdapter, delimiter?: string);
19
+ readonly ipc: Client<S>;
20
+ constructor(delimiter?: string);
42
21
  private makeNamespace;
43
22
  }
44
23
  export {};
@@ -1,34 +1,19 @@
1
- export class IpcMainManager {
2
- adapter;
1
+ import { ipcMain } from "electron";
2
+ export class IpcManager {
3
3
  delimiter;
4
4
  ipc;
5
- constructor(adapter, delimiter = ":") {
6
- this.adapter = adapter;
5
+ constructor(delimiter = ":") {
7
6
  this.delimiter = delimiter;
8
- this.ipc = new Proxy({}, { get: (_t, ns) => this.makeNamespace(ns) });
7
+ this.ipc = new Proxy({}, {
8
+ get: (_target, ns) => this.makeNamespace(ns),
9
+ });
9
10
  }
10
11
  makeNamespace(ns) {
11
12
  const ch = (key) => `${ns}${this.delimiter}${key}`;
12
13
  return {
13
14
  on: (key, handler) => {
14
- this.adapter.handle(ch(key), (...args) => handler(...args));
15
- }
16
- };
17
- }
18
- }
19
- export class IpcRendererManager {
20
- adapter;
21
- delimiter;
22
- ipc;
23
- constructor(adapter, delimiter = ":") {
24
- this.adapter = adapter;
25
- this.delimiter = delimiter;
26
- this.ipc = new Proxy({}, { get: (_t, ns) => this.makeNamespace(ns) });
27
- }
28
- makeNamespace(ns) {
29
- const ch = (key) => `${ns}${this.delimiter}${key}`;
30
- return {
31
- call: (key, ...args) => this.adapter.invoke(ch(key), ...args),
15
+ ipcMain.handle(ch(key), (_event, input) => handler(input));
16
+ },
32
17
  };
33
18
  }
34
19
  }
package/dist/csp/index.js CHANGED
@@ -19,7 +19,7 @@ export const csp = "default-src 'self'; " +
19
19
  "style-src 'self'; " +
20
20
  "img-src 'self' data: https:; " +
21
21
  "font-src 'self' data:; " +
22
- `connect-src 'self' blob: ${getEnv("DB_URL")}; ` +
22
+ `connect-src 'self' blob: ${getEnv("BASE_URL")} ${getEnv("DB_URL")}; ` +
23
23
  "media-src 'self' blob: data:; " +
24
24
  "worker-src 'self' blob:; " +
25
25
  "object-src 'none'; " +
@@ -31,7 +31,7 @@ export const devCsp = "default-src 'self' http://localhost:* blob: data:; " +
31
31
  "img-src 'self' data: blob: http://localhost:* https:; " +
32
32
  "media-src 'self' blob: data:; " +
33
33
  "worker-src 'self' blob: http://localhost:*; " +
34
- `connect-src 'self' blob: http://localhost:* ws://localhost:* ${getEnv("DB_URL")};`;
34
+ `connect-src 'self' blob: http://localhost:* ws://localhost:* ${getEnv("BASE_URL")} ${getEnv("DB_URL")};`;
35
35
  export const setupCspPolicy = () => session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
36
36
  if (details.url.startsWith("file://") || details.url.startsWith("http://localhost")) {
37
37
  callback({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
 
3
3
  "name": "@bouko/electron",
4
- "version": "1.1.7",
4
+ "version": "1.1.9",
5
5
  "description": "",
6
6
  "keywords": [],
7
7
  "author": "",