react-native-electron-platform 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1157 -27
- package/electron-builder.json +3 -2
- package/index.mjs +83 -0
- package/package.json +2 -2
- package/src/webpackConfigHelper.mjs +1 -1
- package/test/package.json +43 -0
- package/src/main.mjs +0 -81
- package/test/electron/electron-builder.json +0 -94
package/README.md
CHANGED
|
@@ -5,61 +5,1191 @@
|
|
|
5
5
|
|
|
6
6
|
A boilerplate and utility library for running React Native applications in Electron, supporting both desktop and web platforms.
|
|
7
7
|
|
|
8
|
-
## Features
|
|
8
|
+
## 🎯 Features
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
- HTML preview functionality
|
|
10
|
+
### Core Capabilities
|
|
11
|
+
- ⚡ **Electron main process setup** - Pre-configured Electron environment with window management
|
|
12
|
+
- 🔄 **Auto-updater integration** - Automatic application update checking and installation
|
|
13
|
+
- 🔒 **Secure IPC communication** - Preload script for safe electron context isolation
|
|
14
|
+
- 🛠️ **Webpack configuration helper** - Ready-to-use webpack config for React Native web builds
|
|
15
|
+
- 🌐 **Cross-platform support** - Build once, run on Electron, Web, Android, and iOS
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
### Built-in Modules
|
|
18
|
+
- 📁 **File Operations** - Read, write, and delete files securely
|
|
19
|
+
- 🖨️ **PDF Generation & Preview** - Generate and preview PDF documents
|
|
20
|
+
- 📋 **Clipboard Management** - Copy/paste functionality
|
|
21
|
+
- 💬 **Dialog System** - File dialogs, save dialogs, message boxes
|
|
22
|
+
- 🌐 **Network Service** - Secure HTTP requests from main process
|
|
23
|
+
- 🔗 **Deep Linking** - Platform-specific deep link handling
|
|
24
|
+
- 🛡️ **Safe Mode** - Recovery utilities for safe application startup
|
|
25
|
+
|
|
26
|
+
### Security Features
|
|
27
|
+
- Main process runs separately from renderer
|
|
28
|
+
- Secure IPC communication with preload scripts
|
|
29
|
+
- No direct Node.js access from renderer process
|
|
30
|
+
- Controlled access to sensitive APIs
|
|
31
|
+
- Context isolation support
|
|
32
|
+
|
|
33
|
+
### Developer Experience
|
|
34
|
+
- Hot Module Replacement (HMR) during development
|
|
35
|
+
- DevTools integration for debugging
|
|
36
|
+
- Cross-platform build tools
|
|
37
|
+
- Webpack dev server integration
|
|
38
|
+
- Automatic platform detection
|
|
39
|
+
- Easy conditional imports per platform
|
|
40
|
+
|
|
41
|
+
## ✅ System Requirements
|
|
42
|
+
|
|
43
|
+
- **Node.js** v14.0.0 or higher
|
|
44
|
+
- **npm** v6.0.0 or higher
|
|
45
|
+
- **Disk space:** ~500MB for node_modules
|
|
46
|
+
- **For iOS:** macOS with Xcode
|
|
47
|
+
- **For Android:** Android SDK
|
|
48
|
+
|
|
49
|
+
## ⚡ One Minute Overview
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
# 1. Install package
|
|
53
|
+
npm install react-native-electron-platform
|
|
54
|
+
|
|
55
|
+
# 2. Copy example and install
|
|
56
|
+
cp -r node_modules/react-native-electron-platform/example-project ../my-app
|
|
57
|
+
cd ../my-app && npm install
|
|
58
|
+
|
|
59
|
+
# 3. Run
|
|
60
|
+
npm run electron # Electron app with hot reload
|
|
61
|
+
npm run web # Web on browser
|
|
62
|
+
npm run android # Android device
|
|
63
|
+
npm run ios # iOS simulator
|
|
64
|
+
npm run electron:build # Build production app
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 📦 Installation
|
|
19
68
|
|
|
20
69
|
```bash
|
|
21
70
|
npm install react-native-electron-platform
|
|
22
71
|
```
|
|
23
72
|
|
|
24
|
-
|
|
73
|
+
### Dependencies
|
|
25
74
|
|
|
26
|
-
|
|
75
|
+
You'll also need to install these peer dependencies:
|
|
27
76
|
|
|
28
|
-
|
|
29
|
-
|
|
77
|
+
```bash
|
|
78
|
+
npm install react react-native cross-env concurrently wait-on electron electron-builder
|
|
79
|
+
npm install --save-dev webpack webpack-cli webpack-dev-server html-webpack-plugin @babel/core @babel/preset-react babel-loader
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## 🚀 Quick Start Guide
|
|
83
|
+
|
|
84
|
+
### ⭐ For New Users - 3 Steps to Get Running
|
|
85
|
+
|
|
86
|
+
**Step 1: Copy the Example Project**
|
|
87
|
+
```bash
|
|
88
|
+
# Copy example-project to your desired location
|
|
89
|
+
cp -r node_modules/react-native-electron-platform/example-project ../my-electron-app
|
|
90
|
+
cd ../my-electron-app
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Step 2: Install Dependencies**
|
|
94
|
+
```bash
|
|
95
|
+
npm install
|
|
96
|
+
```
|
|
30
97
|
|
|
31
|
-
|
|
98
|
+
**Step 3: Run Your App**
|
|
99
|
+
```bash
|
|
100
|
+
npm run electron
|
|
101
|
+
```
|
|
32
102
|
|
|
103
|
+
Visit `http://localhost:5001` and you'll see your app running in an Electron window!
|
|
104
|
+
|
|
105
|
+
### 📚 For Detailed Instructions
|
|
106
|
+
|
|
107
|
+
Read the **[Complete Setup Guide](SETUP.md)** for step-by-step instructions on:
|
|
108
|
+
- Creating a new React Native project from scratch
|
|
109
|
+
- Installing and configuring react-native-electron-platform
|
|
110
|
+
- Setting up project structure
|
|
111
|
+
- Running on all platforms (Electron, Web, Android, iOS)
|
|
112
|
+
- Building for production
|
|
113
|
+
|
|
114
|
+
## 📖 How to Use
|
|
115
|
+
|
|
116
|
+
### Option 1: As an NPM Module (Recommended) ⭐
|
|
117
|
+
|
|
118
|
+
The easiest and recommended way - install as a package and use pre-configured setup:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
npm install react-native-electron-platform
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Update your package.json:**
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
"private": true,
|
|
128
|
+
"main": "node_modules/react-native-electron-platform/index.mjs",
|
|
129
|
+
"scripts": {
|
|
130
|
+
"web": "webpack serve --config node_modules/react-native-electron-platform/webpack.config.mjs --mode development",
|
|
131
|
+
"web:build": "webpack --config node_modules/react-native-electron-platform/webpack.config.mjs --mode production",
|
|
132
|
+
"electron": "cross-env NODE_ENV=development concurrently \"npm run web\" \"wait-on http://localhost:5001 && electron .\"",
|
|
133
|
+
"electron:dev": "cross-env NODE_ENV=development electron . --enable-remote-module",
|
|
134
|
+
"electron:build": "npm run web:build && electron-builder --config node_modules/react-native-electron-platform/electron-builder.json",
|
|
135
|
+
"electron:build:nsis": "npm run web:build && electron-builder --config node_modules/react-native-electron-platform/electron-builder.json --win nsis --publish never",
|
|
136
|
+
"electron:build:msi": "npm run web:build && electron-builder --config node_modules/react-native-electron-platform/electron-builder.json --win msi --publish never",
|
|
137
|
+
"android": "react-native run-android",
|
|
138
|
+
"ios": "react-native run-ios",
|
|
139
|
+
"lint": "eslint .",
|
|
140
|
+
"start": "react-native start",
|
|
141
|
+
"test": "jest"
|
|
142
|
+
},
|
|
143
|
+
"dependencies": {
|
|
144
|
+
"react": "^18.0.0",
|
|
145
|
+
"react-native": "^0.71.0",
|
|
146
|
+
"react-native-electron-platform": "^0.0.12",
|
|
147
|
+
"cross-env": "^7.0.3",
|
|
148
|
+
"concurrently": "^8.0.0",
|
|
149
|
+
"wait-on": "^7.0.0"
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Create Project Structure:**
|
|
155
|
+
```bash
|
|
156
|
+
mkdir -p src electron
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Create `src/App.js`:
|
|
33
160
|
```javascript
|
|
34
|
-
import
|
|
161
|
+
import React from 'react';
|
|
162
|
+
import { View, Text, StyleSheet } from 'react-native';
|
|
35
163
|
|
|
36
|
-
const
|
|
37
|
-
|
|
164
|
+
const App = () => {
|
|
165
|
+
return (
|
|
166
|
+
<View style={styles.container}>
|
|
167
|
+
<Text style={styles.title}>Welcome to Electron + React Native!</Text>
|
|
168
|
+
</View>
|
|
169
|
+
);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const styles = StyleSheet.create({
|
|
173
|
+
container: {
|
|
174
|
+
flex: 1,
|
|
175
|
+
justifyContent: 'center',
|
|
176
|
+
alignItems: 'center',
|
|
177
|
+
backgroundColor: '#f5f5f5',
|
|
178
|
+
},
|
|
179
|
+
title: {
|
|
180
|
+
fontSize: 24,
|
|
181
|
+
fontWeight: 'bold',
|
|
182
|
+
color: '#333',
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
export default App;
|
|
38
187
|
```
|
|
39
188
|
|
|
40
|
-
|
|
189
|
+
Create `electron/index.js`:
|
|
190
|
+
```javascript
|
|
191
|
+
import { AppRegistry } from 'react-native';
|
|
192
|
+
import App from '../src/App';
|
|
193
|
+
|
|
194
|
+
AppRegistry.registerComponent('App', () => App);
|
|
195
|
+
|
|
196
|
+
const root = document.getElementById('root');
|
|
197
|
+
if (root) {
|
|
198
|
+
AppRegistry.runApplication('App', {
|
|
199
|
+
rootTag: root,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Create `index.html`:
|
|
205
|
+
```html
|
|
206
|
+
<!DOCTYPE html>
|
|
207
|
+
<html lang="en">
|
|
208
|
+
<head>
|
|
209
|
+
<meta charset="UTF-8" />
|
|
210
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
211
|
+
<title>My App</title>
|
|
212
|
+
<style>
|
|
213
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
214
|
+
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif; }
|
|
215
|
+
#root { width: 100%; height: 100vh; }
|
|
216
|
+
</style>
|
|
217
|
+
</head>
|
|
218
|
+
<body>
|
|
219
|
+
<div id="root"></div>
|
|
220
|
+
</body>
|
|
221
|
+
</html>
|
|
222
|
+
```
|
|
41
223
|
|
|
224
|
+
**Run Your App:**
|
|
42
225
|
```bash
|
|
43
|
-
npm
|
|
226
|
+
npm run electron
|
|
44
227
|
```
|
|
45
228
|
|
|
46
|
-
|
|
229
|
+
### Option 2: As a Boilerplate (Advanced)
|
|
47
230
|
|
|
48
|
-
|
|
231
|
+
For custom use cases, copy specific files to your Electron project:
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
# Copy Electron entry point
|
|
235
|
+
cp node_modules/react-native-electron-platform/index.mjs ./
|
|
236
|
+
|
|
237
|
+
# Copy webpack config helper
|
|
238
|
+
cp node_modules/react-native-electron-platform/src/webpackConfigHelper.mjs ./src/
|
|
239
|
+
|
|
240
|
+
# Copy preload script (for security)
|
|
241
|
+
cp node_modules/react-native-electron-platform/src/preload.mjs ./src/
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Option 3: As a Library (Advanced)
|
|
245
|
+
|
|
246
|
+
Use utility functions directly in your project:
|
|
247
|
+
|
|
248
|
+
```javascript
|
|
249
|
+
// Analyze dependencies
|
|
250
|
+
import webpackConfigHelper from 'react-native-electron-platform/src/webpackConfigHelper.mjs';
|
|
251
|
+
const packages = webpackConfigHelper.categorizePackages();
|
|
252
|
+
|
|
253
|
+
// Use modules
|
|
254
|
+
import { windowManager, networkService, autoUpdater } from 'react-native-electron-platform/src/modules/';
|
|
255
|
+
|
|
256
|
+
// Create window
|
|
257
|
+
windowManager.createWindow({ width: 1024, height: 768 });
|
|
258
|
+
|
|
259
|
+
// Make secure network requests
|
|
260
|
+
networkService.fetch('https://api.example.com/data');
|
|
261
|
+
|
|
262
|
+
// Check for updates
|
|
263
|
+
autoUpdater.checkForUpdates();
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## Example Project
|
|
267
|
+
|
|
268
|
+
See the [example-project](example-project/) folder for a complete, working example with:
|
|
269
|
+
- Pre-configured `package.json`
|
|
270
|
+
- Sample App component
|
|
271
|
+
- Electron configuration
|
|
272
|
+
- HTML entry point
|
|
273
|
+
|
|
274
|
+
## 🔧 Available NPM Scripts
|
|
275
|
+
|
|
276
|
+
All scripts are configured to work with react-native-electron-platform.
|
|
277
|
+
|
|
278
|
+
### 📱 Mobile Development
|
|
279
|
+
|
|
280
|
+
| Script | Platform | Purpose |
|
|
281
|
+
|--------|----------|---------|
|
|
282
|
+
| `npm run android` | Android | Build and run on Android device/emulator |
|
|
283
|
+
| `npm run ios` | iOS | Build and run on iOS device/simulator |
|
|
284
|
+
| `npm start` | Both | Start React Native dev server |
|
|
285
|
+
|
|
286
|
+
### 🌐 Web Development
|
|
287
|
+
|
|
288
|
+
| Script | Purpose | Usage |
|
|
289
|
+
|--------|---------|-------|
|
|
290
|
+
| `npm run web` | Start webpack dev server | Development with hot reload on `http://localhost:5001` |
|
|
291
|
+
| `npm run web:build` | Production web bundle | Creates optimized bundle for deployment |
|
|
292
|
+
|
|
293
|
+
### 🖥️ Electron Development & Building
|
|
294
|
+
|
|
295
|
+
| Script | Purpose | When to Use |
|
|
296
|
+
|--------|---------|------------|
|
|
297
|
+
| `npm run electron` | Full dev environment | Main development - webpack + Electron with reload |
|
|
298
|
+
| `npm run electron:dev` | Quick test | Fast testing (requires pre-built web bundle) |
|
|
299
|
+
| `npm run electron:build` | Production build | Create installers for all Windows formats |
|
|
300
|
+
| `npm run electron:build:nsis` | NSIS installer | Build Windows NSIS installer (.exe) |
|
|
301
|
+
| `npm run electron:build:msi` | MSI installer | Build Windows MSI installer for enterprises |
|
|
302
|
+
|
|
303
|
+
### 📊 Code Quality
|
|
304
|
+
|
|
305
|
+
| Script | Purpose |
|
|
306
|
+
|--------|---------|
|
|
307
|
+
| `npm run lint` | Run ESLint to check code style |
|
|
308
|
+
| `npm test` | Run Jest test suite |
|
|
309
|
+
|
|
310
|
+
### Quick Development Workflow
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
# Start development
|
|
314
|
+
npm run electron # Starts webpack + Electron automatically
|
|
315
|
+
|
|
316
|
+
# In another terminal, make your changes and save
|
|
317
|
+
# Your app will hot-reload automatically!
|
|
318
|
+
|
|
319
|
+
# When ready to build
|
|
320
|
+
npm run electron:build # Creates production build
|
|
321
|
+
|
|
322
|
+
# Or build specific format for Windows
|
|
323
|
+
npm run electron:build:nsis # NSIS installer
|
|
324
|
+
npm run electron:build:msi # MSI installer (for enterprises)
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### What Each Development Script Does
|
|
328
|
+
|
|
329
|
+
**`npm run electron`** - Recommended for development
|
|
330
|
+
```
|
|
331
|
+
1. Starts webpack dev server (http://localhost:5001)
|
|
332
|
+
2. Waits for server to be ready
|
|
333
|
+
3. Launches Electron window
|
|
334
|
+
4. Enables Hot Module Replacement (HMR)
|
|
335
|
+
5. Auto-reloads on file changes
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
**`npm run electron:dev`** - Quick Electron test
|
|
339
|
+
```
|
|
340
|
+
Requires you to:
|
|
341
|
+
1. Run npm run web:build first
|
|
342
|
+
2. Then start Electron directly
|
|
343
|
+
Faster startup, useful for quick testing of Electron-specific features
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
**`npm run web`** - Web browser testing
|
|
347
|
+
```
|
|
348
|
+
1. Starts webpack dev server on http://localhost:5001
|
|
349
|
+
2. Open in any browser
|
|
350
|
+
3. Great for testing without Electron
|
|
351
|
+
4. Faster reload times
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
## 🔌 API Reference
|
|
49
355
|
|
|
50
356
|
### WebpackConfigHelper
|
|
51
357
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
358
|
+
Utility functions for analyzing and configuring webpack builds:
|
|
359
|
+
|
|
360
|
+
```javascript
|
|
361
|
+
import webpackConfigHelper from 'node_modules/react-native-electron-platform/src/webpackConfigHelper.mjs';
|
|
362
|
+
|
|
363
|
+
// Get all dependencies from package.json
|
|
364
|
+
const allPackages = webpackConfigHelper.getAllPackages();
|
|
365
|
+
|
|
366
|
+
// Categorize packages by platform support
|
|
367
|
+
const { webSupported, webUnsupported } = webpackConfigHelper.categorizePackages();
|
|
368
|
+
|
|
369
|
+
// Check if a specific package supports web
|
|
370
|
+
if (webpackConfigHelper.isWebSupported('react-native-gesture-handler')) {
|
|
371
|
+
console.log('This package works on web');
|
|
372
|
+
} else {
|
|
373
|
+
console.log('This package requires native-only implementation');
|
|
374
|
+
}
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### Available Modules
|
|
378
|
+
|
|
379
|
+
Import and use pre-configured modules in your app:
|
|
380
|
+
|
|
381
|
+
```javascript
|
|
382
|
+
import {
|
|
383
|
+
windowManager,
|
|
384
|
+
networkService,
|
|
385
|
+
autoUpdater,
|
|
386
|
+
deepLinking,
|
|
387
|
+
safeMode,
|
|
388
|
+
pdfHelper
|
|
389
|
+
} from 'react-native-electron-platform/src/modules/';
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
#### 🪟 windowManager
|
|
393
|
+
Manages Electron windows and their lifecycle:
|
|
394
|
+
|
|
395
|
+
```javascript
|
|
396
|
+
import { windowManager } from 'react-native-electron-platform/src/modules/';
|
|
397
|
+
|
|
398
|
+
// Create a new window
|
|
399
|
+
windowManager.createWindow({
|
|
400
|
+
width: 1024,
|
|
401
|
+
height: 768,
|
|
402
|
+
webPreferences: {
|
|
403
|
+
nodeIntegration: false
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
// Manage windows
|
|
408
|
+
windowManager.getWindows();
|
|
409
|
+
windowManager.closeWindow(id);
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
#### 🌐 networkService
|
|
413
|
+
Makes secure HTTP requests from the main process:
|
|
414
|
+
|
|
415
|
+
```javascript
|
|
416
|
+
import { networkService } from 'react-native-electron-platform/src/modules/';
|
|
417
|
+
|
|
418
|
+
// Fetch data securely
|
|
419
|
+
networkService.fetch('https://api.example.com/data', {
|
|
420
|
+
method: 'GET',
|
|
421
|
+
headers: { 'Authorization': 'Bearer token' }
|
|
422
|
+
}).then(response => response.json());
|
|
423
|
+
|
|
424
|
+
// Post data
|
|
425
|
+
networkService.fetch('https://api.example.com/data', {
|
|
426
|
+
method: 'POST',
|
|
427
|
+
body: JSON.stringify({ name: 'John' })
|
|
428
|
+
});
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
#### 🔄 autoUpdater
|
|
432
|
+
Automatically check for and install app updates:
|
|
433
|
+
|
|
434
|
+
```javascript
|
|
435
|
+
import { autoUpdater } from 'react-native-electron-platform/src/modules/';
|
|
436
|
+
|
|
437
|
+
// Check for updates
|
|
438
|
+
autoUpdater.checkForUpdates();
|
|
439
|
+
|
|
440
|
+
// Listen for update events
|
|
441
|
+
autoUpdater.on('update-available', (info) => {
|
|
442
|
+
console.log('Update available:', info.version);
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
autoUpdater.on('update-downloaded', () => {
|
|
446
|
+
console.log('Update downloaded, will install on restart');
|
|
447
|
+
});
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
#### 🔗 deepLinking
|
|
451
|
+
Handle platform-specific deep links:
|
|
452
|
+
|
|
453
|
+
```javascript
|
|
454
|
+
import { deepLinking } from 'react-native-electron-platform/src/modules/';
|
|
455
|
+
|
|
456
|
+
// Set up deep link handler
|
|
457
|
+
deepLinking.onDeepLink((url) => {
|
|
458
|
+
console.log('Deep link received:', url);
|
|
459
|
+
// Navigate to correct screen
|
|
460
|
+
});
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
#### 🛡️ safeMode
|
|
464
|
+
Recovery utilities for safe startup:
|
|
465
|
+
|
|
466
|
+
```javascript
|
|
467
|
+
import { safeMode } from 'react-native-electron-platform/src/modules/';
|
|
468
|
+
|
|
469
|
+
// Enable safe mode for troubleshooting
|
|
470
|
+
safeMode.enable();
|
|
471
|
+
|
|
472
|
+
// Check if safe mode is active
|
|
473
|
+
if (safeMode.isEnabled()) {
|
|
474
|
+
console.log('Running in safe mode');
|
|
475
|
+
}
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
#### 📄 pdfHelper
|
|
479
|
+
Generate and preview PDF documents:
|
|
480
|
+
|
|
481
|
+
```javascript
|
|
482
|
+
import { pdfHelper } from 'react-native-electron-platform/src/modules/';
|
|
483
|
+
|
|
484
|
+
// Generate PDF from content
|
|
485
|
+
pdfHelper.generate({
|
|
486
|
+
content: '<h1>My PDF</h1>',
|
|
487
|
+
outputPath: '/path/to/output.pdf'
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
// Preview PDF
|
|
491
|
+
pdfHelper.preview('/path/to/document.pdf');
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
### IPC Handlers
|
|
495
|
+
|
|
496
|
+
The platform provides pre-configured secure IPC communication for common tasks:
|
|
497
|
+
|
|
498
|
+
#### 📋 Clipboard Operations
|
|
499
|
+
```javascript
|
|
500
|
+
// In React Native component
|
|
501
|
+
import { ipcRenderer } from 'electron';
|
|
502
|
+
|
|
503
|
+
// Copy to clipboard
|
|
504
|
+
ipcRenderer.send('clipboard:write', 'text to copy');
|
|
505
|
+
|
|
506
|
+
// Read from clipboard
|
|
507
|
+
ipcRenderer.invoke('clipboard:read').then(text => {
|
|
508
|
+
console.log('Clipboard content:', text);
|
|
509
|
+
});
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
#### 📁 File Operations
|
|
513
|
+
```javascript
|
|
514
|
+
// Read file
|
|
515
|
+
ipcRenderer.invoke('file:read', '/path/to/file').then(content => {
|
|
516
|
+
console.log(content);
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
// Write file
|
|
520
|
+
ipcRenderer.invoke('file:write', '/path/to/file', 'content');
|
|
521
|
+
|
|
522
|
+
// Delete file
|
|
523
|
+
ipcRenderer.invoke('file:delete', '/path/to/file');
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
#### 💬 Dialog
|
|
527
|
+
```javascript
|
|
528
|
+
// Open file dialog
|
|
529
|
+
ipcRenderer.invoke('dialog:open').then(filePath => {
|
|
530
|
+
console.log('Selected file:', filePath);
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
// Save file dialog
|
|
534
|
+
ipcRenderer.invoke('dialog:save', 'defaultFileName').then(filePath => {
|
|
535
|
+
console.log('Save location:', filePath);
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
// Message box
|
|
539
|
+
ipcRenderer.invoke('dialog:message', {
|
|
540
|
+
type: 'info',
|
|
541
|
+
title: 'Information',
|
|
542
|
+
message: 'This is a message'
|
|
543
|
+
});
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
#### 🌐 Network
|
|
547
|
+
```javascript
|
|
548
|
+
// Make network request through main process
|
|
549
|
+
ipcRenderer.invoke('network:request', {
|
|
550
|
+
url: 'https://api.example.com',
|
|
551
|
+
method: 'GET'
|
|
552
|
+
}).then(response => {
|
|
553
|
+
console.log(response);
|
|
554
|
+
});
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
#### 📄 PDF
|
|
558
|
+
```javascript
|
|
559
|
+
// Generate PDF
|
|
560
|
+
ipcRenderer.invoke('pdf:generate', {
|
|
561
|
+
content: '<h1>PDF Content</h1>',
|
|
562
|
+
outputPath: '/output/file.pdf'
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
// Preview PDF
|
|
566
|
+
ipcRenderer.invoke('pdf:preview', '/path/to/file.pdf');
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
#### 🔄 Auto-Update
|
|
570
|
+
```javascript
|
|
571
|
+
// Check for updates
|
|
572
|
+
ipcRenderer.send('updater:check');
|
|
573
|
+
|
|
574
|
+
// Listen for update events
|
|
575
|
+
ipcRenderer.on('updater:available', (event, info) => {
|
|
576
|
+
console.log('Update available:', info);
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
// Install update on next restart
|
|
580
|
+
ipcRenderer.send('updater:install');
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
## 🏗️ Building for Different Platforms
|
|
584
|
+
|
|
585
|
+
### Electron (Windows/macOS/Linux)
|
|
586
|
+
|
|
587
|
+
**Development:**
|
|
588
|
+
```bash
|
|
589
|
+
npm run electron
|
|
590
|
+
```
|
|
591
|
+
This launches an Electron window with hot reload enabled. Perfect for development.
|
|
592
|
+
|
|
593
|
+
**Production Build:**
|
|
594
|
+
```bash
|
|
595
|
+
# All formats
|
|
596
|
+
npm run electron:build
|
|
597
|
+
|
|
598
|
+
# Windows NSIS installer (recommended for users)
|
|
599
|
+
npm run electron:build:nsis
|
|
600
|
+
|
|
601
|
+
# Windows MSI installer (for enterprise deployments)
|
|
602
|
+
npm run electron:build:msi
|
|
603
|
+
```
|
|
604
|
+
|
|
605
|
+
Output files appear in the `dist/` directory:
|
|
606
|
+
- `.exe` - Executable installer
|
|
607
|
+
- `.zip` - Portable version
|
|
608
|
+
- `.msi` - Microsoft Installer format (for enterprises)
|
|
609
|
+
|
|
610
|
+
### Web (Browser)
|
|
611
|
+
|
|
612
|
+
**Development:**
|
|
613
|
+
```bash
|
|
614
|
+
npm run web
|
|
615
|
+
```
|
|
616
|
+
Starts webpack dev server on `http://localhost:5001` with hot reload.
|
|
617
|
+
|
|
618
|
+
**Production:**
|
|
619
|
+
```bash
|
|
620
|
+
npm run web:build
|
|
621
|
+
```
|
|
622
|
+
Creates optimized bundle in `dist/` folder. Deploy to any web server.
|
|
623
|
+
|
|
624
|
+
### Android
|
|
625
|
+
|
|
626
|
+
**Development:**
|
|
627
|
+
```bash
|
|
628
|
+
npm run android
|
|
629
|
+
```
|
|
630
|
+
Requires Android SDK and emulator or USB device.
|
|
631
|
+
|
|
632
|
+
**Production:**
|
|
633
|
+
```bash
|
|
634
|
+
npm run android -- --variant release
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
### iOS (macOS only)
|
|
638
|
+
|
|
639
|
+
**Development:**
|
|
640
|
+
```bash
|
|
641
|
+
npm run ios
|
|
642
|
+
```
|
|
643
|
+
Requires Xcode and iOS simulator or device.
|
|
644
|
+
|
|
645
|
+
**Production:**
|
|
646
|
+
```bash
|
|
647
|
+
npm run ios -- --configuration Release
|
|
648
|
+
```
|
|
55
649
|
|
|
56
|
-
|
|
650
|
+
### Multi-Platform Build
|
|
57
651
|
|
|
652
|
+
Build once for multiple platforms:
|
|
58
653
|
```bash
|
|
59
|
-
|
|
654
|
+
# Build web
|
|
655
|
+
npm run web:build
|
|
656
|
+
|
|
657
|
+
# Build Android
|
|
658
|
+
npm run android
|
|
659
|
+
|
|
660
|
+
# Build iOS
|
|
661
|
+
npm run ios
|
|
662
|
+
|
|
663
|
+
# Build Electron
|
|
664
|
+
npm run electron:build
|
|
665
|
+
```
|
|
666
|
+
|
|
667
|
+
## 🎯 Platform-Specific Code
|
|
668
|
+
|
|
669
|
+
### Using Platform Detection
|
|
670
|
+
|
|
671
|
+
```javascript
|
|
672
|
+
import { Platform } from 'react-native';
|
|
673
|
+
|
|
674
|
+
if (Platform.OS === 'web') {
|
|
675
|
+
// Web-only code
|
|
676
|
+
} else if (Platform.OS === 'electron') {
|
|
677
|
+
// Electron-only code
|
|
678
|
+
} else if (Platform.OS === 'android') {
|
|
679
|
+
// Android-only code
|
|
680
|
+
} else if (Platform.OS === 'ios') {
|
|
681
|
+
// iOS-only code
|
|
682
|
+
}
|
|
60
683
|
```
|
|
61
684
|
|
|
62
|
-
|
|
685
|
+
### Platform-Specific Imports
|
|
686
|
+
|
|
687
|
+
Create files with platform extensions and React Native automatically uses the correct one:
|
|
688
|
+
|
|
689
|
+
```
|
|
690
|
+
components/
|
|
691
|
+
├── Button.js # Shared base (fallback)
|
|
692
|
+
├── Button.web.js # Used on web
|
|
693
|
+
├── Button.electron.js # Used on Electron
|
|
694
|
+
├── Button.android.js # Used on Android
|
|
695
|
+
└── Button.ios.js # Used on iOS
|
|
696
|
+
```
|
|
697
|
+
|
|
698
|
+
Usage is the same:
|
|
699
|
+
```javascript
|
|
700
|
+
import Button from './Button'; // Automatically loads correct version!
|
|
701
|
+
```
|
|
702
|
+
|
|
703
|
+
### Conditional Imports
|
|
704
|
+
|
|
705
|
+
```javascript
|
|
706
|
+
import { Platform } from 'react-native';
|
|
707
|
+
|
|
708
|
+
let FileModule;
|
|
709
|
+
if (Platform.OS !== 'web') {
|
|
710
|
+
// This import only happens on mobile/Electron
|
|
711
|
+
FileModule = require('react-native-document-picker');
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
export default FileModule;
|
|
715
|
+
```
|
|
716
|
+
|
|
717
|
+
## ⚠️ Web-Unsupported Packages
|
|
718
|
+
|
|
719
|
+
Some React Native packages don't work on the web. The platform provides a list:
|
|
720
|
+
|
|
721
|
+
```javascript
|
|
722
|
+
import { WEB_UNSUPPORTED_PACKAGES } from './electron/nonmodules.mjs';
|
|
723
|
+
```
|
|
724
|
+
|
|
725
|
+
**Common unsupported packages:**
|
|
726
|
+
- `react-native-gesture-handler` - Use web alternatives
|
|
727
|
+
- `react-native-fs` - Use web APIs (File, Blob)
|
|
728
|
+
- `react-native-document-picker` - Use HTML file input
|
|
729
|
+
- `react-native-camera` - Use web `getUserMedia` API
|
|
730
|
+
- `react-native-video` - Use HTML `<video>` tag
|
|
731
|
+
- `@react-native-community/hooks` - Check web compatibility
|
|
732
|
+
|
|
733
|
+
**Solution: Use platform-specific code**
|
|
734
|
+
|
|
735
|
+
```javascript
|
|
736
|
+
import { Platform } from 'react-native';
|
|
737
|
+
|
|
738
|
+
let DocumentPicker;
|
|
739
|
+
if (Platform.OS !== 'web') {
|
|
740
|
+
DocumentPicker = require('react-native-document-picker').default;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
export function selectDocument() {
|
|
744
|
+
if (Platform.OS === 'web') {
|
|
745
|
+
// Use HTML file input
|
|
746
|
+
const input = document.createElement('input');
|
|
747
|
+
input.type = 'file';
|
|
748
|
+
input.click();
|
|
749
|
+
} else {
|
|
750
|
+
// Use native picker
|
|
751
|
+
return DocumentPicker.pick();
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
```
|
|
755
|
+
|
|
756
|
+
## 🏭 Building for Production
|
|
757
|
+
|
|
758
|
+
### Electron Production Build
|
|
759
|
+
|
|
760
|
+
```bash
|
|
761
|
+
# Complete production build
|
|
762
|
+
npm run electron:build
|
|
763
|
+
|
|
764
|
+
# Creates installers in dist/ folder
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
**What it does:**
|
|
768
|
+
1. Builds optimized web bundle (minified, no debug code)
|
|
769
|
+
2. Runs electron-builder to create installers
|
|
770
|
+
3. For each platform, creates appropriate format:
|
|
771
|
+
- **Windows:** `.exe` + `.zip`
|
|
772
|
+
- **macOS:** `.dmg` + `.zip`
|
|
773
|
+
- **Linux:** `.AppImage` + `.deb`
|
|
774
|
+
|
|
775
|
+
**Custom Build Config** (optional `electron-builder.json`):
|
|
776
|
+
```json
|
|
777
|
+
{
|
|
778
|
+
"productName": "My App",
|
|
779
|
+
"appId": "com.example.myapp",
|
|
780
|
+
"directories": {
|
|
781
|
+
"buildResources": "./assets"
|
|
782
|
+
},
|
|
783
|
+
"win": {
|
|
784
|
+
"target": ["nsis", "portable"]
|
|
785
|
+
},
|
|
786
|
+
"nsis": {
|
|
787
|
+
"oneClick": false,
|
|
788
|
+
"allowToChangeInstallationDirectory": true
|
|
789
|
+
},
|
|
790
|
+
"mac": {
|
|
791
|
+
"target": ["dmg", "zip"]
|
|
792
|
+
},
|
|
793
|
+
"linux": {
|
|
794
|
+
"target": ["AppImage", "deb"]
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
```
|
|
798
|
+
|
|
799
|
+
### Web Production Build
|
|
800
|
+
|
|
801
|
+
```bash
|
|
802
|
+
npm run web:build
|
|
803
|
+
```
|
|
804
|
+
|
|
805
|
+
**Deployment:**
|
|
806
|
+
```bash
|
|
807
|
+
# The dist/ folder is ready for any web server
|
|
808
|
+
npm install -g http-server
|
|
809
|
+
http-server dist/
|
|
810
|
+
|
|
811
|
+
# Or deploy to services like:
|
|
812
|
+
# Vercel: vercel
|
|
813
|
+
# Netlify: netlify deploy --prod --dir=dist
|
|
814
|
+
# AWS S3: aws s3 sync dist/ s3://my-bucket
|
|
815
|
+
```
|
|
816
|
+
|
|
817
|
+
### Mobile Production Build
|
|
818
|
+
|
|
819
|
+
**Android:**
|
|
820
|
+
```bash
|
|
821
|
+
npm run android -- --variant release
|
|
822
|
+
```
|
|
823
|
+
|
|
824
|
+
Generates signed APK in `android/app/build/outputs/`.
|
|
825
|
+
|
|
826
|
+
**iOS:**
|
|
827
|
+
```bash
|
|
828
|
+
npm run ios -- --configuration Release
|
|
829
|
+
```
|
|
830
|
+
|
|
831
|
+
Use App Store Connect for distribution.
|
|
832
|
+
|
|
833
|
+
## 🐛 Troubleshooting
|
|
834
|
+
|
|
835
|
+
### Electron Won't Start
|
|
836
|
+
|
|
837
|
+
**Problem:** Blank window or "Cannot find entry point"
|
|
838
|
+
|
|
839
|
+
**Solution:**
|
|
840
|
+
1. Ensure webpack is running: `npm run web`
|
|
841
|
+
2. Check webpack is ready on `http://localhost:5001`
|
|
842
|
+
3. Verify `index.html` exists in project root
|
|
843
|
+
4. Check logs in terminal for errors
|
|
844
|
+
|
|
845
|
+
### Port 5001 Already in Use
|
|
846
|
+
|
|
847
|
+
**Problem:** "Port 5001 already in use"
|
|
848
|
+
|
|
849
|
+
**Windows:**
|
|
850
|
+
```bash
|
|
851
|
+
netstat -ano | findstr :5001
|
|
852
|
+
taskkill /PID <PID> /F
|
|
853
|
+
```
|
|
854
|
+
|
|
855
|
+
**macOS/Linux:**
|
|
856
|
+
```bash
|
|
857
|
+
lsof -i :5001
|
|
858
|
+
kill -9 <PID>
|
|
859
|
+
```
|
|
860
|
+
|
|
861
|
+
### Hot Reload Not Working
|
|
862
|
+
|
|
863
|
+
**Problem:** Changes don't appear when you save
|
|
864
|
+
|
|
865
|
+
**Solution:**
|
|
866
|
+
1. Verify webpack is running
|
|
867
|
+
2. Check file was actually saved
|
|
868
|
+
3. Hard refresh in Electron: `Ctrl+Shift+R`
|
|
869
|
+
4. Restart both webpack and Electron
|
|
870
|
+
|
|
871
|
+
### Module Not Found Errors
|
|
872
|
+
|
|
873
|
+
**Problem:** "Cannot find module 'react-native-electron-platform'"
|
|
874
|
+
|
|
875
|
+
**Solution:**
|
|
876
|
+
```bash
|
|
877
|
+
rm -rf node_modules
|
|
878
|
+
npm install
|
|
879
|
+
npm install react-native-electron-platform
|
|
880
|
+
```
|
|
881
|
+
|
|
882
|
+
### Build Fails with Errors
|
|
883
|
+
|
|
884
|
+
**Problem:** `npm run electron:build` fails
|
|
885
|
+
|
|
886
|
+
**Solution:**
|
|
887
|
+
1. Clear cache: `rm -rf dist`
|
|
888
|
+
2. Update packages: `npm update`
|
|
889
|
+
3. Check Node.js version: `node --version` (requires 14+)
|
|
890
|
+
4. Try clean install: `rm -rf node_modules && npm install`
|
|
891
|
+
|
|
892
|
+
### Blank Electron Window
|
|
893
|
+
|
|
894
|
+
**Problem:** Electron launches but window is blank
|
|
895
|
+
|
|
896
|
+
**Debug steps:**
|
|
897
|
+
1. Open DevTools: `Ctrl+Shift+I` in Electron
|
|
898
|
+
2. Check console for errors
|
|
899
|
+
3. Check Network tab - is webpack loading?
|
|
900
|
+
4. Verify `electron/index.js` is correct
|
|
901
|
+
5. Try `npm run web` to test in browser first
|
|
902
|
+
|
|
903
|
+
### Web App Not Loading
|
|
904
|
+
|
|
905
|
+
**Problem:** `http://localhost:5001` shows blank page
|
|
906
|
+
|
|
907
|
+
**Solution:**
|
|
908
|
+
1. Check webpack output in terminal for errors
|
|
909
|
+
2. Look for "Compiling..." status
|
|
910
|
+
3. Try hard refresh: `Ctrl+Shift+R`
|
|
911
|
+
4. Check if Babel is installed: `npm install @babel/core babel-loader`
|
|
912
|
+
5. Clear browser cache
|
|
913
|
+
|
|
914
|
+
### IPC Communication Not Working
|
|
915
|
+
|
|
916
|
+
**Problem:** "Cannot use ipcRenderer on web"
|
|
917
|
+
|
|
918
|
+
**Solution:** Use platform detection:
|
|
919
|
+
```javascript
|
|
920
|
+
import { Platform, View } from 'react-native';
|
|
921
|
+
|
|
922
|
+
let content;
|
|
923
|
+
if (Platform.OS === 'electron') {
|
|
924
|
+
const { ipcRenderer } = require('electron');
|
|
925
|
+
// Use IPC here
|
|
926
|
+
ipcRenderer.invoke('some-action');
|
|
927
|
+
content = <View>Electron</View>;
|
|
928
|
+
} else {
|
|
929
|
+
// Use REST API or fetch
|
|
930
|
+
fetch('/api/endpoint');
|
|
931
|
+
content = <View>Web</View>;
|
|
932
|
+
}
|
|
933
|
+
```
|
|
934
|
+
|
|
935
|
+
### Performance Issues
|
|
936
|
+
|
|
937
|
+
**Slow Webpack Build:**
|
|
938
|
+
```bash
|
|
939
|
+
# Speed up dev mode
|
|
940
|
+
npm run web -- --mode development --devtool eval-source-map
|
|
941
|
+
```
|
|
942
|
+
|
|
943
|
+
**Large Bundle Size:**
|
|
944
|
+
```bash
|
|
945
|
+
# Analyze bundle
|
|
946
|
+
npm run web:build -- --profile
|
|
947
|
+
|
|
948
|
+
# Remove unused dependencies
|
|
949
|
+
npm prune --production
|
|
950
|
+
```
|
|
951
|
+
|
|
952
|
+
### Debug in DevTools
|
|
953
|
+
|
|
954
|
+
**Electron:**
|
|
955
|
+
1. Press `Ctrl+Shift+I` to open DevTools
|
|
956
|
+
2. Console shows messages from both processes
|
|
957
|
+
3. Use `console.log()` for debugging
|
|
958
|
+
4. DevTools React plugin available
|
|
959
|
+
|
|
960
|
+
**Web:**
|
|
961
|
+
1. Open browser DevTools: `F12`
|
|
962
|
+
2. Install React DevTools extension
|
|
963
|
+
3. Use Network tab to debug API calls
|
|
964
|
+
|
|
965
|
+
**Mobile:**
|
|
966
|
+
1. Android: `adb logcat` for Logcat
|
|
967
|
+
2. iOS: Open Xcode Console
|
|
968
|
+
|
|
969
|
+
## � Project Structure
|
|
970
|
+
|
|
971
|
+
### Recommended Structure
|
|
972
|
+
|
|
973
|
+
```
|
|
974
|
+
your-project/
|
|
975
|
+
├── src/
|
|
976
|
+
│ ├── screens/ # Screen components
|
|
977
|
+
│ │ ├── Home.js
|
|
978
|
+
│ │ ├── Settings.js
|
|
979
|
+
│ │ └── Details.js
|
|
980
|
+
│ ├── components/ # Reusable components
|
|
981
|
+
│ │ ├── Button.js
|
|
982
|
+
│ │ ├── Button.web.js
|
|
983
|
+
│ │ ├── Button.electron.js
|
|
984
|
+
│ │ ├── Header.js
|
|
985
|
+
│ │ └── Card.js
|
|
986
|
+
│ ├── utils/ # Utility functions
|
|
987
|
+
│ │ ├── api.js
|
|
988
|
+
│ │ ├── helpers.js
|
|
989
|
+
│ │ └── constants.js
|
|
990
|
+
│ ├── hooks/ # Custom React hooks
|
|
991
|
+
│ │ ├── useData.js
|
|
992
|
+
│ │ └── useAuth.js
|
|
993
|
+
│ ├── App.js # Root component
|
|
994
|
+
│ └── index.html # Web entry point (webpack output)
|
|
995
|
+
│
|
|
996
|
+
├── electron/
|
|
997
|
+
│ ├── index.js # Electron app initialization
|
|
998
|
+
│ ├── nonmodules.mjs # List of web-unsupported packages
|
|
999
|
+
│ └── modules/ # Custom Electron modules (optional)
|
|
1000
|
+
│ └── customModule.js
|
|
1001
|
+
│
|
|
1002
|
+
├── assets/ # Images, icons, fonts
|
|
1003
|
+
│ ├── icon.ico
|
|
1004
|
+
│ ├── icon.png
|
|
1005
|
+
│ └── logo.svg
|
|
1006
|
+
│
|
|
1007
|
+
├── __tests__/ # Test files
|
|
1008
|
+
│ ├── App.test.js
|
|
1009
|
+
│ └── components/
|
|
1010
|
+
│
|
|
1011
|
+
├── .gitignore
|
|
1012
|
+
├── .env # Environment variables (git-ignored)
|
|
1013
|
+
├── package.json
|
|
1014
|
+
├── index.html # Webpack HTML template
|
|
1015
|
+
├── CONFIGURATION.md # Config documentation
|
|
1016
|
+
├── webpack.config.mjs # (optional) Custom webpack config
|
|
1017
|
+
├── electron-builder.json # (optional) Custom build config
|
|
1018
|
+
└── node_modules/
|
|
1019
|
+
└── react-native-electron-platform/ # This package
|
|
1020
|
+
```
|
|
1021
|
+
|
|
1022
|
+
### Key Directories
|
|
1023
|
+
|
|
1024
|
+
- **src/** - All application source code
|
|
1025
|
+
- **electron/** - Electron-specific code and configuration
|
|
1026
|
+
- **assets/** - Static resources (images, icons, fonts)
|
|
1027
|
+
- **__tests__/** - Test files (mirrors src structure)
|
|
1028
|
+
- **node_modules/** - Dependencies including react-native-electron-platform
|
|
1029
|
+
|
|
1030
|
+
## 📚 Complete Documentation
|
|
1031
|
+
|
|
1032
|
+
Complete documentation to help you get started and understand how to use the platform:
|
|
1033
|
+
|
|
1034
|
+
### 🚀 Getting Started (Quick)
|
|
1035
|
+
- **[SETUP.md](SETUP.md)** ⭐ **START HERE** - Step-by-step setup guide for new projects
|
|
1036
|
+
- **[example-project/](example-project/)** - Ready-to-copy working example project
|
|
1037
|
+
- **[USAGE.md](USAGE.md)** - Comprehensive usage guide with all scripts explained
|
|
1038
|
+
|
|
1039
|
+
### 📖 Reference & Details
|
|
1040
|
+
- **[CONFIGURATION.md](CONFIGURATION.md)** - Detailed explanation of every config and script
|
|
1041
|
+
- **[DOCS_GUIDE.md](DOCS_GUIDE.md)** - Documentation navigation, FAQ, and learning paths
|
|
1042
|
+
|
|
1043
|
+
### 🤝 Contributing & Community
|
|
1044
|
+
- **[CONTRIBUTING.md](CONTRIBUTING.md)** - How to contribute to this project
|
|
1045
|
+
- **[CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md)** - Community guidelines and code of conduct
|
|
1046
|
+
- **[CHANGELOG.md](CHANGELOG.md)** - Version history and what changed between versions
|
|
1047
|
+
|
|
1048
|
+
## �📖 Documentation
|
|
1049
|
+
|
|
1050
|
+
```
|
|
1051
|
+
your-project/
|
|
1052
|
+
├── src/
|
|
1053
|
+
│ ├── App.js # Main React Native component
|
|
1054
|
+
│ └── index.html # Web entry point
|
|
1055
|
+
├── electron/
|
|
1056
|
+
│ ├── index.js # Electron app initialization
|
|
1057
|
+
│ └── nonmodules.mjs # List of web-unsupported packages
|
|
1058
|
+
├── index.html # Webpack HTML template
|
|
1059
|
+
├── package.json # Project configuration
|
|
1060
|
+
└── node_modules/
|
|
1061
|
+
└── react-native-electron-platform/ # Platform utilities
|
|
1062
|
+
```
|
|
1063
|
+
|
|
1064
|
+
## Documentation
|
|
1065
|
+
|
|
1066
|
+
- **[Complete Setup Guide](SETUP.md)** - Step-by-step instructions for creating a new project
|
|
1067
|
+
- **[Usage Documentation](USAGE.md)** - Detailed usage guide with all scripts and configuration
|
|
1068
|
+
- **[Example Project](example-project/)** - Working example with pre-configured setup
|
|
1069
|
+
- **[Contributing Guide](CONTRIBUTING.md)** - How to contribute to this project
|
|
1070
|
+
- **[Code of Conduct](CODE_OF_CONDUCT.md)** - Community guidelines
|
|
1071
|
+
- **[Changelog](CHANGELOG.md)** - Version history and changes
|
|
1072
|
+
|
|
1073
|
+
## 💡 Tips & Best Practices
|
|
1074
|
+
|
|
1075
|
+
### Development Tips
|
|
1076
|
+
|
|
1077
|
+
1. **Use `npm run electron` for main development** - It automatically manages webpack and Electron
|
|
1078
|
+
2. **Test on web first** - `npm run web` is faster for quick iterations
|
|
1079
|
+
3. **Use DevTools** - Press `Ctrl+Shift+I` in Electron for debugging
|
|
1080
|
+
4. **Platform-specific files** - Use `.web.js`, `.electron.js` extensions for platform code
|
|
1081
|
+
5. **Check web-unsupported packages** - Update `electron/nonmodules.mjs` when adding dependencies
|
|
1082
|
+
|
|
1083
|
+
### Production Tips
|
|
1084
|
+
|
|
1085
|
+
1. **Test production build locally first** - `npm run electron:build` creates dist/, test it
|
|
1086
|
+
2. **Sign your code** - Use code signing for macOS/iOS builds
|
|
1087
|
+
3. **Use NSIS for Windows** - Better user experience than portable executable
|
|
1088
|
+
4. **Automate updates** - Use electron-updater for seamless updates
|
|
1089
|
+
5. **Monitor bundle size** - Keep web bundle under 1MB for fast loads
|
|
1090
|
+
|
|
1091
|
+
### Performance Tips
|
|
1092
|
+
|
|
1093
|
+
1. **Code splitting** - Split large bundles for faster loads
|
|
1094
|
+
2. **Lazy loading** - Load screens/components on demand
|
|
1095
|
+
3. **Asset optimization** - Compress images and use appropriate formats
|
|
1096
|
+
4. **Caching** - Configure proper cache headers for web servers
|
|
1097
|
+
5. **Memory management** - Watch for memory leaks in DevTools
|
|
1098
|
+
|
|
1099
|
+
## 🔗 Integration Examples
|
|
1100
|
+
|
|
1101
|
+
### Connect to a Backend API
|
|
1102
|
+
|
|
1103
|
+
```javascript
|
|
1104
|
+
// In your app
|
|
1105
|
+
import { networkService } from 'react-native-electron-platform/src/modules/';
|
|
1106
|
+
|
|
1107
|
+
async function fetchUserData(userId) {
|
|
1108
|
+
const response = await networkService.fetch(`https://api.example.com/users/${userId}`);
|
|
1109
|
+
return response.json();
|
|
1110
|
+
}
|
|
1111
|
+
```
|
|
1112
|
+
|
|
1113
|
+
### Handle File Operations
|
|
1114
|
+
|
|
1115
|
+
```javascript
|
|
1116
|
+
import { ipcRenderer } from 'electron';
|
|
1117
|
+
|
|
1118
|
+
// Read file
|
|
1119
|
+
const content = await ipcRenderer.invoke('file:read', '/path/to/file');
|
|
1120
|
+
|
|
1121
|
+
// Write file
|
|
1122
|
+
await ipcRenderer.invoke('file:write', '/path/to/file', 'content');
|
|
1123
|
+
|
|
1124
|
+
// Delete file
|
|
1125
|
+
await ipcRenderer.invoke('file:delete', '/path/to/file');
|
|
1126
|
+
```
|
|
1127
|
+
|
|
1128
|
+
### Generate PDF
|
|
1129
|
+
|
|
1130
|
+
```javascript
|
|
1131
|
+
import { pdfHelper } from 'react-native-electron-platform/src/modules/';
|
|
1132
|
+
|
|
1133
|
+
// Generate from HTML
|
|
1134
|
+
pdfHelper.generate({
|
|
1135
|
+
content: '<h1>Invoice</h1><p>Total: $100</p>',
|
|
1136
|
+
outputPath: '/path/to/invoice.pdf'
|
|
1137
|
+
});
|
|
1138
|
+
|
|
1139
|
+
// Preview PDF
|
|
1140
|
+
pdfHelper.preview('/path/to/document.pdf');
|
|
1141
|
+
```
|
|
1142
|
+
|
|
1143
|
+
### Check for Updates
|
|
1144
|
+
|
|
1145
|
+
```javascript
|
|
1146
|
+
import { autoUpdater } from 'react-native-electron-platform/src/modules/';
|
|
1147
|
+
|
|
1148
|
+
autoUpdater.checkForUpdates();
|
|
1149
|
+
|
|
1150
|
+
autoUpdater.on('update-available', (info) => {
|
|
1151
|
+
console.log('New version available:', info.version);
|
|
1152
|
+
// Notify user
|
|
1153
|
+
});
|
|
1154
|
+
|
|
1155
|
+
autoUpdater.on('update-downloaded', () => {
|
|
1156
|
+
console.log('Update downloaded, will install on restart');
|
|
1157
|
+
// User can restart app to install
|
|
1158
|
+
});
|
|
1159
|
+
```
|
|
1160
|
+
|
|
1161
|
+
## 📞 Getting Help
|
|
1162
|
+
|
|
1163
|
+
### Common Questions
|
|
1164
|
+
|
|
1165
|
+
**Q: Can I use this with existing React Native projects?**
|
|
1166
|
+
A: Yes! Install the package and copy the configuration from example-project.
|
|
1167
|
+
|
|
1168
|
+
**Q: Does it work offline?**
|
|
1169
|
+
A: Electron apps work offline. Web requires internet for initial load. Use service workers for offline web.
|
|
1170
|
+
|
|
1171
|
+
**Q: Can I add native modules?**
|
|
1172
|
+
A: Yes for mobile (iOS/Android). Electron also supports native modules. Use platform detection.
|
|
1173
|
+
|
|
1174
|
+
**Q: How do I split code for different platforms?**
|
|
1175
|
+
A: Use platform extensions (`.web.js`, `.electron.js`) or import guards.
|
|
1176
|
+
|
|
1177
|
+
**Q: Is it production-ready?**
|
|
1178
|
+
A: Yes! Used in production by many organizations.
|
|
1179
|
+
|
|
1180
|
+
### Documentation Links
|
|
1181
|
+
|
|
1182
|
+
- **Getting Started:** [SETUP.md](SETUP.md)
|
|
1183
|
+
- **All Commands:** [CONFIGURATION.md](CONFIGURATION.md)
|
|
1184
|
+
- **Troubleshooting:** [USAGE.md#troubleshooting](USAGE.md#troubleshooting)
|
|
1185
|
+
- **Example Code:** [example-project/](example-project/)
|
|
1186
|
+
|
|
1187
|
+
### Community
|
|
1188
|
+
|
|
1189
|
+
- **GitHub Issues:** https://github.com/dpraful/react-native-electron-platform/issues
|
|
1190
|
+
- **GitHub Discussions:** https://github.com/dpraful/react-native-electron-platform/discussions
|
|
1191
|
+
|
|
1192
|
+
## 🤝 Contributing
|
|
63
1193
|
|
|
64
1194
|
Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.
|
|
65
1195
|
|