mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-20 02:08:57 +00:00
Add clipboard utility to copy text temporarily
Co-authored-by: trevor-signal <131492920+trevor-signal@users.noreply.github.com>
This commit is contained in:
@@ -760,6 +760,8 @@ export async function startApp(): Promise<void> {
|
||||
|
||||
flushMessageCounter();
|
||||
|
||||
window.SignalClipboard.clearIfNeeded();
|
||||
|
||||
// Hangup active calls
|
||||
calling.hangupAllCalls({
|
||||
excludeRinging: true,
|
||||
|
||||
@@ -35,6 +35,7 @@ import type {
|
||||
} from '../util/os/promptOSAuthMain.main.js';
|
||||
import { ConfirmationDialog } from './ConfirmationDialog.dom.js';
|
||||
import { AxoButton } from '../axo/AxoButton.dom.js';
|
||||
import { SECOND } from '../util/durations/constants.std.js';
|
||||
|
||||
const { noop } = lodash;
|
||||
|
||||
@@ -275,7 +276,7 @@ function LocalBackupsBackupKeyViewer({
|
||||
const onCopyBackupKey = useCallback(
|
||||
async function handleCopyBackupKey(e: React.MouseEvent) {
|
||||
e.preventDefault();
|
||||
await window.navigator.clipboard.writeText(backupKey);
|
||||
await window.SignalClipboard.copyTextTemporarily(backupKey, 45 * SECOND);
|
||||
showToast({ toastType: ToastType.CopiedBackupKey });
|
||||
},
|
||||
[backupKey, showToast]
|
||||
|
||||
6
ts/window.d.ts
vendored
6
ts/window.d.ts
vendored
@@ -192,6 +192,12 @@ declare global {
|
||||
// TODO DESKTOP-4801
|
||||
SignalContext: SignalContextType;
|
||||
|
||||
SignalClipboard: {
|
||||
clear: () => void;
|
||||
clearIfNeeded: () => void;
|
||||
copyTextTemporarily: (text: string, clearAfterMs: number) => void;
|
||||
};
|
||||
|
||||
// Used only in preload to calculate load time
|
||||
preloadCompileStartTime: number;
|
||||
preloadStartTime: number;
|
||||
|
||||
36
ts/windows/clipboard.dom.ts
Normal file
36
ts/windows/clipboard.dom.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright 2025 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { clipboard } from 'electron';
|
||||
|
||||
let doesClipboardNeedClearing = false;
|
||||
|
||||
function clearClipboard(): void {
|
||||
clipboard.clear('clipboard');
|
||||
|
||||
// clipboard.clear is not reliable on Linux, so we actually have to overwrite it
|
||||
if (window.Signal.OS.isLinux()) {
|
||||
clipboard.writeText(' ');
|
||||
}
|
||||
|
||||
doesClipboardNeedClearing = false;
|
||||
}
|
||||
|
||||
function clearClipboardIfNeeded(): void {
|
||||
if (doesClipboardNeedClearing) {
|
||||
clearClipboard();
|
||||
}
|
||||
}
|
||||
|
||||
function copyTextTemporarily(text: string, clearAfterMs: number): void {
|
||||
clipboard.writeText(text);
|
||||
doesClipboardNeedClearing = true;
|
||||
|
||||
setTimeout(() => clearClipboard(), clearAfterMs);
|
||||
}
|
||||
|
||||
window.SignalClipboard = {
|
||||
clearIfNeeded: clearClipboardIfNeeded,
|
||||
clear: clearClipboard,
|
||||
copyTextTemporarily,
|
||||
};
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
DRAFT_PATH,
|
||||
} from '../../util/basePaths.preload.js';
|
||||
import { SignalContext } from '../context.preload.js';
|
||||
import '../clipboard.dom.js';
|
||||
|
||||
initializeLogging();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user