-
Notifications
You must be signed in to change notification settings - Fork 1
/
preload.js
36 lines (34 loc) · 1.12 KB
/
preload.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
const { contextBridge, remote } = require("electron");
const BrowserWindow = remote.BrowserWindow;
const downloadAndParseTranslations = require("./parseXlsx");
const getAppDataPath = require("./getAppDataPath");
const fs = require("fs");
const path = require("path");
contextBridge.exposeInMainWorld("api", {
getTranslations: () => {
const file = path.join(getAppDataPath(), "translation.json");
if (!fs.existsSync(file)) {
return require("./resources/translation.json");
}
const translations = fs.readFileSync(file);
return JSON.parse(translations);
},
updateTranslations: downloadAndParseTranslations,
getPlatform: () => process.platform,
openCombatOverlay: (section) => {
const win = new BrowserWindow({
width: 910,
height: 300,
titleBarStyle: "hidden",
transparent: true,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
enableRemoteModule: true,
preload: path.join(__dirname, "preload.js"),
},
});
win.loadFile(`combat/${section}.html`);
},
getResource: (name) => require(`./resources/${name}.json`),
});