electron#clipboard JavaScript Examples
The following examples show how to use
electron#clipboard.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: App.js From ciphora with MIT License | 5 votes |
// Render the App UI
render () {
const activeChat =
this.state.activeChatId && this.state.chats[this.state.activeChatId]
return (
<div className='App'>
<SetupIdentityModal
open={this.state.setupIdentity}
onImportIdentityClick={() => this.openModal('importIdentity')}
onCreateIdentityClick={() => this.openModal('createIdentity')}
/>
<ImportIdentityModal
open={this.state.importIdentity}
onClose={() => this.openModal('setupIdentity')}
onImportClick={this.importIdentityHandler}
message={this.state.modalMessage}
/>
<CreateIdentityModal
open={this.state.createIdentity}
onClose={() => this.openModal('setupIdentity')}
onCreateClick={this.createIdentityHandler}
message={this.state.modalMessage}
/>
<Messenger
sidebar={
<ChatList
profile={this.state.profile}
chats={Object.values(this.state.chats)}
activeChatId={this.state.activeChatId}
onChatClick={this.activateChat}
onComposeChatClick={this.createComposeChat}
onDeleteClick={this.deleteChatHandler}
onCopyIdClick={() => clipboard.writeText(this.state.profile.id)}
onCopyPGPClick={() => ipcRenderer.send('copy-pgp')}
/>
}
content={
<MessageList
composing={this.state.composing}
onComposeChat={this.composeChatHandler}
activeChatId={this.state.activeChatId}
chat={activeChat}
onComposeMessage={this.composeMessageHandler}
onSendFileClick={this.sendFileHandler}
onFileClick={filePath => shell.openItem(filePath)}
onLinkClick={url => shell.openExternal(url)}
onDeleteClick={this.deleteChatHandler}
onCopyIdClick={() => clipboard.writeText(this.state.activeChatId)}
onCopyPGPClick={() =>
ipcRenderer.send('copy-pgp', this.state.activeChatId)
}
/>
}
/>
</div>
)
}
Example #2
Source File: index.js From lyswhut-lx-music-desktop with Apache License 2.0 | 5 votes |
clipboardWriteText = str => clipboard.writeText(str)
Example #3
Source File: index.js From lyswhut-lx-music-desktop with Apache License 2.0 | 5 votes |
clipboardReadText = str => clipboard.readText()
Example #4
Source File: index.js From desktop with GNU General Public License v3.0 | 4 votes |
app.on('web-contents-created', (event, webContents) => {
webContents.on('context-menu', (event, params) => {
const text = params.selectionText;
const hasText = !!text;
const menuItems = [];
if (params.misspelledWord && params.dictionarySuggestions.length > 0) {
for (const word of params.dictionarySuggestions) {
menuItems.push({
label: word,
click: () => {
webContents.replaceMisspelling(word);
}
});
}
menuItems.push({
type: 'separator'
});
}
const url = params.linkURL;
if (params.linkURL) {
menuItems.push({
id: 'openLink',
label: getTranslation('context.open-link'),
enabled: !url.startsWith('blob:'),
click() {
if (isSafeOpenExternal(url)) {
shell.openExternal(url);
}
}
});
menuItems.push({
type: 'separator'
});
}
if (params.isEditable) {
menuItems.push({
id: 'cut',
label: getTranslation('context.cut'),
enabled: hasText,
click: () => {
clipboard.writeText(text);
webContents.cut();
}
});
}
if (hasText || params.isEditable) {
menuItems.push({
id: 'copy',
label: getTranslation('context.copy'),
enabled: hasText,
click: () => {
clipboard.writeText(text);
}
});
}
if (params.isEditable) {
menuItems.push({
id: 'Paste',
label: getTranslation('context.paste'),
click: () => {
webContents.paste();
}
});
}
if (menuItems.length > 0) {
const menu = Menu.buildFromTemplate(menuItems);
menu.popup();
}
});
if (!isMac) {
// On Mac, shortcuts are handled by the menu bar.
webContents.on('before-input-event', (e, input) => {
if (input.isAutoRepeat || input.isComposing || input.type !== 'keyDown' || input.meta) {
return;
}
const window = BrowserWindow.fromWebContents(webContents);
// Ctrl+Shift+I to open dev tools
if (
input.control &&
input.shift &&
input.key.toLowerCase() === 'i' &&
!input.alt
) {
e.preventDefault();
webContents.toggleDevTools();
}
// Ctrl+N to open new window
if (
input.control &&
input.key.toLowerCase() === 'n'
) {
e.preventDefault();
createEditorWindow();
}
// Ctrl+Equals/Plus to zoom in
if (
input.control &&
input.key === '='
) {
e.preventDefault();
webContents.setZoomLevel(webContents.getZoomLevel() + 1);
}
// Ctrl+Minus/Underscore to zoom out
if (
input.control &&
input.key === '-'
) {
e.preventDefault();
webContents.setZoomLevel(webContents.getZoomLevel() - 1);
}
// Ctrl+0 to reset zoom
if (
input.control &&
input.key === '0'
) {
e.preventDefault();
webContents.setZoomLevel(0);
}
// F11 and alt+enter to toggle fullscreen
if (
input.key === 'F11' ||
(input.key === 'Enter' && input.alt)
) {
e.preventDefault();
window.setFullScreen(!window.isFullScreen());
}
// Escape to exit fullscreen
if (
input.key === 'Escape' &&
window.isFullScreen()
) {
e.preventDefault();
// used by closeWindowWhenPressEscape
e.didJustLeaveFullScreen = true;
window.setFullScreen(false);
}
// Ctrl+R and Ctrl+Shift+R to reload
if (
input.control &&
input.key.toLowerCase() === 'r'
) {
e.preventDefault();
if (input.shift) {
webContents.reloadIgnoringCache();
} else {
webContents.reload();
}
}
});
}
webContents.setWindowOpenHandler(defaultWindowOpenHandler);
webContents.on('will-navigate', (e, url) => {
if (url === 'mailto:[email protected]') {
// If clicking on the contact email address, we'll let the OS figure out how to open it
return;
}
try {
const newURL = new URL(url);
const baseURL = new URL(getURL(''));
if (newURL.href.startsWith(baseURL.href)) {
// Let the editor reload itself
// For example, reloading to apply settings
} else {
e.preventDefault();
if (isSafeOpenExternal(url)) {
shell.openExternal(url);
}
}
} catch (e) {
e.preventDefault();
}
});
});