From f7e3ed8a0c3c42328d3572d4c5cc4418096e0be4 Mon Sep 17 00:00:00 2001 From: akashnimare Date: Thu, 6 Oct 2016 07:43:59 +0530 Subject: [PATCH] :sweat: Fixing Jquery bug attempt 2 --- app/main/domain.js | 38 ++++++++++++++++++++++++++++++++++++++ app/main/index.js | 19 ++++++++++++++----- app/main/preload.js | 2 ++ app/renderer/index.html | 12 ------------ 4 files changed, 54 insertions(+), 17 deletions(-) create mode 100644 app/main/domain.js diff --git a/app/main/domain.js b/app/main/domain.js new file mode 100644 index 00000000..3369a556 --- /dev/null +++ b/app/main/domain.js @@ -0,0 +1,38 @@ +const JsonDB = require('node-json-db'); +const {app} = require('electron').remote; +const request = require('request'); +const ipcRenderer = require('electron').ipcRenderer; + +const db = new JsonDB(app.getPath('userData') + '/domain.json', true, true); +const data = db.getData('/'); + + +console.log(data.domain); + +// if (data.domain && window.location.href.indexOf(data.domain) === -1) { +// window.location.href = data.domain +// } +// require('electron-connect').client.create(); + +window.addDomain = function () { + + document.getElementById('main').innerHTML = 'checking...'; + + let newDomain = document.getElementById('url').value; + newDomain = newDomain.replace(/^https?:\/\//, ''); + + const domain = 'https://' + newDomain; + const checkDomain = domain + '/static/audio/zulip.ogg'; + + request(checkDomain, (error, response) => { + if (!error && response.statusCode !== 404) { + document.getElementById('main').innerHTML = 'Connect'; + db.push('/domain', domain); + ipcRenderer.send('new-domain', domain); + } else { + document.getElementById('main').innerHTML = 'Connect'; + document.getElementById('server-status').innerHTML = 'Not a vaild Zulip Server.'; + }; + }); +} + diff --git a/app/main/index.js b/app/main/index.js index 58d91a01..c53860d3 100644 --- a/app/main/index.js +++ b/app/main/index.js @@ -29,7 +29,16 @@ let mainWindow; let targetLink; // Load this url in main window -const targetUrl = 'file://' + path.join(__dirname, '../renderer', 'index.html'); +const staticURL = 'file://' + path.join(__dirname, '../renderer', 'index.html'); + +const targetURL = function() { + if (data.domain !== undefined) { + return data.domain + } + else { + return staticURL + } +} const isAlreadyRunning = app.makeSingleInstance(() => { if (mainWindow) { @@ -90,13 +99,13 @@ function createMainWindow() { minHeight: 400, webPreferences: { preload: path.join(__dirname, 'preload.js'), - nodeIntegration: true, plugins: true, - allowDisplayingInsecureContent: true - } + allowDisplayingInsecureContent: true, + nodeIntegration: false, + }, }); - win.loadURL(targetUrl); + win.loadURL(targetURL()); win.on('closed', onClosed); win.setTitle('Zulip'); diff --git a/app/main/preload.js b/app/main/preload.js index c87e994f..03f9137a 100644 --- a/app/main/preload.js +++ b/app/main/preload.js @@ -53,3 +53,5 @@ ipcRenderer.on('shortcut', () => { const nodes = document.querySelectorAll('.dropdown-menu li:nth-child(4) a'); nodes[nodes.length - 1].click(); }); + +require('./domain'); diff --git a/app/renderer/index.html b/app/renderer/index.html index cefefe9f..db888e2d 100644 --- a/app/renderer/index.html +++ b/app/renderer/index.html @@ -6,17 +6,6 @@ Login - Zulip - -
@@ -49,6 +38,5 @@
-