This repository has been archived by the owner on Sep 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
111 lines (95 loc) · 2.74 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
const electron = require('electron'); // eslint-disable-line
const { app, BrowserWindow, ipcMain: ipc } = electron;
const settings = require('electron-settings');
const path = require('path');
let externalDisplay;
let configWindow = null;
let outputWindow = null;
function buildConfigWindow() {
if (configWindow === null) {
configWindow = new BrowserWindow({
closable: false,
fullscreen: false,
height: 260,
maxmizable: false,
minimizable: false,
resizable: false,
webPreferences: { nodeIntegration: true },
width: 160
});
configWindow.loadURL(`file://${path.join(__dirname, '/app/config.html')}`);
configWindow.on('closed', () => {
configWindow = null;
});
} else {
configWindow.show();
}
configWindow.webContents.on('did-finish-load', () => {
configWindow.webContents.send('loadSettings', {
displayId: settings.getSync('displayId'),
audio: settings.getSync('audio')
});
});
// configWindow.openDevTools({ mode: 'detach' });
}
function buildOutputWindow(displayId, audio) {
if (outputWindow === null) {
outputWindow = new BrowserWindow({
closable: false,
fullscreen: false,
height: 290,
maxmizable: false,
minimizable: false,
width: 480
});
outputWindow.setAspectRatio(16 / 9);
outputWindow.setBounds({
x: configWindow.getBounds().x + configWindow.getBounds().width,
y: configWindow.getBounds().y
});
outputWindow.on('closed', () => {
outputWindow = null;
});
} else {
outputWindow.show();
}
if (Number.isInteger(displayId)) {
outputWindow.loadURL(
`https://rock.barefootchurch.com/digitalsign/${displayId}?audio=${!!audio}`
);
}
// outputWindow.openDevTools({ mode: 'detach' });
}
app.whenReady().then(() => {
electron.powerMonitor.on('shutdown', () => {
app.quit();
});
[externalDisplay] = electron.screen
.getAllDisplays()
.filter((display) => display.bounds.x !== 0 || display.bounds.y !== 0);
buildConfigWindow();
});
ipc.on('save', (event, displayId, audio) => {
settings.set('displayId', displayId);
settings.set('audio', audio);
});
ipc.on('showOutput', () => {
buildOutputWindow(settings.getSync('displayId'), settings.getSync('audio'));
});
ipc.on('toggleFullscreen', () => {
if (!outputWindow.isSimpleFullScreen()) {
if (externalDisplay) {
outputWindow.setPosition(externalDisplay.bounds.x, externalDisplay.bounds.y);
}
outputWindow.setSimpleFullScreen(true);
} else {
outputWindow.setSimpleFullScreen(false);
outputWindow.setBounds({
x: configWindow.getBounds().x + configWindow.getBounds().width,
y: configWindow.getBounds().y
});
}
});
ipc.on('close', () => {
app.exit();
});