Skip to content

guasam/electron-react-app

Repository files navigation

Electron React App


A modern Electron application template with React, Vite, TypeScript, and TailwindCSS. This project provides a solid foundation for developing cross-platform desktop applications.


Watch Video Preview


Features

  • πŸš€ Electron - Cross-platform desktop application framework
  • βš›οΈ React - Component-based UI library
  • πŸ“¦ TypeScript - Type-safe JavaScript
  • 🎨 TailwindCSS - Utility-first CSS framework
  • ⚑ Vite - Lightning-fast build tool
  • πŸ”₯ Fast HMR - Hot Module Replacement
  • 🎨 Dark/Light Mode - Built-in theme switching
  • πŸͺŸ Custom Window & Titlebar - Professional-looking window with custom titlebar & file menus.
  • πŸ“ Clean Project Structure - Separation of main and renderer processes
  • 🧩 Path Aliases – Keep your code organized.
  • πŸ› οΈ Electron Builder - Configured for packaging applications

Prerequisites

  • Node.js (v18 or higher)
  • npm, yarn, pnpm, or bun

Installation

Clone the repository and install dependencies:

# Clone the repository
git clone https://github.com/guasam/electron-react-app
cd electron-react-app

# Install dependencies
npm install
# or
yarn
# or
pnpm install
# or
bun install

Development

Start the development server:

npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun run dev

This will start Electron with hot-reload enabled so you can see changes in real time.


Building for Production

Build the application for your platform:

# For Windows
npm run build:win

# For macOS
npm run build:mac

# For Linux
npm run build:linux

# Unpacked for all platforms
npm run build:unpack

Distribution files will be located in the dist directory.


IPC Communication

The app uses a secure IPC (Inter-Process Communication) system to communicate between the renderer and main processes:

// Renderer process (send message to main)
window.api.send('channel-name', ...args)

// Renderer process (receive message from main)
window.api.receive('channel-name', (data) => {
  console.log(data)
})

// Renderer process (invoke a method in main and get a response)
const result = await window.api.invoke('channel-name', ...args)

Custom Window Components

This template includes a custom window implementation with:

  • Custom titlebar with app icon
  • Window control buttons (minimize, maximize, close)
  • Menu system with keyboard shortcuts
  • Dark/light mode toggle
  • Cross-platform support for Windows and macOS

Titlebar Menu Toggle

The titlebar menu can be toggled using:

  • Windows: Press the Alt key
  • macOS: Press the Option (βŒ₯) key

When you press the toggle key:

  • If the menu is hidden, it becomes visible
  • If the menu is already visible, it gets hidden
  • The menu only toggles if menu items are available

Customizing Menu Items

To add, remove or modify menu items, update the lib/window/titlebarMenus.ts file.


Tailwind Styling

The project supports TailwindCSS for styling:

// Example component with Tailwind classes
const Button = () => (
  <button className="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">
    Click me
  </button>
);

Contributing

Contributions are welcome! Feel free to submit a Pull Request.


Project Structure

β”œβ”€β”€ app/                        # Renderer process files
β”‚   β”œβ”€β”€ assets/                 # Static assets (images, fonts, etc)
β”‚   β”œβ”€β”€ components/             # React components
β”‚   β”‚   β”œβ”€β”€ App.tsx             # Application component
β”‚   β”œβ”€β”€ styles/                 # CSS and Tailwind files
β”‚   β”‚   β”œβ”€β”€ app.css             # App stylesheet
β”‚   β”‚   └── tailwind.css        # Tailwind stylesheet
β”‚   β”œβ”€β”€ index.html              # Entry HTML file
β”‚   └── renderer.tsx            # Renderer process entry
β”œβ”€β”€ lib/                        # Shared library code
β”‚   β”œβ”€β”€ main/                   # Main process code
β”‚   β”‚   β”œβ”€β”€ index.ts            # Main entry point for Electron
β”‚   β”‚   └── ...                 # Other main process modules
β”‚   β”œβ”€β”€ preload/                # Preload scripts for IPC
β”‚   β”‚   β”œβ”€β”€ index.ts            # Preload script entry
β”‚   β”‚   └── api.ts              # Exposed API for renderer
β”‚   β”œβ”€β”€ welcome/                # Welcome kit components
β”‚   └── window/                 # Custom window implementation
β”œβ”€β”€ resources/                  # Build resources
β”œβ”€β”€ .eslintrc                   # ESLint configuration
β”œβ”€β”€ .prettierrc                 # Prettier format configuration
β”œβ”€β”€ electron-builder.yml        # Electron builder configuration
β”œβ”€β”€ electron.vite.config.ts     # Vite configuration for Electron
β”œβ”€β”€ package.json                # Project dependencies and scripts
└── tsconfig.node.json          # Main process tsconfig
└── tsconfig.web.json           # Renderer process tsconfig

About

Modern Electron application starter kit with React, Vite, TypeScript, and TailwindCSS

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 5

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy