File size: 6,124 Bytes
e07a303
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6e41605
 
 
 
 
 
e07a303
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6e41605
 
 
 
 
 
e07a303
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/**

 * ╔══════════════════════════════════════════════════════════════════════╗

 * ║          CHAHUADEV HUB — Secure Preload Bridge (Context Isolation)  ║

 * ║                    IPC Gateway Pattern                               ║

 * ╚══════════════════════════════════════════════════════════════════════╝

 *

 * @author    Chahuadev

 * @license   NON-COMMERCIAL & ACCEPTABLE USE ONLY.

 *            Strictly prohibited for sale or malicious activities.

 *            See LICENSE.md for full terms.

 *

 * SECURITY:

 *   ✓ contextBridge only — no direct Node.js access from renderer

 *   ✓ All IPC calls validated in main process before execution

 *   ✓ Only whitelisted channels exposed

 */



'use strict';

const { contextBridge, ipcRenderer } = require('electron');

contextBridge.exposeInMainWorld('chahuadevHub', {

  // ── Info ────────────────────────────────────────────────────────────────//
  getDownloadDir: () =>
    ipcRenderer.invoke('get-download-dir'),

  isDev: () =>
    ipcRenderer.invoke('get-is-dev'),

  // ── Data fetching ────────────────────────────────────────────────────────
  fetchDashboard: () =>
    ipcRenderer.invoke('fetch-dashboard'),

  fetchFiles: () =>
    ipcRenderer.invoke('fetch-files'),

  fetchChangelog: () =>
    ipcRenderer.invoke('fetch-changelog'),

  fetchAllRepos: () =>
    ipcRenderer.invoke('fetch-all-repos'),

  fetchRepoCommits: (repoId, repoType) =>
    ipcRenderer.invoke('fetch-repo-commits', repoId, repoType),

  fetchRepoTree: (repoId, repoType, options) =>
    ipcRenderer.invoke('fetch-repo-tree', repoId, repoType, options),

  fetchRepoFile: (repoId, repoType, repoPath) =>
    ipcRenderer.invoke('fetch-repo-file', repoId, repoType, repoPath),

  openRepoFileEditor: (repoId, repoType, repoPath) =>
    ipcRenderer.invoke('open-repo-file-editor', repoId, repoType, repoPath),

  fetchNpmPackages: () =>
    ipcRenderer.invoke('fetch-npm-packages'),

  // ── Download ─────────────────────────────────────────────────────────────
  downloadFile: (filePath, fileSize) =>
    ipcRenderer.invoke('download-file', filePath, fileSize),

  // ── Progress events ───────────────────────────────────────────────────────
  onDownloadProgress: (callback) => {
    ipcRenderer.on('download-progress', (_event, filePath, downloaded, total, pct) => {
      callback({ filePath, received: downloaded, total, percent: pct });
    });
  },

  removeDownloadProgressListeners: () => {
    ipcRenderer.removeAllListeners('download-progress');
  },

  // ── Shell actions ─────────────────────────────────────────────────────────
  checkFileExists: (filePath) =>
    ipcRenderer.invoke('check-file-exists', filePath),

  // ── Update detection ──────────────────────────────────────────────────────
  // Save {version, releaseDate} sidecar after a successful download
  saveFileMeta: (filePath, meta) =>
    ipcRenderer.invoke('save-file-meta', filePath, meta),

  // Read sidecar — returns {version, releaseDate} or null
  getFileMeta: (filePath) =>
    ipcRenderer.invoke('get-file-meta', filePath),

  openFile: (filePath, expectedHash) =>
    ipcRenderer.invoke('open-file', filePath, expectedHash),

  openFileFolder: (filePath) =>
    ipcRenderer.invoke('open-file-folder', filePath),

  openDownloads: () =>
    ipcRenderer.invoke('open-downloads'),

  openExternalUrl: (url) =>
    ipcRenderer.invoke('open-external-url', url),

  // ── App self-update ──────────────────────────────────────────────────────────────
  getAppVersion: () =>
    ipcRenderer.invoke('get-app-version'),

  checkAppUpdate: () =>
    ipcRenderer.invoke('check-app-update'),

  updater: {
    getChannel: () => ipcRenderer.invoke('updater:get-channel'),
    getStatus: () => ipcRenderer.invoke('updater:get-status'),
    checkNow: () => ipcRenderer.invoke('updater:check-now')
  },

  // Run npm install -g @chahuadev/chahuadev-hub-app in background
  // Command is hardcoded in main process — cannot be overridden from renderer
  npmSelfUpdate: () =>
    ipcRenderer.invoke('npm-self-update'),

  onNpmUpdateLog: (callback) =>
    ipcRenderer.on('npm-update-log', (_e, line) => callback(line)),

  removeNpmUpdateLogListeners: () =>
    ipcRenderer.removeAllListeners('npm-update-log'),

  relaunchApp: () =>
    ipcRenderer.invoke('relaunch-app'),

  npmGetInstallPath: (pkgName) =>
    ipcRenderer.invoke('npm-get-install-path', pkgName),

  openNpmPkgFolder: (pkgName) =>
    ipcRenderer.invoke('open-npm-folder', pkgName),

  // Install any whitelisted npm package globally (command locked in main)
  npmInstallPackage: (pkgName) =>
    ipcRenderer.invoke('npm-install-package', pkgName),

  onNpmInstallLog: (callback) =>
    ipcRenderer.on('npm-install-log', (_e, line) => callback(line)),

  removeNpmInstallLogListeners: () =>
    ipcRenderer.removeAllListeners('npm-install-log'),

});