diff --git a/dev-dist/registerSW.js b/dev-dist/registerSW.js new file mode 100644 index 00000000..fdeaac12 --- /dev/null +++ b/dev-dist/registerSW.js @@ -0,0 +1 @@ +if('serviceWorker' in navigator) navigator.serviceWorker.register('/dev-sw.js?dev-sw', { scope: '/', type: 'module' }) \ No newline at end of file diff --git a/electron/before-pack.js b/electron/before-pack.js index 4ad07cf7..1ceef74a 100644 --- a/electron/before-pack.js +++ b/electron/before-pack.js @@ -92,7 +92,7 @@ const download = async (url, destinationPath) => { } const split = url.split('/'); const fileName = split[split.length - 1]; - const dowloadPath = path.join(destinationPath, fileName); + const downloadPath = path.join(destinationPath, fileName); const file = await downloadWithRetry(url); fs.ensureDirSync(destinationPath); await fs.writeFile(binPath, file); @@ -111,14 +111,14 @@ const downloadAndExtract = async (url, destinationPath) => { console.log(`Downloading IPFS client from ${url} to ${destinationPath}`); const split = url.split('/'); const fileName = split[split.length - 1]; - const dowloadPath = path.join(destinationPath, fileName); + const downloadPath = path.join(destinationPath, fileName); const file = await downloadWithRetry(url); fs.ensureDirSync(destinationPath); - await fs.writeFile(dowloadPath, file); - console.log(`Downloaded archive to ${dowloadPath}`); - console.log(`Extracting ${dowloadPath} to ${destinationPath}`); + await fs.writeFile(downloadPath, file); + console.log(`Downloaded archive to ${downloadPath}`); + console.log(`Extracting ${downloadPath} to ${destinationPath}`); try { - await decompress(dowloadPath, destinationPath); + await decompress(downloadPath, destinationPath); console.log('Decompression complete'); } catch (err) { console.error('Error during decompression:', err); @@ -130,8 +130,7 @@ const downloadAndExtract = async (url, destinationPath) => { fs.moveSync(extractedBinPath, binPath); console.log('Binary moved'); console.log('Cleaning up temporary files'); - fs.removeSync(extractedPath); - fs.removeSync(dowloadPath); + fs.removeSync(downloadPath); console.log('Cleanup complete'); }; diff --git a/electron/main.js b/electron/main.js index a90c5d34..cc9b3775 100644 --- a/electron/main.js +++ b/electron/main.js @@ -1,5 +1,5 @@ import './log.js'; -import { app, BrowserWindow, Menu, MenuItem, Tray, screen as electronScreen, shell, dialog, nativeTheme, ipcMain } from 'electron'; +import { app, BrowserWindow, Menu, MenuItem, Tray, shell, dialog, nativeTheme, ipcMain } from 'electron'; import isDev from 'electron-is-dev'; import fs from 'fs'; import path from 'path'; @@ -8,8 +8,13 @@ import startIpfs from './start-ipfs.js'; import './start-plebbit-rpc.js'; import { URL, fileURLToPath } from 'node:url'; import contextMenu from 'electron-context-menu'; -import packageJson from '../package.json' with { type: 'json' }; -const dirname = path.join(path.dirname(fileURLToPath(import.meta.url))); + +// Determine __filename and dirname for ESM +const __filename = fileURLToPath(import.meta.url); +const dirname = path.dirname(__filename); + +// Load package.json dynamically +const packageJson = JSON.parse(fs.readFileSync(path.join(dirname, '../package.json'), 'utf-8')); let startIpfsError; startIpfs.onError = (error) => { @@ -78,7 +83,7 @@ const createMainWindow = () => { nodeIntegration: false, contextIsolation: true, devTools: true, // TODO: change to isDev when no bugs left - preload: path.join(dirname, 'preload.js'), + preload: path.join(dirname, '../build/electron/preload.cjs'), }, }); diff --git a/electron/preload.js b/electron/preload.mjs similarity index 71% rename from electron/preload.js rename to electron/preload.mjs index 40238671..f35cdc48 100644 --- a/electron/preload.js +++ b/electron/preload.mjs @@ -1,10 +1,11 @@ -const { contextBridge, ipcRenderer } = require('electron'); +import { contextBridge, ipcRenderer } from 'electron'; // dev uses http://localhost, prod uses file://...index.html const isDev = window.location.protocol === 'http:'; const defaultPlebbitOptions = { plebbitRpcClientsOptions: ['ws://localhost:9138'], + httpRoutersOptions: ['https://peers.pleb.bot', 'https://routing.lol', 'https://peers.forumindex.com', 'https://peers.plebpubsub.xyz'], }; contextBridge.exposeInMainWorld('isElectron', true); @@ -15,5 +16,4 @@ contextBridge.exposeInMainWorld('defaultMediaIpfsGatewayUrl', 'http://localhost: ipcRenderer.on('plebbit-rpc-auth-key', (event, plebbitRpcAuthKey) => contextBridge.exposeInMainWorld('plebbitRpcAuthKey', plebbitRpcAuthKey)); ipcRenderer.send('get-plebbit-rpc-auth-key'); -// uncomment for logs -// localStorage.debug = 'plebbit-js:*,plebbit-react-hooks:*,plebchan:*' +contextBridge.exposeInMainWorld('electronApi', { isElectron: true }); \ No newline at end of file diff --git a/electron/vite.preload.config.js b/electron/vite.preload.config.js new file mode 100644 index 00000000..fcfd9462 --- /dev/null +++ b/electron/vite.preload.config.js @@ -0,0 +1,27 @@ +import { defineConfig } from 'vite'; +import { resolve, dirname } from 'path'; +import { fileURLToPath } from 'url'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +export default defineConfig({ + resolve: { + conditions: ['node'], + }, + build: { + lib: { + entry: resolve(__dirname, 'preload.mjs'), + name: 'Preload', + fileName: () => 'preload.cjs', + formats: ['cjs'], + }, + outDir: resolve(__dirname, '../build/electron'), + emptyOutDir: true, + rollupOptions: { + external: ['electron'], + }, + target: 'node20', + minify: false, + }, +}); diff --git a/package.json b/package.json index 5a03137a..1a7dce2d 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "dependencies": { "@capacitor/app": "7.0.1", "@floating-ui/react": "0.26.1", - "@plebbit/plebbit-react-hooks": "https://github.com/plebbit/plebbit-react-hooks.git#f760ce2f5961307c93517fed0257b425bbf38c30", + "@plebbit/plebbit-react-hooks": "https://github.com/plebbit/plebbit-react-hooks.git#39cd7c09f1675949193498891fc448f68e42742b", "@react-spring/web": "9.7.5", "@testing-library/jest-dom": "5.14.1", "@testing-library/react": "13.0.0", @@ -49,17 +49,18 @@ "scripts": { "start": "vite", "build": "cross-env PUBLIC_URL=./ GENERATE_SOURCEMAP=false vite build", + "build:preload": "vite build --config electron/vite.preload.config.js", "build-netlify": "cross-env NODE_OPTIONS=\"--max_old_space_size=4096\" PUBLIC_URL=./ GENERATE_SOURCEMAP=true VITE_COMMIT_REF=$COMMIT_REF CI='' vite build", "test": "vitest", "preview": "vite preview", - "analyze-bundle": "cross-env PUBLIC_URL=./ GENERATE_SOURCEMAP=true vite build && source-map-explorer 'build/assets/*.js'", - "electron": "yarn electron:before && electron .", + "analyze-bundle": "cross-env PUBLIC_URL=./ GENERATE_SOURCEMAP=true vite build && npx source-map-explorer 'build/assets/*.js'", + "electron": "yarn build:preload && cross-env ELECTRON_IS_DEV=1 yarn electron:before && cross-env ELECTRON_IS_DEV=1 electron .", "electron:no-delete-data": "yarn electron:before:download-ipfs && electron .", "electron:start": "concurrently \"cross-env BROWSER=none yarn start\" \"wait-on http://localhost:3000 && yarn electron\"", "electron:start:no-delete-data": "concurrently \"cross-env BROWSER=none yarn start\" \"wait-on http://localhost:3000 && yarn electron:no-delete-data\"", - "electron:build:linux": "yarn build && electron-rebuild && electron-builder build --publish never -l", - "electron:build:windows": "yarn build && yarn electron-rebuild && electron-builder build --publish never -w", - "electron:build:mac": "yarn build && yarn electron-rebuild && electron-builder build --publish never -m", + "electron:build:linux": "yarn build && yarn build:preload && electron-rebuild && electron-builder build --publish never -l", + "electron:build:windows": "yarn build && yarn build:preload && yarn electron-rebuild && electron-builder build --publish never -w", + "electron:build:mac": "yarn build && yarn build:preload && yarn electron-rebuild && electron-builder build --publish never -m", "electron:before": "yarn electron-rebuild && yarn electron:before:download-ipfs && yarn electron:before:delete-data", "electron:before:download-ipfs": "node electron/download-ipfs", "electron:before:delete-data": "rimraf .plebbit", @@ -112,12 +113,15 @@ "isomorphic-fetch": "3.0.0", "lint-staged": "12.3.8", "stream-browserify": "3.0.0", - "vite": "6.2.0", + "vite": "6.2.1", "vite-plugin-eslint": "1.8.1", "vite-plugin-node-polyfills": "0.23.0", "vite-plugin-pwa": "0.21.1", "wait-on": "7.0.1" }, + "resolutions": { + "@bonfida/spl-name-service": "3.0.0" + }, "main": "electron/main.js", "build": { "appId": "plebchan.desktop", diff --git a/src/components/catalog-row/catalog-row.tsx b/src/components/catalog-row/catalog-row.tsx index 5cc50d22..a381021f 100644 --- a/src/components/catalog-row/catalog-row.tsx +++ b/src/components/catalog-row/catalog-row.tsx @@ -242,7 +242,7 @@ const CatalogPost = ({ post }: { post: Comment }) => { ) : hasThumbnail ? ( <> - {shouldShowSnow() && hasThumbnail && } + {shouldShowSnow() && hasThumbnail && }
)}
- {shouldShowSnow() && hasThumbnail && } + {shouldShowSnow() && hasThumbnail && } {link && !isHidden && !(deleted || removed) && isValidURL(link) && ( - {shouldShowSnow() && } + {shouldShowSnow() && }
diff --git a/src/components/settings-modal/account-settings/account-settings.tsx b/src/components/settings-modal/account-settings/account-settings.tsx index 3d360b58..f7b06134 100644 --- a/src/components/settings-modal/account-settings/account-settings.tsx +++ b/src/components/settings-modal/account-settings/account-settings.tsx @@ -228,7 +228,7 @@ const AccountSettings = () => {
{t('stored_locally', { - location: window.isElectron ? 'this desktop app' : isAndroid ? 'this mobile app' : window.location.hostname, + location: window.electronApi?.isElectron ? 'this desktop app' : isAndroid ? 'this mobile app' : window.location.hostname, interpolation: { escapeValue: false }, })}
diff --git a/src/components/settings-modal/interface-settings/interface-settings.tsx b/src/components/settings-modal/interface-settings/interface-settings.tsx index 81c17939..b671c104 100644 --- a/src/components/settings-modal/interface-settings/interface-settings.tsx +++ b/src/components/settings-modal/interface-settings/interface-settings.tsx @@ -13,7 +13,7 @@ import { isChristmas } from '../../../lib/utils/time-utils'; import Version from '../../version'; const commitRef = process.env.VITE_COMMIT_REF; -const isElectron = window.isElectron === true; +const isElectron = window.electronApi?.isElectron === true; const CheckForUpdates = () => { const { t } = useTranslation(); diff --git a/src/components/settings-modal/plebbit-options/plebbit-options.tsx b/src/components/settings-modal/plebbit-options/plebbit-options.tsx index b6ccb5ae..cb5973ae 100644 --- a/src/components/settings-modal/plebbit-options/plebbit-options.tsx +++ b/src/components/settings-modal/plebbit-options/plebbit-options.tsx @@ -37,7 +37,15 @@ const IPFSGatewaysSettings = ({ ipfsGatewayUrlsRef, mediaIpfsGatewayUrlRef }: Se
NFT profile pics gateway
- +
); @@ -53,7 +61,15 @@ const PubsubProvidersSettings = ({ pubsubProvidersRef }: SettingsProps) => { return (
-