Skip to content

Commit 010ee6a

Browse files
committed
popup will emit ipc event for main process to write clipboard
1 parent bacccba commit 010ee6a

3 files changed

Lines changed: 29 additions & 8 deletions

File tree

electron_src/popup/popup.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
var remote = require('remote')
44
var ipc = require('ipc')
5-
var clipboard = require('clipboard')
65

76
var SEARCH_INPUT = 1
87
var RESULT_LIST = 2
98
var RESULT_CONTROL = 3
109
var RESULT_CONTENT = 4
11-
var btnClipboard = document.getElementById('btnClipboard')
12-
var btnEdit = document.getElementById('btnEdit')
13-
var btnShare = document.getElementById('btnShare')
10+
// var btnClipboard = document.getElementById('btnClipboard')
11+
// var btnEdit = document.getElementById('btnEdit')
12+
// var btnShare = document.getElementById('btnShare')
1413
var aceView = document.getElementById('aceView')
1514

1615
angular.module('codexen.popup', [
@@ -105,8 +104,7 @@ angular.module('codexen.popup', [
105104
switch ($scope.isFocusing) {
106105
case RESULT_LIST:
107106
console.log($scope.selectedItem.content)
108-
clipboard.writeText($scope.selectedItem.content)
109-
hidePopUp()
107+
ipc.send('writeCode', $scope.selectedItem.content)
110108
break
111109
}
112110
e.preventDefault()

main.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,24 @@ app.on('window-all-closed', function () {
1212
if (process.platform !== 'darwin') app.quit()
1313
})
1414

15+
var robot = require('robotjs')
16+
17+
var clipboard = require('clipboard')
18+
1519
var Tray = require('tray')
1620
var appIcon = null
1721

1822
app.on('ready', function () {
1923
appIcon = new Tray('./icon.png')
2024
appIcon.setToolTip('This is my application.')
2125

22-
mainWindow = new BrowserWindow({width: 800, height: 600})
26+
mainWindow = new BrowserWindow({
27+
width: 800,
28+
height: 600,
29+
'web-preferences': {
30+
'overlay-scrollbars': true
31+
}
32+
})
2333

2434
mainWindow.loadUrl('file://' + __dirname + '/electron_build/index.html')
2535

@@ -36,7 +46,10 @@ app.on('ready', function () {
3646
width: 600,
3747
height: 400,
3848
show: false,
39-
frame: false
49+
frame: false,
50+
'web-preferences': {
51+
'overlay-scrollbars': true
52+
}
4053
})
4154

4255
popUpWindow.loadUrl('file://' + __dirname + '/electron_build/electron/popup/index.html')
@@ -74,6 +87,13 @@ app.on('ready', function () {
7487
ipc.on('hidePopUp', function () {
7588
hidePopUp()
7689
})
90+
ipc.on('writeCode', function (e, code) {
91+
clipboard.writeText(code)
92+
// setTimeout(function () {
93+
// robot.typeString(code)
94+
// }, 200)
95+
hidePopUp()
96+
})
7797

7898
var fromMain
7999
// Register a 'ctrl+x' shortcut listener.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,15 @@
3535
"angular-ui-router": "^0.2.15",
3636
"font-awesome": "^4.3.0",
3737
"moment": "^2.10.3",
38+
"robotjs": "^0.1.2",
3839
"satellizer": "^0.10.1",
3940
"ui-select": "^0.11.2"
4041
},
4142
"devDependencies": {
4243
"bootstrap-sass": "^3.3.4",
4344
"del": "^1.2.0",
45+
"electron-prebuilt": "^0.27.2",
46+
"electron-rebuild": "^0.2.1",
4447
"globby": "^2.0.0",
4548
"gulp": "^3.8.11",
4649
"gulp-angular-templatecache": "^1.6.0",

0 commit comments

Comments
 (0)