feat: electron app (#1586)

This commit is contained in:
Peng Xiao
2023-03-16 22:58:21 +08:00
committed by GitHub
parent 6ae06d5609
commit 88f662e6f6
42 changed files with 6597 additions and 284 deletions
+33
View File
@@ -0,0 +1,33 @@
/**
* @module preload
*/
import { contextBridge } from 'electron';
import { sha256sum } from './sha256sum';
// Expose version number to renderer
contextBridge.exposeInMainWorld('yerba', { version: 0.1 });
/**
* The "Main World" is the JavaScript context that your main renderer code runs in.
* By default, the page you load in your renderer executes code in this world.
*
* @see https://www.electronjs.org/docs/api/context-bridge
*/
/**
* After analyzing the `exposeInMainWorld` calls,
* `packages/preload/exposedInMainWorld.d.ts` file will be generated.
* It contains all interfaces.
* `packages/preload/exposedInMainWorld.d.ts` file is required for TS is `renderer`
*
* @see https://github.com/cawa-93/dts-for-context-bridge
*/
/**
* Safe expose node.js API
* @example
* window.nodeCrypto('data')
*/
contextBridge.exposeInMainWorld('nodeCrypto', { sha256sum });
@@ -0,0 +1,6 @@
import type { BinaryLike } from 'crypto';
import { createHash } from 'crypto';
export function sha256sum(data: BinaryLike) {
return createHash('sha256').update(data).digest('hex');
}