react-native-electron-platform 0.0.24 → 0.0.26
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/package.json +22 -2
- package/src/modules/ipcHandlers/fileOps.js +78 -0
- package/src/preload.mjs +9 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-electron-platform",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.26",
|
|
4
4
|
"description": "A boilerplate and utilities for running React Native applications in Electron",
|
|
5
5
|
"main": "index.mjs",
|
|
6
6
|
"scripts": {
|
|
@@ -9,10 +9,30 @@
|
|
|
9
9
|
},
|
|
10
10
|
"keywords": [
|
|
11
11
|
"react-native",
|
|
12
|
+
"react-native-desktop",
|
|
13
|
+
"react-native-electron",
|
|
12
14
|
"electron",
|
|
15
|
+
"electron-react-native",
|
|
13
16
|
"desktop",
|
|
17
|
+
"cross-platform",
|
|
18
|
+
"universal-app",
|
|
19
|
+
"react-native-web",
|
|
20
|
+
"react-native-windows",
|
|
21
|
+
"react-native-macos",
|
|
22
|
+
"desktop-app",
|
|
23
|
+
"desktop-framework",
|
|
24
|
+
"mobile-to-desktop",
|
|
25
|
+
"react-native-boilerplate",
|
|
26
|
+
"electron-boilerplate",
|
|
27
|
+
"multi-platform",
|
|
28
|
+
"android",
|
|
29
|
+
"ios",
|
|
30
|
+
"windows",
|
|
31
|
+
"macos",
|
|
32
|
+
"linux",
|
|
14
33
|
"web",
|
|
15
|
-
"
|
|
34
|
+
"javascript-framework",
|
|
35
|
+
"react-native-tooling"
|
|
16
36
|
],
|
|
17
37
|
"author": "PRAFULDAS M M",
|
|
18
38
|
"license": "JESCON TECHNOLOGIES PVT LTD",
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { ipcMain, dialog } from "electron";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import https from "https";
|
|
4
|
+
import http from "http";
|
|
5
|
+
import path from "path";
|
|
2
6
|
|
|
3
7
|
export function registerFileHandlers() {
|
|
8
|
+
|
|
9
|
+
// ======================================================
|
|
10
|
+
// SELECT FILE
|
|
11
|
+
// ======================================================
|
|
4
12
|
ipcMain.handle("select-file", async () => {
|
|
5
13
|
try {
|
|
6
14
|
const result = await dialog.showOpenDialog({
|
|
@@ -22,12 +30,82 @@ export function registerFileHandlers() {
|
|
|
22
30
|
status: "selected",
|
|
23
31
|
filePath: result.filePaths[0],
|
|
24
32
|
};
|
|
33
|
+
|
|
25
34
|
} catch (err) {
|
|
35
|
+
|
|
26
36
|
console.error("select-file error:", err);
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
status: "error",
|
|
40
|
+
message: err.message,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// ======================================================
|
|
47
|
+
// UNIVERSAL FILE DOWNLOAD
|
|
48
|
+
// ======================================================
|
|
49
|
+
ipcMain.handle("download-file", async (_event, { url, filename }) => {
|
|
50
|
+
try {
|
|
51
|
+
|
|
52
|
+
const ext = path.extname(url) || "";
|
|
53
|
+
|
|
54
|
+
const { filePath } = await dialog.showSaveDialog({
|
|
55
|
+
title: "Save File",
|
|
56
|
+
defaultPath: filename || `download${ext}`,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
if (!filePath) {
|
|
60
|
+
return {
|
|
61
|
+
status: "cancelled",
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const protocol = url.startsWith("https") ? https : http;
|
|
66
|
+
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
|
|
69
|
+
const file = fs.createWriteStream(filePath);
|
|
70
|
+
|
|
71
|
+
protocol.get(url, (response) => {
|
|
72
|
+
|
|
73
|
+
response.pipe(file);
|
|
74
|
+
|
|
75
|
+
file.on("finish", () => {
|
|
76
|
+
|
|
77
|
+
file.close();
|
|
78
|
+
|
|
79
|
+
resolve({
|
|
80
|
+
status: "success",
|
|
81
|
+
filePath: filePath,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
}).on("error", (err) => {
|
|
87
|
+
|
|
88
|
+
console.error("download-file error:", err);
|
|
89
|
+
|
|
90
|
+
reject({
|
|
91
|
+
status: "error",
|
|
92
|
+
message: err.message,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
} catch (err) {
|
|
100
|
+
|
|
101
|
+
console.error("download-file error:", err);
|
|
102
|
+
|
|
27
103
|
return {
|
|
28
104
|
status: "error",
|
|
29
105
|
message: err.message,
|
|
30
106
|
};
|
|
107
|
+
|
|
31
108
|
}
|
|
32
109
|
});
|
|
110
|
+
|
|
33
111
|
}
|
package/src/preload.mjs
CHANGED
|
@@ -46,6 +46,15 @@ contextBridge.exposeInMainWorld("electronAPI", {
|
|
|
46
46
|
*/
|
|
47
47
|
openURL: (url) => ipcRenderer.invoke('react-native-open-url', url),
|
|
48
48
|
|
|
49
|
+
/**
|
|
50
|
+
* UNIVERSAL FILE DOWNLOAD
|
|
51
|
+
* Supports csv, pdf, excel, images, zip, etc.
|
|
52
|
+
* @param {string} url - File URL
|
|
53
|
+
* @param {string} filename - Suggested filename
|
|
54
|
+
*/
|
|
55
|
+
downloadFile: (url, filename) =>
|
|
56
|
+
ipcRenderer.invoke("download-file", { url, filename }),
|
|
57
|
+
|
|
49
58
|
// ======================================================
|
|
50
59
|
// CLIPBOARD OPERATIONS
|
|
51
60
|
// ======================================================
|