-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwords.js
130 lines (126 loc) · 3.48 KB
/
words.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
const { sleep } = require("asyncbox");
const { screen, ipcMain } = require("electron");
const { BrowserWindow } = require('glasstron');
const { tween } = require('shifty');
const path = require('path');
const config = require('./config');
class WordsWindow {
constructor() {
this.value = '';
this.interest = 0;
}
async init(app) {
this.app = app;
this.shown = false;
this.paused = false;
this.window = new BrowserWindow({
width: 450,
height: 0,
minimizable: false,
maximizable: false,
alwaysOnTop: true,
movable: false,
resizable: false,
show: false,
titleBarStyle: 'hidden',
frame: false,
transparent: true,
backgroundColor: '#0000FFE0',
webPreferences: {
nodeIntegration: true,
experimentalFeatures: true
}
});
this.window.blurType = "acrylic";
this.window.setBlur(true);
this.window.setSkipTaskbar(true);
this.window.menuBarVisible = false;
ipcMain.on('words', async (event, data) => {
if (data.type === 'resize') {
if (!this.paused) {
const size = data.size;
const contains = screen.getPrimaryDisplay().workAreaSize;
const height = this.window.getBounds().height;
this.window.setBounds({ width: size.width, height: height, x: contains.width - size.width - 8, y: contains.height - height - 8 });
this.window.showInactive();
this.window.moveTop();
//animation
tween({
from: { width: size.width, height: height, x: contains.width - size.width - 8, y: contains.height - height - 8 },
to: { width: size.width, height: size.height, x: contains.width - size.width - 8, y: contains.height - size.height - 8 },
duration: 400,
easing: 'easeInOutQuad',
render: ({ width, height, x, y }) => {
this.window.setBounds({ width, height: Math.floor(height), x, y: Math.floor(y) });
}
})
}
} else if (data.type === 'interest') {
this.window.hide();
this.value = data.value;
this.interest = 1;
this.shown = false;
} else if (data.type === 'uninterest') {
this.window.hide();
this.value = data.value;
this.interest = -1;
this.shown = false;
} else if (data.type === 'cancel') {
this.window.hide();
this.shown = false;
}
})
await this.window.loadFile(`windows/words.html`);
}
async show() {
this.shown = true;
this.value = '';
this.interest = 0;
this.window.setBounds({ height: 0 });
this.window.webContents.send('words', { type: 'shown' });
while (this.shown) {
await sleep(500);
}
return {
interest: this.interest,
words: this.value.split(/[\r\n]+/ig)
};
}
async pause() {
this.paused = true;
this.window.hide();
}
async resume() {
this.paused = false;
if (this.shown) {
await this.show();
}
}
close() {
this.window.hide();
this.value = '';
this.interest = 0;
this.shown = false;
}
}
class Words {
static window = new WordsWindow();
static async init(app) {
await Words.window.init(app);
}
static async show() {
return await Words.window.show();
}
static async wait() {
while(Words.window.shown) {
await sleep(500);
}
}
static async isShown() {
return Words.window.shown;
}
static close() {
Words.window.close();
}
}
module.exports = Words;