├── .changeset
├── README.md
└── config.json
├── .eslintrc.cjs
├── .github
├── CONTRIBUTING.md
├── CONTRIBUTING_ZH.md
└── workflows
│ └── release.yml
├── .gitignore
├── .npmrc
├── LICENSE
├── README.md
├── README_ZH.md
├── docs
├── .vitepress
│ ├── cache
│ │ └── deps
│ │ │ ├── _metadata.json
│ │ │ ├── package.json
│ │ │ ├── vitepress___@vue_devtools-api.js
│ │ │ ├── vitepress___@vue_devtools-api.js.map
│ │ │ ├── vue.js
│ │ │ └── vue.js.map
│ ├── config.mts
│ └── theme
│ │ ├── components
│ │ └── NavVisitor.vue
│ │ ├── index.ts
│ │ └── style
│ │ └── var.css
├── api
│ ├── electron-prokit
│ │ ├── db.md
│ │ ├── ffi.md
│ │ ├── http.md
│ │ ├── ipc.md
│ │ ├── schedule.md
│ │ ├── update.md
│ │ └── window.md
│ └── index.md
├── guide
│ ├── index.md
│ └── start.md
├── index.md
├── package.json
├── plugin
│ ├── create-service.md
│ ├── electron-prokit-cli.md
│ └── index.md
├── public
│ ├── api
│ │ └── ipc-demo.png
│ ├── favicon.ico
│ ├── guide
│ │ └── inner.png
│ ├── headlogo.svg
│ ├── logo.svg
│ └── tutorials
│ │ ├── create-vite-electron-service-vue-2.png
│ │ ├── create-vite-electron-service-vue.png
│ │ ├── create-vite-electron-service1.png
│ │ ├── create-vite-electron-service2.png
│ │ └── create-vite-electron-service3.png
├── tutorials
│ ├── create-vite-electron-service-vue.md
│ ├── create-vite-electron-service.md
│ └── index.md
└── zh
│ ├── api
│ ├── electron-prokit
│ │ ├── db.md
│ │ ├── ffi.md
│ │ ├── http.md
│ │ ├── ipc.md
│ │ ├── schedule.md
│ │ ├── update.md
│ │ └── window.md
│ └── index.md
│ ├── guide
│ ├── index.md
│ └── start.md
│ ├── index.md
│ ├── plugin
│ ├── create-service.md
│ ├── electron-prokit-cli.md
│ └── index.md
│ └── tutorials
│ ├── create-vite-electron-service-vue.md
│ ├── create-vite-electron-service.md
│ └── index.md
├── jest.config.cjs
├── package.json
├── packages
├── create-electron-prokit
│ ├── CHANGELOG.md
│ ├── README.md
│ ├── package.json
│ ├── src
│ │ ├── index.ts
│ │ └── modify.ts
│ ├── template-react-ts
│ │ ├── .eslintrc.cjs
│ │ ├── .gitignore
│ │ ├── .npmrc
│ │ ├── README.md
│ │ ├── config
│ │ │ ├── main.ts
│ │ │ ├── preload.ts
│ │ │ ├── render.ts
│ │ │ └── work.ts
│ │ ├── electron-builder.config.json
│ │ ├── index.html
│ │ ├── package.json
│ │ ├── public
│ │ │ └── vite.svg
│ │ ├── resources
│ │ │ └── icon
│ │ │ │ ├── icon.icns
│ │ │ │ ├── icon.ico
│ │ │ │ ├── icon.png
│ │ │ │ └── icon@2x.png
│ │ ├── scripts
│ │ │ ├── build.ts
│ │ │ ├── dev.ts
│ │ │ └── entitlements.mac.plist
│ │ ├── src
│ │ │ ├── main
│ │ │ │ ├── index.ts
│ │ │ │ └── ipc.ts
│ │ │ ├── preload
│ │ │ │ └── index.ts
│ │ │ ├── render
│ │ │ │ ├── App.css
│ │ │ │ ├── App.tsx
│ │ │ │ ├── assets
│ │ │ │ │ ├── logo.svg
│ │ │ │ │ └── react.svg
│ │ │ │ ├── index.css
│ │ │ │ ├── main.tsx
│ │ │ │ └── vite-env.d.ts
│ │ │ ├── type.d.ts
│ │ │ ├── util
│ │ │ │ └── index.ts
│ │ │ └── work
│ │ │ │ ├── App.tsx
│ │ │ │ ├── index.html
│ │ │ │ └── main.tsx
│ │ └── tsconfig.json
│ ├── template-vue-ts
│ │ ├── .gitignore
│ │ ├── .npmrc
│ │ ├── README.md
│ │ ├── config
│ │ │ ├── main.ts
│ │ │ ├── preload.ts
│ │ │ ├── render.ts
│ │ │ └── work.ts
│ │ ├── electron-builder.config.json
│ │ ├── index.html
│ │ ├── package.json
│ │ ├── public
│ │ │ └── vite.svg
│ │ ├── resources
│ │ │ └── icon
│ │ │ │ ├── icon.icns
│ │ │ │ ├── icon.ico
│ │ │ │ ├── icon.png
│ │ │ │ └── icon@2x.png
│ │ ├── scripts
│ │ │ ├── build.ts
│ │ │ ├── dev.ts
│ │ │ └── entitlements.mac.plist
│ │ ├── src
│ │ │ ├── main
│ │ │ │ ├── index.ts
│ │ │ │ └── ipc.ts
│ │ │ ├── preload
│ │ │ │ └── index.ts
│ │ │ ├── render
│ │ │ │ ├── App.vue
│ │ │ │ ├── assets
│ │ │ │ │ ├── logo.svg
│ │ │ │ │ └── vue.svg
│ │ │ │ ├── components
│ │ │ │ │ └── HelloWorld.vue
│ │ │ │ ├── main.ts
│ │ │ │ ├── style.css
│ │ │ │ └── vite-env.d.ts
│ │ │ ├── type.d.ts
│ │ │ └── work
│ │ │ │ ├── index.html
│ │ │ │ └── main.ts
│ │ └── tsconfig.json
│ ├── tsconfig.json
│ └── typings.d.ts
├── create-service
│ ├── CHANGELOG.md
│ ├── README.md
│ ├── package.json
│ ├── src
│ │ └── index.ts
│ └── tsconfig.json
└── electron-prokit
│ ├── CHANGELOG.md
│ ├── README.md
│ ├── package.json
│ ├── src
│ ├── db
│ │ ├── index.ts
│ │ ├── main.ts
│ │ ├── preload.ts
│ │ ├── render.ts
│ │ └── type.d.ts
│ ├── env
│ │ └── index.ts
│ ├── ffi
│ │ └── index.ts
│ ├── hooks
│ │ └── index.ts
│ ├── http
│ │ └── index.ts
│ ├── index.ts
│ ├── ipc
│ │ ├── index.ts
│ │ ├── main.ts
│ │ ├── preload.ts
│ │ └── render.ts
│ ├── locale
│ │ └── index.ts
│ ├── main.ts
│ ├── preload.ts
│ ├── schedule
│ │ └── index.ts
│ ├── update
│ │ └── index.ts
│ └── window
│ │ └── index.ts
│ ├── test
│ └── schedule
│ │ └── index.test.ts
│ ├── tsconfig.json
│ ├── typings.d.ts
│ └── vendor.d.ts
├── play
├── .gitignore
├── .npmrc
├── README.md
├── config
│ ├── main.ts
│ ├── preload.ts
│ ├── render.ts
│ └── work.ts
├── dev-app-update.yml
├── electron-builder.config.json
├── index.html
├── package.json
├── public
│ └── vite.svg
├── resources
│ ├── dll
│ │ ├── mul_and_div.dll
│ │ ├── mul_and_div.dylib
│ │ ├── sum.dll
│ │ └── sum.dylib
│ ├── icon
│ │ ├── icon.icns
│ │ ├── icon.ico
│ │ ├── icon.png
│ │ └── icon@2x.png
│ ├── mul_and_div.c
│ └── sum.c
├── scripts
│ ├── build.ts
│ ├── dev.ts
│ └── entitlements.mac.plist
├── src
│ ├── main
│ │ ├── ffi.ts
│ │ ├── gui.ts
│ │ ├── http.ts
│ │ ├── index.ts
│ │ ├── ipc.ts
│ │ └── window.ts
│ ├── preload
│ │ └── index.ts
│ ├── render
│ │ ├── App.css
│ │ ├── App.tsx
│ │ ├── assets
│ │ │ └── react.svg
│ │ ├── context
│ │ │ └── global.ts
│ │ ├── index.css
│ │ ├── layout
│ │ │ ├── index.tsx
│ │ │ └── menu.ts
│ │ ├── locales
│ │ │ ├── en-us.json
│ │ │ ├── index.ts
│ │ │ └── zh-cn.json
│ │ ├── main.tsx
│ │ ├── pages
│ │ │ ├── db.tsx
│ │ │ ├── error-page.tsx
│ │ │ ├── ffi.tsx
│ │ │ ├── home.tsx
│ │ │ ├── http.tsx
│ │ │ ├── ipc.tsx
│ │ │ ├── schedule.tsx
│ │ │ └── update.tsx
│ │ └── router
│ │ │ └── index.tsx
│ ├── type.d.ts
│ ├── util
│ │ └── index.ts
│ └── work
│ │ ├── App.tsx
│ │ ├── index.html
│ │ └── main.tsx
├── tsconfig.json
└── vendor.d.ts
├── pnpm-lock.yaml
├── pnpm-workspace.yaml
├── rollup.config.js
└── tsconfig.json
/.changeset/README.md:
--------------------------------------------------------------------------------
1 | # Changesets
2 |
3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4 | with multi-package repos, or single-package repos to help you version and publish your code. You can
5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6 |
7 | We have a quick list of common questions to get you started engaging with this project in
8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
9 |
--------------------------------------------------------------------------------
/.changeset/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json",
3 | "changelog": "@changesets/cli/changelog",
4 | "commit": false,
5 | "fixed": [],
6 | "linked": [],
7 | "access": "restricted",
8 | "baseBranch": "main",
9 | "updateInternalDependencies": "patch",
10 | "ignore": []
11 | }
12 |
--------------------------------------------------------------------------------
/.github/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | English | [简体中文](./CONTRIBUTING_ZH.md)
--------------------------------------------------------------------------------
/.github/CONTRIBUTING_ZH.md:
--------------------------------------------------------------------------------
1 | 简体中文 | [English](./CONTRIBUTING.md)
2 |
3 | # 贡献指南
4 |
5 | 你好!很高兴你有兴趣为Electron Prokit做出贡献!在提交贡献之前,请通过以下指南阅读。我们还建议您在文档中阅读项目理念。
6 |
7 | ## 项目目录结构说明
8 |
9 | ```bash
10 | root
11 | |---.changeset # changeset 配置相关文件
12 | |
13 | |---.github # github 配置相关文件
14 | |
15 | |---docs # 项目文档
16 | |
17 | |---packages # 包目录
18 | | |---create-electron-prokit # 脚手架
19 | | |---create-service # 用于快速创建electron相关服务
20 | | |---electron-prokit # electron-prokit 核心包
21 | | | |- src # electron-prokit开发目录
22 | | | | |- db # 数据库模块
23 | | | | |- env # 环境判断env
24 | | | | |- ffi # 跨语言调用模块
25 | | | | |- hooks # 一些hooks
26 | | | | |- http # 网络请求模块
27 | | | | |- ipc # ipc通信模块
28 | | | | |- schedule # 定时任务模块
29 | | | | |- window # 窗口功能模块
30 | | | | |- index.ts # 核心导出
31 | | | | |- main.ts # 主进程相关函数
32 | | | | |- preload.ts # preload相关函数
33 | | | |- test # 测试目录
34 | |
35 | |---play # 演示项目
36 | | |---public # 公共目录
37 | | |---resources # 资源目录
38 | | |---scripts # 脚本
39 | | |---src # 演示项目开发目录
40 | | | |- main # 主进程
41 | | | |- preload # preload脚本
42 | | | |- preload # 渲染进程
43 | | | |- util # 工具库
44 | | | |- work # work进程
45 | | |---electron-builder.config.ts # 打包配置
46 | | |---ep.config.ts # 项目配置
47 | ```
48 |
49 | ## 本地开发
50 |
51 | ```
52 | git clone https://github.com/Xutaotaotao/electron-prokit.git
53 |
54 | pnpm i
55 |
56 | pnpm run dev
57 |
58 | ```
59 |
60 | ## 测试
61 |
62 | 每个package都有测试目录,在相应的包目录下运行`npm run test`
63 |
64 | ## Pull Request
65 |
66 | - fork 项目
67 | - 基于主分支创建分支进行修改
68 | - 如果你修复了一个 bug 或者新增了一个功能,请确保写了相应的测试,这很重要。
69 | - 确认所有的测试都是通过的 `npm run test`
70 | - 然后进行Pull Request
71 |
72 |
73 | ## 开发相关资料
74 |
75 | - pnpm: https://pnpm.io/zh/
76 | - vite: https://cn.vitejs.dev/
77 | - electron: https://www.electronjs.org/zh/
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | # https://docs.github.com/en/actions/using-workflows/about-workflows
2 | name: Release
3 |
4 | on:
5 | push:
6 | branches:
7 | - main
8 |
9 | jobs:
10 | release:
11 | runs-on: ubuntu-latest
12 | steps:
13 | # https://github.com/actions/checkout
14 | - name: Checkout Repo
15 | uses: actions/checkout@v2
16 | # https://github.com/actions/setup-node
17 | - name: Setup Node.js
18 | uses: actions/setup-node@v3
19 | with:
20 | node-version: 16.x
21 | # https://github.com/pnpm/action-setup
22 | - name: Setup Pnpm
23 | uses: pnpm/action-setup@v2
24 | with:
25 | version: 7.x
26 | # https://pnpm.io/zh/cli/install#--frozen-lockfile
27 | - name: Install Dependencies
28 | run: pnpm install --no-frozen-lockfile
29 |
30 | - name: Run Jest tests
31 | run: pnpm test-c
32 |
33 | - name: Coveralls
34 | uses: coverallsapp/github-action@master
35 | with:
36 | github-token: ${{ secrets.GITHUB_TOKEN }}
37 |
38 | - name: Build docs
39 | run: pnpm docs:build
40 |
41 | - name: Deploy to GitHub Pages
42 | uses: crazy-max/ghaction-github-pages@v2
43 | with:
44 | target_branch: gh-pages
45 | build_dir: docs/.vitepress/dist
46 | env:
47 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
48 |
49 | # https://github.com/changesets/action
50 | - name: Create Release Pull Request or Publish to npm
51 | uses: changesets/action@v1
52 | with:
53 | publish: pnpm release
54 | env:
55 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
56 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | dist
12 | dist-ssr
13 | release
14 | coverage
15 | *.local
16 |
17 | # Editor directories and files
18 | .vscode/*
19 | !.vscode/extensions.json
20 | .idea
21 | .DS_Store
22 | *.suo
23 | *.ntvs*
24 | *.njsproj
25 | *.sln
26 | *.sw?
27 |
28 | # lock
29 | yarn.lock
30 | pnpm-lock.yaml
31 | npm.lock
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/
2 | ELECTRON_BUILDER_BINARIES_MIRROR=https://npmmirror.com/mirrors/electron-builder-binaries/
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 electron-prokit
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README_ZH.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
Electron Prokit
6 |
一款基于 Electron 的桌面软件开发框架,让你拥有极致的桌面开发体验。
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | 简体中文 | [English](./README_EN.md)
21 |
22 |
23 | ## ✨ 特性
24 |
25 | - **💡 快速开始**: 脚手架工具助你一键快速开发Electron项目
26 |
27 | - **⚡️ Vite支持**: 所有的进程配置使用方式与 Vite 相同
28 |
29 | - **🛠️ 开箱即用**: 开箱即用支持 Typescript、Vue、React
30 |
31 | - **📦 预设打包**: 一站式打包构建解决方案
32 |
33 | - **🔥 热更新**: 所有进程及脚本都支持热更新
34 |
35 | - **🔑 完全类型化**: 灵活的 API 和完整的 TypeScript 类型
36 |
37 | - **🎨 丰富的API**: 进程通信、窗口管理、网络请求、跨语言调用、任务管理、数据库管理...
38 |
39 | - **📺 最佳实践**: 提供 Electron 应用程序的最佳实践演示
40 |
41 | ## 👜 npm 包
42 |
43 | |Package|npm version|npm downloads|
44 | | :-: | :-: | :-: |
45 | | [electron-prokit](packages/electron-prokit) |  |  |
46 | | [create-electron-prokit](packages/create-electron-prokit) |  |  |
47 | | [@electron-prokit/create-service](packages/create-service)|  |  |
48 |
49 | ## 🔧 创建项目
50 |
51 | 直接使用脚手架快捷创建项目,脚手架结合了electron-prokit相关生态,推荐使用此方式。
52 |
53 | 使用 NPM:
54 |
55 | ```bash
56 | npm create electron-prokit myapp
57 | ```
58 |
59 | 使用 Yarn:
60 |
61 | ```bash
62 | yarn create electron-prokit myapp
63 | ```
64 |
65 | 其中`myapp`为你的项目名,然后按照提示操作即可!
66 |
67 | ## 📖 官方文档
68 |
69 | 文档首页
70 |
71 | API
72 |
73 | 插件
74 |
75 | 教程
76 |
77 |
78 |
79 | ## ⌨️ 演练
80 |
81 | ```bash
82 | git clone https://github.com/Xutaotaotao/electron-prokit.git
83 |
84 | pnpm i
85 |
86 | pnpm run dev
87 |
88 | ```
89 |
90 | ## 📷 截图
91 |
92 |
93 |
94 |
95 |
96 | ## 📱 联系作者
97 |
98 | 微信扫码联系我
99 |
100 |
101 |
102 |
103 |
104 | ## 👥 支持者
105 |
106 | [](https://github.com/Xutaotaotao/electron-prokit/stargazers)
107 |
108 | [](https://github.com/Xutaotaotao/electron-prokit/network/members)
109 |
110 |
111 |
--------------------------------------------------------------------------------
/docs/.vitepress/cache/deps/_metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "hash": "703b586c",
3 | "browserHash": "7ddbb991",
4 | "optimized": {
5 | "vue": {
6 | "src": "../../../../node_modules/.pnpm/vue@3.3.4/node_modules/vue/dist/vue.runtime.esm-bundler.js",
7 | "file": "vue.js",
8 | "fileHash": "b315090c",
9 | "needsInterop": false
10 | },
11 | "vitepress > @vue/devtools-api": {
12 | "src": "../../../../node_modules/.pnpm/@vue+devtools-api@6.5.0/node_modules/@vue/devtools-api/lib/esm/index.js",
13 | "file": "vitepress___@vue_devtools-api.js",
14 | "fileHash": "9ab1749c",
15 | "needsInterop": false
16 | }
17 | },
18 | "chunks": {}
19 | }
--------------------------------------------------------------------------------
/docs/.vitepress/cache/deps/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "type": "module"
3 | }
4 |
--------------------------------------------------------------------------------
/docs/.vitepress/theme/components/NavVisitor.vue:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/docs/.vitepress/theme/index.ts:
--------------------------------------------------------------------------------
1 | import './style/var.css'
2 |
3 | import { h } from 'vue'
4 | import DefaultTheme from 'vitepress/theme'
5 | import NavVisitor from './components/NavVisitor.vue'
6 |
7 | export default {
8 | extends: DefaultTheme,
9 | Layout: () => {
10 | return h(DefaultTheme.Layout,null,{
11 | 'nav-bar-title-after': () => h(NavVisitor),
12 | })
13 | },
14 | }
15 |
--------------------------------------------------------------------------------
/docs/.vitepress/theme/style/var.css:
--------------------------------------------------------------------------------
1 | :root {
2 | --vp-home-hero-name-color: transparent;
3 | --vp-home-hero-name-background: linear-gradient( 135deg, #97ABFF 10%, #3e61c1 100%);
4 |
5 | --vp-home-hero-image-background-image: linear-gradient( 135deg, #97ABFF 50%, #ffffff 100%);;
6 | --vp-home-hero-image-filter: blur(200px);
7 | }
8 |
--------------------------------------------------------------------------------
/docs/api/electron-prokit/db.md:
--------------------------------------------------------------------------------
1 | ---
2 | outline: deep
3 | title: Db
4 | description: electron-prokit Db api
5 | ---
6 |
7 | # Db
8 |
9 | API interfaces related to data storage management.Use in `Main Process`.
10 |
11 | ## Purpose
12 |
13 | Easily manage local data with convenient read and write operations.
14 |
15 |
16 | ## API Usage
17 |
18 | ### initDb
19 |
20 | Initialize the database.
21 |
22 | ```ts
23 | import { initDb } from "electron-prokit";
24 |
25 | initDb()
26 | .then((res) => {
27 | console.error(res);
28 | })
29 | .catch((err) => {
30 | console.error(err);
31 | });
32 | ```
33 |
34 | **:speech_balloon: Parameters**
35 |
36 | ```ts
37 | initDb = (file = defaultFile): Promise
38 | ```
39 |
40 | - file:The location of the data storage file, defaulting to`join(app.getPath("userData"), "db.json")`。
41 |
42 | ### writeDb
43 |
44 | Write data.
45 |
46 | ```ts
47 | import { writeDb } from "electron-prokit";
48 |
49 | writeDb("test", { name: "Hello", age: 11 });
50 | ```
51 |
52 | **:speech_balloon: Parameters**
53 |
54 | ```ts
55 | writeDb = async (key: string, data: any): Promise
56 | ```
57 |
58 | - key: Data storage key
59 | - data: Data to be stored
60 |
61 | ### readDb
62 |
63 | Read data.
64 |
65 | ```ts
66 | import { readDb } from "electron-prokit";
67 |
68 | readDb("test")
69 | .then((res) => {
70 | console.error(res);
71 | })
72 | .catch((err) => {
73 | console.error(err);
74 | });
75 | ```
76 |
77 | **:speech_balloon: Parameters**
78 |
79 | ```ts
80 | readDb = async (key: string, data: any): Promise
81 | ```
82 |
83 | - key: Data storage key
84 |
85 | ### clearDb
86 |
87 | Clear the entire database.
88 |
89 | ```ts
90 | import { clearDb } from "electron-prokit";
91 |
92 | clearDb();
93 | ```
94 |
95 | **:speech_balloon: Parameters**
96 |
97 | ```ts
98 | clearDb = async ():Promise
99 | ```
100 |
--------------------------------------------------------------------------------
/docs/api/electron-prokit/http.md:
--------------------------------------------------------------------------------
1 | ---
2 | outline: deep
3 | title: Http
4 | description: electron-prokit http api
5 | ---
6 |
7 | # Http
8 |
9 | API interfaces related to network communication. Supports `renderer processes`, `main process`, and `preload` and can be called from anywhere.
10 |
11 | ## Purpose
12 |
13 | The primary purpose of Http is to initiate network requests to interact with server interfaces.
14 |
15 | ## Example
16 |
17 | Initiate a GET request.
18 |
19 | ```ts
20 | import { http } from "electron-prokit";
21 |
22 | http({
23 | url: "https://jsonplaceholder.typicode.com/posts/1",
24 | method: "get",
25 | })
26 | .catch(function (error) {
27 | // 处理错误情况
28 | console.log(error);
29 | })
30 | .finally(function () {
31 | // 总是会执行
32 | });
33 | ```
34 |
35 | ## Request Configuration
36 |
37 | These are the configuration options that can be used when creating a request. Only the URL is required. If the method is not specified, the request will default to using the GET method.
38 |
39 | ```ts
40 | {
41 | // `url` is the server URL used for the request
42 | url: '/user',
43 |
44 | // `method` is the method used when creating the request
45 | method: 'get', // Default value
46 |
47 | // Custom request headers
48 | headers: {'X-Requested-With': 'XMLHttpRequest'},
49 |
50 | // `params` are URL parameters sent along with the request
51 | // Must be a simple object or URLSearchParams object
52 | params: {
53 | ID: 12345
54 | },
55 |
56 | // `data` is the data sent as the request body
57 | data: {
58 | firstName: 'Fred'
59 | },
60 |
61 | // `timeout` specifies the timeout for the request in milliseconds.
62 | // If the request takes longer than the `timeout` value, the request will be aborted
63 | timeout: 1000, // Default is `0` (no timeout)
64 |
65 | // Error handling
66 | handleError: function (error) {
67 | console.log()
68 | }
69 |
70 | // Logging handling / boolean type, function, or empty
71 | // boolean means print to console, function allows custom logging
72 | log: true
73 | }
74 |
75 | ```
76 |
77 | ## Interceptors
78 |
79 | ```ts
80 | // Add a request interceptor
81 | http.interceptors.request.use(
82 | function (config) {
83 | // Do something before sending the request
84 | return config;
85 | },
86 | function (error) {
87 | // Do something with the request error
88 | return Promise.reject(error);
89 | }
90 | );
91 |
92 | // Add a response interceptor
93 | http.interceptors.response.use(
94 | function (response) {
95 | // Do something with the response data
96 | return response;
97 | },
98 | function (error) {
99 | // Do something with the response error
100 | return Promise.reject(error);
101 | }
102 | );
103 |
104 | ```
105 |
--------------------------------------------------------------------------------
/docs/api/electron-prokit/schedule.md:
--------------------------------------------------------------------------------
1 | ---
2 | outline: deep
3 | title: Schedule
4 | description: electron-prokit schedule api
5 | ---
6 |
7 | # Schedule
8 |
9 | API interfaces related to task scheduling. Supports `renderer processes`, `main process`, and `preload` and can be called from anywhere.
10 |
11 | ## Purpose
12 |
13 | Easily manage the lifecycle of scheduled tasks, from creation to termination.
14 |
15 | ## API Usage
16 |
17 | ### registerSchedule
18 |
19 | Register a task.
20 |
21 | ```ts
22 | import { registerSchedule } from "electron-prokit";
23 | registerSchedule({
24 | name: "runScheduleTest",
25 | fun: () => {
26 | console.log("registerSchedule");
27 | },
28 | interval: 3000,
29 | });
30 | ```
31 |
32 | **:speech_balloon: Parameters**
33 |
34 | ```ts
35 | registerSchedule (schedule:RegisterScheduleOption):Schedule
36 | ```
37 | - schedule:Task options
38 |
39 | ```ts
40 | interface RegisterScheduleOption {
41 | name: string; // Task name/unique identifier
42 | fun: Function; // Method to be executed
43 | interval: number; // Interval time / in ms
44 | [key: string]: any; // Other options
45 | }
46 |
47 | interface Schedule extends RegisterScheduleOption {
48 | isRunning?: boolean;
49 | instance?: any;
50 | }
51 | ```
52 |
53 | ### runSchedule
54 |
55 | Run a task.
56 |
57 | ```ts
58 | import { runSchedule } from "electron-prokit";
59 |
60 | runSchedule("runScheduleTest");
61 | ```
62 |
63 | **:speech_balloon: Parameters**
64 |
65 | ```ts
66 | runSchedule(name: string,initRun=true):void
67 | ```
68 |
69 | - name:Task name, type `string`
70 | - initRun: Whether to execute the method during initialization, type `boolean`, default is `true`
71 |
72 | ### stopSchedule
73 |
74 | Stop a task.
75 |
76 | ```ts
77 | import { stopSchedule } from "electron-prokit";
78 |
79 | stopSchedule("runScheduleTest");
80 | ```
81 |
82 | **:speech_balloon: Parameters**
83 |
84 |
85 | ```ts
86 | stopSchedule(name:string):void
87 | ```
88 |
89 | - name:Task name, type `string`
90 |
91 |
92 | ### clearSchedule
93 |
94 | Clear a task.
95 |
96 | ```ts
97 | import { clearSchedule } from "electron-prokit";
98 |
99 | clearSchedule("runScheduleTest");
100 | ```
101 |
102 | **:speech_balloon: Parameters**
103 |
104 | ```ts
105 | clearSchedule(name:string):void
106 | ```
107 |
108 | - name:Task name, type `string`
109 |
110 |
111 | ### getSchedule
112 |
113 | Get a task instance.
114 |
115 | ```ts
116 | import { getSchedule } from "electron-prokit";
117 |
118 | getSchedule("runScheduleTest");
119 | ```
120 |
121 | **:speech_balloon: Parameters**
122 |
123 | ```ts
124 | getSchedule(name: string): Schedule
125 | ```
126 |
127 | - name:Task name, type `string`
128 |
129 | ### hasSchedule
130 |
131 | Check if a task exists.
132 |
133 | ```ts
134 | import { hasSchedule } from "electron-prokit";
135 |
136 | hasSchedule("runScheduleTest");
137 | ```
138 |
139 | **:speech_balloon: Parameters**
140 |
141 | ```ts
142 | hasSchedule (name:string):boolean
143 | ```
144 |
145 | - name:Task name, type `string`
146 |
147 | ### isRunningSchedule
148 |
149 | Check if a task is running.
150 |
151 | ```ts
152 | import { isRunningSchedule } from "electron-prokit";
153 |
154 | isRunningSchedule("runScheduleTest");
155 | ```
156 |
157 | **:speech_balloon: Parameters**
158 |
159 | ```ts
160 | isRunningSchedule(name:string) : boolean
161 | ```
162 |
163 | - name:Task name, type `string`
164 |
165 | ### clearAllSchedule
166 |
167 | Clear all tasks.
168 |
169 | ```ts
170 | import { clearAllSchedule } from "electron-prokit";
171 |
172 | clearAllSchedule();
173 | ```
174 |
175 | **:speech_balloon: Parameters**
176 |
177 | ```ts
178 | clearAllSchedule ():void
179 | ```
180 |
181 |
--------------------------------------------------------------------------------
/docs/api/electron-prokit/update.md:
--------------------------------------------------------------------------------
1 | ---
2 | outline: deep
3 | title: Update
4 | description: electron-prokit Update api
5 | ---
6 |
7 | # Update
8 |
9 | Used for software detection updates.
10 |
11 |
12 | ## initUpadate
13 |
14 | Initialize the update operation, the main process is used.
15 |
16 | ```ts
17 | import { initUpadate } from "electron-prokit";
18 | const option = {
19 | forceDevUpdateConfig:true,
20 | autoDownload:true,
21 | updateUrl: 'http://172.17.194.13:8090', // can use live-server to mock the file server/https://www.npmjs.com/package/live-server
22 | updateDownloadedCallBack: () => {
23 | return sendMsgToRender('main','updateDownloaded')
24 | }
25 | }
26 | initUpadate(option)
27 | ```
28 |
29 | **:speech_balloon: Parameters**
30 |
31 | ```ts
32 | interface UpadateOptions {
33 | log?:boolean | Logger // Whether to print or print
34 | forceDevUpdateConfig?: boolean; // Whether the DEV environment is forced to upgrade
35 | autoDownload?: boolean; // Whether to download automatically
36 | updateUrl: string; // Update resource link
37 | updateDownloadedCallBack: () => void; // Update download successfully callBack
38 | }
39 | ```
40 |
41 | ## intsallUpdateApp
42 |
43 | Install the download app.It can be used with `updatedownloadedCallback`.
44 |
45 | ```ts
46 | import { intsallUpdateApp } from "electron-prokit";
47 | intsallUpdateApp()
48 | ```
49 |
50 |
--------------------------------------------------------------------------------
/docs/api/electron-prokit/window.md:
--------------------------------------------------------------------------------
1 | ---
2 | outline: deep
3 | title: Window
4 | description: electron-prokit window api
5 | ---
6 |
7 | # Window
8 |
9 | API interfaces related to windows. It manages the entire lifecycle of windows, from creation to destruction.
10 |
11 | ## Purpose
12 |
13 | It provides operations for creating, retrieving, and destroying windows. This allows for unified management of window lifecycles.
14 |
15 | ## API Overview
16 |
17 | | Function Name | Usage Context | Description |
18 | | ------------- | :------: | -------------------: |
19 | | createWindow | Main | Create a window |
20 | | getWindow | Main | Get a window instance |
21 | | destroyWindow | Main | Destroy a window |
22 | | getAllWindows | Main | Get all windows |
23 | | hasWindow | Main | Check if a window instance exists |
24 | | clearWindows | Main | Clear all windows |
25 |
26 | ## API Usage
27 |
28 | ### createWindow
29 |
30 | Create a window.
31 |
32 | ```ts
33 | import { join, resolve } from "path";
34 | import { app } from "electron";
35 | import { createWindow } from "electron-prokit";
36 |
37 | const initWindowsAction = () => {
38 | const mainWindow = createWindow("main", {
39 | width: 960,
40 | height: 720,
41 | webPreferences: {
42 | contextIsolation: true,
43 | nodeIntegration: true,
44 | webSecurity: false,
45 | preload: join(__dirname, "../preload/index.cjs"),
46 | },
47 | });
48 |
49 | if (mainWindow) {
50 | if (import.meta.env.MODE === "dev") {
51 | if (import.meta.env.VITE_DEV_SERVER_URL) {
52 | mainWindow.loadURL(import.meta.env.VITE_DEV_SERVER_URL);
53 | mainWindow.webContents.openDevTools();
54 | }
55 | } else {
56 | mainWindow.loadFile(resolve(__dirname, "../render/index.html"));
57 | }
58 | }
59 | };
60 |
61 | app.whenReady().then(() => {
62 | initWindowsAction();
63 | });
64 | ```
65 |
66 | **:speech_balloon: Parameters**
67 |
68 | ```ts
69 | createWindow(
70 | name: string,
71 | options: Electron.BrowserWindowConstructorOptions
72 | ): Electron.CrossProcessExports.BrowserWindow
73 | ```
74 |
75 | - name: Window name, type `string`, a unique identifier. You cannot create a new window if the window name is duplicated.
76 | - options: Window options, type `Electron.BrowserWindowConstructorOptions`
77 |
78 | ### getWindow
79 |
80 | Get a window instance.
81 |
82 | ```ts
83 | // Main Process
84 | import { getWindow } from "electron-prokit";
85 | const workWindow = getWindow('getWindow')
86 | ```
87 | **:speech_balloon: Parameters**
88 | ```ts
89 | getWindow(name: string): Electron.CrossProcessExports.BrowserWindow
90 | ```
91 |
92 | - name: Window name, type `string`
93 |
94 | ### destroyWindow
95 |
96 | Destroy a window instance.
97 |
98 | ```ts
99 | // Main Process
100 | import { destroyWindow } from "electron-prokit";
101 | destroyWindow('getWindow')
102 | ```
103 |
104 | **:speech_balloon: Parameters**
105 | ```ts
106 | destroyWindow(name: string): void
107 | ```
108 |
109 | - name: Window name, type `string`
110 |
111 | ### getAllWindows
112 |
113 | Get all windows.
114 |
115 | ```ts
116 | // Main Process
117 | import { getAllWindows } from "electron-prokit";
118 | getAllWindows()
119 | ```
120 |
121 | **:speech_balloon: Parameters**
122 | ```ts
123 | getAllWindows(): Array
124 | ```
125 |
126 | ### hasWindow
127 |
128 | Check if a window exists.
129 |
130 | ```ts
131 | // Main Process
132 | import { hasWindow } from "electron-prokit";
133 | const hasWorkWindow = hasWindow('work')
134 | ```
135 |
136 | **:speech_balloon: Parameters**
137 |
138 | ```ts
139 | hasWindow(name: string): boolean
140 | ```
141 |
142 | - name: Window name, type`string`
143 |
144 | ### clearWindows
145 |
146 | Clear all windows.
147 |
148 | ```ts
149 | // Main Process
150 | import { clearWindows } from "electron-prokit";
151 | clearWindows()
152 | ```
153 |
154 | **:speech_balloon: Parameters**
155 |
156 | ```ts
157 | clearWindows(): void
158 | ```
159 |
--------------------------------------------------------------------------------
/docs/api/index.md:
--------------------------------------------------------------------------------
1 | # All apis
2 |
3 | - [window: window management](/api/electron-prokit/window)
4 | - [ipc: process communication](/api/electron-prokit/ipc)
5 | - [http: network request](/api/electron-prokit/http)
6 | - [ffi: cross-language calling](/api/electron-prokit/ffi)
7 | - [schedule: task management](/api/electron-prokit/schedule)
8 | - [db: database management](/api/electron-prokit/db)
9 |
10 |
--------------------------------------------------------------------------------
/docs/guide/index.md:
--------------------------------------------------------------------------------
1 | # Introduction
2 |
3 | ::: tip Note
4 | This guide assumes you are familiar with [Electron](https://www.electronjs.org/) and [Vite](https://vitejs.dev/). It will be easier to understand the framework's design philosophy if you have experience with them.
5 | :::
6 |
7 | ## What Problems Does it Solve
8 |
9 | There are many solutions for Electron development in the community, but comparing some of them, there are common issues:
10 |
11 | - Tedious steps to setup an Electron project
12 | - Unable to choose front-end frameworks freely
13 | - Hot reload issues for local development code in each process
14 | - Unified configuration for build and packaging
15 | - Inconsistencies when renderer process calls APIs
16 | - Lack of enterprise-level solutions
17 |
18 | electron-prokit aims to solve these problems and provide an ultimate desktop development experience.
19 |
20 | ## Core Philosophy
21 |
22 | Thanks to Vite's ability to handle both Chromium and Node.js environments, we built the [@electron-prokit/create-service](https://www.npmjs.com/package/@electron-prokit/create-service) plugin specifically to read Vite configs for each process, create the services, and then combine them together. This way, hot reloading works for changes in any process, providing the same experience as traditional web development. It greatly improves development efficiency and debugging efficiency.
23 |
24 | 
25 |
26 | ## Notes
27 |
28 | electron-prokit strictly follows [Electron Best Practices](https://www.npmjs.com/package/@electron-prokit/create-service). Node integration (nodeIntegration) is disabled and context isolation (contextIsolation) is enabled. All framework APIs are implemented using contextBridge.
--------------------------------------------------------------------------------
/docs/guide/start.md:
--------------------------------------------------------------------------------
1 | # Getting Started
2 |
3 | ## Overview
4 |
5 | **electron-prokit** is a desktop application development framework based on Electron, giving you an ultimate desktop development experience, suitable for Vite related ecosystems. It mainly consists of three parts:
6 |
7 | ::: tip Scaffolding
8 | Provides configurable project templates to quickly develop Electron projects.
9 | :::
10 |
11 | ::: tip Core API
12 | The core functionalities implemented by the framework, providing solutions for the Electron ecosystem.
13 |
14 | :::
15 |
16 | ::: tip Plugins
17 | Additional plugins that provide extra support for the framework, making development more convenient for users.
18 | :::
19 |
20 | Whether you are a beginner developer or an experienced one, you can leverage electron-prokit to improve productivity and quickly deliver high-quality Electron applications.
21 |
22 | You can learn more about the design philosophy of this project in the [Introduction](./index) section.
23 |
24 | ## Building Your First electron-prokit Project
25 | ::: warning Compatibility Note
26 | electron-prokit requires Node.js version 18+. However, some templates may depend on higher Node versions to function properly. Please watch out for warnings from your package manager and upgrade Node when necessary.
27 | :::
28 |
29 | Directly use the scaffolding to quickly create a project. The scaffolding integrates electron-prokit related ecosystems, so it is recommended to use this method.
30 |
31 | With NPM:
32 |
33 | ```bash
34 | npm create electron-prokit myapp
35 | ```
36 |
37 | With Yarn:
38 |
39 | ```bash
40 | yarn create electron-prokit myapp
41 | ```
42 |
43 | Where myapp is your project name. Then follow the prompts to complete!
44 |
45 | ## Configuring electron-prokit
46 |
47 | Configure `config` in root directory
48 |
49 | - main.ts
50 | - preload.ts
51 | - render.ts
52 | - work.ts
53 |
54 | ## Playground
55 |
56 | By walking through the demo you can learn more about electron-prokit's functionalities in details.
57 |
58 | ```bash
59 | git clone https://github.com/Xutaotaotao/electron-prokit.git
60 | cd electron-prokit
61 | pnpm i
62 | pnpm run dev
63 | ```
64 |
65 | ## Seeking Help
66 |
67 | If you encounter any problems with electron-prokit during development, you can check out [GitHub Issues](https://github.com/Xutaotaotao/electron-prokit/issues?q=is%3Aissue) to see if someone has run into the same problem. If not, feel free to open a [new issue](https://github.com/Xutaotaotao/electron-prokit/issues/new). You can also seek help in the [GitHub Discussions](https://github.com/Xutaotaotao/electron-prokit/discussions) community.
--------------------------------------------------------------------------------
/docs/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | # https://vitepress.dev/reference/default-theme-home-page
3 | layout: home
4 |
5 | hero:
6 | name: "Electron-Prokit"
7 | text: Use Electron like a Pro!
8 | tagline: Ultimate Desktop Development Experience.
9 | image:
10 | src: /logo.svg
11 | alt: logo
12 | actions:
13 | - theme: brand
14 | text: Get Started
15 | link: /guide/start
16 | - theme: alt
17 | text: View on GitHub
18 | link: https://github.com/Xutaotaotao/electron-prokit
19 |
20 | features:
21 | - icon: 💡
22 | title: Quick Start
23 | details: Quickly get started with scaffolding tools!
24 | - icon: ⚡️
25 | title: Use Vite
26 | details: Configure each process like configuring the vite project.
27 | - icon: 🛠️
28 | title: Rich Features
29 | details: Out-of-the-box support for Typescript、Vue、React and more.
30 | - icon: 📦
31 | title: Optimized Build
32 | details: Packing and Construction Integrated solution.
33 | - icon: 🔥
34 | title: Hot Reloading
35 | details: The main process and rendering process and preload scripts support hot reloading.
36 | - icon: 🔑
37 | title: Fully Typed APIs
38 | details: Flexible programmatic APIs with full TypeScript typing.
39 | - icon: 🎨
40 | title: Abundant APIs
41 | details: Process communication, window management, http, ffi, task...
42 | - icon: 📺
43 | title: Best Practices
44 | details: Provide best practices and demo electron applications.
45 | ---
46 |
47 |
--------------------------------------------------------------------------------
/docs/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "docs",
3 | "private": true,
4 | "version": "0.0.0",
5 | "type": "module",
6 | "scripts": {
7 | "dev": "vitepress dev",
8 | "build": "vitepress build",
9 | "preview": "vitepress preview"
10 | },
11 | "devDependencies": {
12 | "@algolia/client-search": "^4.20.0",
13 | "search-insights": "^2.9.0",
14 | "vitepress": "1.0.0-rc.7"
15 | }
16 | }
--------------------------------------------------------------------------------
/docs/plugin/electron-prokit-cli.md:
--------------------------------------------------------------------------------
1 | # electron-prokit-cli
2 |
3 | This is a scaffold for creating Electron projects, integrated with the electron-prokit ecosystem.
4 |
5 | ## Installing Dependencies
6 |
7 | ```bash
8 | npm i @electron-prokit/cli -g
9 | ```
10 |
11 | ## Usage
12 |
13 | ```bash
14 | electron-prokit-cli init project
15 | ```
16 |
17 | Replace project with the name of your project. After creating the project, install the dependencies and start the project.
18 |
19 | ```bash
20 |
21 | cd project && yarn install
22 |
23 | yarn run dev
24 |
25 | ```
26 |
--------------------------------------------------------------------------------
/docs/plugin/index.md:
--------------------------------------------------------------------------------
1 | # Plugin
2 |
3 | - [create-service](/plugin/create-service)
--------------------------------------------------------------------------------
/docs/public/api/ipc-demo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/docs/public/api/ipc-demo.png
--------------------------------------------------------------------------------
/docs/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/docs/public/favicon.ico
--------------------------------------------------------------------------------
/docs/public/guide/inner.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/docs/public/guide/inner.png
--------------------------------------------------------------------------------
/docs/public/tutorials/create-vite-electron-service-vue-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/docs/public/tutorials/create-vite-electron-service-vue-2.png
--------------------------------------------------------------------------------
/docs/public/tutorials/create-vite-electron-service-vue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/docs/public/tutorials/create-vite-electron-service-vue.png
--------------------------------------------------------------------------------
/docs/public/tutorials/create-vite-electron-service1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/docs/public/tutorials/create-vite-electron-service1.png
--------------------------------------------------------------------------------
/docs/public/tutorials/create-vite-electron-service2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/docs/public/tutorials/create-vite-electron-service2.png
--------------------------------------------------------------------------------
/docs/public/tutorials/create-vite-electron-service3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/docs/public/tutorials/create-vite-electron-service3.png
--------------------------------------------------------------------------------
/docs/tutorials/index.md:
--------------------------------------------------------------------------------
1 | # Tutorials
2 |
3 | - [Building an Electron Project Quickly with Vite and React](/tutorials/create-vite-electron-service)
4 |
5 | - [Building an Electron Project Quickly with Vite and Vue3](/tutorials/create-vite-electron-service-vue)
--------------------------------------------------------------------------------
/docs/zh/api/electron-prokit/db.md:
--------------------------------------------------------------------------------
1 | ---
2 | outline: deep
3 | title: Db
4 | description: electron-prokit Db api
5 | ---
6 |
7 | # Db
8 |
9 | 数据存储管理相关的 API 接口。
10 |
11 | ## 作用
12 |
13 | 轻松管理本地数据,读写方便。
14 |
15 | ## initDb
16 |
17 | 初始化数据库。
18 |
19 | ```ts
20 | import { initDb } from "electron-prokit";
21 |
22 | initDb()
23 | .then((res) => {
24 | console.error(res);
25 | })
26 | .catch((err) => {
27 | console.error(err);
28 | });
29 | ```
30 |
31 | **:speech_balloon: 参数**
32 |
33 | ```ts
34 | initDb = (file = defaultFile): Promise
35 | ```
36 |
37 | - file:数据存储文件位置,默认为`join(app.getPath("userData"), "db.json")`。
38 |
39 | ## writeDb
40 |
41 | 写数据。
42 |
43 | ```ts
44 | import { writeDb } from "electron-prokit";
45 |
46 | writeDb("test", { name: "Hello", age: 11 });
47 | ```
48 |
49 | **:speech_balloon: 参数**
50 |
51 | ```ts
52 | writeDb = async (key: string, data: any): Promise
53 | ```
54 |
55 | - key:数据存储 key
56 | - data:数据存储 data
57 |
58 | ## readDb
59 |
60 | 读数据。
61 |
62 | ```ts
63 | import { readDb } from "electron-prokit";
64 |
65 | readDb("test")
66 | .then((res) => {
67 | console.error(res);
68 | })
69 | .catch((err) => {
70 | console.error(err);
71 | });
72 | ```
73 |
74 | **:speech_balloon: 参数**
75 |
76 | ```ts
77 | readDb = async (key: string, data: any): Promise
78 | ```
79 |
80 | - key:数据存储 key
81 |
82 | ## clearDb
83 |
84 | 清除整个数据库。
85 |
86 | ```ts
87 | import { clearDb } from "electron-prokit";
88 |
89 | clearDb();
90 | ```
91 |
92 | **:speech_balloon: 参数**
93 |
94 | ```ts
95 | clearDb = async ():Promise
96 | ```
97 |
--------------------------------------------------------------------------------
/docs/zh/api/electron-prokit/ffi.md:
--------------------------------------------------------------------------------
1 | ---
2 | outline: deep
3 | title: FFI
4 | description: electron-prokit ffi api
5 | ---
6 |
7 | # Ffi
8 |
9 | 跨语言调用相关的 API 接口,`主进程`中使用。接入成本非常低,快捷、方便、速度快。
10 |
11 | ## 作用
12 |
13 | 主要是在Electron应用中调用`dll`或者`dylib`,使你可以跨语言调用一些底层插件。
14 |
15 | ## createEpffi
16 |
17 | 创建注册方法。
18 |
19 | ```ts
20 | import { createEpffi } from "electron-prokit";
21 | import path from "path";
22 |
23 | // 当个方法/即dylib/dll中只有暴露一个方法
24 | const { sum } = createEpffi({
25 | path: path.join(__dirname, "../../resources/dll/sum.dylib"),
26 | function: {
27 | functionName: "sum",
28 | returnType: "int",
29 | inputs: ["int", "int"],
30 | },
31 | });
32 |
33 | sum(100, 22)
34 |
35 | // 多个方法/即dylib/dll中暴露了多个方法
36 | const { mul,div } = createEpffi({
37 | path: path.join(__dirname, "../../resources/dll/mul_and_div.dylib"),
38 | function: [
39 | {
40 | functionName: "mul",
41 | returnType: "int",
42 | inputs: ["int", "int"],
43 | },
44 | {
45 | functionName: "div",
46 | returnType: "int",
47 | inputs: ["int", "int"],
48 | },
49 | ],
50 | });
51 |
52 | mul(100, 22);
53 |
54 | div(100, 2);
55 | ```
56 |
57 | ## 数据类型
58 |
59 | C type | JS type | Bytes | Signedness | Note
60 | ----------------------------- | ---------------- | ----- | ---------- | ---------------------------
61 | void | Undefined | 0 | | Only valid as a return type
62 | int8, int8_t | Number (integer) | 1 | Signed |
63 | uint8, uint8_t | Number (integer) | 1 | Unsigned |
64 | char | Number (integer) | 1 | Signed |
65 | uchar, unsigned char | Number (integer) | 1 | Unsigned |
66 | char16, char16_t | Number (integer) | 2 | Signed |
67 | int16, int16_t | Number (integer) | 2 | Signed |
68 | uint16, uint16_t | Number (integer) | 2 | Unsigned |
69 | short | Number (integer) | 2 | Signed |
70 | ushort, unsigned short | Number (integer) | 2 | Unsigned |
71 | int32, int32_t | Number (integer) | 4 | Signed |
72 | uint32, uint32_t | Number (integer) | 4 | Unsigned |
73 | int | Number (integer) | 4 | Signed |
74 | uint, unsigned int | Number (integer) | 4 | Unsigned |
75 | int64, int64_t | Number (integer) | 8 | Signed |
76 | uint64, uint64_t | Number (integer) | 8 | Unsigned |
77 | longlong, long long | Number (integer) | 8 | Signed |
78 | ulonglong, unsigned long long | Number (integer) | 8 | Unsigned |
79 | float32 | Number (float) | 4 | |
80 | float64 | Number (float) | 8 | |
81 | float | Number (float) | 4 | |
82 | double | Number (float) | 8 | |
83 | bool | Boolean | | Usually one byte
84 | long | Number (integer) | Signed | 4 or 8 bytes depending on platform (LP64, LLP64)
85 | ulong | Number (integer) | Unsigned | 4 or 8 bytes depending on platform (LP64, LLP64)
86 | unsigned long | Number (integer) | Unsigned | 4 or 8 bytes depending on platform (LP64, LLP64)
87 | intptr | Number (integer) | Signed | 4 or 8 bytes depending on register width
88 | intptr_t | Number (integer) | Signed | 4 or 8 bytes depending on register width
89 | uintptr | Number (integer) | Unsigned | 4 or 8 bytes depending on register width
90 | uintptr_t | Number (integer) | Unsigned | 4 or 8 bytes depending on register width
91 | str, string | String | | JS strings are converted to and from UTF-8
92 | str16, string16 | String | | JS strings are converted to and from UTF-16 (LE)
93 |
--------------------------------------------------------------------------------
/docs/zh/api/electron-prokit/http.md:
--------------------------------------------------------------------------------
1 | ---
2 | outline: deep
3 | title: Http
4 | description: electron-prokit http api
5 | ---
6 |
7 | # Http
8 |
9 | 网络通信相关的 API 接口。支持`渲染进程`、`主进程`、`preload`,可以随处调用。
10 |
11 | ## 作用
12 |
13 | Http的主要作用是发起网络请求,实现与服务端接口的交互。
14 |
15 | ## 用例
16 |
17 | 发起一个 Get 请求
18 |
19 | ```ts
20 | import { http } from "electron-prokit";
21 |
22 | http({
23 | url: "https://jsonplaceholder.typicode.com/posts/1",
24 | method: "get",
25 | })
26 | .catch(function (error) {
27 | // 处理错误情况
28 | console.log(error);
29 | })
30 | .finally(function () {
31 | // 总是会执行
32 | });
33 | ```
34 |
35 | ## 请求配置
36 |
37 | 这些是创建请求时可以用的配置选项。只有 url 是必需的。如果没有指定 method,请求将默认使用 GET 方法。
38 |
39 | ```ts
40 | {
41 | // `url` 是用于请求的服务器 URL
42 | url: '/user',
43 |
44 | // `method` 是创建请求时使用的方法
45 | method: 'get', // 默认值
46 |
47 | // 自定义请求头
48 | headers: {'X-Requested-With': 'XMLHttpRequest'},
49 |
50 | // `params` 是与请求一起发送的 URL 参数
51 | // 必须是一个简单对象或 URLSearchParams 对象
52 | params: {
53 | ID: 12345
54 | },
55 |
56 | // `data` 是作为请求体被发送的数据
57 | data: {
58 | firstName: 'Fred'
59 | },
60 |
61 | // `timeout` 指定请求超时的毫秒数。
62 | // 如果请求时间超过 `timeout` 的值,则请求会被中断
63 | timeout: 1000, // 默认值是 `0` (永不超时)
64 |
65 | // 错误处理
66 | handleError:function (error) {
67 | console.log()
68 | }
69 |
70 | // 日志处理 / boolean类型 或者 function 或者 空
71 | // boolean 就是打印console, function 可以用自己的自定义函数
72 | log: true
73 | }
74 | ```
75 |
76 | ## 拦截器
77 |
78 | ```ts
79 | // 添加请求拦截器
80 | http.interceptors.request.use(
81 | function (config) {
82 | // 在发送请求之前做些什么
83 | return config;
84 | },
85 | function (error) {
86 | // 对请求错误做些什么
87 | return Promise.reject(error);
88 | }
89 | );
90 |
91 | // 添加响应拦截器
92 | http.interceptors.response.use(
93 | function (response) {
94 | // 对响应数据做点什么
95 | return response;
96 | },
97 | function (error) {
98 | // 对响应错误做点什么
99 | return Promise.reject(error);
100 | }
101 | );
102 | ```
103 |
--------------------------------------------------------------------------------
/docs/zh/api/electron-prokit/schedule.md:
--------------------------------------------------------------------------------
1 | ---
2 | outline: deep
3 | title: Schedule
4 | description: electron-prokit schedule api
5 | ---
6 |
7 | # Schedule
8 |
9 | 定时任务管理器相关的 API 接口。支持`渲染进程`、`主进程`、`任务进程`,可以随处调用。
10 |
11 | ## 作用
12 |
13 | 轻松管理定时任务的生命周期,从创建到销毁。
14 |
15 | ## API 使用
16 |
17 | ### registerSchedule
18 |
19 | 注册任务。
20 |
21 | ```ts
22 | import { registerSchedule } from "electron-prokit";
23 | registerSchedule({
24 | name: "runScheduleTest",
25 | fun: () => {
26 | console.log("registerSchedule");
27 | },
28 | interval: 3000,
29 | });
30 | ```
31 |
32 | **:speech_balloon: 参数**
33 |
34 | ```ts
35 | registerSchedule (schedule:RegisterScheduleOption):Schedule
36 | ```
37 | - schedule:任务选项
38 |
39 | ```ts
40 | interface RegisterScheduleOption {
41 | name: string; // 任务名/唯一值
42 | fun: Function; // 需要执行的方法
43 | interval: number; // 间隔时间 / 单位ms
44 | [key: string]: any; // 其他选项
45 | }
46 |
47 | interface Schedule extends RegisterScheduleOption {
48 | isRunning?: boolean;
49 | instance?: any
50 | }
51 | ```
52 |
53 | ### runSchedule
54 |
55 | 运行任务。
56 |
57 | ```ts
58 | import { runSchedule } from "electron-prokit";
59 |
60 | runSchedule("runScheduleTest");
61 | ```
62 |
63 | **:speech_balloon: 参数**
64 |
65 | ```ts
66 | runSchedule(name: string,initRun=true):void
67 | ```
68 |
69 | - name:任务名称,类型`string`
70 | - initRun:是否初始化的时候就执行方法,类型`boolean`,默认为`true`
71 |
72 | ### stopSchedule
73 |
74 | 停止任务。
75 |
76 | ```ts
77 | import { stopSchedule } from "electron-prokit";
78 |
79 | stopSchedule("runScheduleTest");
80 | ```
81 |
82 | **:speech_balloon: 参数**
83 |
84 |
85 | ```ts
86 | stopSchedule(name:string):void
87 | ```
88 |
89 | - name:任务名称,类型`string`
90 |
91 |
92 | ### clearSchedule
93 |
94 | 清除任务。
95 |
96 | ```ts
97 | import { clearSchedule } from "electron-prokit";
98 |
99 | clearSchedule("runScheduleTest");
100 | ```
101 |
102 | **:speech_balloon: 参数**
103 |
104 | ```ts
105 | clearSchedule(name:string):void
106 | ```
107 |
108 | - name:任务名称,类型`string`
109 |
110 |
111 | ### getSchedule
112 |
113 | 获取任务实例。
114 |
115 | ```ts
116 | import { getSchedule } from "electron-prokit";
117 |
118 | getSchedule("runScheduleTest");
119 | ```
120 |
121 | **:speech_balloon: 参数**
122 |
123 | ```ts
124 | getSchedule(name: string): Schedule
125 | ```
126 |
127 | - name:任务名称,类型`string`
128 |
129 |
130 | ### hasSchedule
131 |
132 | 判断是否存在任务。
133 |
134 | ```ts
135 | import { hasSchedule } from "electron-prokit";
136 |
137 | hasSchedule("runScheduleTest");
138 | ```
139 |
140 | **:speech_balloon: 参数**
141 |
142 | ```ts
143 | hasSchedule (name:string):boolean
144 | ```
145 |
146 | - name:任务名称,类型`string`
147 |
148 | ### isRunningSchedule
149 |
150 | 判断任务是否运行。
151 |
152 | ```ts
153 | import { isRunningSchedule } from "electron-prokit";
154 |
155 | isRunningSchedule("runScheduleTest");
156 | ```
157 |
158 | **:speech_balloon: 参数**
159 |
160 | ```ts
161 | isRunningSchedule(name:string) : boolean
162 | ```
163 |
164 | - name:任务名称,类型`string`
165 |
166 | ### clearAllSchedule
167 |
168 | 清除所有任务。
169 |
170 | ```ts
171 | import { clearAllSchedule } from "electron-prokit";
172 |
173 | clearAllSchedule();
174 | ```
175 |
176 | **:speech_balloon: 参数**
177 |
178 | ```ts
179 | clearAllSchedule ():void
180 | ```
181 |
182 |
--------------------------------------------------------------------------------
/docs/zh/api/electron-prokit/update.md:
--------------------------------------------------------------------------------
1 | ---
2 | outline: deep
3 | title: Update
4 | description: electron-prokit Update api
5 | ---
6 |
7 | # Update
8 |
9 | 用于软件的检测更新。
10 |
11 |
12 | ## initUpadate
13 |
14 | 初始化更新操作,主进程使用。
15 |
16 | ```ts
17 | import { initUpadate } from "electron-prokit";
18 | const option = {
19 | forceDevUpdateConfig:true,
20 | autoDownload:true,
21 | updateUrl: 'http://172.17.194.13:8090', // can use live-server to mock the file server/https://www.npmjs.com/package/live-server
22 | updateDownloadedCallBack: () => {
23 | return sendMsgToRender('main','updateDownloaded')
24 | }
25 | }
26 | initUpadate(option)
27 | ```
28 |
29 | **:speech_balloon: 参数**
30 |
31 | ```ts
32 | interface UpadateOptions {
33 | log?:boolean | Logger // 是否打印或者打印的方法
34 | forceDevUpdateConfig?: boolean; // 是否dev环境强制升级
35 | autoDownload?: boolean; // 是否自动下载
36 | updateUrl: string; // 更新资源链接
37 | updateDownloadedCallBack: () => void; // 更新下载后的成功回调
38 | }
39 | ```
40 |
41 | ## intsallUpdateApp
42 |
43 | 安装下载完成后的app。可配合`updateDownloadedCallBack`使用。
44 |
45 | ```ts
46 | import { intsallUpdateApp } from "electron-prokit";
47 | intsallUpdateApp()
48 | ```
49 |
50 |
--------------------------------------------------------------------------------
/docs/zh/api/electron-prokit/window.md:
--------------------------------------------------------------------------------
1 | ---
2 | outline: deep
3 | title: Window
4 | description: electron-prokit window api
5 | ---
6 |
7 | # Window
8 |
9 | 窗口相关的 API 接口。管理整个窗口的生命周期,从创建到销毁。
10 |
11 | ## 作用
12 |
13 | 提供窗口的创建、获取、销毁等操作。使得窗口的生命周期可以被统一管理。
14 |
15 | ## API 概览
16 |
17 | | 函数名 | 使用环境 | 描述 |
18 | | ------------- | :------: | -------------------: |
19 | | createWindow | 主进程 | 创建窗口 |
20 | | getWindow | 主进程 | 获取窗口实例 |
21 | | destroyWindow | 主进程 | 销毁窗口 |
22 | | getAllWindows | 主进程 | 获取所有窗口 |
23 | | hasWindow | 主进程 | 是否有对应的窗口实例 |
24 | | clearWindows | 主进程 | 清除所有的窗口 |
25 |
26 | ## API 使用
27 |
28 | ### createWindow
29 |
30 | 创建窗口。
31 |
32 | ```ts
33 | import { join, resolve } from "path";
34 | import { app } from "electron";
35 | import { createWindow } from "electron-prokit";
36 |
37 | const initWindowsAction = () => {
38 | const mainWindow = createWindow("main", {
39 | width: 960,
40 | height: 720,
41 | webPreferences: {
42 | contextIsolation: true,
43 | nodeIntegration: true,
44 | webSecurity: false,
45 | preload: join(__dirname, "../preload/index.cjs"),
46 | },
47 | });
48 |
49 | if (mainWindow) {
50 | if (import.meta.env.MODE === "dev") {
51 | if (import.meta.env.VITE_DEV_SERVER_URL) {
52 | mainWindow.loadURL(import.meta.env.VITE_DEV_SERVER_URL);
53 | mainWindow.webContents.openDevTools();
54 | }
55 | } else {
56 | mainWindow.loadFile(resolve(__dirname, "../render/index.html"));
57 | }
58 | }
59 | };
60 |
61 | app.whenReady().then(() => {
62 | initWindowsAction();
63 | });
64 | ```
65 |
66 | **:speech_balloon: 参数**
67 |
68 | ```ts
69 | createWindow(
70 | name: string,
71 | options: Electron.BrowserWindowConstructorOptions
72 | ): Electron.CrossProcessExports.BrowserWindow
73 | ```
74 |
75 | - name: 窗口名称,类型`string`,唯一标志,如果窗口名称重复就无法创建新的窗口
76 | - options: 窗口选项,类型`Electron.BrowserWindowConstructorOptions`
77 |
78 | ### getWindow
79 |
80 | 获取窗口实例。
81 |
82 | ```ts
83 | // 主进程
84 | import { getWindow } from "electron-prokit";
85 | const workWindow = getWindow('getWindow')
86 | ```
87 | **:speech_balloon: 参数**
88 | ```ts
89 | getWindow(name: string): Electron.CrossProcessExports.BrowserWindow
90 | ```
91 |
92 | - name: 窗口名称,类型`string`
93 |
94 | ### destroyWindow
95 |
96 | 销毁窗口实例。
97 |
98 | ```ts
99 | // 主进程
100 | import { destroyWindow } from "electron-prokit";
101 | destroyWindow('getWindow')
102 | ```
103 |
104 | **:speech_balloon: 参数**
105 | ```ts
106 | destroyWindow(name: string): void
107 | ```
108 |
109 | - name: 窗口名称,类型`string`
110 |
111 | ### getAllWindows
112 |
113 | 获取所有窗口实例。
114 |
115 | ```ts
116 | // 主进程
117 | import { getAllWindows } from "electron-prokit";
118 | getAllWindows()
119 | ```
120 |
121 | **:speech_balloon: 参数**
122 | ```ts
123 | getAllWindows(): Array
124 | ```
125 |
126 | ### hasWindow
127 |
128 | 是否有某个窗口。
129 |
130 | ```ts
131 | // 主进程
132 | import { hasWindow } from "electron-prokit";
133 | const hasWorkWindow = hasWindow('work')
134 | ```
135 |
136 | **:speech_balloon: 参数**
137 |
138 | ```ts
139 | hasWindow(name: string): boolean
140 | ```
141 |
142 | - name: 窗口名称,类型`string`
143 |
144 | ### clearWindows
145 |
146 | 清除所有的窗口。
147 |
148 | ```ts
149 | // 主进程
150 | import { clearWindows } from "electron-prokit";
151 | clearWindows()
152 | ```
153 |
154 | **:speech_balloon: 参数**
155 |
156 | ```ts
157 | clearWindows(): void
158 | ```
159 |
--------------------------------------------------------------------------------
/docs/zh/api/index.md:
--------------------------------------------------------------------------------
1 | # API 总览
2 |
3 | - [ipc 进程通信](/zh/api/electron-prokit/ipc)
4 | - [window 窗口](/zh/api/electron-prokit/window)
5 | - [http 网络](/zh/api/electron-prokit/http)
6 | - [ffi 跨语言调用](/zh/api/electron-prokit/ffi)
7 | - [schedule 任务管理](/zh/api/electron-prokit/schedule)
8 | - [db 数据库管理](/zh/api/electron-prokit/db)
9 |
10 |
--------------------------------------------------------------------------------
/docs/zh/guide/index.md:
--------------------------------------------------------------------------------
1 | # 简介
2 |
3 | ::: tip 提示
4 | 本指南假设你熟悉 [Electron](https://www.electronjs.org/) 和 [Vite](https://vitejs.dev/),熟悉之后阅读本指南更加容易理解框架的设计思想。
5 | :::
6 |
7 | ## 解决什么样的问题
8 |
9 | Electron开发在社区中有很多的解决方案,比较了一些方案,大概有这些共同的问题:
10 |
11 | - 繁琐的搭建Electron项目的步骤
12 | - 无法自主选择前端框架
13 | - 各个进程本地开发代码热更新问题
14 | - 构建打包一体化配置问题
15 | - 渲染进程调用无法抹平差异问题
16 | - 缺少成套的企业级解决方案
17 |
18 | electron-prokit旨在解决这些问题,让你拥有极致的桌面开发体验。
19 |
20 | ## 核心理念
21 |
22 | 因为Vite 有能力同时处理 Chromium 和 Node.js这两种环境的程序的能力,所以就单独写了 [@electron-prokit/create-service](https://www.npmjs.com/package/@electron-prokit/create-service) 这个插件去读取各个进程的vite配置,然后去创建各个服务,最后再融合到一起,这样不管是哪个进程的变动都可以进行热更新处理,达到跟开发传统Web开发一样的感觉,这也大大得提高了开发效率和调试效率。
23 |
24 | 
25 |
26 |
27 | ## 注意事项
28 |
29 | electron-prokit 严格按照[Electron最佳实践](https://www.electronjs.org/docs/latest/tutorial/security),没有开启node集成(nodeIntegration)和关闭上下文隔离(contentIsolation),框架内部的方法都是用contextBridge实现的。
30 |
31 |
32 |
--------------------------------------------------------------------------------
/docs/zh/guide/start.md:
--------------------------------------------------------------------------------
1 | # 快速开始
2 |
3 | ## 总览
4 |
5 | **electron-prokit**是一款基于 Electron 的桌面软件开发框架,让你拥有极致的桌面开发体验,适用于Vite相关生态。
6 |
7 | 主要由三个部分组成:
8 |
9 | ::: tip 脚手架
10 | 提供配置化的项目模板,让你快速开发Electron项目。
11 | :::
12 |
13 | ::: tip 核心API
14 | 框架实现的核心功能,提供一些electron生态的解决方案。
15 | :::
16 |
17 | ::: tip 插件
18 | 为框架提供额外支撑的插件,让使用者开发更加方便。
19 | :::
20 |
21 |
22 | 不管是开发初学者还是经验丰富的开发者,都可以利用electron-prokit提升生产力,快速交付高质量的Electron应用。
23 |
24 | 你可以在[简介](./index)部分深入了解该项目的设计理念。
25 |
26 | ## 搭建第一个electron-prokit项目
27 |
28 | ::: warning 兼容性注意
29 | electron-prokit 需要 Node.js 版本 18+。然而,有些模板需要依赖更高的 Node 版本才能正常运行,当你的包管理器发出警告时,请注意升级你的 Node 版本。
30 | :::
31 |
32 | 直接使用脚手架快捷创建项目,脚手架结合了electron-prokit相关生态,推荐使用此方式。
33 |
34 | 使用 NPM:
35 |
36 | ```bash
37 | npm create electron-prokit myapp
38 | ```
39 |
40 | 使用 Yarn:
41 |
42 | ```bash
43 | yarn create electron-prokit myapp
44 | ```
45 |
46 | 其中`myapp`为你的项目名,然后按照提示操作即可!
47 |
48 | ## 配置 electron-prokit
49 |
50 | 根目录配置`config`
51 |
52 | - main.ts 主进程
53 | - preload.ts 预加载
54 | - render.ts 渲染进程
55 | - work.ts work进程
56 |
57 |
58 | ## 演练
59 |
60 | 通过演练你可以更加详细地了解electron-prokit相关的功能。
61 |
62 | ```bash
63 | git clone https://github.com/Xutaotaotao/electron-prokit.git
64 |
65 | cd electron-prokit
66 |
67 | pnpm i
68 |
69 | pnpm run dev
70 |
71 | ```
72 |
73 | ## 寻求帮助
74 |
75 | 如果你在开发过程中遇到 electron-prokit 的疑难问题,你可以去 [GitHub issue](https://github.com/Xutaotaotao/electron-prokit/issues?q=is%3Aissue) 查看是否有人已经遇到相同的问题。如果没有,欢迎[提交](https://github.com/Xutaotaotao/electron-prokit/issues/new) issue,另外你也可以在[GitHub Discussions](https://github.com/Xutaotaotao/electron-prokit/discussions) 社区来寻求帮助。
--------------------------------------------------------------------------------
/docs/zh/index.md:
--------------------------------------------------------------------------------
1 | ---
2 | # https://vitepress.dev/reference/default-theme-home-page
3 | title: Electron-Prokit
4 | description: Electron-Prokit 首页
5 | layout: home
6 |
7 | hero:
8 | name: "Electron-Prokit"
9 | text: 一款基于Electron的桌面软件开发框架
10 | tagline: 极致的桌面开发体验
11 | image:
12 | src: /logo.svg
13 | alt: logo
14 | actions:
15 | - theme: brand
16 | text: 开始使用
17 | link: /zh/guide/start
18 | - theme: alt
19 | text: 在GitHub上查看
20 | link: https://github.com/Xutaotaotao/electron-prokit
21 |
22 | features:
23 | - icon: 💡
24 | title: 快速开始
25 | details: 脚手架工具助你一键快速开发Electron项目
26 | - icon: ⚡️
27 | title: Vite支持
28 | details: 所有的进程配置使用方式与 Vite 相同
29 | - icon: 🛠️
30 | title: 开箱即用
31 | details: 开箱即用支持 Typescript、Vue、React
32 | - icon: 📦
33 | title: 预设打包
34 | details: 一站式打包构建解决方案
35 | - icon: 🔥
36 | title: 热更新
37 | details: 所有进程及脚本都支持热更新
38 | - icon: 🔑
39 | title: 完全类型化
40 | details: 灵活的 API 和完整的 TypeScript 类型
41 | - icon: 🎨
42 | title: 丰富的API
43 | details: 进程通信、窗口、网络、跨语言、任务、数据库...
44 | - icon: 📺
45 | title: 最佳实践
46 | details: 提供 Electron 应用程序的最佳实践演示
47 | ---
48 |
--------------------------------------------------------------------------------
/docs/zh/plugin/electron-prokit-cli.md:
--------------------------------------------------------------------------------
1 | # electron-prokit-cli
2 |
3 | 创建electron项目的脚手架,结合了electron-prokit相关生态。
4 |
5 | ## 安装依赖
6 |
7 | ```bash
8 | npm i @electron-prokit/cli -g
9 | ```
10 |
11 | ## 使用
12 |
13 | ```bash
14 | electron-prokit-cli init project
15 | ```
16 |
17 | 其中`project`为项目名。项目创建完毕后安装依赖并启动项目。
18 |
19 | ```bash
20 |
21 | cd project && yarn install
22 |
23 | yarn run dev
24 |
25 | ```
26 |
--------------------------------------------------------------------------------
/docs/zh/plugin/index.md:
--------------------------------------------------------------------------------
1 | # 插件 总览
2 |
3 | - [create-service 一键创建electron服务](/zh/plugin/create-service)
4 |
--------------------------------------------------------------------------------
/docs/zh/tutorials/index.md:
--------------------------------------------------------------------------------
1 | # 教程总览
2 |
3 | - [用 Vite+React 快速构建一个 Electron 项目](/zh/tutorials/create-vite-electron-service)
4 |
5 | - [用 Vite+Vue3 快速构建一个 Electron 项目](/zh/tutorials/create-vite-electron-service-vue)
--------------------------------------------------------------------------------
/jest.config.cjs:
--------------------------------------------------------------------------------
1 | /** @type {import('ts-jest').JestConfigWithTsJest} */
2 | module.exports = {
3 | preset: 'ts-jest',
4 | testEnvironment: 'node',
5 | transform: {
6 | // '^.+\\.[tj]sx?$' to process js/ts with `ts-jest`
7 | // '^.+\\.m?[tj]sx?$' to process js/ts/mjs/mts with `ts-jest`
8 | '^.+\\.tsx?$': [
9 | 'ts-jest',
10 | {
11 | useESM: true,
12 | },
13 | ],
14 | },
15 | moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
16 | };
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "engines": {
4 | "node": "^14.8.0 || >=16.0.0"
5 | },
6 | "workspaces": [
7 | "packages/*",
8 | "play",
9 | "docs"
10 | ],
11 | "scripts": {
12 | "preinstall": "npx only-allow pnpm",
13 | "dev": "pnpm -C play dev",
14 | "docs:dev": "pnpm run -C docs dev",
15 | "docs:build": "pnpm run -C docs build",
16 | "docs:preview": "pnpm run -C docs preview",
17 | "test": "jest",
18 | "test-c": "jest --coverage",
19 | "build": "rollup --config",
20 | "release": "pnpm run build && pnpm changeset publish"
21 | },
22 | "keywords": [],
23 | "author": "",
24 | "license": "ISC",
25 | "devDependencies": {
26 | "@changesets/cli": "^2.26.2",
27 | "@jest/globals": "^29.7.0",
28 | "@rollup/plugin-commonjs": "^25.0.4",
29 | "@rollup/plugin-json": "^6.0.0",
30 | "@rollup/plugin-node-resolve": "^15.2.1",
31 | "@types/jest": "^29.5.5",
32 | "@types/node": "^20.5.7",
33 | "@typescript-eslint/eslint-plugin": "^6.0.0",
34 | "@typescript-eslint/parser": "^6.0.0",
35 | "eslint": "^8.45.0",
36 | "eslint-define-config": "^1.23.0",
37 | "eslint-plugin-import": "^2.28.0",
38 | "eslint-plugin-n": "^16.0.1",
39 | "eslint-plugin-regexp": "^1.15.0",
40 | "execa": "5.1.1",
41 | "jest": "^29.7.0",
42 | "rollup": "^3.28.1",
43 | "rollup-plugin-peer-deps-external": "^2.2.4",
44 | "rollup-plugin-shebang-bin": "^0.0.5",
45 | "rollup-plugin-typescript2": "^0.35.0",
46 | "ts-jest": "^29.1.1",
47 | "typescript": "^5.2.2"
48 | },
49 | "pnpm": {
50 | "peerDependencyRules": {
51 | "ignoreMissing": [
52 | "vite",
53 | "react",
54 | "react-dom"
55 | ]
56 | }
57 | },
58 | "publishConfig": {
59 | "access": "public",
60 | "registry": "https://registry.npmjs.org/"
61 | }
62 | }
--------------------------------------------------------------------------------
/packages/create-electron-prokit/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # create-electron-prokit
2 |
3 | ## 3.0.0
4 |
5 | ### Major Changes
6 |
7 | - 358a65f: fix: compile error reslove
8 |
9 | ## 2.0.0
10 |
11 | ### Major Changes
12 |
13 | - e6e10b7: fix: build action
14 |
15 | ## 1.0.5
16 |
17 | ### Patch Changes
18 |
19 | - 131e15a: feat:update electron-prokit
20 |
21 | ## 1.0.4
22 |
23 | ### Patch Changes
24 |
25 | - 1bd2d65: fix: template home edit info
26 |
27 | ## 1.0.3
28 |
29 | ### Patch Changes
30 |
31 | - 551985d: fix: gitclone error,change inner templateDir.
32 |
33 | ## 1.0.2
34 |
35 | ### Patch Changes
36 |
37 | - a0531d6: fix: change main function
38 |
39 | ## 1.0.1
40 |
41 | ### Patch Changes
42 |
43 | - dbf4c9b: fix: gitclone error with promise
44 | - 8c0cc9c: feat: add node engines version
45 |
46 | ## 1.0.0
47 |
48 | ### Major Changes
49 |
50 | - 7a05dad: feat: relase a major version
51 |
52 | ## 0.0.2
53 |
54 | ### Patch Changes
55 |
56 | - 6fc23c0: fix: build
57 |
58 | ## 0.0.1
59 |
60 | ### Patch Changes
61 |
62 | - 8fc37e2: feat:create-electron-prokit
63 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/README.md:
--------------------------------------------------------------------------------
1 | # create-electron-prokit
2 |
3 | ## Start
4 |
5 | yarn create electron-prokit my-app
--------------------------------------------------------------------------------
/packages/create-electron-prokit/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "create-electron-prokit",
3 | "version": "3.0.0",
4 | "engines": {
5 | "node": "^14.8.0 || >=16.0.0"
6 | },
7 | "description": "A cli to create a electron prokit project",
8 | "publishConfig": {
9 | "main": "dist/index.cjs.js",
10 | "module": "dist/index.esm.js",
11 | "types": "dist/index.d.ts",
12 | "access": "public",
13 | "registry": "https://registry.npmjs.org/"
14 | },
15 | "main": "src/index.ts",
16 | "type": "module",
17 | "files": [
18 | "dist",
19 | "template-*"
20 | ],
21 | "exports": {
22 | ".": {
23 | "import": "./dist/index.esm.js",
24 | "require": "./dist/index.cjs.js"
25 | }
26 | },
27 | "bin": {
28 | "create-electron-prokit": "dist/index.js"
29 | },
30 | "scripts": {
31 | "dev": "node --experimental-specifier-resolution=node --loader ts-node/esm src/index.ts",
32 | "build": "tsc",
33 | "start": "node --experimental-specifier-resolution=node dist/index.js"
34 | },
35 | "keywords": [
36 | "Electron",
37 | "electron",
38 | "electron-prokit",
39 | "electron prokit",
40 | "Electron Prokit",
41 | "Prokit",
42 | "prokit",
43 | "create-electron-prokit"
44 | ],
45 | "author": "Xutaotaotao",
46 | "license": "MIT",
47 | "devDependencies": {
48 | "@types/node": "^20.5.7",
49 | "ts-node": "^10.9.1",
50 | "tslib": "^2.6.2",
51 | "typescript": "^5.0.2"
52 | },
53 | "dependencies": {
54 | "@types/fs-extra": "^11.0.2",
55 | "@types/inquirer": "^9.0.3",
56 | "fs-extra": "^11.1.1",
57 | "handlebars": "^4.7.8",
58 | "inquirer": "^9.2.11",
59 | "ora": "^7.0.1"
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/src/index.ts:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node --experimental-specifier-resolution=node
2 | import path from "path";
3 | import { fileURLToPath } from "node:url";
4 | import type { QuestionCollection } from "inquirer";
5 | import inquirer from "inquirer";
6 | import ora from "ora";
7 | import fs from "fs-extra";
8 | import type { Options } from "../typings";
9 | import { modifyPackageJson } from "./modify";
10 |
11 | const log = ora("modify");
12 |
13 | function copy(src: string, dest: string) {
14 | const stat = fs.statSync(src);
15 | if (stat.isDirectory()) {
16 | copyDir(src, dest);
17 | } else {
18 | fs.copyFileSync(src, dest);
19 | }
20 | }
21 |
22 | function copyDir(srcDir: string, destDir: string) {
23 | fs.mkdirSync(destDir, { recursive: true });
24 | for (const file of fs.readdirSync(srcDir)) {
25 | const srcFile = path.resolve(srcDir, file);
26 | const destFile = path.resolve(destDir, file);
27 | copy(srcFile, destFile);
28 | }
29 | }
30 |
31 | async function init(name: string) {
32 | const ReactTemplateGitUrl =
33 | "https://github.com/Xutaotaotao/ep-vite-react-electron-template";
34 |
35 | const VueTemplateGitUrl =
36 | "https://github.com/Xutaotaotao/ep-vite-vue3-electron-template";
37 |
38 | const InitPrompts: QuestionCollection = [
39 | {
40 | name: "description",
41 | message: "please input description",
42 | default: "",
43 | },
44 | {
45 | name: "author",
46 | message: "please input author",
47 | default: "",
48 | },
49 | ];
50 |
51 | const FrameworkOptions: QuestionCollection = {
52 | type: "list",
53 | name: "framework",
54 | message: "Select a framework",
55 | choices: [
56 | {
57 | name: "react-ts",
58 | value: "react-ts",
59 | },
60 | {
61 | name: "vue-ts",
62 | value: "vue-ts",
63 | },
64 | ],
65 | };
66 | if (fs.existsSync(name)) {
67 | log.warn(`Has the same name project,please create another project!`);
68 | return;
69 | }
70 | log.info(`Start init create-electron-prokit project: ${name}`);
71 | const initOptions = await inquirer.prompt(InitPrompts);
72 | const frameworkOptions = await inquirer.prompt(FrameworkOptions);
73 | const framework = frameworkOptions.framework;
74 | const templateDir = path.resolve(
75 | fileURLToPath(import.meta.url),
76 | "../..",
77 | `template-${framework}`
78 | );
79 |
80 | try {
81 | const targetPath = `./${name}`;
82 | copy(templateDir, targetPath);
83 | modifyPackageJson(targetPath, { name, ...initOptions } as Options);
84 | } catch (error) {
85 | console.error(error);
86 | }
87 | }
88 |
89 | function main() {
90 | const name = process.argv[2];
91 | if (!name) {
92 | log.warn("The project name cannot be empty!");
93 | process.exit(1);
94 | } else {
95 | init(name);
96 | }
97 | }
98 |
99 | main();
100 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/src/modify.ts:
--------------------------------------------------------------------------------
1 | import path from "path"
2 | import fs from "fs-extra"
3 | import handlebars from "handlebars"
4 | import ora from "ora"
5 | import type { Options } from '../typings'
6 |
7 | const log = ora("modify")
8 |
9 |
10 | export const modifyPackageJson = function (downloadPath: string, options: Options):void {
11 | const packagePath = path.join(downloadPath, "package.json")
12 | log.start("start modifying package.json")
13 | if (fs.existsSync(packagePath)) {
14 | const content = fs.readFileSync(packagePath).toString()
15 | const template = handlebars.compile(content)
16 |
17 | const param = {
18 | name: options.name,
19 | description: options.description,
20 | author: options.author,
21 | }
22 |
23 | const result = template(param)
24 | fs.writeFileSync(packagePath, result)
25 | log.stop()
26 | log.succeed("This project has been successfully created! ")
27 | log.info(`Install dependencies:
28 |
29 | cd ${downloadPath} && yarn install
30 | `)
31 | log.info(`Run project:
32 |
33 | yarn run dev
34 | `)
35 | } else {
36 | log.stop()
37 | log.fail("modify package.json fail")
38 | throw new Error("no package.json")
39 | }
40 | }
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/.eslintrc.cjs:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | root: true,
3 | env: { browser: true, es2020: true },
4 | extends: [
5 | 'eslint:recommended',
6 | 'plugin:@typescript-eslint/recommended',
7 | 'plugin:react-hooks/recommended',
8 | ],
9 | ignorePatterns: ['dist', '.eslintrc.cjs'],
10 | parser: '@typescript-eslint/parser',
11 | plugins: ['react-refresh'],
12 | rules: {
13 | 'react-refresh/only-export-components': [
14 | 'warn',
15 | { allowConstantExport: true },
16 | ],
17 | "@typescript-eslint/no-explicit-any": "off"
18 | },
19 | }
20 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | dist
12 | dist-ssr
13 | release
14 | *.local
15 |
16 | # Editor directories and files
17 | .vscode/*
18 | !.vscode/extensions.json
19 | .idea
20 | .DS_Store
21 | *.suo
22 | *.ntvs*
23 | *.njsproj
24 | *.sln
25 | *.sw?
26 |
27 | # lock
28 | yarn.lock
29 | pnpm.lock
30 | npm.lock
31 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/.npmrc:
--------------------------------------------------------------------------------
1 | ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/
2 | ELECTRON_BUILDER_BINARIES_MIRROR=https://npmmirror.com/mirrors/electron-builder-binaries/
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/README.md:
--------------------------------------------------------------------------------
1 | # A vite + react + electron template with electron-prokit.
2 |
3 | `.npmrc` can change `electron_mirror`.
4 |
5 | ## Install
6 |
7 | ```bash
8 | yarn install
9 | ```
10 |
11 | ## Dev
12 |
13 | ```bash
14 | yarn run dev
15 | ```
16 |
17 | ## Build
18 |
19 | ```bash
20 | yarn run build
21 | ```
22 |
23 | ## Compile
24 |
25 | ```bash
26 | yarn run compile
27 | ```
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/config/main.ts:
--------------------------------------------------------------------------------
1 | import { cwd } from "process";
2 | import { defineConfig } from "vite";
3 | import path from "path";
4 | import { builtinModules } from "module";
5 | import { fileURLToPath } from "url";
6 |
7 | const __dirname = fileURLToPath(new URL(".", import.meta.url));
8 |
9 | const sharedResolve = {
10 | alias: {
11 | "@": path.resolve(__dirname, "src"),
12 | },
13 | };
14 |
15 | export default defineConfig({
16 | root: path.resolve(__dirname, "../src/main"),
17 | envDir: cwd(),
18 | resolve: sharedResolve,
19 | build: {
20 | outDir: path.resolve(__dirname, "../dist/main"),
21 | minify: false,
22 | lib: {
23 | entry: path.resolve(__dirname, "../src/main/index.ts"),
24 | formats: ["cjs"],
25 | },
26 | rollupOptions: {
27 | external: [
28 | "electron",
29 | "lowdb",
30 | "koffi",
31 | "electron-updater",
32 | ...builtinModules,
33 | ],
34 | output: {
35 | entryFileNames: "[name].cjs",
36 | },
37 | },
38 | emptyOutDir: true,
39 | chunkSizeWarningLimit: 2048,
40 | },
41 | })
42 |
43 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/config/preload.ts:
--------------------------------------------------------------------------------
1 | import { cwd } from "process";
2 | import { defineConfig } from "vite";
3 | import path from "path";
4 | import { builtinModules } from "module";
5 | import { fileURLToPath } from "url";
6 |
7 | const __dirname = fileURLToPath(new URL(".", import.meta.url));
8 |
9 |
10 | const sharedResolve = {
11 | alias: {
12 | "@": path.resolve(__dirname, "src"),
13 | },
14 | };
15 |
16 | export default defineConfig({
17 | root: path.resolve(__dirname, "../src/preload"),
18 | envDir: cwd(),
19 | resolve: sharedResolve,
20 | build: {
21 | watch: {},
22 | outDir: path.resolve(__dirname, "../dist/preload"),
23 | minify: false,
24 | lib: {
25 | entry: path.resolve(__dirname, "../src/preload/index.ts"),
26 | formats: ["cjs"],
27 | },
28 | rollupOptions: {
29 | external: ["electron", "lowdb", ...builtinModules],
30 | output: {
31 | entryFileNames: "[name].cjs",
32 | },
33 | },
34 | emptyOutDir: true,
35 | chunkSizeWarningLimit: 2048,
36 | },
37 | })
38 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/config/render.ts:
--------------------------------------------------------------------------------
1 | import { defineConfig } from "vite";
2 | import path from "path";
3 | import react from "@vitejs/plugin-react-swc";
4 | import { builtinModules } from "module";
5 | import { fileURLToPath } from "url";
6 |
7 | const __dirname = fileURLToPath(new URL(".", import.meta.url));
8 |
9 | const sharedResolve = {
10 | alias: {
11 | "@": path.resolve(__dirname, "src"),
12 | },
13 | };
14 |
15 | export default defineConfig({
16 | root: path.resolve(__dirname, "../"),
17 | resolve: sharedResolve,
18 | base: "./",
19 | build: {
20 | watch: {},
21 | outDir: path.resolve(__dirname, "../dist/render"),
22 | minify: true,
23 | assetsInlineLimit: 1048576,
24 | emptyOutDir: true,
25 | chunkSizeWarningLimit: 2048,
26 | rollupOptions: {
27 | external: [...builtinModules, "electron", "lowdb"],
28 | },
29 | commonjsOptions: {
30 | include: [/node_modules/],
31 | },
32 | },
33 | plugins: [react()],
34 | optimizeDeps: {
35 | include: ["@ant-design/icons-svg", "antd"],
36 | },
37 | });
38 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/config/work.ts:
--------------------------------------------------------------------------------
1 | import { defineConfig } from "vite";
2 | import path from "path";
3 | import react from "@vitejs/plugin-react-swc";
4 | import { builtinModules } from "module";
5 | import { fileURLToPath } from "url";
6 |
7 | const __dirname = fileURLToPath(new URL(".", import.meta.url));
8 |
9 |
10 | const sharedResolve = {
11 | alias: {
12 | "@": path.resolve(__dirname, "src"),
13 | },
14 | };
15 |
16 | export default defineConfig({
17 | root: path.resolve(__dirname, "../src/work"),
18 | base: "./",
19 | resolve: sharedResolve,
20 | build: {
21 | watch: {},
22 | outDir: path.resolve(__dirname, "../dist/work"),
23 | minify: true,
24 | assetsInlineLimit: 1048576,
25 | emptyOutDir: true,
26 | chunkSizeWarningLimit: 2048,
27 | rollupOptions: {
28 | external: [...builtinModules, "electron", "lowdb"],
29 | },
30 | },
31 | plugins: [react()],
32 | })
33 |
34 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/electron-builder.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "productName": "ElectronProkit",
3 | "appId": "electron.prokit.com",
4 | "copyright": "Copyright © 2023",
5 | "asar": false,
6 | "files": ["dist/**", "package.json"],
7 | "directories": {
8 | "output": "release",
9 | "buildResources": "resources"
10 | },
11 | "extraResources": {
12 | "from": "resources",
13 | "to": "resources"
14 | },
15 | "mac": {
16 | "hardenedRuntime": true,
17 | "gatekeeperAssess": false,
18 | "target": ["dmg", "zip"],
19 | "entitlements": "./scripts/entitlements.mac.plist",
20 | "entitlementsInherit": "./scripts/entitlements.mac.plist",
21 | "identity": "",
22 | "icon": "./resources/icon/icon.icns",
23 | "extendInfo": {
24 | "LSUIElement": true,
25 | "SUFeedURL": "",
26 | "SUPublicEDKey": ""
27 | }
28 | },
29 | "dmg": {
30 | "backgroundColor": "#ffffff",
31 | "window": { "width": 540, "height": 380 },
32 | "icon": "./resources/icon/icon.icns",
33 | "iconSize": 128,
34 | "contents": [
35 | { "x": 410, "y": 190, "type": "link", "path": "/Applications" },
36 | { "x": 130, "y": 190, "type": "file" }
37 | ],
38 | "title": "ElectronProkit"
39 | },
40 | "win": {
41 | "icon": "./resources/icon/icon.ico",
42 | "target": "nsis",
43 | "verifyUpdateCodeSignature": false
44 | },
45 | "nsis": {
46 | "oneClick": true,
47 | "language": "2052",
48 | "perMachine": true,
49 | "createDesktopShortcut": true,
50 | "createStartMenuShortcut": true,
51 | "guid": "ElectronProkit",
52 | "shortcutName": "ElectronProkit",
53 | "artifactName": "ElectronProkit@${version}.${ext}"
54 | },
55 | "publish": {
56 | "provider": "generic",
57 | "url": "http://172.17.194.13:8090"
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | electron-prokit + react + ts
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "{{name}}",
3 | "private": true,
4 | "version": "1.0.0",
5 | "type": "module",
6 | "description": "{{ description }}",
7 | "author": "{{ author }}",
8 | "main": "dist/main/index.cjs",
9 | "scripts": {
10 | "dev": "node --experimental-specifier-resolution=node --loader ts-node/esm ./scripts/dev.ts",
11 | "build": "node --experimental-specifier-resolution=node --loader ts-node/esm ./scripts/build.ts",
12 | "compile": "electron-builder build --config ./electron-builder.config.json",
13 | "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
14 | "preview": "vite preview"
15 | },
16 | "dependencies": {
17 | "react": "^18.2.0",
18 | "react-dom": "^18.2.0",
19 | "koffi": "2.3.20"
20 | },
21 | "devDependencies": {
22 | "@electron-prokit/create-service": "^3.0.0",
23 | "@types/react": "^18.2.15",
24 | "@types/react-dom": "^18.2.7",
25 | "@typescript-eslint/eslint-plugin": "^6.0.0",
26 | "@typescript-eslint/parser": "^6.0.0",
27 | "@vitejs/plugin-react-swc": "^3.3.2",
28 | "electron": "^26.2.0",
29 | "electron-builder": "^24.6.4",
30 | "eslint": "^8.45.0",
31 | "electron-prokit": "^16.1.2",
32 | "eslint-plugin-react-hooks": "^4.6.0",
33 | "eslint-plugin-react-refresh": "^0.4.3",
34 | "ts-node": "^10.9.1",
35 | "typescript": "^5.0.2",
36 | "vite": "^4.4.5"
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/public/vite.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/resources/icon/icon.icns:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/packages/create-electron-prokit/template-react-ts/resources/icon/icon.icns
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/resources/icon/icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/packages/create-electron-prokit/template-react-ts/resources/icon/icon.ico
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/resources/icon/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/packages/create-electron-prokit/template-react-ts/resources/icon/icon.png
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/resources/icon/icon@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/packages/create-electron-prokit/template-react-ts/resources/icon/icon@2x.png
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/scripts/build.ts:
--------------------------------------------------------------------------------
1 | #!/usr/bin/node
2 | import { fileURLToPath } from 'url';
3 | import { dirname, resolve } from 'path';
4 | import { build } from 'vite';
5 | import pkgJson from '../package.json' assert { type: 'json' };
6 |
7 | const __filename = fileURLToPath(import.meta.url);
8 | const __dirname = dirname(__filename);
9 |
10 | const processArgv = process.argv.splice(2);
11 | const mode = processArgv && processArgv.length > 0 ? processArgv[0] : 'production';
12 |
13 | const packagesConfigs = [
14 | resolve(__dirname, '../config/render'),
15 | resolve(__dirname, '../config/work'),
16 | resolve(__dirname, '../config/main'),
17 | resolve(__dirname, '../config/preload'),
18 | ];
19 |
20 | // Set environment variables
21 | process.env.VITE_CURRENT_RUN_MODE = 'render';
22 | process.env.VITE_CURRENT_VERSION = pkgJson.version;
23 | process.env.MODE = mode;
24 | process.env.VITE_CURRENT_OS = process.platform;
25 |
26 | const buildByConfig = async (configFile:string) => {
27 | try {
28 | await build({ configFile, mode });
29 | } catch (error) {
30 | console.error(`Error building ${configFile}:`, error);
31 | throw error;
32 | }
33 | };
34 |
35 | const delay = (ms:number) => new Promise(resolve => setTimeout(resolve, ms));
36 |
37 | const main = async () => {
38 | try {
39 | console.time('Total bundling time');
40 | for (const config of packagesConfigs) {
41 | const modeMap:any = {
42 | main: 'main',
43 | render: 'render',
44 | preload: 'preload',
45 | work: 'work',
46 | };
47 |
48 | for (const key in modeMap) {
49 | if (config.includes(key)) {
50 | process.env.VITE_CURRENT_RUN_MODE = modeMap[key];
51 | break;
52 | }
53 | }
54 |
55 | console.time(`Bundling ${config}`);
56 | await buildByConfig(config);
57 | console.timeEnd(`Bundling ${config}`);
58 | }
59 | console.timeEnd('Total bundling time');
60 | } catch (error) {
61 | console.error('Build failed:', error);
62 | process.exit(1);
63 | }
64 | await delay(3000)
65 | process.exit(0);
66 | };
67 |
68 | main();
69 |
70 | process.on('unhandledRejection', (reason, promise) => {
71 | console.error('Unhandled Rejection at:', promise, 'reason:', reason);
72 | process.exit(1);
73 | });
74 |
75 | process.on('uncaughtException', (err) => {
76 | console.error('Uncaught Exception thrown:', err);
77 | process.exit(1);
78 | });
79 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/scripts/dev.ts:
--------------------------------------------------------------------------------
1 | import createViteElectronService from '@electron-prokit/create-service';
2 | import electronPath from "electron";
3 | import main from "../config/main";
4 | import render from "../config/render";
5 | import work from "../config/work";
6 | import preload from "../config/preload";
7 |
8 | createViteElectronService({
9 | render: render,
10 | preload: preload,
11 | work: work,
12 | main: main,
13 | electronPath: electronPath
14 | });
15 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/scripts/entitlements.mac.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.cs.allow-unsigned-executable-memory
6 |
7 |
8 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/src/main/index.ts:
--------------------------------------------------------------------------------
1 | import { join,resolve } from "path";
2 | import {
3 | app,
4 | } from "electron";
5 | import {createWindow} from 'electron-prokit';
6 | import ipc from './ipc'
7 |
8 | const initWindowsAction = () => {
9 | const mainWindow = createWindow('main',{
10 | width: 960,
11 | height: 720,
12 | webPreferences: {
13 | contextIsolation: true,
14 | nodeIntegration: true,
15 | webSecurity: false,
16 | preload: join(__dirname, "../preload/index.cjs"),
17 | },
18 | })
19 |
20 | if (mainWindow) {
21 | if (import.meta.env.MODE === "dev") {
22 | if (import.meta.env.VITE_DEV_SERVER_URL) {
23 | mainWindow.loadURL(import.meta.env.VITE_DEV_SERVER_URL);
24 | }
25 | } else {
26 | mainWindow.loadFile(resolve(__dirname, "../render/index.html"));
27 | }
28 | }
29 | }
30 |
31 |
32 | app.whenReady().then(() => {
33 | initWindowsAction()
34 | ipc()
35 | })
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/src/main/ipc.ts:
--------------------------------------------------------------------------------
1 | import {initIpc,onMsgFromRender } from "electron-prokit";
2 | import { shell } from 'electron';
3 |
4 | const main = ():void => {
5 | initIpc();
6 | onMsgFromRender(async (_e: Electron.IpcMainEvent, args: Msg) => {
7 | if (args.key === 'openUrl') {
8 | shell.openExternal(args.data.url)
9 | return true
10 | }
11 | return `Main have get data is ${args}`;
12 | });
13 | };
14 |
15 | export default main;
16 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/src/preload/index.ts:
--------------------------------------------------------------------------------
1 | import {initExposeInMainWorld} from 'electron-prokit'
2 |
3 | initExposeInMainWorld()
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/src/render/App.css:
--------------------------------------------------------------------------------
1 | #root {
2 | max-width: 1280px;
3 | margin: 0 auto;
4 | padding: 2rem;
5 | text-align: center;
6 | }
7 |
8 | .logo {
9 | height: 12em;
10 | padding: 1.5em;
11 | will-change: filter;
12 | transition: filter 300ms;
13 | cursor:pointer;
14 | }
15 | .logo:hover {
16 | filter: drop-shadow(0 0 2em #646cffaa);
17 | }
18 | .logo.react:hover {
19 | filter: drop-shadow(0 0 2em #61dafbaa);
20 | }
21 |
22 | @keyframes logo-spin {
23 | from {
24 | transform: rotate(0deg);
25 | }
26 | to {
27 | transform: rotate(360deg);
28 | }
29 | }
30 |
31 | @media (prefers-reduced-motion: no-preference) {
32 | a:nth-of-type(2) .logo {
33 | animation: logo-spin infinite 20s linear;
34 | }
35 | }
36 |
37 | .card {
38 | padding: 2em;
39 | }
40 |
41 | .read-the-docs {
42 | color: #888;
43 | }
44 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/src/render/App.tsx:
--------------------------------------------------------------------------------
1 | import { useState } from 'react'
2 | import Logo from './assets/logo.svg'
3 | import { sendMsgToMain } from 'electron-prokit'
4 | import './App.css'
5 |
6 | function App() {
7 | const [count, setCount] = useState(0)
8 |
9 | return (
10 | <>
11 | sendMsgToMain({
12 | key:'openUrl',
13 | data: {
14 | url:'https://xutaotaotao.github.io/electron-prokit/'
15 | }
16 | })}>
17 |

18 |
19 | A vite + react + electron template with electron-prokit.
20 |
21 |
24 |
25 | Edit src/render/App.tsx
and save to test HMR
26 |
27 |
28 |
29 | Click on the logo to learn more
30 |
31 | >
32 | )
33 | }
34 |
35 | export default App
36 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/src/render/assets/react.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/src/render/index.css:
--------------------------------------------------------------------------------
1 | :root {
2 | font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
3 | line-height: 1.5;
4 | font-weight: 400;
5 |
6 | color-scheme: light dark;
7 | color: rgba(255, 255, 255, 0.87);
8 | background-color: #242424;
9 |
10 | font-synthesis: none;
11 | text-rendering: optimizeLegibility;
12 | -webkit-font-smoothing: antialiased;
13 | -moz-osx-font-smoothing: grayscale;
14 | -webkit-text-size-adjust: 100%;
15 | }
16 |
17 | a {
18 | font-weight: 500;
19 | color: #646cff;
20 | text-decoration: inherit;
21 | }
22 | a:hover {
23 | color: #535bf2;
24 | }
25 |
26 | body {
27 | margin: 0;
28 | display: flex;
29 | place-items: center;
30 | min-width: 320px;
31 | min-height: 100vh;
32 | }
33 |
34 | h1 {
35 | font-size: 3.2em;
36 | line-height: 1.1;
37 | }
38 |
39 | button {
40 | border-radius: 8px;
41 | border: 1px solid transparent;
42 | padding: 0.6em 1.2em;
43 | font-size: 1em;
44 | font-weight: 500;
45 | font-family: inherit;
46 | background-color: #1a1a1a;
47 | cursor: pointer;
48 | transition: border-color 0.25s;
49 | }
50 | button:hover {
51 | border-color: #646cff;
52 | }
53 | button:focus,
54 | button:focus-visible {
55 | outline: 4px auto -webkit-focus-ring-color;
56 | }
57 |
58 | @media (prefers-color-scheme: light) {
59 | :root {
60 | color: #213547;
61 | background-color: #ffffff;
62 | }
63 | a:hover {
64 | color: #747bff;
65 | }
66 | button {
67 | background-color: #f9f9f9;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/src/render/main.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ReactDOM from 'react-dom/client'
3 | import App from './App.tsx'
4 | import './index.css'
5 |
6 | ReactDOM.createRoot(document.getElementById('root')!).render(
7 |
8 |
9 | ,
10 | )
11 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/src/render/vite-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/src/type.d.ts:
--------------------------------------------------------------------------------
1 | interface Msg {
2 | key:string,
3 | [key: string]: any;
4 | }
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/src/util/index.ts:
--------------------------------------------------------------------------------
1 | export const getResourcesPath = (path:string) => {
2 | if (import.meta.env.MODE === 'production') {
3 | return `../../../${path}`
4 | }
5 | return `../../${path}`
6 | }
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/src/work/App.tsx:
--------------------------------------------------------------------------------
1 | import {onMsgFormOtherRender} from 'electron-prokit'
2 |
3 | onMsgFormOtherRender((e,arg) => {
4 | console.log(e,arg)
5 | })
6 |
7 | function App() {
8 | return work
9 | }
10 |
11 | export default App
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/src/work/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Electron Prokit Work
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/src/work/main.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ReactDOM from 'react-dom/client'
3 | import App from './App.tsx'
4 |
5 | ReactDOM.createRoot(document.getElementById('root')!).render(
6 |
7 |
8 | ,
9 | )
10 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-react-ts/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES2020",
4 | "useDefineForClassFields": true,
5 | "lib": ["ES2020", "DOM", "DOM.Iterable"],
6 | "module": "ESNext",
7 | "skipLibCheck": true,
8 |
9 | /* Bundler mode */
10 | "moduleResolution": "bundler",
11 | "allowImportingTsExtensions": true,
12 | "resolveJsonModule": true,
13 | "isolatedModules": true,
14 | "noEmit": true,
15 | "jsx": "react-jsx",
16 |
17 | /* Linting */
18 | "strict": true,
19 | "noUnusedLocals": true,
20 | "noUnusedParameters": true,
21 | "noFallthroughCasesInSwitch": true
22 | },
23 | "include": ["src","scripts","config"],
24 | }
25 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | dist
12 | release
13 | dist-ssr
14 | *.local
15 |
16 | # Editor directories and files
17 | .vscode/*
18 | !.vscode/extensions.json
19 | .idea
20 | .DS_Store
21 | *.suo
22 | *.ntvs*
23 | *.njsproj
24 | *.sln
25 | *.sw?
26 |
27 | # lock
28 | pnpm-lock.yaml
29 | yarn.lock
30 | pnpm.lock
31 | npm.lock
32 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/.npmrc:
--------------------------------------------------------------------------------
1 | ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/
2 | ELECTRON_BUILDER_BINARIES_MIRROR=https://npmmirror.com/mirrors/electron-builder-binaries/
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/README.md:
--------------------------------------------------------------------------------
1 | # A vite + Vue3 + electron template with electron-prokit.
2 |
3 | `.npmrc` can change `electron_mirror`.
4 |
5 | ## Install
6 |
7 | ```bash
8 | yarn install
9 | ```
10 |
11 | ## Dev
12 |
13 | ```bash
14 | yarn run dev
15 | ```
16 |
17 | ## Build
18 |
19 | ```bash
20 | yarn run build
21 | ```
22 |
23 | ## Compile
24 |
25 | ```bash
26 | yarn run compile
27 | ```
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/config/main.ts:
--------------------------------------------------------------------------------
1 | import { cwd } from "process";
2 | import path from "path";
3 | import { builtinModules } from "module";
4 | import { fileURLToPath } from "url";
5 | import { defineConfig } from "vite";
6 |
7 | const __dirname = fileURLToPath(new URL(".", import.meta.url));
8 |
9 | const sharedResolve = {
10 | alias: {
11 | "@": path.resolve(__dirname, "src"),
12 | },
13 | };
14 |
15 | export default defineConfig({
16 | root: path.resolve(__dirname, "../src/main"),
17 | envDir: cwd(),
18 | resolve: sharedResolve,
19 | build: {
20 | outDir: path.resolve(__dirname, "../dist/main"),
21 | minify: false,
22 | lib: {
23 | entry: path.resolve(__dirname, "../src/main/index.ts"),
24 | formats: ["cjs"],
25 | },
26 | rollupOptions: {
27 | external: [
28 | "electron",
29 | "lowdb",
30 | "koffi",
31 | "electron-updater",
32 | ...builtinModules,
33 | ],
34 | output: {
35 | entryFileNames: "[name].cjs",
36 | },
37 | },
38 | emptyOutDir: true,
39 | chunkSizeWarningLimit: 2048,
40 | },
41 | })
42 |
43 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/config/preload.ts:
--------------------------------------------------------------------------------
1 | import { cwd } from "process";
2 | import path from "path";
3 | import { builtinModules } from "module";
4 | import { fileURLToPath } from "url";
5 | import { defineConfig } from "vite";
6 |
7 | const __dirname = fileURLToPath(new URL(".", import.meta.url));
8 |
9 |
10 | const sharedResolve = {
11 | alias: {
12 | "@": path.resolve(__dirname, "src"),
13 | },
14 | };
15 |
16 | export default defineConfig({
17 | root: path.resolve(__dirname, "../src/preload"),
18 | envDir: cwd(),
19 | resolve: sharedResolve,
20 | build: {
21 | watch: {},
22 | outDir: path.resolve(__dirname, "../dist/preload"),
23 | minify: false,
24 | lib: {
25 | entry: path.resolve(__dirname, "../src/preload/index.ts"),
26 | formats: ["cjs"],
27 | },
28 | rollupOptions: {
29 | external: ["electron", "lowdb", ...builtinModules],
30 | output: {
31 | entryFileNames: "[name].cjs",
32 | },
33 | },
34 | emptyOutDir: true,
35 | chunkSizeWarningLimit: 2048,
36 | },
37 | })
38 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/config/render.ts:
--------------------------------------------------------------------------------
1 | import path from "path";
2 | import { builtinModules } from "module";
3 | import { fileURLToPath } from "url";
4 | import { defineConfig } from "vite";
5 | import vue from '@vitejs/plugin-vue'
6 |
7 | const __dirname = fileURLToPath(new URL(".", import.meta.url));
8 |
9 | const sharedResolve = {
10 | alias: {
11 | "@": path.resolve(__dirname, "src"),
12 | },
13 | };
14 |
15 | export default defineConfig({
16 | root: path.resolve(__dirname, "../"),
17 | base: "./",
18 | resolve: sharedResolve,
19 | build: {
20 | watch: {},
21 | outDir: path.resolve(__dirname, "../dist/render"),
22 | minify: true,
23 | assetsInlineLimit: 1048576,
24 | emptyOutDir: true,
25 | chunkSizeWarningLimit: 2048,
26 | rollupOptions: {
27 | external: [...builtinModules, "electron", "lowdb"],
28 | },
29 | commonjsOptions: {
30 | include: [/node_modules/],
31 | },
32 | },
33 | plugins: [vue()],
34 | });
35 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/config/work.ts:
--------------------------------------------------------------------------------
1 | import path from "path";
2 | import { builtinModules } from "module";
3 | import { fileURLToPath } from "url";
4 | import { defineConfig } from "vite";
5 |
6 | const __dirname = fileURLToPath(new URL(".", import.meta.url));
7 |
8 |
9 | const sharedResolve = {
10 | alias: {
11 | "@": path.resolve(__dirname, "src"),
12 | },
13 | };
14 |
15 | export default defineConfig({
16 | root: path.resolve(__dirname, "../src/work"),
17 | base: "./",
18 | resolve: sharedResolve,
19 | build: {
20 | watch: {},
21 | outDir: path.resolve(__dirname, "../dist/work"),
22 | minify: true,
23 | assetsInlineLimit: 1048576,
24 | emptyOutDir: true,
25 | chunkSizeWarningLimit: 2048,
26 | rollupOptions: {
27 | external: [...builtinModules, "electron", "lowdb"],
28 | },
29 | },
30 | })
31 |
32 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/electron-builder.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "productName": "ElectronProkit",
3 | "appId": "electron.prokit.com",
4 | "copyright": "Copyright © 2023",
5 | "asar": false,
6 | "files": ["dist/**", "package.json"],
7 | "directories": {
8 | "output": "release",
9 | "buildResources": "resources"
10 | },
11 | "extraResources": {
12 | "from": "resources",
13 | "to": "resources"
14 | },
15 | "mac": {
16 | "hardenedRuntime": true,
17 | "gatekeeperAssess": false,
18 | "target": ["dmg", "zip"],
19 | "entitlements": "./scripts/entitlements.mac.plist",
20 | "entitlementsInherit": "./scripts/entitlements.mac.plist",
21 | "identity": "",
22 | "icon": "./resources/icon/icon.icns",
23 | "extendInfo": {
24 | "LSUIElement": true,
25 | "SUFeedURL": "",
26 | "SUPublicEDKey": ""
27 | }
28 | },
29 | "dmg": {
30 | "backgroundColor": "#ffffff",
31 | "window": { "width": 540, "height": 380 },
32 | "icon": "./resources/icon/icon.icns",
33 | "iconSize": 128,
34 | "contents": [
35 | { "x": 410, "y": 190, "type": "link", "path": "/Applications" },
36 | { "x": 130, "y": 190, "type": "file" }
37 | ],
38 | "title": "ElectronProkit"
39 | },
40 | "win": {
41 | "icon": "./resources/icon/icon.ico",
42 | "target": "nsis",
43 | "verifyUpdateCodeSignature": false
44 | },
45 | "nsis": {
46 | "oneClick": true,
47 | "language": "2052",
48 | "perMachine": true,
49 | "createDesktopShortcut": true,
50 | "createStartMenuShortcut": true,
51 | "guid": "ElectronProkit",
52 | "shortcutName": "ElectronProkit",
53 | "artifactName": "ElectronProkit@${version}.${ext}"
54 | },
55 | "publish": {
56 | "provider": "generic",
57 | "url": "http://172.17.194.13:8090"
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | electron-prokit + vue + ts
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "{{name}}",
3 | "private": true,
4 | "version": "1.0.0",
5 | "type": "module",
6 | "main": "dist/main/index.cjs",
7 | "description": "{{ description }}",
8 | "author": "{{ author }}",
9 | "scripts": {
10 | "dev": "node --experimental-specifier-resolution=node --loader ts-node/esm ./scripts/dev.ts",
11 | "build": "node --experimental-specifier-resolution=node --loader ts-node/esm ./scripts/build.ts",
12 | "compile": "electron-builder build --config ./electron-builder.config.json",
13 | "preview": "vite preview"
14 | },
15 | "dependencies": {
16 | "koffi": "2.3.20",
17 | "vue": "^3.3.4"
18 | },
19 | "devDependencies": {
20 | "@electron-prokit/create-service": "^3.0.0",
21 | "@vitejs/plugin-vue": "^4.2.3",
22 | "electron": "^26.2.0",
23 | "electron-builder": "^24.6.4",
24 | "ts-node": "^10.9.1",
25 | "electron-prokit": "^16.1.2",
26 | "typescript": "^5.0.2",
27 | "vite": "^4.4.5",
28 | "vue-tsc": "^1.8.5"
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/public/vite.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/resources/icon/icon.icns:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/packages/create-electron-prokit/template-vue-ts/resources/icon/icon.icns
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/resources/icon/icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/packages/create-electron-prokit/template-vue-ts/resources/icon/icon.ico
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/resources/icon/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/packages/create-electron-prokit/template-vue-ts/resources/icon/icon.png
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/resources/icon/icon@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/packages/create-electron-prokit/template-vue-ts/resources/icon/icon@2x.png
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/scripts/build.ts:
--------------------------------------------------------------------------------
1 | #!/usr/bin/node
2 | import { fileURLToPath } from 'url';
3 | import { dirname, resolve } from 'path';
4 | import { build } from 'vite';
5 | import pkgJson from '../package.json' assert { type: 'json' };
6 |
7 | const __filename = fileURLToPath(import.meta.url);
8 | const __dirname = dirname(__filename);
9 |
10 | const processArgv = process.argv.splice(2);
11 | const mode = processArgv && processArgv.length > 0 ? processArgv[0] : 'production';
12 |
13 | const packagesConfigs = [
14 | resolve(__dirname, '../config/render'),
15 | resolve(__dirname, '../config/work'),
16 | resolve(__dirname, '../config/main'),
17 | resolve(__dirname, '../config/preload'),
18 | ];
19 |
20 | // Set environment variables
21 | process.env.VITE_CURRENT_RUN_MODE = 'render';
22 | process.env.VITE_CURRENT_VERSION = pkgJson.version;
23 | process.env.MODE = mode;
24 | process.env.VITE_CURRENT_OS = process.platform;
25 |
26 | const buildByConfig = async (configFile:string) => {
27 | try {
28 | await build({ configFile, mode });
29 | } catch (error) {
30 | console.error(`Error building ${configFile}:`, error);
31 | throw error;
32 | }
33 | };
34 |
35 | const delay = (ms:number) => new Promise(resolve => setTimeout(resolve, ms));
36 |
37 | const main = async () => {
38 | try {
39 | console.time('Total bundling time');
40 | for (const config of packagesConfigs) {
41 | const modeMap:any = {
42 | main: 'main',
43 | render: 'render',
44 | preload: 'preload',
45 | work: 'work',
46 | };
47 |
48 | for (const key in modeMap) {
49 | if (config.includes(key)) {
50 | process.env.VITE_CURRENT_RUN_MODE = modeMap[key];
51 | break;
52 | }
53 | }
54 |
55 | console.time(`Bundling ${config}`);
56 | await buildByConfig(config);
57 | console.timeEnd(`Bundling ${config}`);
58 | }
59 | console.timeEnd('Total bundling time');
60 | } catch (error) {
61 | console.error('Build failed:', error);
62 | process.exit(1);
63 | }
64 | await delay(3000)
65 | process.exit(0);
66 | };
67 |
68 | main();
69 |
70 | process.on('unhandledRejection', (reason, promise) => {
71 | console.error('Unhandled Rejection at:', promise, 'reason:', reason);
72 | process.exit(1);
73 | });
74 |
75 | process.on('uncaughtException', (err) => {
76 | console.error('Uncaught Exception thrown:', err);
77 | process.exit(1);
78 | });
79 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/scripts/dev.ts:
--------------------------------------------------------------------------------
1 | import createViteElectronService from '@electron-prokit/create-service';
2 | import electronPath from "electron";
3 | import main from "../config/main";
4 | import render from "../config/render";
5 | import work from "../config/work";
6 | import preload from "../config/preload";
7 |
8 |
9 | createViteElectronService({
10 | render: render,
11 | preload: preload,
12 | work: work,
13 | main: main,
14 | electronPath: electronPath
15 | });
16 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/scripts/entitlements.mac.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.cs.allow-unsigned-executable-memory
6 |
7 |
8 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/src/main/index.ts:
--------------------------------------------------------------------------------
1 | import { join,resolve } from "path";
2 | import {
3 | app,
4 | } from "electron";
5 | import {createWindow} from 'electron-prokit';
6 | import ipc from './ipc'
7 |
8 | const initWindowsAction = () => {
9 | const mainWindow = createWindow('main',{
10 | width: 960,
11 | height: 720,
12 | webPreferences: {
13 | contextIsolation: true,
14 | nodeIntegration: true,
15 | webSecurity: false,
16 | preload: join(__dirname, "../preload/index.cjs"),
17 | },
18 | })
19 |
20 | if (mainWindow) {
21 | if (import.meta.env.MODE === "dev") {
22 | if (import.meta.env.VITE_DEV_SERVER_URL) {
23 | mainWindow.loadURL(import.meta.env.VITE_DEV_SERVER_URL);
24 | }
25 | } else {
26 | mainWindow.loadFile(resolve(__dirname, "../render/index.html"));
27 | }
28 | }
29 | }
30 |
31 |
32 | app.whenReady().then(() => {
33 | initWindowsAction()
34 | ipc()
35 | })
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/src/main/ipc.ts:
--------------------------------------------------------------------------------
1 | import {initIpc,onMsgFromRender } from "electron-prokit";
2 | import { shell } from 'electron';
3 |
4 | const main = ():void => {
5 | initIpc();
6 | onMsgFromRender(async (_e: Electron.IpcMainEvent, args: Msg) => {
7 | if (args.key === 'openUrl') {
8 | shell.openExternal(args.data.url)
9 | return true
10 | }
11 | return `Main have get data is ${args}`;
12 | });
13 | };
14 |
15 | export default main;
16 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/src/preload/index.ts:
--------------------------------------------------------------------------------
1 | import {initExposeInMainWorld} from 'electron-prokit'
2 |
3 | initExposeInMainWorld()
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/src/render/App.vue:
--------------------------------------------------------------------------------
1 |
13 |
14 |
15 |
16 |

17 |
18 |
19 |
20 |
21 |
37 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/src/render/assets/vue.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/src/render/components/HelloWorld.vue:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 | {{ msg }}
11 |
12 |
13 |
14 |
15 | Edit
16 | src/render/components/HelloWorld.vue
to test HMR
17 |
18 |
19 | Click on the logos to learn more
20 |
21 |
22 |
27 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/src/render/main.ts:
--------------------------------------------------------------------------------
1 | import { createApp } from 'vue'
2 | import './style.css'
3 | import App from './App.vue'
4 |
5 | createApp(App).mount('#app')
6 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/src/render/style.css:
--------------------------------------------------------------------------------
1 | :root {
2 | font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
3 | line-height: 1.5;
4 | font-weight: 400;
5 |
6 | color-scheme: light dark;
7 | color: rgba(255, 255, 255, 0.87);
8 | background-color: #242424;
9 |
10 | font-synthesis: none;
11 | text-rendering: optimizeLegibility;
12 | -webkit-font-smoothing: antialiased;
13 | -moz-osx-font-smoothing: grayscale;
14 | -webkit-text-size-adjust: 100%;
15 | }
16 |
17 | a {
18 | font-weight: 500;
19 | color: #646cff;
20 | text-decoration: inherit;
21 | }
22 | a:hover {
23 | color: #535bf2;
24 | }
25 |
26 | body {
27 | margin: 0;
28 | display: flex;
29 | place-items: center;
30 | min-width: 320px;
31 | min-height: 100vh;
32 | }
33 |
34 | h1 {
35 | font-size: 3.2em;
36 | line-height: 1.1;
37 | }
38 |
39 | button {
40 | border-radius: 8px;
41 | border: 1px solid transparent;
42 | padding: 0.6em 1.2em;
43 | font-size: 1em;
44 | font-weight: 500;
45 | font-family: inherit;
46 | background-color: #1a1a1a;
47 | cursor: pointer;
48 | transition: border-color 0.25s;
49 | }
50 | button:hover {
51 | border-color: #646cff;
52 | }
53 | button:focus,
54 | button:focus-visible {
55 | outline: 4px auto -webkit-focus-ring-color;
56 | }
57 |
58 | .card {
59 | padding: 2em;
60 | }
61 |
62 | #app {
63 | max-width: 1280px;
64 | margin: 0 auto;
65 | padding: 2rem;
66 | text-align: center;
67 | }
68 |
69 | @media (prefers-color-scheme: light) {
70 | :root {
71 | color: #213547;
72 | background-color: #ffffff;
73 | }
74 | a:hover {
75 | color: #747bff;
76 | }
77 | button {
78 | background-color: #f9f9f9;
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/src/render/vite-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/src/type.d.ts:
--------------------------------------------------------------------------------
1 | interface Msg {
2 | key:string,
3 | [key: string]: any;
4 | }
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/src/work/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Electron Prokit Work
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/src/work/main.ts:
--------------------------------------------------------------------------------
1 | console.log('work')
2 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/template-vue-ts/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES2020",
4 | "useDefineForClassFields": true,
5 | "module": "ESNext",
6 | "lib": ["ES2020", "DOM", "DOM.Iterable"],
7 | "skipLibCheck": true,
8 |
9 | /* Bundler mode */
10 | "moduleResolution": "bundler",
11 | "allowImportingTsExtensions": true,
12 | "resolveJsonModule": true,
13 | "isolatedModules": true,
14 | "noEmit": true,
15 | "jsx": "preserve",
16 |
17 | /* Linting */
18 | "strict": true,
19 | "noUnusedLocals": true,
20 | "noUnusedParameters": true,
21 | "noFallthroughCasesInSwitch": true
22 | },
23 | "include": ["src","scripts","config"],
24 | }
25 |
--------------------------------------------------------------------------------
/packages/create-electron-prokit/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es2016",
4 | "module": "ESNext",
5 | "moduleResolution": "node",
6 | "esModuleInterop": true,
7 | "forceConsistentCasingInFileNames": true,
8 | "strict": true,
9 | "sourceMap": true,
10 | "outDir": "./dist",
11 | "importHelpers": true,
12 | },
13 | "include": ["src/**/*","typings.d.ts"],
14 | "exclude": ["node_modules", "dist/**/*"],
15 | }
--------------------------------------------------------------------------------
/packages/create-electron-prokit/typings.d.ts:
--------------------------------------------------------------------------------
1 | export interface Options {
2 | name:string;
3 | description:string;
4 | author:string;
5 | }
--------------------------------------------------------------------------------
/packages/create-service/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # @electron-prokit/create-service
2 |
3 | ## 4.0.0
4 |
5 | ### Major Changes
6 |
7 | - e6e10b7: fix: build action
8 |
9 | ## 3.0.1
10 |
11 | ### Patch Changes
12 |
13 | - 8c0cc9c: feat: add node engines version
14 |
15 | ## 3.0.0
16 |
17 | ### Major Changes
18 |
19 | - e0ecd29: feat: exports types
20 |
21 | ## 2.1.0
22 |
23 | ### Minor Changes
24 |
25 | - be810e7: feat: publishConfig exports
26 |
27 | ## 2.0.0
28 |
29 | ### Major Changes
30 |
31 | - 5e61af4: feat: change this Config.
32 |
33 | ## 1.0.0
34 |
35 | ### Major Changes
36 |
37 | - 800cccf: feat: Relase this package.
38 |
--------------------------------------------------------------------------------
/packages/create-service/README.md:
--------------------------------------------------------------------------------
1 | # @electron-prokit/create-service
2 |
3 | ## Install
4 | `npm i @electron-prokit/create-service`
5 |
6 | ## Usage
7 |
8 | ```ts
9 | import createViteElectronService from '@electron-prokit/create-service';
10 | import config from "../ep.config";
11 | createViteElectronService({
12 | render: config.render,
13 | preload: config.preload,
14 | work: config.work,
15 | main: config.main,
16 | electronPath: config.electronPath
17 | });
18 | ```
19 |
20 | - `ep.config.ts`
21 |
22 | ```ts
23 | import { builtinModules } from "module";
24 | import { fileURLToPath } from "url";
25 | import { cwd } from "process";
26 | import path from "path";
27 | import vue from '@vitejs/plugin-vue'
28 | import electronPath from "electron";
29 | import type { UserConfig } from "vite";
30 |
31 | const __dirname = fileURLToPath(new URL(".", import.meta.url));
32 |
33 | const sharedResolve = {
34 | alias: {
35 | "@": path.resolve(__dirname, "src"),
36 | },
37 | };
38 |
39 | interface Config {
40 | main: UserConfig;
41 | preload: UserConfig;
42 | render: UserConfig;
43 | work: UserConfig;
44 | electronPath:any;
45 | }
46 |
47 | const config: Config = {
48 | // 主进程配置
49 | main: {
50 | root: cwd(),
51 | resolve: sharedResolve,
52 | build: {
53 | outDir: path.resolve(__dirname, "dist/main"),
54 | minify: false,
55 | lib: {
56 | entry: path.resolve(__dirname, "src/main/index.ts"),
57 | formats: ["cjs"],
58 | },
59 | rollupOptions: {
60 | external: ["electron", "koffi", ...builtinModules],
61 | output: {
62 | entryFileNames: "[name].cjs",
63 | },
64 | },
65 | emptyOutDir: true,
66 | chunkSizeWarningLimit: 2048,
67 | },
68 | },
69 | // preload配置
70 | preload: {
71 | root: cwd(),
72 | resolve: sharedResolve,
73 | build: {
74 | outDir: path.resolve(__dirname, "dist/preload"),
75 | minify: false,
76 | lib: {
77 | entry: path.resolve(__dirname, "src/preload/index.ts"),
78 | formats: ["cjs"],
79 | },
80 | rollupOptions: {
81 | external: ["electron", ...builtinModules],
82 | output: {
83 | entryFileNames: "[name].cjs",
84 | },
85 | },
86 | emptyOutDir: true,
87 | chunkSizeWarningLimit: 2048,
88 | },
89 | },
90 | // 渲染进程配置
91 | render: {
92 | root: cwd(),
93 | base: "./",
94 | resolve: sharedResolve,
95 | build: {
96 | outDir: path.resolve(__dirname, "../dist/render"),
97 | minify: true,
98 | assetsInlineLimit: 1048576,
99 | emptyOutDir: true,
100 | chunkSizeWarningLimit: 2048,
101 | rollupOptions: {
102 | external: [...builtinModules, "electron"],
103 | },
104 | },
105 | plugins: [vue()],
106 | },
107 | // work进程配置
108 | work: {
109 | root: path.resolve(__dirname, "src/work"),
110 | envDir: cwd(),
111 | resolve: sharedResolve,
112 | build: {
113 | outDir: path.resolve(__dirname, "dist/work"),
114 | assetsDir: ".",
115 | minify: false,
116 | lib: {
117 | entry: path.resolve(__dirname, "src/work/index.ts"),
118 | formats: ["cjs"],
119 | },
120 | rollupOptions: {
121 | external: ["electron", ...builtinModules],
122 | output: {
123 | entryFileNames: "[name].cjs",
124 | },
125 | },
126 | emptyOutDir: true,
127 | chunkSizeWarningLimit: 2048,
128 | },
129 | },
130 | electronPath,
131 | };
132 |
133 | export default config;
134 |
135 | ```
136 |
137 |
--------------------------------------------------------------------------------
/packages/create-service/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@electron-prokit/create-service",
3 | "version": "4.0.0",
4 | "engines": {
5 | "node": "^14.8.0 || >=16.0.0"
6 | },
7 | "description": "",
8 | "type": "module",
9 | "main": "src/index.ts",
10 | "publishConfig": {
11 | "main": "dist/index.js",
12 | "module": "dist/index.esm.js",
13 | "types": "dist/index.d.ts",
14 | "access": "public",
15 | "registry": "https://registry.npmjs.org/",
16 | "exports": {
17 | ".": {
18 | "import": {
19 | "default": "./dist/index.js",
20 | "types": "./dist/index.d.ts"
21 | },
22 | "require": {
23 | "default": "./dist/index.cjs.js"
24 | }
25 | }
26 | }
27 | },
28 | "files": [
29 | "dist"
30 | ],
31 | "scripts": {
32 | "test": "echo \"Error: no test specified\" && exit 1"
33 | },
34 | "keywords": [],
35 | "author": "",
36 | "license": "ISC",
37 | "dependencies": {
38 | "vite": "^4.4.5"
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/packages/create-service/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES2020",
4 | "useDefineForClassFields": true,
5 | "lib": ["ES2020", "DOM", "DOM.Iterable"],
6 | "allowJs": true,
7 | "module": "ESNext",
8 | "skipLibCheck": true,
9 | "moduleResolution": "node",
10 | "downlevelIteration": true,
11 | "declaration": true,
12 | },
13 | "types": [
14 | "jest"
15 | ],
16 | "include": ["src","vendor.d.ts","typings.d.ts"],
17 | "exclude": ["node_modules", "dist/**/*"],
18 | }
19 |
--------------------------------------------------------------------------------
/packages/electron-prokit/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # electron-prokit
2 |
3 | ## 16.1.2
4 |
5 | ### Patch Changes
6 |
7 | - 70bffbb: fix:change types file import path
8 |
9 | ## 16.1.1
10 |
11 | ### Patch Changes
12 |
13 | - 6065321: fix:types
14 |
15 | ## 16.1.0
16 |
17 | ### Minor Changes
18 |
19 | - ecc6ea5: feat: add update
20 |
21 | ## 16.0.3
22 |
23 | ### Patch Changes
24 |
25 | - 8c0cc9c: feat: add node engines version
26 |
27 | ## 16.0.2
28 |
29 | ### Patch Changes
30 |
31 | - 8fc37e2: feat:create-electron-prokit
32 |
33 | ## 16.0.1
34 |
35 | ### Patch Changes
36 |
37 | - b641ff7: fix: db initDb error.
38 |
39 | ## 16.0.0
40 |
41 | ### Major Changes
42 |
43 | - d88f923: feat: A release version publish
44 |
45 | ## 1.0.0
46 |
47 | ### Major Changes
48 |
49 | - 800cccf: feat: Relase this package.
50 |
--------------------------------------------------------------------------------
/packages/electron-prokit/README.md:
--------------------------------------------------------------------------------
1 | # electron-prokit
2 |
3 | electron-prokit core api.
4 |
5 | ## Install
6 | `npm i electron-prokit`
7 |
8 | ## Documentation
9 |
10 | For detailed usage instructions and documentation, please refer to [the Documentation](https://xutaotaotao.github.io/electron-prokit/) section.
--------------------------------------------------------------------------------
/packages/electron-prokit/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "electron-prokit",
3 | "version": "16.1.2",
4 | "engines": {
5 | "node": "^14.8.0 || >=16.0.0"
6 | },
7 | "description": "A desktop app framework based on Electron,develop desktop applications like a pro!",
8 | "type": "module",
9 | "main": "src/index.ts",
10 | "publishConfig": {
11 | "main": "dist/index.cjs.js",
12 | "module": "dist/index.esm.js",
13 | "access": "public",
14 | "types": "dist/src/index.d.ts",
15 | "registry": "https://registry.npmjs.org/"
16 | },
17 | "files": [
18 | "dist"
19 | ],
20 | "keywords": [
21 | "Electron",
22 | "electron",
23 | "electron-prokit",
24 | "electron prokit",
25 | "Electron Prokit",
26 | "Prokit",
27 | "prokit"
28 | ],
29 | "author": "Xutaotaotao",
30 | "license": "MIT",
31 | "devDependencies": {
32 | "@types/node": "^20.5.7",
33 | "chalk": "^5.3.0",
34 | "electron": "^26.1.0",
35 | "js-beautify": "^1.14.9",
36 | "pnpm": "^8.7.6",
37 | "typescript": "^5.0.2"
38 | },
39 | "dependencies": {
40 | "axios": "^1.5.0",
41 | "koffi": "2.3.20",
42 | "lowdb": "3.0.0",
43 | "electron-updater": "^6.1.4"
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/packages/electron-prokit/src/db/index.ts:
--------------------------------------------------------------------------------
1 | import { isMain,isRender } from "../env";
2 |
3 | import {
4 | clearDb as mainClearDb,
5 | initDb as mainInitDb,
6 | readDb as mainReadDb,
7 | writeDb as mainWriteDb
8 | } from './main'
9 | import {
10 | clearDb as renderClearDb,
11 | initDb as renderInitDb,
12 | readDb as renderReadDb,
13 | writeDb as renderWriteDb
14 | } from './render'
15 | import {
16 | clearDb as preloadClearDb,
17 | initDb as preloadInitDb,
18 | readDb as preloadReadDb,
19 | writeDb as preloadWriteDb
20 | } from './preload'
21 |
22 | export const initDb = isMain ? mainInitDb : isRender ? renderInitDb : preloadInitDb
23 |
24 | export const readDb = isMain ? mainReadDb : isRender ? renderReadDb : preloadReadDb
25 |
26 | export const writeDb = isMain ? mainWriteDb: isRender ? renderWriteDb : preloadWriteDb
27 |
28 | export const clearDb = isMain ? mainClearDb : isRender ? renderClearDb : preloadClearDb
--------------------------------------------------------------------------------
/packages/electron-prokit/src/db/main.ts:
--------------------------------------------------------------------------------
1 | import type {LowSync} from 'lowdb'
2 | import { useDbFile, useLowdb } from "../hooks";
3 | import type { ClearDbFunc, InitDbFunc, ReadDbFunc, WriteDbFunc } from './type';
4 |
5 | let db: LowSync | null = null;
6 |
7 | const defaultFile = useDbFile();
8 |
9 | export const initDb:InitDbFunc = (file = defaultFile) => {
10 | // eslint-disable-next-line no-async-promise-executor
11 | return new Promise(async (resolve, reject) => {
12 | if (db) {
13 | resolve(true);
14 | } else {
15 | try {
16 | const lowdb = await useLowdb(file);
17 | await lowdb.read();
18 | db = lowdb;
19 | resolve(true);
20 | } catch (err) {
21 | reject(err);
22 | }
23 | }
24 | });
25 | };
26 |
27 | // todo data type constrains
28 | export const writeDb:WriteDbFunc = async (key, data) => {
29 | if (!db) {
30 | await initDb();
31 | }
32 | await db.read();
33 | const oldData = db.data || {}
34 | db.data = {
35 | ...oldData,
36 | [key]: data,
37 | };
38 | await db.write();
39 | };
40 |
41 | export const readDb:ReadDbFunc = async (key) => {
42 | if (!db) {
43 | await initDb();
44 | }
45 | await db.read();
46 | const res = db.data?.[key];
47 | return res;
48 | };
49 |
50 | export const clearDb:ClearDbFunc = async () => {
51 | if (!db) {
52 | return;
53 | }
54 | db.data = {};
55 | await db.write();
56 | };
57 |
--------------------------------------------------------------------------------
/packages/electron-prokit/src/db/preload.ts:
--------------------------------------------------------------------------------
1 | import { useIpcRenderer } from "../hooks";
2 | import type { ClearDbFunc, InitDbFunc, ReadDbFunc, WriteDbFunc } from "./type";
3 |
4 | const ipcRenderer = useIpcRenderer();
5 |
6 | export const initDb:InitDbFunc = (file) => {
7 | return ipcRenderer.invoke("EPinitDb", {
8 | fun:'initDb',
9 | file
10 | });
11 | }
12 |
13 | export const writeDb:WriteDbFunc = (key, data) => {
14 | return ipcRenderer.invoke("EPinitDb", {
15 | fun:'writeDb',
16 | key,
17 | data
18 | });
19 | }
20 |
21 | export const readDb:ReadDbFunc = (key) => {
22 | return ipcRenderer.invoke("EPinitDb", {
23 | fun:'readDb',
24 | key,
25 | });
26 | }
27 |
28 |
29 | export const clearDb:ClearDbFunc = () => {
30 | return ipcRenderer.invoke("EPinitDb", {
31 | fun:'clearDb',
32 | });
33 | }
--------------------------------------------------------------------------------
/packages/electron-prokit/src/db/render.ts:
--------------------------------------------------------------------------------
1 | import type { ClearDbFunc, InitDbFunc, ReadDbFunc, WriteDbFunc } from "./type";
2 |
3 | export const initDb:InitDbFunc = (file) => {
4 | return window.electronProkit.initDb(file);
5 | };
6 |
7 | export const writeDb:WriteDbFunc = (key, data) => {
8 | return window.electronProkit.writeDb(key, data);
9 | };
10 |
11 | export const readDb:ReadDbFunc = (key) => {
12 | return window.electronProkit.readDb(key);
13 | };
14 |
15 | export const clearDb:ClearDbFunc = () => {
16 | return window.electronProkit.clearDb();
17 | };
18 |
--------------------------------------------------------------------------------
/packages/electron-prokit/src/db/type.d.ts:
--------------------------------------------------------------------------------
1 |
2 | export type InitDbFunc = (file?: string) => Promise
3 | export type WriteDbFunc = (key: string, data: any) => Promise
4 | export type ReadDbFunc = (key: string) => Promise
5 | export type ClearDbFunc = () => void
6 |
--------------------------------------------------------------------------------
/packages/electron-prokit/src/env/index.ts:
--------------------------------------------------------------------------------
1 | export const hasElectron = typeof process !== 'undefined' && typeof process.versions === 'object' && !!process.versions.electron
2 | export const hasUserAgent = typeof navigator === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent.indexOf('Electron') >= 0
3 |
4 | export const isMain:boolean = hasElectron && !hasUserAgent;
5 | export const isRender:boolean = !hasElectron && hasUserAgent;
6 | export const isPreload:boolean = hasElectron && hasUserAgent;
--------------------------------------------------------------------------------
/packages/electron-prokit/src/ffi/index.ts:
--------------------------------------------------------------------------------
1 | import { useKoffi } from "../hooks"
2 |
3 | interface BindingFun {
4 | functionName:string,
5 | returnType:string,
6 | inputs:Array
7 | }
8 |
9 | interface InitFfiOptions {
10 | path: string,
11 | function: BindingFun | Array
12 | }
13 |
14 | export const epffi = useKoffi()
15 |
16 | export const createEpffi= (options:InitFfiOptions):Record => {
17 | const functions: Record = {};
18 | const lib = epffi.load(options.path)
19 | if (Array.isArray(options.function)) {
20 | options.function.map((fun) => {
21 | functions[fun.functionName] = lib.func(fun.functionName,fun.returnType,fun.inputs)
22 | })
23 | } else {
24 | functions[options.function.functionName] = lib.func(options.function.functionName,options.function.returnType,options.function.inputs)
25 | }
26 | return functions
27 | }
--------------------------------------------------------------------------------
/packages/electron-prokit/src/hooks/index.ts:
--------------------------------------------------------------------------------
1 | import type { LowSync } from "lowdb/lib";
2 | import type { AppUpdater } from "electron-updater";
3 | import { isMain, isPreload } from "../env";
4 |
5 |
6 | export function useBrowserWindow(
7 | options: Electron.BrowserWindowConstructorOptions
8 | ): Electron.BrowserWindow | undefined {
9 | if (isMain) {
10 | const { BrowserWindow } = require("electron");
11 | return new BrowserWindow(options);
12 | }
13 | return undefined;
14 | }
15 |
16 | export function useIpcMain(): Electron.IpcMain | undefined {
17 | if (isMain) {
18 | return require("electron").ipcMain;
19 | }
20 | return undefined;
21 | }
22 |
23 | export function useIpcRenderer(): Electron.IpcRenderer | undefined {
24 | if (isPreload) {
25 | return require("electron").ipcRenderer;
26 | }
27 | return undefined;
28 | }
29 |
30 | export function useContextBridge(): Electron.ContextBridge | undefined {
31 | if (isPreload) {
32 | return require("electron").contextBridge;
33 | }
34 | return undefined;
35 | }
36 |
37 | export function useKoffi ():any {
38 | if (isMain) {
39 | return require("koffi")
40 | }
41 | }
42 |
43 | export function useDbFile ():string {
44 | if (isMain) {
45 | const { join } = require('path');
46 | const {app} = require('electron')
47 | const defaultFile = join(app.getPath("userData"), "db.json");
48 | return defaultFile
49 | }
50 | return 'db.json'
51 | }
52 |
53 | export async function useLowdb (file:string):Promise> {
54 | if (isMain) {
55 | const { LowSync, JSONFileSync } = await import("lowdb");
56 | const adapter = new JSONFileSync(file);
57 | const lowdb = new LowSync(adapter);
58 | return lowdb
59 | }
60 | return Promise.resolve(undefined as unknown as LowSync)
61 | }
62 |
63 | export function useUpdater ():AppUpdater {
64 | if (isMain) {
65 | return require("electron-updater").autoUpdater
66 | }
67 | }
--------------------------------------------------------------------------------
/packages/electron-prokit/src/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./http";
2 | export * from './window'
3 | export * from './ipc'
4 | export * from './ffi'
5 | export * from './schedule'
6 | export * from './db'
7 | export * from './preload'
8 | export * from './main'
9 | export * from './env'
10 | export * from './update'
--------------------------------------------------------------------------------
/packages/electron-prokit/src/ipc/index.ts:
--------------------------------------------------------------------------------
1 | import { isRender } from "../env";
2 | import {
3 | offMsgFromMain as renderOffMsgFromMain,
4 | onMsgFromMain as renderOnMsgFromMain,
5 | onRenderMsgToRender as renderOnRenderMsgToRender,
6 | renderMsgToMain as renderRenderMsgToMain,
7 | renderMsgToRender as renderRenderMsgToRender,
8 | } from "./render";
9 | import {
10 | offMsgFromMain as preloadOffMsgFromMain,
11 | onMsgFromMain as preloadOnMsgFromMain,
12 | onRenderMsgToRender as preloadOnRenderMsgToRender,
13 | renderMsgToMain as preloadRenderMsgToMain,
14 | renderMsgToRender as preloadRenderMsgToRender,
15 | } from "./preload";
16 |
17 | export * from "./main";
18 | export const offMsgFromMain = isRender
19 | ? renderOffMsgFromMain
20 | : preloadOffMsgFromMain;
21 | export const onMsgFromMain = isRender
22 | ? renderOnMsgFromMain
23 | : preloadOnMsgFromMain;
24 | export const onMsgFormOtherRender = isRender
25 | ? renderOnRenderMsgToRender
26 | : preloadOnRenderMsgToRender;
27 | export const sendMsgToMain = isRender
28 | ? renderRenderMsgToMain
29 | : preloadRenderMsgToMain;
30 | export const sendMsgToOtherRender = isRender
31 | ? renderRenderMsgToRender
32 | : preloadRenderMsgToRender;
33 |
--------------------------------------------------------------------------------
/packages/electron-prokit/src/ipc/main.ts:
--------------------------------------------------------------------------------
1 | import { useIpcMain } from "../hooks";
2 | import { getWindow } from "../window";
3 |
4 | const ipcMain = useIpcMain();
5 |
6 | type Callback = (event: Electron.IpcMainEvent, args: any) => void;
7 |
8 | function onMsgFromRender(callBack: Callback): void {
9 | ipcMain.handle(
10 | "EPrenderMsgToMain",
11 | (event: Electron.IpcMainEvent, args: any) => {
12 | return callBack(event, args);
13 | }
14 | );
15 | }
16 |
17 | function sendMsgToRender(windowName: string, msg: any): void {
18 | const windowInstance = getWindow(windowName);
19 | if (windowInstance) {
20 | windowInstance.webContents.send("EPmainMsgToRender", msg);
21 | } else {
22 | throw new Error("not find windowInstance");
23 | }
24 | }
25 |
26 | export { onMsgFromRender, sendMsgToRender };
27 |
--------------------------------------------------------------------------------
/packages/electron-prokit/src/ipc/preload.ts:
--------------------------------------------------------------------------------
1 | import type { IpcRendererEvent } from "electron";
2 | import { useIpcRenderer } from "../hooks";
3 | const ipcRenderer = useIpcRenderer();
4 |
5 |
6 | type Callback = (event: IpcRendererEvent, args: any) => void;
7 |
8 | const renderMsgToMain = (msg: T): Promise => {
9 | return ipcRenderer.invoke("EPrenderMsgToMain", msg);
10 | };
11 |
12 | const onMsgFromMain = (callback: Callback): void => {
13 | ipcRenderer.on("EPmainMsgToRender", (event: IpcRendererEvent, args: any) => {
14 | callback(event, args);
15 | });
16 | };
17 |
18 | const offMsgFromMain = (callback: Callback): void => {
19 | ipcRenderer.removeListener("EPmainMsgToRender", callback);
20 | };
21 |
22 | const renderMsgToRender = (windowName: string, msg: any): void => {
23 | ipcRenderer.send("EPrenderMsgToRender", {
24 | windowName,
25 | msg,
26 | });
27 | };
28 |
29 | const onRenderMsgToRender = (callback: Callback): void => {
30 | ipcRenderer.on(
31 | "EPrenderMsgToRender",
32 | (event: IpcRendererEvent, args: any) => {
33 | callback(event, args);
34 | }
35 | );
36 | };
37 |
38 | export {
39 | renderMsgToMain,
40 | onMsgFromMain,
41 | offMsgFromMain,
42 | renderMsgToRender,
43 | onRenderMsgToRender,
44 | };
45 |
--------------------------------------------------------------------------------
/packages/electron-prokit/src/ipc/render.ts:
--------------------------------------------------------------------------------
1 | import type { IpcRendererEvent} from "electron";
2 |
3 | type Callback = (event: IpcRendererEvent, args: any) => void
4 |
5 | export const renderMsgToMain = (msg: T): Promise => {
6 | return window.electronProkit.renderMsgToMain(msg)
7 | }
8 |
9 | export const onMsgFromMain = (callback:Callback):void => {
10 | return window.electronProkit.onMsgFromMain(callback)
11 | }
12 |
13 | export const offMsgFromMain = (callback:Callback):void => {
14 | return window.electronProkit.offMsgFromMain(callback)
15 | }
16 |
17 | export const renderMsgToRender = (windowName:string,msg:any):void => {
18 | window.electronProkit.renderMsgToRender(windowName,msg)
19 | }
20 |
21 | export const onRenderMsgToRender = (callback:Callback):void => {
22 | return window.electronProkit.onRenderMsgToRender(callback)
23 | }
--------------------------------------------------------------------------------
/packages/electron-prokit/src/locale/index.ts:
--------------------------------------------------------------------------------
1 | // locale todo
--------------------------------------------------------------------------------
/packages/electron-prokit/src/main.ts:
--------------------------------------------------------------------------------
1 | import { useIpcMain } from "./hooks";
2 | import { clearDb, initDb, readDb, writeDb } from "./db/main";
3 | import { getWindow } from "./window";
4 |
5 | const ipcMain = useIpcMain();
6 |
7 | function initIpcMainDb(): void {
8 | ipcMain.handle(
9 | "EPinitDb",
10 | (event: Electron.IpcMainEvent, args: IpcDBArgs) => {
11 | if (args.fun === "initDb") {
12 | return initDb(args.file);
13 | }
14 | if (args.fun === "writeDb") {
15 | return writeDb(args.key, args.data);
16 | }
17 | if (args.fun === "readDb") {
18 | return readDb(args.key);
19 | }
20 | if (args.fun === "clearDb") {
21 | return clearDb();
22 | }
23 | }
24 | );
25 | }
26 |
27 | function initOnRenderMsgToRender(): void {
28 | ipcMain.on(
29 | "EPrenderMsgToRender",
30 | (event: Electron.IpcMainEvent, args: any) => {
31 | const windowInstance = getWindow(args.windowName);
32 | if (windowInstance) {
33 | windowInstance.webContents.send("EPrenderMsgToRender", args.msg);
34 | } else {
35 | throw new Error("not find windowInstance");
36 | }
37 | }
38 | );
39 | }
40 |
41 | export function initIpc(): void {
42 | initOnRenderMsgToRender();
43 | initIpcMainDb();
44 | }
45 |
--------------------------------------------------------------------------------
/packages/electron-prokit/src/preload.ts:
--------------------------------------------------------------------------------
1 | import { useContextBridge } from "./hooks";
2 | import {
3 | offMsgFromMain,
4 | onMsgFromMain,
5 | onRenderMsgToRender,
6 | renderMsgToMain,
7 | renderMsgToRender,
8 | } from './ipc/preload'
9 | import {
10 | clearDb,
11 | initDb,
12 | readDb,
13 | writeDb
14 | } from './db/preload'
15 |
16 | const contextBridge = useContextBridge();
17 |
18 | export function initExposeInMainWorld(): void {
19 | contextBridge.exposeInMainWorld("electronProkit", {
20 | // communication
21 | renderMsgToMain,
22 | onMsgFromMain,
23 | offMsgFromMain,
24 | renderMsgToRender,
25 | onRenderMsgToRender,
26 |
27 | // db
28 | clearDb,
29 | initDb,
30 | readDb,
31 | writeDb,
32 |
33 |
34 | });
35 | }
--------------------------------------------------------------------------------
/packages/electron-prokit/src/schedule/index.ts:
--------------------------------------------------------------------------------
1 | interface RegisterScheduleOption {
2 | name: string;
3 | fun: Function;
4 | interval: number;
5 | [key: string]: any;
6 | }
7 |
8 | interface Schedule extends RegisterScheduleOption {
9 | isRunning?: boolean;
10 | instance?: any
11 | }
12 |
13 | const schedules = new Map()
14 |
15 | function registerSchedule(schedule: RegisterScheduleOption): Schedule {
16 | if (hasSchedule(schedule.name)) {
17 | const thisSchedule = getSchedule(schedule.name)
18 | if (thisSchedule?.isRunning) {
19 | console.warn("has same name schedule and isRunning");
20 | return thisSchedule
21 | } else {
22 | schedules.set(schedule.name, schedule)
23 | return schedule
24 | }
25 | } else {
26 | schedules.set(schedule.name, schedule)
27 | return schedule
28 | }
29 | }
30 |
31 | function hasSchedule(name: string): boolean {
32 | return schedules.has(name)
33 | }
34 |
35 | function getSchedule(name: string): Schedule | undefined {
36 | return schedules.get(name);
37 | }
38 |
39 | function isRunningSchedule(name: string): boolean {
40 | return schedules.get(name)?.isRunning ? true : false
41 | }
42 |
43 | function runSchedule(name: string, initRun = true): void {
44 | const schedule = getSchedule(name)
45 | if (!schedule) {
46 | console.warn('not register this schedule')
47 | return
48 | }
49 | const { isRunning, instance, fun, interval } = schedule
50 | if (isRunning && instance) {
51 | instance.clear()
52 | }
53 | if (initRun) {
54 | fun()
55 | }
56 | schedules.set(name, {
57 | ...schedule,
58 | instance: EpSetInterval(() => {
59 | fun()
60 | }, interval),
61 | isRunning: true
62 | })
63 | }
64 |
65 | function stopSchedule(name: string): void {
66 | if (!hasSchedule(name)) {
67 | return
68 | } else {
69 | const thisSchedule = getSchedule(name)
70 | if (thisSchedule?.instance) {
71 | thisSchedule.instance.clear()
72 | schedules.set(name, {
73 | ...thisSchedule,
74 | instance: null,
75 | isRunning: false
76 | })
77 | }
78 |
79 | }
80 | }
81 |
82 | function clearSchedule(name: string): void {
83 | if (!hasSchedule(name)) {
84 | return
85 | } else {
86 | const thisSchedule = getSchedule(name)
87 | if (thisSchedule?.instance) {
88 | thisSchedule.instance.clear()
89 | }
90 | schedules.delete(name)
91 | }
92 | }
93 |
94 | function EpSetInterval(callback: any, delay: number) {
95 | let timeoutId = setTimeout(function repeat() {
96 | callback();
97 | timeoutId = setTimeout(repeat, delay);
98 | }, delay);
99 |
100 | return {
101 | clear() {
102 | clearTimeout(timeoutId);
103 | }
104 | };
105 | }
106 |
107 | function clearAllSchedule(): void {
108 | const schedulesArray = Array.from(schedules.values());
109 | schedulesArray.forEach(schedule => {
110 | if (schedule.instance) {
111 | schedule.instance.clear();
112 | }
113 | })
114 | schedules.clear()
115 | }
116 |
117 | export {
118 | registerSchedule,
119 | runSchedule,
120 | stopSchedule,
121 | clearSchedule,
122 | hasSchedule,
123 | getSchedule,
124 | isRunningSchedule,
125 | schedules,
126 | clearAllSchedule
127 | }
--------------------------------------------------------------------------------
/packages/electron-prokit/src/update/index.ts:
--------------------------------------------------------------------------------
1 | import type {Logger} from "electron-updater"
2 | import { useUpdater } from "../hooks";
3 |
4 | let autoUpdater = null
5 | interface UpadateOptions {
6 | log?:boolean | Logger
7 | forceDevUpdateConfig?: boolean;
8 | autoDownload?: boolean;
9 | updateUrl: string;
10 | updateDownloadedCallBack: () => void;
11 | }
12 |
13 | const logger = {
14 | info(message?: any, ...optionalParams: any[]) {
15 | console.log(message);
16 | },
17 | warn(warn?: any, ...optionalParams: any[]) {
18 | console.warn(warn);
19 | },
20 | error(err?: any, ...optionalParams: any[]) {
21 | console.error(err);
22 | },
23 | };
24 |
25 | export const initUpadate = (options: UpadateOptions) => {
26 | if (autoUpdater) {
27 | autoUpdater.removeAllListeners();
28 | autoUpdater = null;
29 | }
30 | autoUpdater = useUpdater()
31 | autoUpdater.logger = options.log && typeof options.log === 'boolean' ? logger : options.log;
32 | autoUpdater.forceDevUpdateConfig = options.forceDevUpdateConfig;
33 | autoUpdater.autoDownload = options.autoDownload;
34 | autoUpdater.setFeedURL(options.updateUrl);
35 | autoUpdater.checkForUpdates();
36 | autoUpdater.checkForUpdatesAndNotify();
37 |
38 | autoUpdater.on("error", function (error: Error) {
39 | printUpdaterMessage("error");
40 | });
41 |
42 | autoUpdater.on("checking-for-update", function () {
43 | printUpdaterMessage("checking-for-update");
44 | });
45 |
46 | autoUpdater.on("update-available", function (info) {
47 | printUpdaterMessage("update-available");
48 | logger.info(info);
49 | });
50 |
51 | autoUpdater.on("update-not-available", function (info) {
52 | printUpdaterMessage("update-not-available");
53 | logger.info(info);
54 | });
55 |
56 | autoUpdater.on("download-progress", function (info) {
57 | printUpdaterMessage("download-progress");
58 | logger.info(info);
59 | });
60 |
61 | autoUpdater.on("update-downloaded", function (info) {
62 | printUpdaterMessage("update-downloaded");
63 | options.updateDownloadedCallBack();
64 | logger.info(info);
65 | });
66 |
67 | return autoUpdater
68 | };
69 |
70 | function printUpdaterMessage(key: string) {
71 | const message = {
72 | error: "Update error ",
73 | "checking-for-update": "Checking update",
74 | "update-available": "Update available",
75 | "download-progress": "Downloading",
76 | "update-not-available": "Update not available",
77 | "update-downloaded": "Update downloaded",
78 | };
79 | logger.info("printUpdaterMessage", message[key]);
80 | }
81 |
82 | export const intsallUpdateApp = () => {
83 | logger.info("update", "intsallUpdateApp");
84 | autoUpdater.quitAndInstall();
85 | };
86 |
--------------------------------------------------------------------------------
/packages/electron-prokit/src/window/index.ts:
--------------------------------------------------------------------------------
1 | import { useBrowserWindow } from "../hooks";
2 |
3 | const windows = new Map();
4 |
5 | function createWindow(
6 | name: string,
7 | options: Electron.BrowserWindowConstructorOptions
8 | ): Electron.CrossProcessExports.BrowserWindow {
9 | if (hasWindow(name)) {
10 | console.warn("has same name window");
11 | return getWindow(name);
12 | } else {
13 | const win = useBrowserWindow(options);
14 | windows.set(name, win);
15 | return win;
16 | }
17 | }
18 |
19 | function getWindow(name: string): Electron.CrossProcessExports.BrowserWindow {
20 | return windows.get(name);
21 | }
22 |
23 | function destroyWindow(name: string): void {
24 | const win = getWindow(name);
25 | if (win) {
26 | win.destroy();
27 | windows.delete(name);
28 | }
29 | }
30 |
31 | function getAllWindows(): Array {
32 | return Array.from(windows.values());
33 | }
34 |
35 | function hasWindow(name: string): boolean {
36 | return windows.has(name);
37 | }
38 |
39 | function clearWindows(): void {
40 | for (const key in windows) {
41 | destroyWindow(key)
42 | }
43 | windows.clear();
44 | }
45 |
46 | function showWindow(name: string = 'main'):void {
47 | const win = getWindow(name);
48 | if (win && win.show) {
49 | win.show();
50 | if (win && win.center) {
51 | win.center();
52 | }
53 | } else {
54 | console.error("showWindow", "no windowInstance");
55 | }
56 | }
57 |
58 | export {
59 | createWindow,
60 | getWindow,
61 | destroyWindow,
62 | getAllWindows,
63 | hasWindow,
64 | clearWindows,
65 | showWindow
66 | };
67 |
--------------------------------------------------------------------------------
/packages/electron-prokit/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ESNext",
4 | "useDefineForClassFields": true,
5 | "lib": ["ES2020", "DOM", "DOM.Iterable"],
6 | "allowJs": true,
7 | "module": "ESNext",
8 | "skipLibCheck": true,
9 | "moduleResolution": "Node",
10 | "downlevelIteration": true,
11 | "declaration": true,
12 | "esModuleInterop": true
13 | },
14 | "types": [
15 | "jest"
16 | ],
17 | "include": ["src","test","vendor.d.ts","typings.d.ts"],
18 | "exclude": ["node_modules", "dist/**/*"],
19 | }
20 |
--------------------------------------------------------------------------------
/packages/electron-prokit/typings.d.ts:
--------------------------------------------------------------------------------
1 | interface ImportMetaEnv {
2 | readonly VITE_CURRENT_RUN_MODE: 'render' | 'preload' | 'main' | 'work'
3 | }
4 |
5 | interface ImportMeta {
6 | readonly env: ImportMetaEnv
7 | }
8 |
9 | interface IpcDBArgs {
10 | fun: 'initDb' | 'writeDb' | 'readDb' | 'clearDb';
11 | file?: string;
12 | key?:string;
13 | data?:any
14 | }
--------------------------------------------------------------------------------
/packages/electron-prokit/vendor.d.ts:
--------------------------------------------------------------------------------
1 | export {};
2 | interface WindowElectronProkit {
3 | renderMsgToMain(msg: T): Promise;
4 | onMsgFromMain(callBack): void;
5 | offMsgFromMain(callBack): void;
6 | renderMsgToRender(windowName:string,msg:any):void;
7 | onRenderMsgToRender(callBack): void;
8 |
9 | initDb(file:string):Promise;
10 | writeDb(key: string, data: any):Promise;
11 | readDb(key: string):Promise;
12 | clearDb():void;
13 | }
14 | declare global {
15 | interface Window {
16 | electronProkit: WindowElectronProkit
17 | }
18 | }
--------------------------------------------------------------------------------
/play/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | dist
12 | dist-ssr
13 | *.local
14 |
15 | # Editor directories and files
16 | .vscode/*
17 | !.vscode/extensions.json
18 | .idea
19 | .DS_Store
20 | *.suo
21 | *.ntvs*
22 | *.njsproj
23 | *.sln
24 | *.sw?
25 |
--------------------------------------------------------------------------------
/play/.npmrc:
--------------------------------------------------------------------------------
1 | ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/
2 | ELECTRON_BUILDER_BINARIES_MIRROR=https://npmmirror.com/mirrors/electron-builder-binaries/
--------------------------------------------------------------------------------
/play/README.md:
--------------------------------------------------------------------------------
1 | # A playground with electron-prokit
2 |
3 | # Start
4 |
5 | `npm run dev`
6 |
7 | # Build
8 |
9 | `npm run build`
10 |
11 | # Compile
12 |
13 | `npm run compile`
14 |
--------------------------------------------------------------------------------
/play/config/main.ts:
--------------------------------------------------------------------------------
1 | import { cwd } from "process";
2 | import path from "path";
3 | import { builtinModules } from "module";
4 | import { fileURLToPath } from "url";
5 | import type { UserConfig } from "vite";
6 |
7 |
8 | const __dirname = fileURLToPath(new URL(".", import.meta.url));
9 |
10 | const sharedResolve = {
11 | alias: {
12 | "@": path.resolve(__dirname, "src"),
13 | },
14 | };
15 |
16 | const config:UserConfig = {
17 | root: path.resolve(__dirname, "../src/main"),
18 | envDir: cwd(),
19 | resolve: sharedResolve,
20 | build: {
21 | outDir: path.resolve(__dirname, "../dist/main"),
22 | minify: false,
23 | lib: {
24 | entry: path.resolve(__dirname, "../src/main/index.ts"),
25 | formats: ["cjs"],
26 | },
27 | rollupOptions: {
28 | external: [
29 | "electron",
30 | "lowdb",
31 | "koffi",
32 | "electron-updater",
33 | ...builtinModules,
34 | ],
35 | output: {
36 | entryFileNames: "[name].cjs",
37 | },
38 | },
39 | emptyOutDir: true,
40 | chunkSizeWarningLimit: 2048,
41 | },
42 | };
43 |
44 | export default config;
45 |
--------------------------------------------------------------------------------
/play/config/preload.ts:
--------------------------------------------------------------------------------
1 | import { cwd } from "process";
2 | import path from "path";
3 | import { builtinModules } from "module";
4 | import { fileURLToPath } from "url";
5 | import type { UserConfig } from "vite";
6 |
7 | const __dirname = fileURLToPath(new URL(".", import.meta.url));
8 |
9 |
10 | const sharedResolve = {
11 | alias: {
12 | "@": path.resolve(__dirname, "src"),
13 | },
14 | };
15 |
16 | const config:UserConfig = {
17 | root: path.resolve(__dirname, "../src/preload"),
18 | envDir: cwd(),
19 | resolve: sharedResolve,
20 | build: {
21 | watch: {},
22 | outDir: path.resolve(__dirname, "../dist/preload"),
23 | minify: false,
24 | lib: {
25 | entry: path.resolve(__dirname, "../src/preload/index.ts"),
26 | formats: ["cjs"],
27 | },
28 | rollupOptions: {
29 | external: ["electron", "lowdb", ...builtinModules],
30 | output: {
31 | entryFileNames: "[name].cjs",
32 | },
33 | onwarn(warning, warn) {
34 | if (
35 | warning.code === "MODULE_LEVEL_DIRECTIVE" &&
36 | warning.message.includes(`"use client"`)
37 | ) {
38 | return;
39 | }
40 | warn(warning);
41 | },
42 | },
43 | emptyOutDir: true,
44 | chunkSizeWarningLimit: 2048,
45 | },
46 | };
47 |
48 | export default config;
49 |
--------------------------------------------------------------------------------
/play/config/render.ts:
--------------------------------------------------------------------------------
1 | import path from "path";
2 | import { builtinModules } from "module";
3 | import { fileURLToPath } from "url";
4 | import react from "@vitejs/plugin-react-swc";
5 | import { defineConfig } from "vite";
6 |
7 | const __dirname = fileURLToPath(new URL(".", import.meta.url));
8 |
9 | const sharedResolve = {
10 | alias: {
11 | "@": path.resolve(__dirname, "src"),
12 | },
13 | };
14 |
15 | export default defineConfig({
16 | root: path.resolve(__dirname, "../"),
17 | base: "./",
18 | resolve: sharedResolve,
19 | build: {
20 | watch: {},
21 | outDir: path.resolve(__dirname, "../dist/render"),
22 | minify: true,
23 | assetsInlineLimit: 1048576,
24 | emptyOutDir: true,
25 | chunkSizeWarningLimit: 2048,
26 | rollupOptions: {
27 | onwarn(warning, warn) {
28 | if (
29 | warning.code === "MODULE_LEVEL_DIRECTIVE" &&
30 | warning.message.includes(`"use client"`)
31 | ) {
32 | return;
33 | }
34 | warn(warning);
35 | },
36 | external: [...builtinModules, "electron", "lowdb"],
37 | },
38 | commonjsOptions: {
39 | include: [/node_modules/],
40 | },
41 | },
42 | plugins: [react()],
43 | optimizeDeps: {
44 | include: ["@ant-design/icons-svg", "antd"],
45 | },
46 | });
47 |
--------------------------------------------------------------------------------
/play/config/work.ts:
--------------------------------------------------------------------------------
1 | import { defineConfig } from "vite";
2 | import path from "path";
3 | import react from "@vitejs/plugin-react-swc";
4 | import { builtinModules } from "module";
5 | import { fileURLToPath } from "url";
6 |
7 | const __dirname = fileURLToPath(new URL(".", import.meta.url));
8 |
9 |
10 | const sharedResolve = {
11 | alias: {
12 | "@": path.resolve(__dirname, "src"),
13 | },
14 | };
15 |
16 | export default defineConfig( {
17 | root: path.resolve(__dirname, "../src/work"),
18 | base: "./",
19 | resolve: sharedResolve,
20 | build: {
21 | watch: {},
22 | outDir: path.resolve(__dirname, "../dist/work"),
23 | minify: true,
24 | assetsInlineLimit: 1048576,
25 | emptyOutDir: true,
26 | chunkSizeWarningLimit: 2048,
27 | rollupOptions: {
28 | external: [...builtinModules, "electron", "lowdb"],
29 | onwarn(warning, warn) {
30 | if (
31 | warning.code === "MODULE_LEVEL_DIRECTIVE" &&
32 | warning.message.includes(`"use client"`)
33 | ) {
34 | return;
35 | }
36 | warn(warning);
37 | },
38 | },
39 | },
40 | plugins: [react()],
41 | })
--------------------------------------------------------------------------------
/play/dev-app-update.yml:
--------------------------------------------------------------------------------
1 | provider: generic
2 | url: 'http://172.17.194.13:8090'
--------------------------------------------------------------------------------
/play/electron-builder.config.json:
--------------------------------------------------------------------------------
1 | {
2 | "productName": "ElectronProkit",
3 | "appId": "electron.prokit.com",
4 | "copyright": "Copyright © 2023",
5 | "asar": false,
6 | "files": ["dist/**", "package.json"],
7 | "directories": {
8 | "output": "release",
9 | "buildResources": "resources"
10 | },
11 | "extraResources": {
12 | "from": "resources",
13 | "to": "resources"
14 | },
15 | "mac": {
16 | "hardenedRuntime": true,
17 | "gatekeeperAssess": false,
18 | "target": ["dmg", "zip"],
19 | "entitlements": "./scripts/entitlements.mac.plist",
20 | "entitlementsInherit": "./scripts/entitlements.mac.plist",
21 | "identity": "",
22 | "icon": "./resources/icon/icon.icns",
23 | "extendInfo": {
24 | "LSUIElement": true,
25 | "SUFeedURL": "",
26 | "SUPublicEDKey": ""
27 | }
28 | },
29 | "dmg": {
30 | "backgroundColor": "#ffffff",
31 | "window": { "width": 540, "height": 380 },
32 | "icon": "./resources/icon/icon.icns",
33 | "iconSize": 128,
34 | "contents": [
35 | { "x": 410, "y": 190, "type": "link", "path": "/Applications" },
36 | { "x": 130, "y": 190, "type": "file" }
37 | ],
38 | "title": "ElectronProkit"
39 | },
40 | "win": {
41 | "icon": "./resources/icon/icon.ico",
42 | "target": "nsis",
43 | "verifyUpdateCodeSignature": false
44 | },
45 | "nsis": {
46 | "oneClick": true,
47 | "language": "2052",
48 | "perMachine": true,
49 | "createDesktopShortcut": true,
50 | "createStartMenuShortcut": true,
51 | "guid": "ElectronProkit",
52 | "shortcutName": "ElectronProkit",
53 | "artifactName": "ElectronProkit@${version}.${ext}"
54 | },
55 | "publish": {
56 | "provider": "generic",
57 | "url": "http://172.17.194.13:8090"
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/play/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Electron Prokit
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/play/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "play",
3 | "private": true,
4 | "author": "xutaotaotao",
5 | "description": "A playground with electron-prokit",
6 | "version": "1.0.0",
7 | "type": "module",
8 | "main": "dist/main/index.cjs",
9 | "scripts": {
10 | "dev": "node --experimental-specifier-resolution=node --loader ts-node/esm ./scripts/dev.ts",
11 | "build": "node --experimental-specifier-resolution=node --loader ts-node/esm ./scripts/build.ts",
12 | "compile": "electron-builder build --config ./electron-builder.config.json",
13 | "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0"
14 | },
15 | "dependencies": {
16 | "electron-updater": "^6.1.4",
17 | "koffi": "2.3.20",
18 | "react": "^18.2.0",
19 | "react-dom": "^18.2.0",
20 | "lowdb": "3.0.0"
21 | },
22 | "devDependencies": {
23 | "@ant-design/icons": "^5.2.6",
24 | "@electron-prokit/create-service": "workspace:^4.0.0",
25 | "@types/node": "^20.5.7",
26 | "@types/react": "^18.2.15",
27 | "@types/react-dom": "^18.2.7",
28 | "@typescript-eslint/eslint-plugin": "^6.0.0",
29 | "@typescript-eslint/parser": "^6.0.0",
30 | "@vitejs/plugin-react-swc": "^3.3.2",
31 | "antd": "^5.9.0",
32 | "electron": "^26.1.0",
33 | "electron-builder": "^24.6.4",
34 | "electron-prokit": "workspace:^16.0.0",
35 | "esbuild": "^0.19.2",
36 | "esbuild-plugin-polyfill-node": "^0.3.0",
37 | "eslint": "^8.45.0",
38 | "eslint-plugin-react-hooks": "^4.6.0",
39 | "eslint-plugin-react-refresh": "^0.4.3",
40 | "i18next": "^23.6.0",
41 | "minimist": "^1.2.8",
42 | "react-i18next": "^13.3.1",
43 | "react-router-dom": "^6.15.0",
44 | "ts-node": "^10.9.1",
45 | "typescript": "^5.0.2",
46 | "vite": "^4.4.5",
47 | "vite-plugin-node": "^3.0.2"
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/play/public/vite.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/play/resources/dll/mul_and_div.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/play/resources/dll/mul_and_div.dll
--------------------------------------------------------------------------------
/play/resources/dll/mul_and_div.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/play/resources/dll/mul_and_div.dylib
--------------------------------------------------------------------------------
/play/resources/dll/sum.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/play/resources/dll/sum.dll
--------------------------------------------------------------------------------
/play/resources/dll/sum.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/play/resources/dll/sum.dylib
--------------------------------------------------------------------------------
/play/resources/icon/icon.icns:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/play/resources/icon/icon.icns
--------------------------------------------------------------------------------
/play/resources/icon/icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/play/resources/icon/icon.ico
--------------------------------------------------------------------------------
/play/resources/icon/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/play/resources/icon/icon.png
--------------------------------------------------------------------------------
/play/resources/icon/icon@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Xutaotaotao/electron-prokit/fe0eeda90b4fb6607f16266f948dfb258b7d5c44/play/resources/icon/icon@2x.png
--------------------------------------------------------------------------------
/play/resources/mul_and_div.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #if defined(WIN32) || defined(_WIN32)
4 | #define EXPORT __declspec(dllexport)
5 | #else
6 | #define EXPORT
7 | #endif
8 |
9 | EXPORT uint64_t mul(int a,int b) {
10 | return a * b;
11 | }
12 |
13 | EXPORT double divide(int a, int b) {
14 | if (b == 0) {
15 | // 避免除以零的情况
16 | return 0.0;
17 | }
18 | return a / b;
19 | }
20 |
--------------------------------------------------------------------------------
/play/resources/sum.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | #if defined(WIN32) || defined(_WIN32)
4 | #define EXPORT __declspec(dllexport)
5 | #else
6 | #define EXPORT
7 | #endif
8 |
9 | EXPORT uint64_t sum(int a,int b) {
10 | return a + b;
11 | }
12 |
--------------------------------------------------------------------------------
/play/scripts/build.ts:
--------------------------------------------------------------------------------
1 | #!/usr/bin/node
2 | import { fileURLToPath } from 'url';
3 | import { dirname, resolve } from 'path';
4 | import { build } from 'vite';
5 | import pkgJson from '../package.json' assert { type: 'json' };
6 |
7 | const __filename = fileURLToPath(import.meta.url);
8 | const __dirname = dirname(__filename);
9 |
10 | const processArgv = process.argv.splice(2);
11 | const mode = processArgv && processArgv.length > 0 ? processArgv[0] : 'production';
12 |
13 | const packagesConfigs = [
14 | resolve(__dirname, '../config/render'),
15 | resolve(__dirname, '../config/work'),
16 | resolve(__dirname, '../config/main'),
17 | resolve(__dirname, '../config/preload'),
18 | ];
19 |
20 | // Set environment variables
21 | process.env.VITE_CURRENT_RUN_MODE = 'render';
22 | process.env.VITE_CURRENT_VERSION = pkgJson.version;
23 | process.env.MODE = mode;
24 | process.env.VITE_CURRENT_OS = process.platform;
25 |
26 | const buildByConfig = async (configFile:string) => {
27 | try {
28 | await build({ configFile, mode });
29 | } catch (error) {
30 | console.error(`Error building ${configFile}:`, error);
31 | throw error;
32 | }
33 | };
34 |
35 | const main = async () => {
36 | try {
37 | console.time('Total bundling time');
38 | for (const config of packagesConfigs) {
39 | const modeMap:any = {
40 | main: 'main',
41 | render: 'render',
42 | preload: 'preload',
43 | work: 'work',
44 | };
45 |
46 | for (const key in modeMap) {
47 | if (config.includes(key)) {
48 | process.env.VITE_CURRENT_RUN_MODE = modeMap[key];
49 | break;
50 | }
51 | }
52 |
53 | console.time(`Bundling ${config}`);
54 | await buildByConfig(config);
55 | console.timeEnd(`Bundling ${config}`);
56 | }
57 | console.timeEnd('Total bundling time');
58 | } catch (error) {
59 | console.error('Build failed:', error);
60 | process.exit(1);
61 | }
62 | };
63 |
64 | main();
65 |
66 | process.on('unhandledRejection', (reason, promise) => {
67 | console.error('Unhandled Rejection at:', promise, 'reason:', reason);
68 | process.exit(1);
69 | });
70 |
71 | process.on('uncaughtException', (err) => {
72 | console.error('Uncaught Exception thrown:', err);
73 | process.exit(1);
74 | });
75 |
--------------------------------------------------------------------------------
/play/scripts/dev.ts:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | import createViteElectronService from "@electron-prokit/create-service";
3 | import electronPath from "electron";
4 | import main from "../config/main";
5 | import render from "../config/render";
6 | import work from "../config/work";
7 | import preload from "../config/preload";
8 |
9 | createViteElectronService({
10 | render,
11 | preload,
12 | work,
13 | main,
14 | electronPath
15 | });
16 |
--------------------------------------------------------------------------------
/play/scripts/entitlements.mac.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.cs.allow-unsigned-executable-memory
6 |
7 |
8 |
--------------------------------------------------------------------------------
/play/src/main/ffi.ts:
--------------------------------------------------------------------------------
1 | import path from "path";
2 | import { createEpffi } from "electron-prokit";
3 | import { getResourcesPath } from "../util";
4 |
5 | export const {sum} = createEpffi({
6 | path: path.join(__dirname,process.platform === 'win32' ? getResourcesPath('resources/dll/sum.dll') : getResourcesPath('resources/dll/sum.dylib')),
7 | function:{
8 | functionName:'sum',
9 | returnType:'int',
10 | inputs:['int','int']
11 | }
12 | })
13 |
14 | export const { mul,divide } = createEpffi({
15 | path: path.join(__dirname,process.platform === 'win32' ? getResourcesPath("resources/dll/mul_and_div.dll") : getResourcesPath("resources/dll/mul_and_div.dylib")),
16 | function: [
17 | {
18 | functionName: "mul",
19 | returnType: "int",
20 | inputs: ["int", "int"],
21 | },
22 | {
23 | functionName: "divide",
24 | returnType: "int",
25 | inputs: ["int", "int"],
26 | },
27 | ],
28 | });
29 |
--------------------------------------------------------------------------------
/play/src/main/gui.ts:
--------------------------------------------------------------------------------
1 | import { join } from "path";
2 | import { Menu, Tray, nativeImage } from "electron";
3 | import { sendMsgToRender, showWindow } from "electron-prokit";
4 | import { getResourcesPath } from "../util";
5 |
6 | let menu: Electron.Menu;
7 | let tray: Electron.Tray;
8 |
9 | const initMenu = () => {
10 | menu = Menu.buildFromTemplate([
11 | {
12 | label: "Electron Prokit",
13 | click: () => {
14 | showWindow();
15 | },
16 | },
17 | {
18 | type: "separator",
19 | },
20 | {
21 | label: "sendMsgToRender",
22 | click: () => sendMsgToRender("main", "msg from main"),
23 | },
24 | ]);
25 |
26 | Menu.setApplicationMenu(menu);
27 | };
28 |
29 | const initTray = () => {
30 | try {
31 | const iconPath = nativeImage.createFromPath(
32 | join(__dirname, getResourcesPath("resources/icon/icon.png"))
33 | );
34 | tray = new Tray(iconPath);
35 | tray.setContextMenu(menu);
36 | tray.on("click", () => {
37 | showWindow();
38 | });
39 | } catch (err) {
40 | console.error(err);
41 | }
42 | };
43 |
44 | const main = () => {
45 | initMenu();
46 | initTray();
47 | };
48 |
49 | export default main;
50 |
--------------------------------------------------------------------------------
/play/src/main/http.ts:
--------------------------------------------------------------------------------
1 | import {
2 | http
3 | } from "electron-prokit";
4 |
5 | export const testGetHttp = () => {
6 | return http({
7 | url:'https://jsonplaceholder.typicode.com/posts/1',
8 | method:'get',
9 | log:true
10 | })
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/play/src/main/index.ts:
--------------------------------------------------------------------------------
1 | import { app } from "electron";
2 | import initWindow from './window'
3 | import initIpc from './ipc'
4 | // import initGui from './gui'
5 |
6 | app.whenReady().then(() => {
7 | initWindow()
8 | initIpc()
9 | // initGui()
10 | });
11 |
--------------------------------------------------------------------------------
/play/src/main/ipc.ts:
--------------------------------------------------------------------------------
1 | import {app,nativeTheme} from 'electron'
2 | import { initIpc,initUpadate,intsallUpdateApp,onMsgFromRender, sendMsgToRender } from "electron-prokit";
3 | import { divide, mul,sum } from "./ffi";
4 | import { testGetHttp } from "./http";
5 |
6 | const option = {
7 | forceDevUpdateConfig:true,
8 | autoDownload:true,
9 | updateUrl: 'http://172.17.194.13:8090', // can use live-server to mock the file server/https://www.npmjs.com/package/live-server
10 | updateDownloadedCallBack: () => {
11 | return sendMsgToRender('main','updateDownloaded')
12 | }
13 | }
14 |
15 | const main = ():void => {
16 | initIpc();
17 | onMsgFromRender(async (_e: Electron.IpcMainEvent, args: Msg) => {
18 | if (args.key === 'testGetHttp') {
19 | const data = await testGetHttp()
20 | return data
21 | }
22 | if (args.key === 'nativeSum') {
23 | return sum(100, 22);
24 | }
25 | if (args.key === 'nativeMul') {
26 | return mul(100, 22);
27 | }
28 | if (args.key === 'nativeDiv') {
29 | return divide(100, 5);
30 | }
31 | if (args.key === 'changeTheme') {
32 | nativeTheme.themeSource = args.data
33 | }
34 | if (args.key === 'update') {
35 | console.log('update')
36 | initUpadate(option)
37 | }
38 | if (args.key === 'intsallUpdateApp') {
39 | intsallUpdateApp()
40 | }
41 | if (args.key === 'getAppVersion') {
42 | return app.getVersion()
43 | }
44 | return `Main have get data is ${args}`;
45 | });
46 | };
47 |
48 | export default main;
49 |
--------------------------------------------------------------------------------
/play/src/main/window.ts:
--------------------------------------------------------------------------------
1 | import { join, resolve } from "path";
2 | import {
3 | createWindow,
4 | } from "electron-prokit";
5 |
6 | const initMainWin = () => {
7 | const mainWindow = createWindow("main", {
8 | width: 960,
9 | height: 720,
10 | webPreferences: {
11 | preload: join(__dirname, "../preload/index.cjs"),
12 | },
13 | });
14 |
15 | if (mainWindow) {
16 | if (import.meta.env.MODE === "dev") {
17 | if (import.meta.env.VITE_DEV_SERVER_URL) {
18 | mainWindow.loadURL(import.meta.env.VITE_DEV_SERVER_URL);
19 | mainWindow.webContents.openDevTools();
20 | }
21 | } else {
22 | mainWindow.loadFile(resolve(__dirname, "../render/index.html"));
23 | }
24 | }
25 | }
26 |
27 | const initWorkWin = () => {
28 | const workWindow = createWindow("work", {
29 | show: false,
30 | webPreferences: {
31 | preload: join(__dirname, "../preload/index.cjs"),
32 | },
33 | });
34 | workWindow.hide();
35 | if (import.meta.env.MODE === "dev") {
36 | workWindow.webContents.openDevTools();
37 | }
38 | workWindow.loadFile(resolve(__dirname, "../work/index.html"));
39 | }
40 |
41 | const main = () => {
42 | initMainWin()
43 | setTimeout(() => {
44 | initWorkWin()
45 | },3000)
46 |
47 | };
48 |
49 | export default main
--------------------------------------------------------------------------------
/play/src/preload/index.ts:
--------------------------------------------------------------------------------
1 | import {initExposeInMainWorld} from 'electron-prokit'
2 |
3 | initExposeInMainWorld()
--------------------------------------------------------------------------------
/play/src/render/App.css:
--------------------------------------------------------------------------------
1 | #root {
2 | margin: 0;
3 | padding: 0;
4 | display: flex;
5 | width: 100%;
6 | height: 100%;
7 | }
8 |
--------------------------------------------------------------------------------
/play/src/render/App.tsx:
--------------------------------------------------------------------------------
1 | import { useEffect, useState } from "react";
2 | import { ConfigProvider, theme } from "antd";
3 | import { readDb, sendMsgToMain, writeDb } from "electron-prokit";
4 | import GlobalContext from "./context/global.ts";
5 | import "./App.css";
6 | import AppRouter from "./router";
7 |
8 | function App() {
9 |
10 | const [themeData,setThemeData] = useState('defaultAlgorithm')
11 |
12 | const changeTheme = (val: 'darkAlgorithm' | 'defaultAlgorithm') => {
13 | setThemeData(val)
14 | writeDb('theme',val)
15 | sendMsgToMain({key:'changeTheme',data:val === 'darkAlgorithm' ? 'dark' : 'light'})
16 | }
17 |
18 | useEffect(() => {
19 | readDb('theme').then(res => {
20 | if (res) {
21 | setThemeData(res)
22 | sendMsgToMain({key:'changeTheme',data:res === 'darkAlgorithm' ? 'dark' : 'light'})
23 | } else {
24 | setThemeData('defaultAlgorithm')
25 | sendMsgToMain({key:'changeTheme',data:'light'})
26 | }
27 | }).catch(() => {
28 | setThemeData('defaultAlgorithm')
29 | sendMsgToMain({key:'changeTheme',data:'light'})
30 | })
31 | },[])
32 |
33 | return
34 |
38 |
39 |
40 | ;
41 | }
42 |
43 | export default App;
44 |
--------------------------------------------------------------------------------
/play/src/render/assets/react.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/play/src/render/context/global.ts:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | const GlobalContext = React.createContext(({} as any as {
4 | changeTheme: any,
5 | themeData:string
6 | }));
7 |
8 | export default GlobalContext;
--------------------------------------------------------------------------------
/play/src/render/index.css:
--------------------------------------------------------------------------------
1 | html, body {
2 | padding: 0;
3 | margin: 0;
4 | background: #fff;
5 | height: 100%;
6 | width: 100%;
7 | }
--------------------------------------------------------------------------------
/play/src/render/layout/menu.ts:
--------------------------------------------------------------------------------
1 |
2 | import type { ComponentClass, FunctionComponent } from 'react';
3 | import { CloudSyncOutlined,ClusterOutlined,DatabaseOutlined,FilterOutlined,HomeOutlined,UsbOutlined,WifiOutlined } from '@ant-design/icons';
4 |
5 |
6 | export interface Menu {
7 | path:string;
8 | icon: string | FunctionComponent | ComponentClass;
9 | name:string;
10 | }
11 |
12 | export const menus:Array