This repository has been archived by the owner on Dec 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditor.js
77 lines (71 loc) · 2.23 KB
/
editor.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
const {app, BrowserWindow, ipcMain, globalShortcut} = require("electron");
const path = require("path");
const url = require("url");
const backendModule = require("./backend");
let win;
let backend = new backendModule();
let port = 8080;
let credentials = {
username: null,
password: null
};
ipcMain.on("setCredentials", (event, username, password) => {
credentials.username = username;
credentials.password = password;
});
ipcMain.on("getCredentials", (event) => event.returnValue = credentials);
ipcMain.on("checkForRepo", (event) => event.returnValue = backend.checkForRepo());
ipcMain.on("fetchRepo", (event) => {
backend.fetchRepo(
(err) => win.webContents.send("fetchRepoErr", err),
(currentBytes, totalBytes) => win.webContents.send("fetchRepoProgress", currentBytes, totalBytes),
() => win.webContents.send("fetchRepoSuccess")
);
});
ipcMain.on("deleteRepo", (event) => {
backend.deleteRepo((err) => win.webContents.send("deletedRepo", err));
});
ipcMain.on("checkForUpdates", (event) => {
backend.checkForUpdates(
(msg) => win.webContents.send("updatesAvailable", msg),
(err) => win.webContents.send("updateCheckFailed", err));
});
ipcMain.on("startServer", (event) => {
backend.startServer(port, () => {
win.webContents.send("serverStarted");
});
});
ipcMain.on("compile", (event) => {
backend.compile(() => win.webContents.send("compileFinished"));
});
ipcMain.on("getJSONForPage", (event, page) => event.returnValue = backend.getJSONForPage(page));
ipcMain.on("setJSONForPage", (event, page, json) => {
backend.setJSONForPage(page, json, (err) => {
if (err) win.webContents.send("setJSONForPageFailed", err);
});
});
ipcMain.on("getFileContentsBase64", (event, path) => event.returnValue = backend.getFileContentsBase64(path));
function createWindow() {
win = new BrowserWindow({
minWidth: 768,
minHeight: 480,
width: 800,
height: 600,
icon: __dirname + "/img/icon.ico"
});
win.loadURL(`file:///${__dirname}/login.html`);
win.setMenuBarVisibility(false);
globalShortcut.register("F12", () => {
win.webContents.openDevTools();
});
win.on("closed", () => {
win = null;
});
}
app.on("ready", createWindow);
app.on('activate', () => {
if (win === null) {
createWindow();
}
});
app.on("window-all-closed", app.quit);