/** * ╔══════════════════════════════════════════════════════════════════════╗ * ║ 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'), });