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 { 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 fs from 'fs';
|
||||
import path from 'path';
|
||||
@@ -321,3 +321,23 @@ app.on('window-all-closed', () => {
|
||||
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.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'),
|
||||
});
|
||||
Reference in New Issue
Block a user