This repository has been archived by the owner on Apr 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
76 lines (68 loc) · 1.97 KB
/
main.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
const { app, BrowserWindow, screen, nativeTheme, clipboard } = require('electron')
const path = require('path')
const exec = require('child_process').exec;
function createWindow()
{
let display = screen.getPrimaryDisplay();
let width = display.bounds.width;
const mainWindow = new BrowserWindow({
width: 200,
height: 200,
maxWidth: 325,
maxHeight: 350,
minimizable: false,
maximizable: false,
minHeight: 200,
minWidth: 200,
alwaysOnTop: true,
x: width - 200,
y: 0,
skipTaskbar: true,
show: false
})
if (process.argv[ 2 ] === "--dev")
{
exec('npm run start:only', (e, d, t) => console.log(e, d, t));
mainWindow.loadURL(`http://localhost:8080`);
}
else
mainWindow.loadFile(`./dist/index.html`)
let board = "";
setInterval(function ()
{
mainWindow.setAlwaysOnTop(true);
}, 1);
setInterval(() =>
{
// lucsoft.de
const newBoard = clipboard.readText();
if (newBoard !== board)
{
board = newBoard;
if (validURL(newBoard))
{
mainWindow.webContents.executeJavaScript(`updateQRCode("${newBoard}")`);
mainWindow.show();
mainWindow.moveTop();
}
}
}, 100);
mainWindow.removeMenu();
mainWindow.on('close', (event) =>
{
mainWindow.hide();
event.preventDefault();
});
}
app.on('ready', createWindow)
setInterval(() => { }, 1000);
function validURL(str)
{
var pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,5}|' + // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
'(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
return !!pattern.test(str);
}