Skip to content

Commit

Permalink
Forces the browser to not zoom.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderson1993 committed Jan 24, 2018
1 parent 7c7d367 commit 881f1bc
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 108 deletions.
4 changes: 3 additions & 1 deletion freakout.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var robot = require("robotjs");
/*var robot = require("robotjs");
//console.log(process.version);
module.exports = function() {
// Speed up the mouse.
Expand All @@ -20,4 +20,6 @@ module.exports = function() {
setTimeout(moveMouse, 20);
}
}
*/

module.exports = function() {}
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
</style>
</head>
<body>
<body style="background-color: rgba(255,0,0,1)">
<img src="logo.png" draggable="false" />
<h1>Thorium</h1>
<svg class="lds-spinner" width="55px" height="55px" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" style="background-image: none; background-position: initial initial; background-repeat: initial initial;"><g transform="rotate(0 50 50)">
Expand Down
146 changes: 44 additions & 102 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
const electron = require("electron");
// Module to control application life.
const password = "rommel1942";

const app = electron.app;
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;
const os = require("os");
const prompt = require("electron-prompt");
const path = require("path");
const url = require("url");

const powerOff = require("power-off");
const sleepMode = require("sleep-mode");
const shell = electron.shell;

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

const storage = require("electron-json-storage");
const freakout = require("./freakout");

const dialog = electron.dialog;
const globalShortcut = electron.globalShortcut;
// Keep a global reference of the window object, if you don't, the window will
Expand Down Expand Up @@ -61,7 +54,6 @@ app.on("ready", function() {
event.returnValue = "pong";
});

const discover = new Discovery();
mainWindow = new BrowserWindow({
backgroundColor: "#2e2c29",
width: 800,
Expand All @@ -74,10 +66,10 @@ app.on("ready", function() {
});
let webContents = mainWindow.webContents;

storage.get('url', function(err, res){
if (res.url) {
storage.get("url", function(err, res) {
if (res && res.url) {
mainWindow.loadURL(res.url);
triggerWindow();
triggerWindow();
} else {
mainWindow.loadURL(
url.format({
Expand All @@ -87,95 +79,71 @@ app.on("ready", function() {
})
);
}
})
});

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

globalShortcut.register("CommandOrControl+D", function() {
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
webContents.on("did-fail-load", () => {
// Load the default page
mainWindow &&
mainWindow.loadURL(
url.format({
pathname: path.join(__dirname, "index.html"),
protocol: "file:",
slashes: true
})
.catch(console.error);
} else {
);
});
globalShortcut.register("CommandOrControl+D", function() {
storage.get("url", function(err, res) {
prompt({
title: "Enter the IP address of the server",
label: "URL:",
value: "192.168.1.4",
value: res.url,
inputAttrs: {
type: "text"
}
})
.then(r => {
storage.set('url', {url:`http://${r}:3000/client`})
mainWindow.loadURL(`http://${r}:3000/client`);
r = r.replace("http://", "").replace(":3000/client", "");
storage.set("url", { url: `http://${r}:3000/client` });
mainWindow && mainWindow.loadURL(`http://${r}:3000/client`);
triggerWindow();
})
.catch(console.error);
}
});
});
discover.on("MessageBus", gotEvent);
discover.announce("client", {}, 500, true);
});

function gotEvent(event, data) {
if (event === "ClientConnect") {
uri = `http://${data.address}:${data.port || 3000}/client`;
if (uri !== mainWindow.webContents.getURL().replace(`#`, ``)) {
mainWindow.loadURL(uri);
storage.set('url', {url:uri})
triggerWindow();
// Auto-discovery
const bonjour = require('bonjour')();
bonjour.find({ type: 'http' }, newService);

function newService(service) {
if (service.name === "Thorium" && service.type === 'http') {
const ipregex = /[0-2]?[0-9]{1,2}\.[0-2]?[0-9]{1,2}\.[0-2]?[0-9]{1,2}\.[0-2]?[0-9]{1,2}/gi
const address = service.addresses.find(a => ipregex.test(a));
const uri = `http://${address}:${service.port || 3000}/client`;
if (uri !== mainWindow.webContents.getURL().replace(`#`, ``)) {
mainWindow.loadURL(uri);
storage.set("url", { url: uri });
triggerWindow();
}
}
}
}
});



function triggerWindow() {
mainWindow.setKiosk(true);

// Create the browser window.
globalShortcut.register("CommandOrControl+Alt+E", function() {
// Open the DevTools.
prompt({
title: "",
label: "You must enter the password to open the dev tools:",
value: "",
inputAttrs: {
type: "password"
}
})
.then(r => {
if (r === password) {
mainWindow.webContents.openDevTools();
} //null if window was closed, or user clicked Cancel
})
.catch(console.error);
mainWindow.webContents.openDevTools();
});

globalShortcut.register("CommandOrControl+Q", function(evt) {
Expand All @@ -195,39 +163,13 @@ function triggerWindow() {
});
globalShortcut.register("CommandOrControl+Alt+K", function() {
if (mainWindow.isKiosk()) {
prompt({
title: "",
label: "You must enter the password to exit kiosk mode:",
value: "",
inputAttrs: {
type: "password"
}
})
.then(r => {
if (r === password) {
mainWindow.setKiosk(false);
} //null if window was closed, or user clicked Cancel
})
.catch(console.error);
mainWindow.setKiosk(false);
} else {
mainWindow.setKiosk(true);
}
});
globalShortcut.register("CommandOrControl+Alt+Q", function() {
prompt({
title: "",
label: "You must enter the password to quit:",
value: "",
inputAttrs: {
type: "password"
}
})
.then(r => {
if (r === password) {
app.quit();
} //null if window was closed, or user clicked Cancel
})
.catch(console.error);
app.quit();
});
// Emitted when the window is closed.
mainWindow.on("closed", function() {
Expand Down
74 changes: 74 additions & 0 deletions package-lock.json

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

Loading

0 comments on commit 881f1bc

Please sign in to comment.