Skip to content

Commit 0d8ab95

Browse files
Angelo ManganielloAngelo Manganiello
authored andcommitted
fix reload on electron-client project
1 parent a89ed99 commit 0d8ab95

File tree

2 files changed

+57
-29
lines changed

2 files changed

+57
-29
lines changed

electron-client/main.js

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,66 @@
11
const electron = require("electron"),
2-
app = electron.app,
3-
BrowserWindow = electron.BrowserWindow;
2+
app = electron.app,
3+
BrowserWindow = electron.BrowserWindow;
44

5-
require('electron-debug')({ enabled: true});
5+
require('electron-debug')({
6+
enabled: true
7+
});
68
let mainWindow;
9+
const fs = require('fs');
10+
let url = `${__dirname}/dist/index.html`;
11+
const globalShortcut = electron.globalShortcut;
712

813
function createWindow() {
9-
mainWindow = new BrowserWindow({
10-
autoHideMenuBar: true,
11-
width: 640,
12-
height: 480,
13-
webPreferences: {
14-
nodeIntegration: false }
15-
});
16-
mainWindow.loadURL(`file://${__dirname}/dist/index.html`);
17-
//mainWindow.webContents.openDevTools();
18-
mainWindow.on("closed", function() {
19-
mainWindow = null;
20-
});
14+
mainWindow = new BrowserWindow({
15+
autoHideMenuBar: true,
16+
width: 640,
17+
height: 480,
18+
webPreferences: {
19+
nodeIntegration: false
20+
}
21+
});
22+
mainWindow.loadURL(url);
23+
//mainWindow.webContents.openDevTools();
24+
mainWindow.on("closed", function () {
25+
mainWindow = null;
26+
});
27+
28+
globalShortcut.register('f5', function () {
29+
reloadPage();
30+
});
31+
globalShortcut.register('CommandOrControl+R', function () {
32+
reloadPage();
33+
});
34+
}
35+
36+
function reloadPage() {
37+
var currentURL = mainWindow.webContents.getURL();
38+
let urlWithoutFileProtocol = currentURL.split('file:///');
39+
currentURL = urlWithoutFileProtocol[1];
40+
try {
41+
if (fs.statSync(currentURL).isFile()) {
42+
mainWindow.reload();
43+
} else {
44+
mainWindow.loadURL(url);
45+
}
46+
} catch (err) {
47+
mainWindow.loadURL(url);
48+
}
2149
}
2250

2351
app.on("ready", createWindow);
24-
app.on("browser-window-created", function(e, window) {
25-
window.setMenu(null);
52+
app.on("browser-window-created", function (e, window) {
53+
window.setMenu(null);
2654
});
2755

28-
app.on("window-all-closed", function() {
29-
if (process.platform !== "darwin") {
30-
app.quit();
31-
}
56+
app.on("window-all-closed", function () {
57+
if (process.platform !== "darwin") {
58+
app.quit();
59+
}
3260
});
3361

34-
app.on("activate", function() {
35-
if (mainWindow === null) {
36-
createWindow();
37-
}
62+
app.on("activate", function () {
63+
if (mainWindow === null) {
64+
createWindow();
65+
}
3866
});

electron-client/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
resolved "http://artifactory-pro.au-sdc.com:8081/artifactory/api/npm/oneleo-repo-npm-virtual/7zip-bin/-/7zip-bin-4.0.2.tgz#6abbdc22f33cab742053777a26db2e25ca527179"
88

99
"@types/node@^8.0.24":
10-
version "8.10.22"
11-
resolved "http://artifactory-pro.au-sdc.com:8081/artifactory/api/npm/oneleo-repo-npm-virtual/@types/node/-/node-8.10.22.tgz#c095d7c668908d48b95ae11fcc4a6d6b1c116a35"
10+
version "8.10.23"
11+
resolved "http://artifactory-pro.au-sdc.com:8081/artifactory/api/npm/oneleo-repo-npm-virtual/@types/node/-/node-8.10.23.tgz#e5ccfdafff42af5397c29669b6d7d65f7d629a00"
1212

1313
abbrev@1:
1414
version "1.1.1"
@@ -217,8 +217,8 @@ braces@^1.8.2:
217217
repeat-element "^1.1.2"
218218

219219
buffer-from@^1.0.0:
220-
version "1.1.0"
221-
resolved "http://artifactory-pro.au-sdc.com:8081/artifactory/api/npm/oneleo-repo-npm-virtual/buffer-from/-/buffer-from-1.1.0.tgz#87fcaa3a298358e0ade6e442cfce840740d1ad04"
220+
version "1.1.1"
221+
resolved "http://artifactory-pro.au-sdc.com:8081/artifactory/api/npm/oneleo-repo-npm-virtual/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
222222

223223
224224
version "4.2.1"

0 commit comments

Comments
 (0)