-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib.js
72 lines (66 loc) · 1.8 KB
/
lib.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict'
const screencapture = require('./fork/screencapture')
const async = require('async')
module.exports = function shot(gui, cb) {
const osx = process.platform === 'darwin'
const gwin = gui.Window.get()
const screen = gwin.window.screen
const width = screen.width
const height = screen.height
async.parallel([
function capture(next) {
screencapture(next)
},
function open(next) {
const win = gui.Window.open('./screen.html', {
x: -32000,
y: -32000,
width: width,
height: height,
frame: false,
toolbar: false,
resizable: false,
})
win.on('loaded', function () {
next(null, win)
})
win.on('closed', function () {
cb()
})
},
], function (err, arr) {
if (err) {
return gwin.window.alert(err)
}
const filename = arr[0]
const win = arr[1]
const doc = win.window.document
const canvas = doc.querySelector('#canvas')
const ctx = canvas.getContext('2d')
const img = new win.window.Image()
canvas.setAttribute('width', width)
canvas.setAttribute('height', height)
img.src = `file:\/\/${filename}`
img.addEventListener('load', function () {
// todo: retina 5k img
ctx.drawImage(img, 0, 0, width, height)
setTimeout(function () {
if (osx) {
win.hide()
win.moveTo(0, 0)
// win.moveTo(-6, -6) // no fullscreen
}
win.enterFullscreen()
if (osx) win.show()
win.focus()
}, 300) // 等待窗口动画+draw时间
})
doc.addEventListener('keydown', function(ev) {
if (ev.metaKey || ev.ctrlKey)
if (ev.keyCode === 73 &&
(ev.ctrlKey && ev.shiftKey || ev.metaKey && ev.altKey)) {
win.showDevTools()
}
})
})
}