@thirty-coder/electron-base-kit 0.0.0-stage → 0.1.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.
- package/README.md +82 -2
- package/dist/index.d.ts +53 -0
- package/dist/index.js +34 -0
- package/package.json +34 -4
package/README.md
CHANGED
|
@@ -1,3 +1,83 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @thirty-coder/electron-base-kit
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Electron 桌面应用的基础能力,业务项目以 npm 依赖引入。
|
|
4
|
+
|
|
5
|
+
## 包含什么
|
|
6
|
+
|
|
7
|
+
16 项运行时能力,开箱即用。
|
|
8
|
+
|
|
9
|
+
| 能力 | 说明 | 开关 |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| 窗口管理 | 创建、多屏适配、记忆位置和尺寸 | 常开 |
|
|
12
|
+
| 单实例锁 | 二次启动唤起已有窗口,不开第二个 | 常开 |
|
|
13
|
+
| 安全基线 | contextIsolation、CSP、外链拦截、禁用 webview | 常开 |
|
|
14
|
+
| 日志 | 分级、落盘、按天轮转、一键导出 | 常开 |
|
|
15
|
+
| 崩溃捕获 | 主进程 + 渲染进程,本地留存 | 常开 |
|
|
16
|
+
| IPC 契约 | 类型安全的通道定义,不手写 channel 字符串 | 常开 |
|
|
17
|
+
| 配置存储 | 用户配置持久化,区分用户可改与只读 | 常开 |
|
|
18
|
+
| 自动更新 | Windows 静默更新,macOS 未签名时引导下载 | `updater` |
|
|
19
|
+
| 授权校验 | 非对称签名、离线验签、机器绑定 | `license` |
|
|
20
|
+
| 系统托盘 | 托盘图标、右键菜单、未读角标 | `tray` |
|
|
21
|
+
| 系统通知 | 原生通知 + 点击回调 | `notify` |
|
|
22
|
+
| 全局快捷键 | 注册/注销、冲突检测 | `shortcut` |
|
|
23
|
+
| 文件对话框 | 打开、保存、选目录 | `dialog` |
|
|
24
|
+
| 剪贴板 | 文本、图片读写 | `clipboard` |
|
|
25
|
+
| 开机自启 | 登录项注册 | `autolaunch` |
|
|
26
|
+
| deep link | 协议注册与参数解析 | `deeplink` |
|
|
27
|
+
|
|
28
|
+
带开关的能力在 `app.config.json` 里控制,关掉就不会初始化。
|
|
29
|
+
|
|
30
|
+
## 用法
|
|
31
|
+
|
|
32
|
+
业务项目在 `electron/main.ts` 里调用:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { bootstrap } from '@thirty-coder/electron-base-kit'
|
|
36
|
+
import config from '../app.config.json'
|
|
37
|
+
|
|
38
|
+
bootstrap(config)
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
框架不读配置文件,config 由项目传入。
|
|
42
|
+
|
|
43
|
+
## 配置
|
|
44
|
+
|
|
45
|
+
`app.config.json` 由业务项目维护,结构对应 `AppConfig` 类型:
|
|
46
|
+
|
|
47
|
+
```json
|
|
48
|
+
{
|
|
49
|
+
"appId": "com.example.my-app",
|
|
50
|
+
"productName": "My App",
|
|
51
|
+
"protocol": "myapp",
|
|
52
|
+
"features": {
|
|
53
|
+
"updater": true,
|
|
54
|
+
"license": false,
|
|
55
|
+
"tray": false
|
|
56
|
+
},
|
|
57
|
+
"update": {
|
|
58
|
+
"provider": "generic",
|
|
59
|
+
"url": "https://dl.example.com/myapp"
|
|
60
|
+
},
|
|
61
|
+
"license": { "publicKey": "" },
|
|
62
|
+
"window": { "width": 1200, "height": 800, "minWidth": 900, "minHeight": 600 }
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`updater` 打开后要填 `update`,`license` 打开后要填 `publicKey`。
|
|
67
|
+
|
|
68
|
+
## 升级
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
pnpm up @thirty-coder/electron-base-kit
|
|
72
|
+
pnpm dev
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## 开发
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pnpm build # 产出 dist
|
|
79
|
+
pnpm typecheck # 只做类型检查
|
|
80
|
+
cd playground && pnpm start # 在最小环境里验证
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
本包怎么改见 [MAINTAINING.md](./MAINTAINING.md)。
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/** 能力开关。未声明的能力视为关闭。 */
|
|
2
|
+
interface FeatureFlags {
|
|
3
|
+
updater?: boolean;
|
|
4
|
+
license?: boolean;
|
|
5
|
+
tray?: boolean;
|
|
6
|
+
notify?: boolean;
|
|
7
|
+
shortcut?: boolean;
|
|
8
|
+
dialog?: boolean;
|
|
9
|
+
clipboard?: boolean;
|
|
10
|
+
autolaunch?: boolean;
|
|
11
|
+
deeplink?: boolean;
|
|
12
|
+
}
|
|
13
|
+
type UpdateProvider = 'generic' | 'github';
|
|
14
|
+
interface UpdateConfig {
|
|
15
|
+
provider: UpdateProvider;
|
|
16
|
+
/** generic 时必填,产物根地址,例如 https://dl.example.com/myapp */
|
|
17
|
+
url?: string;
|
|
18
|
+
/** github 时必填 */
|
|
19
|
+
owner?: string;
|
|
20
|
+
/** github 时必填 */
|
|
21
|
+
repo?: string;
|
|
22
|
+
}
|
|
23
|
+
interface LicenseConfig {
|
|
24
|
+
/** 验签公钥,签发私钥不在此处 */
|
|
25
|
+
publicKey: string;
|
|
26
|
+
}
|
|
27
|
+
interface WindowConfig {
|
|
28
|
+
width?: number;
|
|
29
|
+
height?: number;
|
|
30
|
+
minWidth?: number;
|
|
31
|
+
minHeight?: number;
|
|
32
|
+
}
|
|
33
|
+
/** 由业务项目传入,框架不读文件。 */
|
|
34
|
+
interface AppConfig {
|
|
35
|
+
appId: string;
|
|
36
|
+
productName: string;
|
|
37
|
+
/** deep link 协议名,例如 myapp */
|
|
38
|
+
protocol?: string;
|
|
39
|
+
features?: FeatureFlags;
|
|
40
|
+
update?: UpdateConfig;
|
|
41
|
+
license?: LicenseConfig;
|
|
42
|
+
window?: WindowConfig;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 初始化框架。
|
|
47
|
+
*
|
|
48
|
+
* 骨架阶段只保存配置,各能力后续逐个接入。
|
|
49
|
+
*/
|
|
50
|
+
declare function bootstrap(config: AppConfig): void;
|
|
51
|
+
|
|
52
|
+
export { bootstrap };
|
|
53
|
+
export type { AppConfig, FeatureFlags, LicenseConfig, UpdateConfig, UpdateProvider, WindowConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
bootstrap: () => bootstrap
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/bootstrap.ts
|
|
28
|
+
function bootstrap(config) {
|
|
29
|
+
void config;
|
|
30
|
+
}
|
|
31
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
+
0 && (module.exports = {
|
|
33
|
+
bootstrap
|
|
34
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thirty-coder/electron-base-kit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Electron 桌面应用基础能力",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/sanshi26910/electron-base-kit.git"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"require": "./dist/index.js",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsup",
|
|
24
|
+
"dev": "tsup --watch",
|
|
25
|
+
"typecheck": "tsc --noEmit",
|
|
26
|
+
"release": "node scripts/release.mjs"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"electron": ">=30"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"electron": "^45.6.0",
|
|
33
|
+
"tsup": "^9.0.0",
|
|
34
|
+
"typescript": "^6.0.3"
|
|
35
|
+
}
|
|
36
|
+
}
|