This repository has been archived by the owner on Jan 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
114 lines (90 loc) · 2.85 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
112
113
114
const { app, BrowserWindow, ipcMain, nativeTheme, autoUpdater } = require("electron");
const {
Socket,
Transport,
} = require("electron-ipc-socket");
const path = require("path");
const fs = require("fs");
const isDev = require('electron-is-dev');
const { logPlayerDataLocation, logOpponentDataLocation, playerInfoLocation } = require("./src/const");
if (isDev) {
const fsExtra = require('fs-extra')
const localPath = 'C:/Users/' + require("os").userInfo().username + '/AppData/Roaming/gu-decks-assistant/Local Storage'
fsExtra.emptyDirSync(localPath)
} else {
const server = 'https://update.electronjs.org'
const feed = `${server}/p2etools/gu-decks-assistant/${process.platform}-${process.arch}/${app.getVersion()}`
autoUpdater.setFeedURL(feed)
setInterval(() => {
autoUpdater.checkForUpdates()
}, 10 * 60 * 1000)
}
if (require("electron-squirrel-startup")) return;
require('./src/processLog')
async function createWindow() {
const win = new BrowserWindow({
width: 615,
height: 726,
webPreferences: {
preload: path.join(__dirname, "src", "core", "preload.js"),
contextIsolation: true,
enableRemoteModule: false,
},
// webPreferences: {
// nodeIntegration: true
// },
});
win.loadFile("index.html");
// win.webContents.on("did-finish-load", () => {
// win.webContents.send("ping", "whoooooooh!");
// });
win.setAlwaysOnTop(true, 'screen');
const socket = new Socket(new Transport(ipcMain, win));
socket.open("main-win");
let version = app.getVersion();
version = JSON.stringify(version)
await win.webContents.executeJavaScript(`localStorage.setItem("appVersion", ${version})`, true)
socket.onEvent("ready", (evt) => {
console.log("Renderer process is ready", { evt });
});
socket.onRequest("set-player-name", async (req) => {
fs.writeFileSync(playerInfoLocation, req.data.playerName, 'utf-8')
return 'ok'
});
socket.onRequest("get-deck-data", (req) => {
let opponentData;
let playerData;
try {
playerData = JSON.parse(fs.readFileSync(logPlayerDataLocation, 'utf-8'));
} catch (error) {
}
try {
opponentData = JSON.parse(fs.readFileSync(logOpponentDataLocation, 'utf-8'));
} catch (error) {
}
return {
playerData,
opponentData,
}
});
ipcMain.handle("dark-mode:toggle", () => {
if (nativeTheme.shouldUseDarkColors) {
nativeTheme.themeSource = "light";
} else {
nativeTheme.themeSource = "dark";
}
return nativeTheme.shouldUseDarkColors;
});
ipcMain.handle("dark-mode:system", () => {
nativeTheme.themeSource = "system";
});
// ipcMain.on("toMain", (event, args) => {
// win.webContents.send("fromMain", data);
// });
}
app.whenReady().then(() => {
createWindow();
});
app.on("window-all-closed", function () {
if (process.platform !== "darwin") app.quit();
});