-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreload.js
More file actions
60 lines (54 loc) · 1.71 KB
/
Copy pathpreload.js
File metadata and controls
60 lines (54 loc) · 1.71 KB
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
// All of the Node.js APIs are available in the preload process.
// It has the same sandbox as a Chrome extension.
const { format } = require('date-fns');
const pug = require('pug');
const { contextBridge, ipcRenderer } = require('electron');
const clockTemplate = pug.compileFile('./templates/clock.pug');
const {
DISPLAY_CORNER_TITLE,
DISPLAY_RENDER_MODE_LEFT,
DISPLAY_RENDER_MODE_RIGHT,
MAX_REFRESH_INTERVAL,
} = process.env;
// main template global
let renderModeSingle = true;
// Configure rendering mode and constants for control:
// options for DISPLAY_RENDER_MODEs: "LABOR", "EVENTS", or "EMS-EVENTS"
// LABOR = When I Work Labor (condensed view)
// EVENTS = When I Work labor events associated with an event
// EMS-EVENTS = Events scheduled in EMS (regardless of labor assignment)
const ACCEPTABLE_SETTINGS = ['LABOR', 'EVENTS', 'EMS-EVENTS'];
const SETTINGS_DATA_MAPPING = {
LABOR: 'WIW',
EVENTS: 'WIW',
'EMS-EVENTS': 'EMS',
};
if (DISPLAY_RENDER_MODE_LEFT !== DISPLAY_RENDER_MODE_RIGHT) {
renderModeSingle = false;
}
if (!ACCEPTABLE_SETTINGS.includes(DISPLAY_RENDER_MODE_LEFT)
|| !ACCEPTABLE_SETTINGS.includes(DISPLAY_RENDER_MODE_RIGHT)) {
throw new Error(`IMPROPER CONFIGURATION; RENDER MODE NOT SET TO ONE OF ${ACCEPTABLE_SETTINGS.toString()}`);
}
// ContextBridge exposes functions, IPC, utilities, variables to the renderer context
contextBridge.exposeInMainWorld('preload', {
templates: {
clockTemplate,
},
// IPC functions
ipc: {
updateApiContent: () => ipcRenderer.invoke(
'load-api-data',
renderModeSingle,
SETTINGS_DATA_MAPPING,
ACCEPTABLE_SETTINGS,
),
},
utils: {
format,
},
envVars: {
DISPLAY_CORNER_TITLE,
MAX_REFRESH_INTERVAL,
},
});