This repository has been archived by the owner on Aug 31, 2020. It is now read-only.
forked from kimbtech/electron-window-position
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
93 lines (78 loc) · 1.88 KB
/
test.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
/*
* NPM Module "electron-window-position" by KIMB-technologies
* https://github.com/kimbtech/electron-window-position
* MIT License
*/
/**
* This test opens two windows, one on the top left corner and one centered.
* Also is opens error dialoges if something goes wrong.
*/
// Electron API
const electron = require('electron');
// WindowPosition Class
const WindowPosition = require( __dirname + '/' );
// noch gibt es Fehler
var error = [true, true];
// Calculate Data
var pos = new WindowPosition( function ( topleft ){
// test callback
openWindowOne( topleft );
// test direct callback
var pos2 = new WindowPosition( pos2 => {
if( pos2.x != topleft.x || pos2.y != topleft.y ){
electron.dialog.showErrorBox( 'Error', 'Incorrect data at direct callback.' );
}
error[0] = false;
});
// test direct calls
openWindowTwo( pos.getActiveScreenCenter(300,300) );
});
// test exception
try {
pos.getActiveScreenCenter(300,300)
} catch (e) {
error[1] = false;
}
// global refs for main Windows
let mainWindowOne = null;
let mainWindowRwo = null;
// main window top left
function openWindowOne( pos ){
mainWindowOne = new electron.BrowserWindow({
x: pos.x,
y: pos.y,
width: 300,
height: 300,
show: true,
resizable: false
});
mainWindowOne.on('closed', () => {
mainWindowOne = null;
});
//no menue
electron.Menu.setApplicationMenu(null);
}
// main window centered
function openWindowTwo( pos ){
mainWindowTwo = new electron.BrowserWindow({
x: pos.x,
y: pos.y,
width: 300,
height: 300,
show: true,
resizable: false
});
mainWindowTwo.on('closed', () => {
mainWindowTwo = null;
});
}
// quit program if all windows closed
electron.app.on('window-all-closed', () => {
if( error[0] ) {
electron.dialog.showErrorBox('Error', 'No direct callback!');
}
if( error[1] ) {
electron.dialog.showErrorBox('Error', 'No Exception!');
}
electron.app.quit();
});