Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #16526 from atom/wl-rm-safe-clipboard
Browse files Browse the repository at this point in the history
Directly require clipboard from Electron
  • Loading branch information
Max Brunsfeld committed Aug 24, 2018
2 parents bc2310b + 467415a commit 1668617
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 17 deletions.
1 change: 0 additions & 1 deletion script/lib/generate-startup-snapshot.js
Expand Up @@ -38,7 +38,6 @@ module.exports = function (packagedAppPath) {
requiredModuleRelativePath.endsWith(path.join('node_modules', 'request', 'request.js')) ||
requiredModuleRelativePath === path.join('..', 'exports', 'atom.js') ||
requiredModuleRelativePath === path.join('..', 'src', 'electron-shims.js') ||
requiredModuleRelativePath === path.join('..', 'src', 'safe-clipboard.js') ||
requiredModuleRelativePath === path.join('..', 'node_modules', 'atom-keymap', 'lib', 'command-event.js') ||
requiredModuleRelativePath === path.join('..', 'node_modules', 'babel-core', 'index.js') ||
requiredModuleRelativePath === path.join('..', 'node_modules', 'cached-run-in-this-context', 'lib', 'main.js') ||
Expand Down
2 changes: 1 addition & 1 deletion spec/spec-helper.coffee
Expand Up @@ -12,7 +12,7 @@ FindParentDir = require 'find-parent-dir'
TextEditor = require '../src/text-editor'
TextEditorElement = require '../src/text-editor-element'
TextMateLanguageMode = require '../src/text-mate-language-mode'
clipboard = require '../src/safe-clipboard'
{clipboard} = require 'electron'

jasmineStyle = document.createElement('style')
jasmineStyle.textContent = atom.themes.loadStylesheet(atom.themes.resolveStylesheet('../static/jasmine'))
Expand Down
2 changes: 1 addition & 1 deletion spec/text-editor-component-spec.js
Expand Up @@ -11,7 +11,7 @@ const fs = require('fs')
const path = require('path')
const Grim = require('grim')
const electron = require('electron')
const clipboard = require('../src/safe-clipboard')
const clipboard = electron.clipboard

const SAMPLE_TEXT = fs.readFileSync(path.join(__dirname, 'fixtures', 'sample.js'), 'utf8')

Expand Down
2 changes: 1 addition & 1 deletion spec/text-editor-spec.js
Expand Up @@ -4,7 +4,7 @@ const fs = require('fs')
const path = require('path')
const temp = require('temp').track()
const dedent = require('dedent')
const clipboard = require('../src/safe-clipboard')
const {clipboard} = require('electron')
const TextEditor = require('../src/text-editor')
const TextBuffer = require('text-buffer')
const TextMateLanguageMode = require('../src/text-mate-language-mode')
Expand Down
8 changes: 4 additions & 4 deletions src/clipboard.js
@@ -1,16 +1,16 @@
const crypto = require('crypto')
const clipboard = require('./safe-clipboard')
const {clipboard} = require('electron')

// Extended: Represents the clipboard used for copying and pasting in Atom.
//
// An instance of this class is always available as the `atom.clipboard` global.
//
// ## Examples
//
// ```coffee
// ```js
// atom.clipboard.write('hello')
//
// console.log(atom.clipboard.read()) # 'hello'
// console.log(atom.clipboard.read()) // 'hello'
// ```
module.exports =
class Clipboard {
Expand Down Expand Up @@ -59,7 +59,7 @@ class Clipboard {
// * `text` The {String} clipboard text.
// * `metadata` The metadata stored by an earlier call to {::write}.
readWithMetadata () {
let text = this.read()
const text = this.read()
if (this.signatureForMetadata === this.md5(text)) {
return {text, metadata: this.metadata}
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/main-process/atom-application.js
Expand Up @@ -7,7 +7,7 @@ const Config = require('../config')
const ConfigFile = require('../config-file')
const FileRecoveryService = require('./file-recovery-service')
const ipcHelpers = require('../ipc-helpers')
const {BrowserWindow, Menu, app, dialog, ipcMain, shell, screen} = require('electron')
const {BrowserWindow, Menu, app, clipboard, dialog, ipcMain, shell, screen} = require('electron')
const {CompositeDisposable, Disposable} = require('event-kit')
const crypto = require('crypto')
const fs = require('fs-plus')
Expand Down Expand Up @@ -583,7 +583,6 @@ class AtomApplication extends EventEmitter {
win.temporaryState = state
}))

const clipboard = require('../safe-clipboard')
this.disposable.add(ipcHelpers.on(ipcMain, 'write-text-to-selection-clipboard', (event, text) =>
clipboard.writeText(text, 'selection')
))
Expand Down
6 changes: 0 additions & 6 deletions src/safe-clipboard.coffee

This file was deleted.

2 changes: 1 addition & 1 deletion src/text-editor-component.js
Expand Up @@ -5,8 +5,8 @@ const {Point, Range} = require('text-buffer')
const LineTopIndex = require('line-top-index')
const TextEditor = require('./text-editor')
const {isPairedCharacter} = require('./text-utils')
const clipboard = require('./safe-clipboard')
const electron = require('electron')
const clipboard = electron.clipboard
const $ = etch.dom

let TextEditorElement
Expand Down

0 comments on commit 1668617

Please sign in to comment.