1 import { ipcMain } from 'electron';
3 import type { ClipboardStoreProperties } from '@proton/pass/types/desktop';
4 import noop from '@proton/utils/noop';
6 import { clipboard } from '../../native';
7 import { store } from '../store';
9 export const setupIpcHandlers = () => {
10 let clipboardTimer: NodeJS.Timeout;
12 ipcMain.handle('clipboard:setConfig', (_, config: ClipboardStoreProperties) => store.set('clipboard', config));
13 ipcMain.handle('clipboard:getConfig', () => store.get('clipboard'));
15 ipcMain.handle('clipboard:writeText', (_event, text) => {
16 if (clipboardTimer !== undefined) clearTimeout(clipboardTimer);
18 clipboard.writeText(text, true).catch(noop);
20 const { timeoutMs } = store.get('clipboard') || {};
21 if (!timeoutMs || timeoutMs <= 0) return;
23 clipboardTimer = setTimeout(async () => {
24 const currentText = await clipboard.read();
25 if (currentText !== text) return;
26 clipboard.writeText('', true).catch(noop);