refactor(core): remove legacy plebbit terminology

This commit is contained in:
Tommaso Casaburi
2026-04-17 10:48:27 +07:00
parent e366dac25c
commit ee7a5b5778
158 changed files with 626 additions and 836 deletions
-6
View File
@@ -12,12 +12,6 @@ const ipfsClientMacPath = path.join(ipfsClientsPath, 'mac');
const ipfsClientLinuxPath = path.join(ipfsClientsPath, 'linux');
const kuboReleaseBaseUrl = 'https://github.com/ipfs/kubo/releases/download';
// plebbit kubo download links https://github.com/plebbit/kubo/releases
// const ipfsClientVersion = '0.20.0'
// const ipfsClientWindowsUrl = `https://github.com/plebbit/kubo/releases/download/v${ipfsClientVersion}/ipfs-windows-amd64`
// const ipfsClientMacUrl = `https://github.com/plebbit/kubo/releases/download/v${ipfsClientVersion}/ipfs-darwin-amd64`
// const ipfsClientLinuxUrl = `https://github.com/plebbit/kubo/releases/download/v${ipfsClientVersion}/ipfs-linux-amd64`
const ipfsClientVersion = '0.39.0';
// Resolve desired build arch: allow overriding via env (so cross-arch builds pick correct binary)
+6 -6
View File
@@ -3,18 +3,18 @@
import util from 'util';
import fs from 'fs-extra';
import path from 'path';
import EnvPaths from 'env-paths';
const envPaths = EnvPaths('plebbit', { suffix: false });
import { getPkcLogPath } from './pkc-paths.js';
const logRootPath = getPkcLogPath();
// previous version created a file instead of folder
// we should remove this at some point
try {
if (fs.lstatSync(envPaths.log).isFile()) {
fs.removeSync(envPaths.log);
if (fs.lstatSync(logRootPath).isFile()) {
fs.removeSync(logRootPath);
}
} catch (e) {}
const logFilePath = path.join(envPaths.log, new Date().toISOString().substring(0, 7));
const logFilePath = path.join(logRootPath, new Date().toISOString().substring(0, 7));
fs.ensureFileSync(logFilePath);
const logFile = fs.createWriteStream(logFilePath, { flags: 'a' });
const writeLog = (...args) => {
@@ -54,4 +54,4 @@ console.debug = (...args) => {
process.on('uncaughtException', console.error);
process.on('unhandledRejection', console.error);
console.log(envPaths);
console.log({ logRootPath });
+6 -6
View File
@@ -5,11 +5,11 @@ import { downloadAndInstallUpdate } from './app-updater.js';
import isDev from 'electron-is-dev';
import fs from 'fs';
import path from 'path';
import EnvPaths from 'env-paths';
import startIpfs from './start-ipfs.js';
import './start-plebbit-rpc.js';
import './start-pkc-rpc.js';
import { URL, fileURLToPath } from 'node:url';
import contextMenu from 'electron-context-menu';
import { getPkcDataPath } from './pkc-paths.js';
// Determine __filename and dirname for ESM
const __filename = fileURLToPath(import.meta.url);
@@ -39,10 +39,10 @@ startIpfs.onError = (error) => {
}
};
// send plebbit rpc auth key to renderer
const plebbitDataPath = !isDev ? EnvPaths('plebbit', { suffix: false }).data : path.join(dirname, '..', '.plebbit');
const plebbitRpcAuthKey = fs.readFileSync(path.join(plebbitDataPath, 'auth-key'), 'utf8');
ipcMain.on('get-plebbit-rpc-auth-key', (event) => event.reply('plebbit-rpc-auth-key', plebbitRpcAuthKey));
// Send the local PKC RPC auth key to the isolated renderer bridge.
const pkcDataPath = getPkcDataPath({ isDev, projectRoot: path.join(dirname, '..') });
const pkcRpcAuthKey = fs.readFileSync(path.join(pkcDataPath, 'auth-key'), 'utf8');
ipcMain.on('get-pkc-rpc-auth-key', (event) => event.reply('pkc-rpc-auth-key', pkcRpcAuthKey));
// use common user agent instead of electron so img, video, audio, iframe elements don't get blocked
// https://www.whatismybrowser.com/guides/the-latest-version/chrome
+13
View File
@@ -0,0 +1,13 @@
import path from 'path';
import EnvPaths from 'env-paths';
const PKC_APP_NAME = 'pkc';
const PKC_DEV_DATA_DIR = '.pkc';
export const getDevPkcDataPath = (projectRoot) => path.join(projectRoot, PKC_DEV_DATA_DIR);
const getProductionPkcDataPath = () => EnvPaths(PKC_APP_NAME, { suffix: false }).data;
export const getPkcLogPath = () => EnvPaths(PKC_APP_NAME, { suffix: false }).log;
export const getPkcDataPath = ({ isDev, projectRoot }) => (isDev ? getDevPkcDataPath(projectRoot) : getProductionPkcDataPath());
+6 -6
View File
@@ -3,18 +3,18 @@ import { contextBridge, ipcRenderer, webUtils } from 'electron';
// dev uses http://localhost, prod uses file://...index.html
const isDev = window.location.protocol === 'http:';
const defaultPlebbitOptions = {
plebbitRpcClientsOptions: ['ws://localhost:9138'],
const defaultPkcOptions = {
pkcRpcClientsOptions: ['ws://localhost:9138'],
httpRoutersOptions: ['https://peers.pleb.bot', 'https://routing.lol', 'https://peers.forumindex.com', 'https://peers.plebpubsub.xyz'],
};
contextBridge.exposeInMainWorld('isElectron', true);
contextBridge.exposeInMainWorld('defaultPlebbitOptions', defaultPlebbitOptions);
contextBridge.exposeInMainWorld('defaultPkcOptions', defaultPkcOptions);
contextBridge.exposeInMainWorld('defaultMediaIpfsGatewayUrl', 'http://localhost:6473');
// receive plebbit rpc auth key from main
ipcRenderer.on('plebbit-rpc-auth-key', (event, plebbitRpcAuthKey) => contextBridge.exposeInMainWorld('plebbitRpcAuthKey', plebbitRpcAuthKey));
ipcRenderer.send('get-plebbit-rpc-auth-key');
// receive PKC RPC auth key from main
ipcRenderer.on('pkc-rpc-auth-key', (event, pkcRpcAuthKey) => contextBridge.exposeInMainWorld('pkcRpcAuthKey', pkcRpcAuthKey));
ipcRenderer.send('get-pkc-rpc-auth-key');
contextBridge.exposeInMainWorld('electronApi', {
isElectron: true,
+3 -3
View File
@@ -5,10 +5,10 @@ import fs from 'fs-extra';
import ps from 'node:process';
import proxyServer from './proxy-server.js';
import tcpPortUsed from 'tcp-port-used';
import EnvPaths from 'env-paths';
import { fileURLToPath, pathToFileURL } from 'url';
import { getPkcDataPath } from './pkc-paths.js';
const dirname = path.join(path.dirname(fileURLToPath(import.meta.url)));
const envPaths = EnvPaths('plebbit', { suffix: false });
const projectRoot = path.join(dirname, '..');
// Get platform-specific binary name
const getIpfsBinaryName = () => (process.platform === 'win32' ? 'ipfs.exe' : 'ipfs');
@@ -112,7 +112,7 @@ const spawnAsync = (...args) =>
const startIpfs = async () => {
const ipfsPath = await getKuboPath();
const ipfsDataPath = isDev ? path.join(dirname, '..', '.plebbit', 'ipfs') : path.join(envPaths.data, 'ipfs');
const ipfsDataPath = path.join(getPkcDataPath({ isDev, projectRoot }), 'ipfs');
if (!fs.existsSync(ipfsPath)) {
throw Error(`ipfs binary '${ipfsPath}' doesn't exist`);
+67
View File
@@ -0,0 +1,67 @@
import tcpPortUsed from 'tcp-port-used';
import { randomBytes } from 'crypto';
import fs from 'fs-extra';
import PKCRpc from '@pkcprotocol/pkc-js/rpc';
import path from 'path';
import { fileURLToPath } from 'url';
import isDev from 'electron-is-dev';
import { getPkcDataPath } from './pkc-paths.js';
const dirname = path.join(path.dirname(fileURLToPath(import.meta.url)));
const projectRoot = path.join(dirname, '..');
// Always run the local PKC RPC server on this port so all desktop clients can reuse it.
const port = 9138;
const defaultPkcOptions = {
// find the user's OS data path
dataPath: getPkcDataPath({ isDev, projectRoot }),
kuboRpcClientsOptions: [{ url: 'http://localhost:50019/api/v0' }],
httpRoutersOptions: ['https://routing.lol', 'https://peers.pleb.bot', 'https://peers.plebpubsub.xyz', 'https://peers.forumindex.com'],
};
// Generate the local PKC RPC auth key if it does not exist yet.
const pkcRpcAuthKeyPath = path.join(defaultPkcOptions.dataPath, 'auth-key');
let pkcRpcAuthKey;
try {
pkcRpcAuthKey = fs.readFileSync(pkcRpcAuthKeyPath, 'utf8');
} catch (e) {
pkcRpcAuthKey = randomBytes(32).toString('base64').replace(/[/+=]/g, '').substring(0, 40);
fs.ensureFileSync(pkcRpcAuthKeyPath);
fs.writeFileSync(pkcRpcAuthKeyPath, pkcRpcAuthKey);
}
const startPkcRpcAutoRestart = async () => {
let pendingStart = false;
const start = async () => {
if (pendingStart) {
return;
}
pendingStart = true;
try {
const started = await tcpPortUsed.check(port, '127.0.0.1');
if (!started) {
const pkcWebSocketServer = await PKCRpc.PKCWsServer({ port, pkc: defaultPkcOptions, authKey: pkcRpcAuthKey });
pkcWebSocketServer.on('error', (e) => console.log('pkc rpc error', e));
console.log(`pkc rpc: listening on ws://localhost:${port} (local connections only)`);
console.log(`pkc rpc: listening on ws://localhost:${port}/${pkcRpcAuthKey} (secret auth key for remote connections)`);
pkcWebSocketServer.ws.on('connection', (socket, request) => {
console.log('pkc rpc: new connection');
// debug raw JSON RPC messages in console
if (isDev) {
socket.on('message', (message) => console.log(`pkc rpc: ${message.toString()}`));
}
});
}
} catch (e) {
console.log('failed starting pkc rpc server', e);
}
pendingStart = false;
};
// Retry every second in case another client briefly owned the shared local server.
start();
setInterval(() => {
start();
}, 1000);
};
startPkcRpcAutoRestart();
-68
View File
@@ -1,68 +0,0 @@
import tcpPortUsed from 'tcp-port-used';
import EnvPaths from 'env-paths';
import { randomBytes } from 'crypto';
import fs from 'fs-extra';
import PlebbitRpc from '@pkcprotocol/pkc-js/rpc';
import path from 'path';
import { fileURLToPath } from 'url';
import isDev from 'electron-is-dev';
const dirname = path.join(path.dirname(fileURLToPath(import.meta.url)));
const envPaths = EnvPaths('plebbit', { suffix: false });
// PLEB, always run plebbit rpc on this port so all clients can use it
const port = 9138;
const defaultPlebbitOptions = {
// find the user's OS data path
dataPath: !isDev ? envPaths.data : path.join(dirname, '..', '.plebbit'),
kuboRpcClientsOptions: [{ url: 'http://localhost:50019/api/v0' }],
httpRoutersOptions: ['https://routing.lol', 'https://peers.pleb.bot', 'https://peers.plebpubsub.xyz', 'https://peers.forumindex.com'],
};
// generate plebbit rpc auth key if doesn't exist
const plebbitRpcAuthKeyPath = path.join(defaultPlebbitOptions.dataPath, 'auth-key');
let plebbitRpcAuthKey;
try {
plebbitRpcAuthKey = fs.readFileSync(plebbitRpcAuthKeyPath, 'utf8');
} catch (e) {
plebbitRpcAuthKey = randomBytes(32).toString('base64').replace(/[/+=]/g, '').substring(0, 40);
fs.ensureFileSync(plebbitRpcAuthKeyPath);
fs.writeFileSync(plebbitRpcAuthKeyPath, plebbitRpcAuthKey);
}
const startPlebbitRpcAutoRestart = async () => {
let pendingStart = false;
const start = async () => {
if (pendingStart) {
return;
}
pendingStart = true;
try {
const started = await tcpPortUsed.check(port, '127.0.0.1');
if (!started) {
const plebbitWebSocketServer = await PlebbitRpc.PlebbitWsServer({ port, plebbitOptions: defaultPlebbitOptions, authKey: plebbitRpcAuthKey });
plebbitWebSocketServer.on('error', (e) => console.log('plebbit rpc error', e));
console.log(`plebbit rpc: listening on ws://localhost:${port} (local connections only)`);
console.log(`plebbit rpc: listening on ws://localhost:${port}/${plebbitRpcAuthKey} (secret auth key for remote connections)`);
plebbitWebSocketServer.ws.on('connection', (socket, request) => {
console.log('plebbit rpc: new connection');
// debug raw JSON RPC messages in console
if (isDev) {
socket.on('message', (message) => console.log(`plebbit rpc: ${message.toString()}`));
}
});
}
} catch (e) {
console.log('failed starting plebbit rpc server', e);
}
pendingStart = false;
};
// retry starting the plebbit rpc server every 1 second,
// in case it was started by another client that shut down and shut down the server with it
start();
setInterval(() => {
start();
}, 1000);
};
startPlebbitRpcAutoRestart();