-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
149 lines (113 loc) · 3.1 KB
/
index.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/* global __dirname, process */
const { app, BrowserWindow, screen, ipcMain } = require('electron');
const path = require('path');
/*** * * ***/
const clippyW = 125;
const clippyH = 100;
const msgWelcome = `
<h1>Hello, from Clippy !</h1>
<br>
<h5>Give the double-click a whirl to set the animation in motion and toggle the opening/closing of this modal.</h5>
<h5>A single click sets the animation in motion.</h5>
<h5>Gently guiding your mouse over Clippy or giving it a jolly good press reveals the close button.</h5>
`;
/*** * * ***/
let modalWindow;
function modalWindowCreate(text = "") {
const display = screen.getDisplayNearestPoint(screen.getCursorScreenPoint());
const displayW = display.workArea.width;
const displayH = display.workArea.height;
const modalMarginTopBottom = clippyW*2;
const modalMarginLeftRight = clippyH*2;
/*** * * ***/
if (typeof modalWindow != "undefined") {
modalWindowDestroy();
}
/*** * * ***/
modalWindow = new BrowserWindow({
width: (displayW - modalMarginTopBottom),
height: (displayH - modalMarginLeftRight),
title: 'Clippy',
frame: false,
transparent: true,
icon: __dirname + '/assets/icon/icon.png'
});
modalWindow.loadURL('data:text/html;charset=utf-8,' + encodeURIComponent(`
<html>
<head>
<style>
body {
color: white;
margin: 0;
font-family: system-ui;
background-color: #333;
}
#content {
text-align: center;
top: 50%;
position: absolute;
width: 100vw;
transform: translate(0,-50%);
}
</style>
</head>
<body>
<div id="content">
`+text+`
</div>
</body>
</html>
`));
}
function modalWindowDestroy() {
modalWindow.close();
modalWindow = undefined;
}
function mainWindowCreate() {
const display = screen.getDisplayNearestPoint(screen.getCursorScreenPoint());
const displayW = display.workArea.width;
const displayH = display.workArea.height;
/*** * * ***/
const win = new BrowserWindow({
width: clippyW,
height: clippyH,
title: 'Clippy',
webPreferences: {
preload: path.join(__dirname, 'preload.js')
},
transparent: true,
frame: false,
icon: __dirname + '/assets/icon/icon.png'
});
/*** * * ***/
win.setPosition((displayW - clippyW), (displayH - clippyH));
win.setAlwaysOnTop(true, 'screen');
win.loadFile('index.html');
// win.setIgnoreMouseEvents(true, { forward: true });
}
app.whenReady().then(() => {
mainWindowCreate();
/*** * * ***/
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
mainWindowCreate();
}
});
/*** * * ***/
ipcMain.handle('quit-app', () => {
app.quit();
});
ipcMain.handle('dblclick', () => {
if (typeof modalWindow != "undefined") {
modalWindowDestroy();
} else {
modalWindowCreate(msgWelcome);
}
});
modalWindowCreate(msgWelcome);
});
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});