-
Notifications
You must be signed in to change notification settings - Fork 1
/
screen.html
53 lines (53 loc) · 1.28 KB
/
screen.html
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style>
body {
margin: 0;
overflow: hidden;
cursor: crosshair;
}
.overlay {
width: 100%;
height: 100%;
opacity: .5;
background-color: black;
position: fixed;
}
</style>
</head>
<body>
<div class="overlay"></div>
<canvas id="canvas"></canvas>
<script>
'use strict'
const osx = process.platform === 'darwin'
const gui = require('nw.gui')
const win = gui.Window.get()
let _exited = false
document.addEventListener('mousedown', function (ev) {
if (ev.which === 3) exit()
})
document.addEventListener('keydown', function (ev) {
if (ev.keyCode === 27) exit()
})
document.addEventListener('blur', function (ev) {
exit()
})
function exit() {
if (_exited) return // 确保只exit一次
_exited = true
win.leaveFullscreen()
setTimeout(function(){
// document.body.style.cursor = 'default'
win.moveTo(-32000, -32000) // cursor自动复原
setTimeout(function () {
win.close()
}, 100) // 确保cursor复原
}, osx ? 1000 : 0) // 确保大于1s 等待leaveFullscreen结束 (osx)
}
</script>
</body>
</html>