Skip to content

Commit

Permalink
Saves the last-used URL.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderson1993 committed Sep 7, 2017
1 parent 8708c76 commit 7c7d367
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 17 deletions.
56 changes: 47 additions & 9 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const sleepMode = require("sleep-mode");
const shell = electron.shell;

const Discovery = require("udp-discovery").Discovery;
const storage = require('electron-json-storage');

const freakout = require("./freakout");

Expand Down Expand Up @@ -73,22 +74,57 @@ app.on("ready", function() {
});
let webContents = mainWindow.webContents;

mainWindow.loadURL(
url.format({
pathname: path.join(__dirname, "index.html"),
protocol: "file:",
slashes: true
})
);
storage.get('url', function(err, res){
if (res.url) {
mainWindow.loadURL(res.url);
triggerWindow();
} else {
mainWindow.loadURL(
url.format({
pathname: path.join(__dirname, "index.html"),
protocol: "file:",
slashes: true
})
);
}
})

webContents.once("did-start-loading", () => {
mainWindow.webContents.executeJavaScript(
"localStorage.setItem('thorium_clientId','" + os.hostname() + "');"
);
});

globalShortcut.register("CommandOrControl+D", function() {
console.log(mainWindow.isKiosk())
if (!mainWindow.isKiosk()) {
if (mainWindow.isKiosk()) {
prompt({
title: "",
label: "You must enter the password to open the dev tools:",
value: "",
inputAttrs: {
type: "password"
}
})
.then(r => {
if (r === password) {
prompt({
title: "Enter the IP address of the server",
label: "URL:",
value: "192.168.1.4",
inputAttrs: {
type: "text"
}
})
.then(r => {
storage.set('url', {url:`http://${r}:3000/client`})
mainWindow.loadURL(`http://${r}:3000/client`);
triggerWindow();
})
.catch(console.error);
} //null if window was closed, or user clicked Cancel
})
.catch(console.error);
} else {
prompt({
title: "Enter the IP address of the server",
label: "URL:",
Expand All @@ -98,6 +134,7 @@ app.on("ready", function() {
}
})
.then(r => {
storage.set('url', {url:`http://${r}:3000/client`})
mainWindow.loadURL(`http://${r}:3000/client`);
triggerWindow();
})
Expand All @@ -113,6 +150,7 @@ function gotEvent(event, data) {
uri = `http://${data.address}:${data.port || 3000}/client`;
if (uri !== mainWindow.webContents.getURL().replace(`#`, ``)) {
mainWindow.loadURL(uri);
storage.set('url', {url:uri})
triggerWindow();
}
}
Expand Down
46 changes: 38 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"dependencies": {
"dialogs": "^1.1.20",
"electron": "^1.6.13",
"electron-json-storage": "^3.1.0",
"electron-prompt": "^0.3.0",
"power-off": "^1.1.2",
"robotjs": "^0.4.7",
Expand Down

0 comments on commit 7c7d367

Please sign in to comment.