2 |
3 | > This process is done via [v8 bytecode compilation](https://nodejs.org/api/vm.html#vm_script_createcacheddata), to get more knowledge about it, please, [check the Electron Vite docs](https://evite.netlify.app/guide/source-code-protection.html).
4 |
5 | Use the `bytecodePlugin` from `electron-vite` to enable it in the **electron.vite.config.ts**:
6 |
7 | ```ts
8 | import { defineConfig, bytecodePlugin } from 'electron-vite'
9 |
10 | export default defineConfig({
11 | main: {
12 | plugins: [tsconfigPaths, bytecodePlugin()]
13 | },
14 |
15 | preload: {
16 | // Note: you will get the following warning using bytecodePlugin in the preload script in production build: "The vm module of Node.js is deprecated in the renderer process and will be removed", is up to you to keep bytecodePlugin here. Also, keep following the Electron Vite docs for more updates about this plugin!
17 | plugins: [tsconfigPaths, bytecodePlugin()]
18 | },
19 |
20 | renderer: {
21 | // ...
22 | }
23 | })
24 | ```
25 | Also, `sandbox` should be `false` in `webPreferences` for the windows you are using a preload script like:
26 | ```ts
27 | const window = createWindow({
28 | id: 'main',
29 |
30 | webPreferences: {
31 | preload: join(__dirname, '../preload/index.js'),
32 | sandbox: false,
33 | },
34 | })
35 | ```
--------------------------------------------------------------------------------
/docs/FAQ.md:
--------------------------------------------------------------------------------
1 |
FAQ - Frequently Asked Questions
2 |
3 | ## How can I fix the `electron-builder install-app-deps Windows Script Host` error?
4 | If you are trying to use this boilerplate with npm instead pnpm on Windows, you will get that error related to `electron-builder install-app-deps`, so:
5 | - Take a look at [this comment](https://github.com/ficonsulting/RInno/issues/44#issuecomment-992299431) to fix it!
6 |
7 | ## What should I do if the release action fails and the re-run failed jobs keep failing?
8 | Go to the releases page in your repository and delete the draft release, then execute the action again but in the `re-run all jobs` mode.
9 |
10 | ## What are Autofill errors in the terminal?
11 | If you see the following errors in the terminal, you can ignore them:
12 | ```bash
13 | [97794:0301/202707.879855:ERROR:CONSOLE(1)] "Request Autofill.enable failed. {"code":-32601,"message":"'Autofill.enable' wasn't found"}", source: devtools://devtools/bundled/core/protocol_client/protocol_client.js (1)
14 | [97794:0301/202707.879884:ERROR:CONSOLE(1)] "Request Autofill.setAddresses failed. {"code":-32601,"message":"'Autofill.setAddresses' wasn't found"}", source: devtools://devtools/bundled/core/protocol_client/protocol_client.js (1)
15 | ```
16 | It only happens when devtools panel is open and it's not an issue with your app.
17 |
18 | For more information, take a look at [this issue](https://github.com/electron/electron/issues/41614).
19 |
20 |
--------------------------------------------------------------------------------
/template/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | on:
2 | push:
3 | tags: ["*"]
4 |
5 | jobs:
6 | release:
7 | if: startsWith(github.ref, 'refs/tags/v')
8 | runs-on: ${{ matrix.os }}
9 |
10 | strategy:
11 | matrix:
12 | os: [macos-latest, ubuntu-latest, windows-latest]
13 |
14 | steps:
15 | - name: Checkout
16 | uses: actions/checkout@v4
17 | - run: npm i -g --force corepack && corepack enable
18 |
19 | - name: Install Node.js, NPM and PNPM
20 | uses: actions/setup-node@v4
21 | with:
22 | node-version: 20
23 | cache: "pnpm"
24 | - run: pnpm install
25 |
26 | - name: apt-update
27 | if: startsWith(matrix.os, 'ubuntu-latest')
28 | run: sudo apt-get update
29 |
30 | - name: autoremove
31 | if: startsWith(matrix.os, 'ubuntu-latest')
32 | run: sudo apt autoremove
33 |
34 | - name: Install libarchive rpm on Linux
35 | if: startsWith(matrix.os, 'ubuntu-latest')
36 | run: sudo apt-get install libarchive-tools rpm
37 |
38 | - name: Release Electron app
39 | uses: daltonmenezes/action-electron-builder@v1.0.1
40 | with:
41 | package_manager: "pnpm"
42 | # GitHub token, automatically provided to the action
43 | # (No need to define this secret in the repo settings)
44 | github_token: ${{ secrets.github_token }}
45 |
46 | # If the commit is tagged with a version (e.g. "v1.0.0"),
47 | # release the app after building
48 | release: true
49 |
--------------------------------------------------------------------------------
/template/src/lib/electron-app/factories/app/setup.ts:
--------------------------------------------------------------------------------
1 | import { app, BrowserWindow } from 'electron'
2 |
3 | import {
4 | installExtension,
5 | REACT_DEVELOPER_TOOLS,
6 | } from 'electron-extension-installer'
7 |
8 | import { ignoreConsoleWarnings } from '../../utils/ignore-console-warnings'
9 | import { PLATFORM, ENVIRONMENT } from 'shared/constants'
10 | import { makeAppId } from 'shared/utils'
11 |
12 | ignoreConsoleWarnings(['Manifest version 2 is deprecated'])
13 |
14 | export async function makeAppSetup(createWindow: () => Promise) {
15 | if (ENVIRONMENT.IS_DEV) {
16 | await installExtension([REACT_DEVELOPER_TOOLS], {
17 | loadExtensionOptions: {
18 | allowFileAccess: true,
19 | },
20 | })
21 | }
22 |
23 | let window = await createWindow()
24 |
25 | app.on('activate', async () => {
26 | const windows = BrowserWindow.getAllWindows()
27 |
28 | if (!windows.length) {
29 | window = await createWindow()
30 | } else {
31 | for (window of windows.reverse()) {
32 | window.restore()
33 | }
34 | }
35 | })
36 |
37 | app.on('web-contents-created', (_, contents) =>
38 | contents.on(
39 | 'will-navigate',
40 | (event, _) => !ENVIRONMENT.IS_DEV && event.preventDefault()
41 | )
42 | )
43 |
44 | app.on('window-all-closed', () => !PLATFORM.IS_MAC && app.quit())
45 |
46 | return window
47 | }
48 |
49 | PLATFORM.IS_LINUX && app.disableHardwareAcceleration()
50 |
51 | PLATFORM.IS_WINDOWS &&
52 | app.setAppUserModelId(ENVIRONMENT.IS_DEV ? process.execPath : makeAppId())
53 |
54 | app.commandLine.appendSwitch('force-color-profile', 'srgb')
55 |
--------------------------------------------------------------------------------
/docs/images/bullet.svg:
--------------------------------------------------------------------------------
1 |
21 |
--------------------------------------------------------------------------------
/docs/UNSIGNED_APPS.md:
--------------------------------------------------------------------------------
1 |
28 |
29 | # Features
30 | - **Stands out**
31 | - 🔥 Fast and Ready-to-go with a well-thought-out structure
32 | - 🚀 Auto reload for main and **Fast Refresh** for renderer process
33 | - 🎉 Window/Screen routing included
34 | - 😎 Preload (context bridge) already configured
35 | - 🔮 GitHub Action releases with `Windows`, `Mac` and `Linux` binaries
36 | - 🔒 Source Code Protection support
37 | - 🍪 Absolute paths support
38 | - **Technologies**:
39 | - 🔋 Electron
40 | - 🔥 ReactJS v19
41 | - 🌎 React Router DOM v7 and Electron Router DOM v2
42 | - 🧐 React Developer Tools
43 | - 🔍 Code inspector (holding `Alt` or `Option` key on DOM element and clicking on it)
44 | - 💙 TypeScript v5
45 | - 📦 Electron Vite
46 | - ✨ TailwindCSS v4
47 | - 🎨 shadcn/ui
48 | - 🍦 lucide-icons
49 | - 💫 Biome / EditorConfig
50 | - 📦 Electron Builder
51 | - 🔮 action-electron-builder
52 |
53 |
54 |
55 | > :warning: If **Windows 7** and **8** support is important for your project, you should know that Electron in a version greater than 22x no longer supports it. You can read more about it [here](https://www.electronjs.org/docs/latest/breaking-changes#removed-windows-7--8--81-support). Therefore, you must downgrade Electron to 22x version if it's important for you!
56 |
57 | # Requirements
58 | - [Node.js 20](https://nodejs.org/en/download/)
59 | - [pnpm 10](https://pnpm.io/installation)
60 |
61 | # Installation
62 | ```bash
63 | npx degit daltonmenezes/electron-app/template project_name
64 | ```
65 | ```bash
66 | cd project_name
67 | pnpm install
68 | pnpm dev
69 | ```
70 |
71 | Now, look at the **package.json** file in the root directory, you should update some of that settings with your project branding.
72 |
73 | # Adding new dependencies
74 | For security reasons, **pnpm** has the [onlyBuiltDependenciesFile](https://pnpm.io/package_json#pnpmonlybuiltdependenciesfile) property where only
75 | dependencies listed in the [trusted-dependencies-scripts.json](./template/trusted-dependencies-scripts.json) file can perform the postscripts execution. So, if you want to add a new dependency that needs to run a postscript, you should add it to the [trusted-dependencies-scripts.json](./template/trusted-dependencies-scripts.json) file list.
76 |
77 | # Distribution
78 |
79 | ### For all platforms
80 |
81 | > **Note**: Check [Electron Builder docs](https://www.electron.build/cli) for more knowledge
82 |
83 | ```
84 | pnpm build
85 | ```
86 |
87 | ### For a specific one
88 |
89 | ```bash
90 | pnpm build --mac
91 | # OR
92 | pnpm build --win
93 | # OR
94 | pnpm build --linux
95 | ```
96 |
97 | The builded apps will be available in the `dist` folder.
98 |
99 | # Documents
100 |