1+ const { app, BrowserWindow, screen, nativeTheme, clipboard } = require ( 'electron' )
2+ const path = require ( 'path' )
3+ const exec = require ( 'child_process' ) . exec ;
4+
5+ function createWindow ( )
6+ {
7+ let display = screen . getPrimaryDisplay ( ) ;
8+ let width = display . bounds . width ;
9+
10+ const mainWindow = new BrowserWindow ( {
11+ width : 200 ,
12+ height : 200 ,
13+ maxWidth : 325 ,
14+ maxHeight : 350 ,
15+ minimizable : false ,
16+ maximizable : false ,
17+ minHeight : 200 ,
18+ minWidth : 200 ,
19+ alwaysOnTop : true ,
20+ x : width - 200 ,
21+ y : 0 ,
22+ skipTaskbar : true ,
23+ show : false
24+ } )
25+
26+ if ( process . argv [ 2 ] === "--dev" )
27+ {
28+ exec ( 'npm run start:only' , ( e , d , t ) => console . log ( e , d , t ) ) ;
29+ mainWindow . loadURL ( `http://localhost:8080` ) ;
30+ }
31+ else
32+ mainWindow . loadFile ( `./dist/index.html` )
33+
34+ let board = "" ;
35+ setInterval ( function ( )
36+ {
37+ mainWindow . setAlwaysOnTop ( true ) ;
38+ } , 1 ) ;
39+ setInterval ( ( ) =>
40+ {
41+ // lucsoft.de
42+ const newBoard = clipboard . readText ( ) ;
43+
44+ if ( newBoard !== board )
45+ {
46+ board = newBoard ;
47+ if ( validURL ( newBoard ) )
48+ {
49+ mainWindow . webContents . executeJavaScript ( `updateQRCode("${ newBoard } ")` ) ;
50+ mainWindow . show ( ) ;
51+ mainWindow . moveTop ( ) ;
52+ }
53+ }
54+
55+ } , 100 ) ;
56+ mainWindow . removeMenu ( ) ;
57+ mainWindow . on ( 'close' , ( event ) =>
58+ {
59+ mainWindow . hide ( ) ;
60+ event . preventDefault ( ) ;
61+ } ) ;
62+ }
63+
64+ app . on ( 'ready' , createWindow )
65+ setInterval ( ( ) => { } , 1000 ) ;
66+
67+ function validURL ( str )
68+ {
69+ var pattern = new RegExp ( '^(https?:\\/\\/)?' + // protocol
70+ '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,5}|' + // domain name
71+ '((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
72+ '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
73+ '(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
74+ '(\\#[-a-z\\d_]*)?$' , 'i' ) ; // fragment locator
75+ return ! ! pattern . test ( str ) ;
76+ }
0 commit comments