-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathscript.js
64 lines (55 loc) · 1.99 KB
/
script.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
var gui = require('nw.gui');
var win = gui.Window.get();
var isMac = require('os').platform() === 'darwin';
// win.showDevTools(); // uncomment if you want to debug
if(isMac) {
document.title = '\u3000'; // to get around https://github.com/nwjs/nw.js/issues/3645
}
// don't let clippy.js add any handlers
$.fn.on = function(){};
// show clippy
clippy.load('Clippy', function(agent){
agent.show();
var intiialSpeechTimeoutId = setTimeout(function() {
agent.speak("Need some help closing me? Try double-clicking...");
}, 20000);
var windowX = null;
var windowY = null;
setTimeout(function(){
windowX = win.x;
windowY = win.y;
}, 250);
// to be safe: use focus as a click handler kinda, to trigger animations. Blur when done so every click triggers
// an animation
win.on('focus', function(){
agent.animate();
win.blur();
});
// In case the OS doesn't support blurring, we'll just call animate every now and again anyway
setInterval(function(){
agent.animate();
}, 12000);
// Since double-clicking draggable areas triggers maximizing on some platforms, when tell the user double-clicking
// closes clippy but actually we'll hide the window, unmaximize, resize back to the normal size and show again
// with a speech bubble
win.on('maximize', function(){
document.body.classList.add('hidden');
win.hide();
if(intiialSpeechTimeoutId) {
clearTimeout(intiialSpeechTimeoutId);
intiialSpeechTimeoutId = null;
}
setTimeout(function(){
win.unmaximize();
win.resizeTo(gui.App.manifest.window.width, gui.App.manifest.window.height);
win.moveTo(windowX, windowY);
}, 250);
setTimeout(function(){
win.show();
document.body.classList.remove('hidden');
setTimeout(function(){
agent.speak("Need some help?");
}, 500);
}, 2000);
});
});