Merge branch 'development' into master

This commit is contained in:
plebeius
2025-05-22 17:51:10 +02:00
committed by GitHub
18 changed files with 144 additions and 47 deletions
+1
View File
@@ -0,0 +1 @@
if('serviceWorker' in navigator) navigator.serviceWorker.register('/dev-sw.js?dev-sw', { scope: '/', type: 'module' })
+7 -8
View File
@@ -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');
};
+9 -4
View File
@@ -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'),
},
});
+3 -3
View File
@@ -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 });
+27
View File
@@ -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,
},
});
+11 -7
View File
@@ -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",
+1 -1
View File
@@ -242,7 +242,7 @@ const CatalogPost = ({ post }: { post: Comment }) => {
</Link>
) : hasThumbnail ? (
<>
{shouldShowSnow() && hasThumbnail && <img src={`${process.env.PUBLIC_URL}/assets/xmashat.gif`} className={styles.xmasHat} alt='' />}
{shouldShowSnow() && hasThumbnail && <img src='assets/xmashat.gif' className={styles.xmasHat} alt='' />}
<Link to={postLink}>
<div
className={`${styles.mediaPaddingWrapper} ${hidden && styles.hidden}`}
+1 -1
View File
@@ -401,7 +401,7 @@ const PostDesktop = ({ post, roles, showAllReplies, showReplies = true }: PostPr
</span>
)}
<div data-cid={cid} data-author-address={author?.shortAddress} data-post-cid={postCid} className={shouldShowSnow() && hasThumbnail ? styles.xmasHatWrapper : ''}>
{shouldShowSnow() && hasThumbnail && <img src={`${process.env.PUBLIC_URL}/assets/xmashat.gif`} className={styles.xmasHat} alt='' />}
{shouldShowSnow() && hasThumbnail && <img src='assets/xmashat.gif' className={styles.xmasHat} alt='' />}
{link && !isHidden && !(deleted || removed) && isValidURL(link) && (
<PostMedia
commentMediaInfo={commentMediaInfo}
+1 -1
View File
@@ -336,7 +336,7 @@ const PostMobile = ({ post, roles, showAllReplies, showReplies = true }: PostPro
data-author-address={author?.shortAddress}
data-post-cid={postCid}
>
{shouldShowSnow() && <img src={`${process.env.PUBLIC_URL}/assets/xmashat.gif`} className={styles.xmasHat} alt='' />}
{shouldShowSnow() && <img src='assets/xmashat.gif' className={styles.xmasHat} alt='' />}
<PostInfoAndMedia post={post} postReplyCount={replyCount} roles={roles} />
<CommentContent comment={post} />
</div>
@@ -228,7 +228,7 @@ const AccountSettings = () => {
<button onClick={handleImportAccount}>{t('import')}</button> <button onClick={handleExportAccount}>{t('export')}</button>
<div className={styles.warning}>
{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 },
})}
</div>
@@ -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();
@@ -37,7 +37,15 @@ const IPFSGatewaysSettings = ({ ipfsGatewayUrlsRef, mediaIpfsGatewayUrlRef }: Se
</div>
<span className={styles.settingTip}>NFT profile pics gateway</span>
<div>
<input type='text' defaultValue={mediaIpfsGatewayUrl} ref={mediaIpfsGatewayUrlRef} disabled={isConnectedToRpc} />
<input
type='text'
defaultValue={mediaIpfsGatewayUrl}
ref={mediaIpfsGatewayUrlRef}
disabled={isConnectedToRpc}
autoCorrect='off'
autoCapitalize='off'
spellCheck='false'
/>
</div>
</div>
);
@@ -53,7 +61,15 @@ const PubsubProvidersSettings = ({ pubsubProvidersRef }: SettingsProps) => {
return (
<div className={styles.pubsubProvidersSettings}>
<textarea defaultValue={pubsubProvidersDefaultValue} ref={pubsubProvidersRef} disabled={isConnectedToRpc} autoCorrect='off' autoComplete='off' spellCheck='false' />
<textarea
defaultValue={pubsubProvidersDefaultValue}
ref={pubsubProvidersRef}
disabled={isConnectedToRpc}
autoCorrect='off'
autoCapitalize='off'
autoComplete='off'
spellCheck='false'
/>
</div>
);
};
@@ -98,7 +114,7 @@ const PlebbitRPCSettings = ({ plebbitRpcRef }: SettingsProps) => {
return (
<div className={styles.plebbitRPCSettings}>
<div>
<input type='text' defaultValue={plebbitRpcClientsOptions} ref={plebbitRpcRef} />
<input type='text' defaultValue={plebbitRpcClientsOptions} ref={plebbitRpcRef} autoCorrect='off' autoCapitalize='off' spellCheck='false' />
<button onClick={() => setShowInfo(!showInfo)}>{showInfo ? 'X' : '?'}</button>
</div>
{showInfo && (
@@ -123,18 +139,18 @@ const PlebbitDataPathSettings = ({ plebbitDataPathRef }: SettingsProps) => {
const plebbitRpc = usePlebbitRpcSettings();
const { plebbitRpcSettings } = plebbitRpc || {};
const isConnectedToRpc = plebbitRpc?.state === 'succeeded';
const path = plebbitRpcSettings?.plebbitOptions?.plebbitDataPath || '';
const path = plebbitRpcSettings?.plebbitOptions?.dataPath || '';
return (
<div className={styles.plebbitDataPathSettings}>
<div>
<input type='text' defaultValue={path} disabled={!isConnectedToRpc} ref={plebbitDataPathRef} />
<input autoCorrect='off' autoCapitalize='off' spellCheck='false' type='text' defaultValue={path} disabled={!isConnectedToRpc} ref={plebbitDataPathRef} />
</div>
</div>
);
};
const isElectron = window.isElectron === true;
const isElectron = window.electronApi?.isElectron === true;
const PlebbitOptions = () => {
const { t } = useTranslation();
+3 -4
View File
@@ -2,12 +2,11 @@ import { useTranslation } from 'react-i18next';
import packageJson from '../../../package.json';
const { version } = packageJson;
const commitRef = process.env.VITE_COMMIT_REF;
const isElectron = window.isElectron === true;
const commitRef = import.meta.env.VITE_COMMIT_REF;
const isElectron = window.electronApi?.isElectron === true;
const Version = () => {
const { t } = useTranslation();
return (
<>
<a
@@ -15,7 +14,7 @@ const Version = () => {
target='_blank'
rel='noopener noreferrer'
>
plebchan v{commitRef ? `${version}-dev (#${commitRef.slice(0, 7)})` : version}
v{commitRef ? `${version}#${commitRef.slice(0, 7)}` : version}
</a>
{isElectron && (
<>
+9
View File
@@ -0,0 +1,9 @@
/// <reference types="vite/client" />
declare interface ImportMetaEnv {
readonly VITE_COMMIT_REF: string;
}
declare interface ImportMeta {
readonly env: ImportMetaEnv;
}
+12
View File
@@ -4,4 +4,16 @@ declare global {
}
}
declare global {
interface Window {
electronApi?: {
isElectron: boolean;
invoke: (channel: string, ...args: any[]) => Promise<any>;
getNotificationStatus: () => Promise<'granted' | 'denied' | 'not-determined' | 'not-supported'>;
getPlatform: () => Promise<NodeJS.Platform>;
testNotification: () => Promise<{ success: boolean; reason?: string }>;
};
}
}
export {};
+15
View File
@@ -0,0 +1,15 @@
/// <reference lib="webworker" />
/* eslint-disable no-restricted-globals */
import { clientsClaim } from 'workbox-core';
import { precacheAndRoute, cleanupOutdatedCaches } from 'workbox-precaching';
declare const self: ServiceWorkerGlobalScope;
// Precache all assets specified in the manifest
cleanupOutdatedCaches();
precacheAndRoute(self.__WB_MANIFEST);
// Standard SW lifecycle methods
self.skipWaiting();
clientsClaim();
+10
View File
@@ -37,6 +37,16 @@ export default defineConfig({
VitePWA({
strategies: 'generateSW',
registerType: 'autoUpdate',
strategies: 'injectManifest',
injectManifest: {
maximumFileSizeToCacheInBytes: 6000000,
},
srcDir: 'src',
filename: 'sw.ts',
devOptions: {
enabled: true,
type: 'module',
},
includeAssets: ['favicon.ico', 'robots.txt', 'apple-touch-icon.png'],
injectManifest: {
maximumFileSizeToCacheInBytes: 6000000,
+10 -10
View File
@@ -1084,10 +1084,10 @@
bs58 "5.0.0"
buffer "^6.0.3"
"@bonfida/spl-name-service@3.0.10":
version "3.0.10"
resolved "https://registry.yarnpkg.com/@bonfida/spl-name-service/-/spl-name-service-3.0.10.tgz#883f2e077eef7d91147f44ae383990a82479d5f8"
integrity sha512-CrqlEDz43K9fPIVaUXn29OiMWZUOs3+sxU7zHrlPjjdXn9GrJSVao5gjmflfK6tcwLxSSGC4F4GOg5erSfyR/A==
"@bonfida/spl-name-service@3.0.0", "@bonfida/spl-name-service@3.0.10":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@bonfida/spl-name-service/-/spl-name-service-3.0.0.tgz#2b1e187be46162be1b729a938deb162f8f08f386"
integrity sha512-kucOqVtABXOkUJS/GwfCjnDyDGEiXEn9G0wG4hGDZb2Yq1JJ+2pgHLtBPEt1ZAYcvWISHSnWJIh4JFjQ1o/GVQ==
dependencies:
"@bonfida/sns-records" "0.0.1"
"@noble/curves" "^1.4.0"
@@ -3671,9 +3671,9 @@
dependencies:
debug "4.3.4"
"@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":
version "0.0.1"
resolved "https://github.com/plebbit/plebbit-react-hooks.git#f760ce2f5961307c93517fed0257b425bbf38c30"
resolved "https://github.com/plebbit/plebbit-react-hooks.git#39cd7c09f1675949193498891fc448f68e42742b"
dependencies:
"@plebbit/plebbit-js" "https://github.com/plebbit/plebbit-js.git#a2cb6ca6462b2e2e3b66f71204375a81ed05cf80"
"@plebbit/plebbit-logger" "https://github.com/plebbit/plebbit-logger.git"
@@ -15369,10 +15369,10 @@ vite-plugin-pwa@0.21.1:
workbox-build "^7.3.0"
workbox-window "^7.3.0"
vite@6.2.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/vite/-/vite-6.2.0.tgz#9dcb543380dab18d8384eb840a76bf30d78633f0"
integrity sha512-7dPxoo+WsT/64rDcwoOjk76XHj+TqNTIvHKcuMQ1k4/SeHDaQt5GFAeLYzrimZrMpn/O6DtdI03WUjdxuPM0oQ==
vite@6.2.1:
version "6.2.1"
resolved "https://registry.yarnpkg.com/vite/-/vite-6.2.1.tgz#ae865d4bb93a11844be1bc647c8b2dd1856ea180"
integrity sha512-n2GnqDb6XPhlt9B8olZPrgMD/es/Nd1RdChF6CBD/fHW6pUyUTt2sQW2fPRX5GiD9XEa6+8A6A4f2vT6pSsE7Q==
dependencies:
esbuild "^0.25.0"
postcss "^8.5.3"