diff --git a/js/background.js b/js/background.js index a98388f02..9fd6ab131 100644 --- a/js/background.js +++ b/js/background.js @@ -39,6 +39,10 @@ }); var SERVER_URL = 'https://textsecure-service-staging.whispersystems.org'; + if (window.env && window.env.node_env === 'production') { + SERVER_URL = 'https://textsecure-service-ca.whispersystems.org'; + } + var SERVER_PORTS = [80, 4433, 8443]; var messageReceiver; window.getSocketStatus = function() { diff --git a/main.js b/main.js index 76d6da7bc..119cbddcb 100644 --- a/main.js +++ b/main.js @@ -3,6 +3,7 @@ const app = electron.app const BrowserWindow = electron.BrowserWindow const path = require('path') const url = require('url') +const fs = require('fs') const autoUpdater = require('electron-updater').autoUpdater const autoUpdaterInterval = 60 * 60 * 1000; @@ -22,6 +23,14 @@ if (shouldQuit) { return; } +// Read package.json +const package_json = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf-8')) +const NODE_ENV = process.env.NODE_ENV || package_json.NODE_ENV || 'development'; + +// use a separate data directory for development +if (NODE_ENV !== 'production') { + app.setPath('userData', path.join(app.getPath('appData'), 'Signal-' + NODE_ENV)) +} // 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 @@ -31,14 +40,19 @@ function createWindow () { mainWindow = new BrowserWindow({ width: 800, height: 600, - webPreferences: { nodeIntegration: false, sandbox: true } + webPreferences: { + nodeIntegration: false, + sandbox: true, + preload: path.join(__dirname, 'preload.js') + } }) // and load the index.html of the app. mainWindow.loadURL(url.format({ pathname: path.join(__dirname, 'background.html'), protocol: 'file:', - slashes: true + slashes: true, + query: { node_env: NODE_ENV } })) // Open the DevTools. diff --git a/package.json b/package.json index 9d1fa737d..c48e3761f 100644 --- a/package.json +++ b/package.json @@ -32,9 +32,9 @@ "test": "grunt test", "lint": "grunt jshint", "start": "electron .", - "pack": "build --dir", - "dist": "build", - "release": "build" + "pack": "build --dir --em.NODE_ENV=$NODE_ENV", + "dist": "build --em.NODE_ENV=$NODE_ENV", + "release": "build --em.NODE_ENV=$NODE_ENV" }, "build": { "appId": "org.whispersystems.signal-desktop", diff --git a/preload.js b/preload.js new file mode 100644 index 000000000..dc24352c6 --- /dev/null +++ b/preload.js @@ -0,0 +1,10 @@ +/* + * Pending electron 1.6.x + * const env = require('url').parse(window.location, true).query; +*/ + +window.env = {}; +window.location.search.substring(1).split('&').forEach(function(variable) { + var pair = variable.split('='); + env[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]); +});