diff --git a/index.html b/index.html index 1cab7e0..a0998dc 100644 --- a/index.html +++ b/index.html @@ -1,83 +1,144 @@ - - - Thorium - - - - -

Thorium

- + + + + Thorium + + + + + +

Thorium

+
+ + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + + - + +

Searching for Thorium Server...

-

⌘ + D to enter server address

- +
+ +

+ + ⌘ + D + to enter server address

+ + \ No newline at end of file diff --git a/main.js b/main.js index 1d7e4a6..51595c5 100644 --- a/main.js +++ b/main.js @@ -3,24 +3,24 @@ const electron = require("electron"); 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 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 // be closed automatically when the JavaScript object is garbage collected. let mainWindow; -let uri; app.on("ready", function() { const ipcMain = electron.ipcMain; + ipcMain.on('loadPage', function(evt, uri) { + mainWindow && mainWindow.loadURL(uri); + triggerWindow(); + }); ipcMain.on("synchronous-message", function(event, arg) { if (arg) { switch (arg.action) { @@ -49,6 +49,8 @@ app.on("ready", function() { case "quit": app.quit(); break; + default: + break; } } event.returnValue = "pong"; @@ -66,26 +68,14 @@ app.on("ready", function() { }); let webContents = mainWindow.webContents; - storage.get("url", function(err, res) { - if (res && res.url) { - mainWindow.loadURL(res.url); - triggerWindow(); - } else { - mainWindow.loadURL( - url.format({ - pathname: path.join(__dirname, "index.html"), - protocol: "file:", - slashes: true - }) - ); - } - }); + mainWindow.loadURL( + url.format({ + pathname: path.join(__dirname, "index.html"), + protocol: "file:", + slashes: true + }) + ); - webContents.on("did-start-loading", () => { - mainWindow.webContents.executeJavaScript( - "localStorage.setItem('thorium_clientId','" + os.hostname() + "');" - ); - }); webContents.on("did-fail-load", () => { // Load the default page mainWindow && @@ -98,45 +88,51 @@ app.on("ready", function() { ); }); globalShortcut.register("CommandOrControl+D", function() { - storage.get("url", function(err, res) { - prompt({ - title: "Enter the IP address of the server", - label: "URL:", - value: res.url, - inputAttrs: { - type: "text" - } + prompt({ + title: "Enter the IP address of the server, including the port", + label: "URL:", + value: "", + inputAttrs: { + type: "text" + } + }) + .then(r => { + r = r.replace("http://", "").replace(/:[0-9]{4}\/client/gi, ""); + mainWindow && mainWindow.loadURL(`http://${r}/client`); + triggerWindow(); }) - .then(r => { - 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); - }); + .catch(console.error); }); // Auto-discovery - const bonjour = require('bonjour')(); - bonjour.find({ type: 'http' }, newService); - + const bonjour = require("bonjour")(); + bonjour.find({ type: "thorium-http" }, newService); + const servers = []; + const autoLoad = () => { + if (servers.length === 1) { + mainWindow.loadURL(servers[0].url); + triggerWindow(); + } else if (servers.length === 0) { + setTimeout(autoLoad, 3000); + } + }; + setTimeout(autoLoad, 3000); 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 + if (service.type === "app") { + 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(); - } + servers.push({ + name: service.name, + url: uri + }); + setTimeout(() => { + mainWindow.webContents.send("updateServers", servers); + }, 500); } } }); - - function triggerWindow() { mainWindow.setKiosk(true); @@ -146,7 +142,7 @@ function triggerWindow() { mainWindow.webContents.openDevTools(); }); - globalShortcut.register("CommandOrControl+Q", function(evt) { + globalShortcut.register("CommandOrControl+Q", function() { // Do nothing. }); @@ -160,6 +156,7 @@ function triggerWindow() { globalShortcut.register("CommandOrControl+Alt+I", function() { // Do nothing. + mainWindow.webContents.openDevTools(); }); globalShortcut.register("CommandOrControl+Alt+K", function() { if (mainWindow.isKiosk()) { diff --git a/package-lock.json b/package-lock.json index 1ff696e..8b887f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -347,11 +347,6 @@ "array-find-index": "1.0.2" } }, - "currify": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/currify/-/currify-2.0.6.tgz", - "integrity": "sha512-F0lbcoBkA2FMcejFeHJkDEhQ1AvVkTpkn9PMzJch+7mHy5WdteZ9t+nhT6cOdga4uRay3rjvprgp8tUkixFy8w==" - }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -367,11 +362,6 @@ } } }, - "debug": { - "version": "0.7.4", - "resolved": "https://registry.npmjs.org/debug/-/debug-0.7.4.tgz", - "integrity": "sha1-BuHqgILCyxTjmAbiLi9vdX+Srzk=" - }, "decamelize": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", @@ -428,11 +418,6 @@ "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.4.2.tgz", "integrity": "sha1-SLaZwn4zS/ifEIkr5DL25MfTSn8=" }, - "deep-is": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.2.tgz", - "integrity": "sha1-nO1l6gvAsJ9CptecGxkD+dkTzBg=" - }, "delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", @@ -530,9 +515,9 @@ } }, "electron": { - "version": "1.7.6", - "resolved": "https://registry.npmjs.org/electron/-/electron-1.7.6.tgz", - "integrity": "sha1-+2nqMb0D3w7/JH8m8LU4vSm27nI=", + "version": "1.7.11", + "resolved": "https://registry.npmjs.org/electron/-/electron-1.7.11.tgz", + "integrity": "sha1-mTtqp54OeafPzDafTIE/vZoLCNk=", "requires": { "@types/node": "7.0.43", "electron-download": "3.3.0", @@ -540,9 +525,9 @@ }, "dependencies": { "debug": { - "version": "2.6.8", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", - "integrity": "sha1-5zFTHKLt4n0YgiJCfaF4IdaP9Pw=", + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", "requires": { "ms": "2.0.0" } @@ -552,7 +537,7 @@ "resolved": "https://registry.npmjs.org/electron-download/-/electron-download-3.3.0.tgz", "integrity": "sha1-LP1U1pZsAZxNSa1l++Zcyc3vaMg=", "requires": { - "debug": "2.6.8", + "debug": "2.6.9", "fs-extra": "0.30.0", "home-path": "1.0.5", "minimist": "1.2.0", @@ -588,7 +573,7 @@ "resolved": "https://registry.npmjs.org/sumchecker/-/sumchecker-1.3.1.tgz", "integrity": "sha1-ebs7RFbdBPGOvbwNcDodHa7FEF0=", "requires": { - "debug": "2.6.8", + "debug": "2.6.9", "es6-promise": "4.1.1" } } @@ -918,11 +903,6 @@ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, - "fullstore": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fullstore/-/fullstore-1.0.0.tgz", - "integrity": "sha1-7SIvR2kREHlrhTuykLkJHMe+oOw=" - }, "function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -1234,14 +1214,6 @@ "resolved": "https://registry.npmjs.org/is-windows/-/is-windows-1.0.1.tgz", "integrity": "sha1-MQ23D3QtJZoWo2kgK1GvhCMzENk=" }, - "is2": { - "version": "0.0.12", - "resolved": "https://registry.npmjs.org/is2/-/is2-0.0.12.tgz", - "integrity": "sha1-zriH9RakgtAn53EP21fA/9kp8Nc=", - "requires": { - "deep-is": "0.1.2" - } - }, "isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", @@ -1564,15 +1536,6 @@ "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz", "integrity": "sha1-Rqarfwrq2N6unsBWV4C31O/rnUM=" }, - "obj-to-json": { - "version": "0.0.2", - "resolved": "https://registry.npmjs.org/obj-to-json/-/obj-to-json-0.0.2.tgz", - "integrity": "sha1-1EKCy9El4qdjPAJrZ3+iuxcYFjs=", - "requires": { - "debug": "0.7.4", - "is2": "0.0.12" - } - }, "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", @@ -2073,16 +2036,6 @@ } } }, - "smalltalk": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/smalltalk/-/smalltalk-2.4.1.tgz", - "integrity": "sha512-Aw70JGHPZfRoD0DPUeT6DgxbI5dLmCBwFgEq0TNXpxF6AWl+NTXZsbs5vqebMl3YAMV4fUbH+VAX4mJWtY3mmQ==", - "requires": { - "currify": "2.0.6", - "es6-promise": "4.1.1", - "fullstore": "1.0.0" - } - }, "sntp": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/sntp/-/sntp-1.0.9.tgz", @@ -2441,16 +2394,6 @@ "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=" }, - "udp-discovery": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/udp-discovery/-/udp-discovery-0.0.3.tgz", - "integrity": "sha1-C6VJNaLc+ubcGg5gYMR3rySJwkw=", - "requires": { - "debug": "0.7.4", - "is2": "0.0.12", - "obj-to-json": "0.0.2" - } - }, "universalify": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.1.tgz", diff --git a/package.json b/package.json index 9ab1f07..a8437a3 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "dependencies": { "bonjour": "^3.5.0", "dialogs": "^1.1.20", - "electron": "^1.6.13", + "electron": "^1.7.11", "electron-json-storage": "^3.1.0", "electron-prompt": "^0.3.0", "power-off": "^1.1.2", diff --git a/preload.js b/preload.js index 42b4559..17faf47 100644 --- a/preload.js +++ b/preload.js @@ -1,12 +1,33 @@ const ipcRenderer = require("electron").ipcRenderer; -var webFrame = require('electron').webFrame; +var webFrame = require("electron").webFrame; webFrame.setVisualZoomLevelLimits(1, 1); webFrame.setLayoutZoomLevelLimits(0, 0); +localStorage.setItem("thorium_clientId", require("os").hostname()); + const thorium = { sendMessage: function(arg) { return ipcRenderer.sendSync("synchronous-message", arg); } }; +ipcRenderer.on("updateServers", function updateServers(e, servers) { + if (servers.length === 0) { + document.getElementById("loading").classList.remove("hidden"); + document.getElementById("servers").classList.add("hidden"); + } else { + document.getElementById("loading").classList.add("hidden"); + document.getElementById("servers").classList.remove("hidden"); + } + const markup = servers.map( + s => `` + ); + document.getElementById("serverList").innerHTML = markup; +}); + +window.loadPage = function loadPage(url) { + ipcRenderer.send("loadPage", url); + return; +}; + window.thorium = thorium;