mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(electron): app couldn't copy share links to clipboard
This commit is contained in:
+21
-1
@@ -1,5 +1,5 @@
|
|||||||
import './log.js';
|
import './log.js';
|
||||||
import { app, BrowserWindow, Menu, MenuItem, Tray, shell, dialog, nativeTheme, ipcMain } from 'electron';
|
import { app, BrowserWindow, Menu, MenuItem, Tray, shell, dialog, nativeTheme, ipcMain, clipboard } from 'electron';
|
||||||
import isDev from 'electron-is-dev';
|
import isDev from 'electron-is-dev';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
@@ -321,3 +321,23 @@ app.on('window-all-closed', () => {
|
|||||||
app.quit();
|
app.quit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle request to copy text to clipboard
|
||||||
|
ipcMain.handle('copy-to-clipboard', async (event, text) => {
|
||||||
|
try {
|
||||||
|
clipboard.writeText(text);
|
||||||
|
return { success: true };
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[Electron Main] Error copying to clipboard:', error);
|
||||||
|
return { success: false, error: error.message };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle request for platform info
|
||||||
|
ipcMain.handle('get-platform', async () => {
|
||||||
|
return {
|
||||||
|
platform: process.platform,
|
||||||
|
arch: process.arch,
|
||||||
|
version: process.version,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|||||||
@@ -16,4 +16,8 @@ contextBridge.exposeInMainWorld('defaultMediaIpfsGatewayUrl', 'http://localhost:
|
|||||||
ipcRenderer.on('plebbit-rpc-auth-key', (event, plebbitRpcAuthKey) => contextBridge.exposeInMainWorld('plebbitRpcAuthKey', plebbitRpcAuthKey));
|
ipcRenderer.on('plebbit-rpc-auth-key', (event, plebbitRpcAuthKey) => contextBridge.exposeInMainWorld('plebbitRpcAuthKey', plebbitRpcAuthKey));
|
||||||
ipcRenderer.send('get-plebbit-rpc-auth-key');
|
ipcRenderer.send('get-plebbit-rpc-auth-key');
|
||||||
|
|
||||||
contextBridge.exposeInMainWorld('electronApi', { isElectron: true });
|
contextBridge.exposeInMainWorld('electronApi', {
|
||||||
|
isElectron: true,
|
||||||
|
copyToClipboard: (text) => ipcRenderer.invoke('copy-to-clipboard', text),
|
||||||
|
getPlatform: () => ipcRenderer.invoke('get-platform'),
|
||||||
|
});
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { copyToClipboard } from './clipboard-utils';
|
||||||
|
|
||||||
export const getHostname = (url: string) => {
|
export const getHostname = (url: string) => {
|
||||||
try {
|
try {
|
||||||
return new URL(url).hostname.replace(/^www\./, '');
|
return new URL(url).hostname.replace(/^www\./, '');
|
||||||
@@ -15,12 +17,7 @@ export const isValidURL = (url: string) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const copyShareLinkToClipboard = (subplebbitAddress: string, cid: string) => {
|
export const copyShareLinkToClipboard = async (subplebbitAddress: string, cid: string) => {
|
||||||
const shareLink = `https://pleb.bz/p/${subplebbitAddress}/c/${cid}?redirect=plebchan.eth.limo`;
|
const shareLink = `https://pleb.bz/p/${subplebbitAddress}/c/${cid}?redirect=plebchan.app`;
|
||||||
|
await copyToClipboard(shareLink);
|
||||||
if (navigator.clipboard) {
|
|
||||||
navigator.clipboard.writeText(shareLink);
|
|
||||||
} else {
|
|
||||||
alert('Your browser does not support clipboard API');
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user