From 6d87904d1857c65cbda1f6f56a0612ee86d4c9b9 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Thu, 26 Mar 2020 15:22:46 +1100 Subject: [PATCH 01/10] Clean up config files. Removed unused scripts. Removed unused files. --- CONTRIBUTING.md | 4 +-- config/default.json | 1 - config/development-1.json | 15 +------- config/development-2.json | 16 --------- config/staging.json | 4 --- config/swarm-testing-2.json | 3 ++ config/swarm-testing2.json | 11 ------ main.js | 1 - package.json | 28 +++++---------- preload.js | 2 -- prepare_beta_build.js | 66 ----------------------------------- prepare_import_build.js | 69 ------------------------------------- 12 files changed, 14 insertions(+), 206 deletions(-) delete mode 100644 config/development-2.json delete mode 100644 config/staging.json create mode 100644 config/swarm-testing-2.json delete mode 100644 config/swarm-testing2.json delete mode 100644 prepare_beta_build.js delete mode 100644 prepare_import_build.js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 04557db73..61cd4f4d6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -95,8 +95,7 @@ yarn start-multi ``` For more than 2 clients, you can setup additional storage profiles and switch -between them using the `NODE_APP_INSTANCE` environment variable and specifying a -new localServerPort in the config. +between them using the `NODE_APP_INSTANCE` environment variable. For example, to create an 'alice' profile, put a file called `local-alice.json` in the `config` directory: @@ -104,7 +103,6 @@ For example, to create an 'alice' profile, put a file called `local-alice.json` ``` { "storageProfile": "aliceProfile", - "localServerPort": "8082", } ``` diff --git a/config/default.json b/config/default.json index b08784f25..b8a2dcc33 100644 --- a/config/default.json +++ b/config/default.json @@ -3,7 +3,6 @@ "localUrl": "localhost.loki", "cdnUrl": "random.snode", "contentProxyUrl": "", - "localServerPort": "8081", "defaultPoWDifficulty": "1", "seedNodeList": [ { diff --git a/config/development-1.json b/config/development-1.json index 2ff930238..0cccc8bd9 100644 --- a/config/development-1.json +++ b/config/development-1.json @@ -1,16 +1,3 @@ { - "storageProfile": "development1", - "localServerPort": "8082", - "seedNodeList": [ - { - "ip": "public.loki.foundation", - "port": "38157" - }, - { - "ip": "storage.testnetseed1.loki.network", - "port": "38157" - } - ], - "openDevTools": true, - "defaultPublicChatServer": "https://chat-dev.lokinet.org/" + "storageProfile": "development1" } diff --git a/config/development-2.json b/config/development-2.json deleted file mode 100644 index bf4c93258..000000000 --- a/config/development-2.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "storageProfile": "development2", - "localServerPort": "8083", - "seedNodeList": [ - { - "ip": "public.loki.foundation", - "port": "38157" - }, - { - "ip": "storage.testnetseed1.loki.network", - "port": "38157" - } - ], - "openDevTools": true, - "defaultPublicChatServer": "https://chat-dev.lokinet.org/" -} diff --git a/config/staging.json b/config/staging.json deleted file mode 100644 index f74f4b48e..000000000 --- a/config/staging.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "storageProfile": "staging", - "openDevTools": true -} diff --git a/config/swarm-testing-2.json b/config/swarm-testing-2.json new file mode 100644 index 000000000..0c69c0be1 --- /dev/null +++ b/config/swarm-testing-2.json @@ -0,0 +1,3 @@ +{ + "storageProfile": "swarm-testing2" +} diff --git a/config/swarm-testing2.json b/config/swarm-testing2.json deleted file mode 100644 index 5469d9dab..000000000 --- a/config/swarm-testing2.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "storageProfile": "swarm-testing2", - "seedNodeList": [ - { - "ip": "localhost", - "port": "22129" - } - ], - "openDevTools": true, - "defaultPublicChatServer": "https://team-chat.lokinet.org/" -} diff --git a/main.js b/main.js index 3c0943e6d..c32457be9 100644 --- a/main.js +++ b/main.js @@ -155,7 +155,6 @@ function prepareURL(pathSegments, moreKeys) { serverUrl: config.get('serverUrl'), localUrl: config.get('localUrl'), cdnUrl: config.get('cdnUrl'), - localServerPort: config.get('localServerPort'), defaultPoWDifficulty: config.get('defaultPoWDifficulty'), seedNodeList: JSON.stringify(config.get('seedNodeList')), certificateAuthority: config.get('certificateAuthority'), diff --git a/package.json b/package.json index e6bfcf6ca..9ba68d708 100644 --- a/package.json +++ b/package.json @@ -20,21 +20,15 @@ "start-multi2": "cross-env NODE_APP_INSTANCE=2 electron .", "start-prod": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod LOKI_DEV=1 electron .", "start-prod-multi": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod1 LOKI_DEV=1 electron .", - "start-swarm-test": "cross-env NODE_ENV=swarm-testing NODE_APP_INSTANCE=test1 LOKI_DEV=1 electron .", - "start-swarm-test-2": "cross-env NODE_ENV=swarm-testing2 NODE_APP_INSTANCE=test2 LOKI_DEV=1 electron .", + "start-swarm-test": "cross-env NODE_ENV=swarm-testing NODE_APP_INSTANCE=1 LOKI_DEV=1 electron .", + "start-swarm-test-2": "cross-env NODE_ENV=swarm-testing NODE_APP_INSTANCE=2 LOKI_DEV=1 electron .", "grunt": "grunt", "icon-gen": "electron-icon-maker --input=images/icon_1024.png --output=./build", "generate": "yarn icon-gen && yarn grunt", - "build": "electron-builder --config.extraMetadata.environment=$SIGNAL_ENV", - "build-release": "cross-env SIGNAL_ENV=production npm run build -- --config.directories.output=release", - "make:linux:x64:appimage": "electron-builder build --linux appimage --x64", "build-module-protobuf": "pbjs --target static-module --wrap commonjs --out ts/protobuf/compiled.js protos/*.proto && pbts --out ts/protobuf/compiled.d.ts ts/protobuf/compiled.js", "clean-module-protobuf": "rm -f ts/protobuf/compiled.d.ts ts/protobuf/compiled.js", "build-protobuf": "yarn build-module-protobuf", "clean-protobuf": "yarn clean-module-protobuf", - "prepare-beta-build": "node prepare_beta_build.js", - "prepare-import-build": "node prepare_import_build.js", - "publish-to-apt": "NAME=$npm_package_name VERSION=$npm_package_version ./aptly.sh", "test": "yarn test-node && yarn test-electron", "test-view": "NODE_ENV=test yarn run start", "test-lib-view": "NODE_ENV=test-lib yarn run start", @@ -42,24 +36,20 @@ "test-electron": "yarn grunt test", "test-integration-session": "ELECTRON_DISABLE_SANDBOX=1 mocha --exit --timeout 5000 integration_test/integration_test.js", "test-node": "mocha --recursive --exit test/app test/modules ts/test libloki/test/node", - "test-node-coverage": "nyc --reporter=lcov --reporter=text mocha --recursive test/app test/modules ts/test libloki/test/node", - "test-node-coverage-html": "nyc --reporter=lcov --reporter=html mocha --recursive test/a/* */pp test/modules ts/test libloki/test/node", "eslint": "eslint --cache .", "eslint-fix": "eslint --fix .", "eslint-full": "eslint .", - "lint": "yarn format --list-different && yarn lint-windows", - "lint-full": "yarn format-full --list-different; yarn lint-windows-full", - "dev-lint": "yarn format --list-different; yarn lint-windows", - "lint-windows": "yarn eslint && yarn tslint", - "lint-windows-full": "yarn eslint-full && yarn tslint", + "lint": "yarn format && yarn lint-files", + "lint-full": "yarn format-full && yarn lint-files-full", + "dev-lint": "yarn format && yarn lint-files", + "lint-files": "yarn eslint && yarn tslint", + "lint-files-full": "yarn eslint-full && yarn tslint", "lint-deps": "node ts/util/lint/linter.js", "tslint": "tslint --format stylish --project .", - "format": "prettier --write `git ls-files --modified *.{css,js,json,md,scss,ts,tsx}` `git ls-files --modified ./**/*.{css,js,json,md,scss,ts,tsx}`", - "format-full": "prettier --write \"*.{css,js,json,md,scss,ts,tsx}\" \"./**/*.{css,js,json,md,scss,ts,tsx}\"", + "format": "prettier --list-different --write `git ls-files --modified *.{css,js,json,md,scss,ts,tsx}` `git ls-files --modified ./**/*.{css,js,json,md,scss,ts,tsx}`", + "format-full": "prettier --list-different --write \"*.{css,js,json,md,scss,ts,tsx}\" \"./**/*.{css,js,json,md,scss,ts,tsx}\"", "transpile": "tsc", "clean-transpile": "rimraf ts/**/*.js && rimraf ts/*.js", - "open-coverage": "open coverage/lcov-report/index.html", - "styleguide": "styleguidist server", "pow-metrics": "node metrics_app.js localhost 9000", "ready": "yarn clean-transpile && yarn grunt && yarn lint-full && yarn test-node && yarn test-electron && yarn lint-deps" }, diff --git a/preload.js b/preload.js index 4b1e6220d..6232c2cd5 100644 --- a/preload.js +++ b/preload.js @@ -317,8 +317,6 @@ window.LokiFileServerAPI = require('./js/modules/loki_file_server_api'); window.LokiRssAPI = require('./js/modules/loki_rss_api'); -window.localServerPort = config.localServerPort; - window.mnemonic = require('./libloki/modules/mnemonic'); const WorkerInterface = require('./js/modules/util_worker_interface'); diff --git a/prepare_beta_build.js b/prepare_beta_build.js deleted file mode 100644 index 13e297297..000000000 --- a/prepare_beta_build.js +++ /dev/null @@ -1,66 +0,0 @@ -/* eslint-disable no-console */ - -const fs = require('fs'); -const _ = require('lodash'); - -const packageJson = require('./package.json'); - -const { version } = packageJson; -const beta = /beta/; - -// You might be wondering why this file is necessary. It comes down to our desire to allow -// side-by-side installation of production and beta builds. Electron-Builder uses -// top-level data from package.json for many things, like the executable name, the -// debian package name, the install directory under /opt on linux, etc. We tried -// adding the ${channel} macro to these values, but Electron-Builder didn't like that. - -if (!beta.test(version)) { - process.exit(); -} - -console.log('prepare_beta_build: updating package.json'); - -// ------- - -const NAME_PATH = 'name'; -const PRODUCTION_NAME = 'loki-messenger-desktop'; -const BETA_NAME = 'loki-messenger-desktop-beta'; - -const PRODUCT_NAME_PATH = 'productName'; -const PRODUCTION_PRODUCT_NAME = 'Session'; -const BETA_PRODUCT_NAME = 'Session Beta'; - -const APP_ID_PATH = 'build.appId'; -const PRODUCTION_APP_ID = 'com.loki-project.messenger-desktop'; -const BETA_APP_ID = 'com.loki-project.messenger-desktop-beta'; - -const STARTUP_WM_CLASS_PATH = 'build.linux.desktop.StartupWMClass'; -const PRODUCTION_STARTUP_WM_CLASS = 'Session'; -const BETA_STARTUP_WM_CLASS = 'Session Beta'; - -// ------- - -function checkValue(object, objectPath, expected) { - const actual = _.get(object, objectPath); - if (actual !== expected) { - throw new Error(`${objectPath} was ${actual}; expected ${expected}`); - } -} - -// ------ - -checkValue(packageJson, NAME_PATH, PRODUCTION_NAME); -checkValue(packageJson, PRODUCT_NAME_PATH, PRODUCTION_PRODUCT_NAME); -checkValue(packageJson, APP_ID_PATH, PRODUCTION_APP_ID); -checkValue(packageJson, STARTUP_WM_CLASS_PATH, PRODUCTION_STARTUP_WM_CLASS); - -// ------- - -_.set(packageJson, NAME_PATH, BETA_NAME); -_.set(packageJson, PRODUCT_NAME_PATH, BETA_PRODUCT_NAME); -_.set(packageJson, APP_ID_PATH, BETA_APP_ID); -_.set(packageJson, STARTUP_WM_CLASS_PATH, BETA_STARTUP_WM_CLASS); - -// ------- - -fs.writeFileSync('./package.json', JSON.stringify(packageJson, null, ' ')); diff --git a/prepare_import_build.js b/prepare_import_build.js deleted file mode 100644 index e74a168ed..000000000 --- a/prepare_import_build.js +++ /dev/null @@ -1,69 +0,0 @@ -/* eslint-disable no-console */ - -const fs = require('fs'); -const _ = require('lodash'); - -const packageJson = require('./package.json'); -const defaultConfig = require('./config/default.json'); - -function checkValue(object, objectPath, expected) { - const actual = _.get(object, objectPath); - if (actual !== expected) { - throw new Error(`${objectPath} was ${actual}; expected ${expected}`); - } -} - -// You might be wondering why this file is necessary. We have some very specific -// requirements around our import-flavor builds. They need to look exactly the same as -// normal builds, but they must immediately open into import mode. So they need a -// slight config tweak, and then a change to the .app/.exe name (note: we do NOT want to -// change where data is stored or anything, since that would make these builds -// incompatible with the mainline builds) So we just change the artifact name. -// -// Another key thing to know about these builds is that we should not upload the -// latest.yml (windows) and latest-mac.yml (mac) that go along with the executables. -// This would interrupt the normal install flow for users installing from -// signal.org/download. So any release script will need to upload these files manually -// instead of relying on electron-builder, which will upload everything. - -// ------- - -console.log('prepare_import_build: updating config/default.json'); - -const IMPORT_PATH = 'import'; -const IMPORT_START_VALUE = false; -const IMPORT_END_VALUE = true; - -checkValue(defaultConfig, IMPORT_PATH, IMPORT_START_VALUE); - -_.set(defaultConfig, IMPORT_PATH, IMPORT_END_VALUE); - -// ------- - -console.log('prepare_import_build: updating package.json'); - -const MAC_ASSET_PATH = 'build.mac.artifactName'; -// eslint-disable-next-line no-template-curly-in-string -const MAC_ASSET_START_VALUE = '${name}-mac-${version}.${ext}'; -// eslint-disable-next-line no-template-curly-in-string -const MAC_ASSET_END_VALUE = '${name}-mac-${version}-import.${ext}'; - -const WIN_ASSET_PATH = 'build.win.artifactName'; -// eslint-disable-next-line no-template-curly-in-string -const WIN_ASSET_START_VALUE = '${name}-win-${version}.${ext}'; -// eslint-disable-next-line no-template-curly-in-string -const WIN_ASSET_END_VALUE = '${name}-win-${version}-import.${ext}'; - -checkValue(packageJson, MAC_ASSET_PATH, MAC_ASSET_START_VALUE); -checkValue(packageJson, WIN_ASSET_PATH, WIN_ASSET_START_VALUE); - -_.set(packageJson, MAC_ASSET_PATH, MAC_ASSET_END_VALUE); -_.set(packageJson, WIN_ASSET_PATH, WIN_ASSET_END_VALUE); - -// --- - -fs.writeFileSync( - './config/default.json', - JSON.stringify(defaultConfig, null, ' ') -); -fs.writeFileSync('./package.json', JSON.stringify(packageJson, null, ' ')); From 5f98f702d4dfeb528a7818e57a939484d4f0fdc8 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Thu, 26 Mar 2020 15:42:26 +1100 Subject: [PATCH 02/10] Generate storage profile dynamically --- app/config.js | 2 +- app/user_config.js | 21 ++++++++++++++++--- config/development-1.json | 3 --- config/development.json | 1 - config/local-devprod1.json | 6 ------ ...l-devprod.json => production-devprod.json} | 1 - config/production-devprod1.json | 4 ++++ config/swarm-testing-2.json | 3 --- config/swarm-testing.json | 1 - 9 files changed, 23 insertions(+), 19 deletions(-) delete mode 100644 config/development-1.json delete mode 100644 config/local-devprod1.json rename config/{local-devprod.json => production-devprod.json} (58%) create mode 100644 config/production-devprod1.json delete mode 100644 config/swarm-testing-2.json diff --git a/app/config.js b/app/config.js index 3a865109d..bd71b799c 100644 --- a/app/config.js +++ b/app/config.js @@ -36,11 +36,11 @@ config.environment = environment; // Log resulting env vars in use by config [ 'NODE_ENV', + 'NODE_APP_INSTANCE', 'NODE_CONFIG_DIR', 'NODE_CONFIG', 'ALLOW_CONFIG_MUTATIONS', 'HOSTNAME', - 'NODE_APP_INSTANCE', 'SUPPRESS_NO_CONFIG_WARNING', ].forEach(s => { console.log(`${s} ${config.util.getEnv(s)}`); diff --git a/app/user_config.js b/app/user_config.js index 12cdded84..63d0b3dd5 100644 --- a/app/user_config.js +++ b/app/user_config.js @@ -1,15 +1,30 @@ const path = require('path'); +const process = require('process'); const { app } = require('electron'); const { start } = require('./base_config'); const config = require('./config'); -// Use separate data directory for development -if (config.has('storageProfile')) { +let storageProfile; +const { NODE_ENV: environment, NODE_APP_INSTANCE:instance } = process.env; +const isProduction = environment === 'production' && !instance; + +// Use seperate data directories for each different environment and app instances +// We should prioritise config values first +if (config.has(storageProfile)) { + storageProfile = config.get('storageProfile'); +} else if (!isProduction) { + storageProfile = environment; + if (instance) { + storageProfile = storageProfile.concat(`-${instance}`) + } +} + +if (storageProfile) { const userData = path.join( app.getPath('appData'), - `Loki-Messenger-${config.get('storageProfile')}` + `Session-${storageProfile}` ); app.setPath('userData', userData); diff --git a/config/development-1.json b/config/development-1.json deleted file mode 100644 index 0cccc8bd9..000000000 --- a/config/development-1.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "storageProfile": "development1" -} diff --git a/config/development.json b/config/development.json index 89ac6c6f7..ba141816b 100644 --- a/config/development.json +++ b/config/development.json @@ -1,5 +1,4 @@ { - "storageProfile": "development", "seedNodeList": [ { "ip": "public.loki.foundation", diff --git a/config/local-devprod1.json b/config/local-devprod1.json deleted file mode 100644 index 9d3b12053..000000000 --- a/config/local-devprod1.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "storageProfile": "devprod1Profile", - "localServerPort": "8082", - "openDevTools": true, - "updatesEnabled": false -} diff --git a/config/local-devprod.json b/config/production-devprod.json similarity index 58% rename from config/local-devprod.json rename to config/production-devprod.json index 45797645e..62437286b 100644 --- a/config/local-devprod.json +++ b/config/production-devprod.json @@ -1,5 +1,4 @@ { - "storageProfile": "devprodProfile", "openDevTools": true, "updatesEnabled": false } diff --git a/config/production-devprod1.json b/config/production-devprod1.json new file mode 100644 index 000000000..62437286b --- /dev/null +++ b/config/production-devprod1.json @@ -0,0 +1,4 @@ +{ + "openDevTools": true, + "updatesEnabled": false +} diff --git a/config/swarm-testing-2.json b/config/swarm-testing-2.json deleted file mode 100644 index 0c69c0be1..000000000 --- a/config/swarm-testing-2.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "storageProfile": "swarm-testing2" -} diff --git a/config/swarm-testing.json b/config/swarm-testing.json index 9df9b3340..4e7ab7fee 100644 --- a/config/swarm-testing.json +++ b/config/swarm-testing.json @@ -1,5 +1,4 @@ { - "storageProfile": "swarm-testing", "seedNodeList": [ { "ip": "localhost", From 57239932ba417c03131e1862bd04e158c3aff975 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Thu, 26 Mar 2020 15:49:18 +1100 Subject: [PATCH 03/10] Fix integration test --- config/default-test-integration-session-2.json | 4 +--- config/default-test-integration-session.json | 2 +- integration_test/common.js | 4 +--- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/config/default-test-integration-session-2.json b/config/default-test-integration-session-2.json index e6a66e69d..a8a83dedc 100644 --- a/config/default-test-integration-session-2.json +++ b/config/default-test-integration-session-2.json @@ -1,6 +1,4 @@ { - "storageProfile": "testIntegration2Profile", - "openDevTools": false, - "updatesEnabled": false, + "storageProfile": "test-integration-session-2", "localServerPort": "8082" } diff --git a/config/default-test-integration-session.json b/config/default-test-integration-session.json index fc1ea41a9..2feee3707 100644 --- a/config/default-test-integration-session.json +++ b/config/default-test-integration-session.json @@ -1,5 +1,5 @@ { - "storageProfile": "testIntegrationProfile", + "storageProfile": "test-integration-session", "openDevTools": false, "updatesEnabled": false } diff --git a/integration_test/common.js b/integration_test/common.js index 90f231c71..4d9d36055 100644 --- a/integration_test/common.js +++ b/integration_test/common.js @@ -122,11 +122,9 @@ module.exports = { }, async startAndAssureCleanedApp(env = 'test-integration-session') { - const prefix = 'test-integration-session-'; - const envNumber = env.substr(env.lastIndexOf(prefix) + prefix.length) || ''; const userData = path.join( this.USER_DATA_ROOT_FOLDER, - `Loki-Messenger-testIntegration${envNumber}Profile` + `Session-${env}` ); await this.rmFolder(userData); From b97a68c7f6f9b712e53bcf058f8dff356c80da6e Mon Sep 17 00:00:00 2001 From: Mikunj Date: Thu, 26 Mar 2020 15:56:15 +1100 Subject: [PATCH 04/10] Guard against empty NODE_APP_INSTANCE --- app/user_config.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/user_config.js b/app/user_config.js index 63d0b3dd5..20b5b70c3 100644 --- a/app/user_config.js +++ b/app/user_config.js @@ -8,7 +8,8 @@ const config = require('./config'); let storageProfile; const { NODE_ENV: environment, NODE_APP_INSTANCE:instance } = process.env; -const isProduction = environment === 'production' && !instance; +const isValidInstance = instance && instance.length > 0; +const isProduction = environment === 'production' && !isValidInstance; // Use seperate data directories for each different environment and app instances // We should prioritise config values first @@ -16,7 +17,7 @@ if (config.has(storageProfile)) { storageProfile = config.get('storageProfile'); } else if (!isProduction) { storageProfile = environment; - if (instance) { + if (isValidInstance) { storageProfile = storageProfile.concat(`-${instance}`) } } From 3f5a8e7b1bd62d9c1d4d5166d4760d557bfa6866 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Thu, 26 Mar 2020 16:15:34 +1100 Subject: [PATCH 05/10] Remove redundance LOKI_DEV variable in scripts --- app/config.js | 13 +++++++------ integration_test/common.js | 1 - package.json | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/config.js b/app/config.js index bd71b799c..d3a97becb 100644 --- a/app/config.js +++ b/app/config.js @@ -1,12 +1,14 @@ const path = require('path'); -const electronIsDev = require('electron-is-dev'); +const isDevelopment = require('electron-is-dev'); let environment; // In production mode, NODE_ENV cannot be customized by the user -if (electronIsDev) { +if (isDevelopment) { + console.log('development'); environment = process.env.NODE_ENV || 'development'; + process.env.LOKI_DEV = 1; } else { environment = 'production'; } @@ -23,7 +25,9 @@ if (environment === 'production') { process.env.ALLOW_CONFIG_MUTATIONS = ''; process.env.SUPPRESS_NO_CONFIG_WARNING = ''; process.env.NODE_TLS_REJECT_UNAUTHORIZED = ''; - if (!process.env.LOKI_DEV) { + + // We could be running againt production but still be in dev mode, we need to handle that + if (!isDevelopment) { process.env.NODE_APP_INSTANCE = ''; } } @@ -39,9 +43,6 @@ config.environment = environment; 'NODE_APP_INSTANCE', 'NODE_CONFIG_DIR', 'NODE_CONFIG', - 'ALLOW_CONFIG_MUTATIONS', - 'HOSTNAME', - 'SUPPRESS_NO_CONFIG_WARNING', ].forEach(s => { console.log(`${s} ${config.util.getEnv(s)}`); }); diff --git a/integration_test/common.js b/integration_test/common.js index 4d9d36055..35e2067ec 100644 --- a/integration_test/common.js +++ b/integration_test/common.js @@ -57,7 +57,6 @@ module.exports = { env: { NODE_APP_INSTANCE: env, NODE_ENV: 'production', - LOKI_DEV: 1, USE_STUBBED_NETWORK: true, ELECTRON_ENABLE_LOGGING: true, ELECTRON_ENABLE_STACK_DUMPING: true, diff --git a/package.json b/package.json index 9ba68d708..6cc5f7249 100644 --- a/package.json +++ b/package.json @@ -18,10 +18,10 @@ "start": "electron .", "start-multi": "cross-env NODE_APP_INSTANCE=1 electron .", "start-multi2": "cross-env NODE_APP_INSTANCE=2 electron .", - "start-prod": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod LOKI_DEV=1 electron .", - "start-prod-multi": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod1 LOKI_DEV=1 electron .", - "start-swarm-test": "cross-env NODE_ENV=swarm-testing NODE_APP_INSTANCE=1 LOKI_DEV=1 electron .", - "start-swarm-test-2": "cross-env NODE_ENV=swarm-testing NODE_APP_INSTANCE=2 LOKI_DEV=1 electron .", + "start-prod": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod electron .", + "start-prod-multi": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod1 electron .", + "start-swarm-test": "cross-env NODE_ENV=swarm-testing NODE_APP_INSTANCE=1 electron .", + "start-swarm-test-2": "cross-env NODE_ENV=swarm-testing NODE_APP_INSTANCE=2 electron .", "grunt": "grunt", "icon-gen": "electron-icon-maker --input=images/icon_1024.png --output=./build", "generate": "yarn icon-gen && yarn grunt", From 0cccc70b9b942e6925c64eae56c3f2e2df7d6a02 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Thu, 26 Mar 2020 16:34:34 +1100 Subject: [PATCH 06/10] Fix integration test running on the wrong environment --- app/config.js | 2 +- app/sql_channel.js | 2 +- integration_test/common.js | 3 +-- main.js | 11 +++++------ package.json | 2 +- preload.js | 4 ++-- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/app/config.js b/app/config.js index d3a97becb..6156d7f41 100644 --- a/app/config.js +++ b/app/config.js @@ -20,7 +20,7 @@ process.env.NODE_CONFIG_DIR = path.join(__dirname, '..', 'config'); if (environment === 'production') { // harden production config against the local env process.env.NODE_CONFIG = ''; - process.env.NODE_CONFIG_STRICT_MODE = true; + process.env.NODE_CONFIG_STRICT_MODE = !isDevelopment; process.env.HOSTNAME = ''; process.env.ALLOW_CONFIG_MUTATIONS = ''; process.env.SUPPRESS_NO_CONFIG_WARNING = ''; diff --git a/app/sql_channel.js b/app/sql_channel.js index f7e3a177e..f4b99ecea 100644 --- a/app/sql_channel.js +++ b/app/sql_channel.js @@ -37,7 +37,7 @@ function initialize() { `sql channel error with call ${callName}: ${errorForDisplay}` ); // FIXME this line cause the test-integration to fail and we probably don't need it during test - if (!process.env.NODE_APP_INSTANCE.includes('test-integration')) { + if (!process.env.NODE_ENV.includes('test-integration')) { event.sender.send(`${SQL_CHANNEL_KEY}-done`, jobId, errorForDisplay); } } diff --git a/integration_test/common.js b/integration_test/common.js index 35e2067ec..53f3aef25 100644 --- a/integration_test/common.js +++ b/integration_test/common.js @@ -55,8 +55,7 @@ module.exports = { path: path.join(__dirname, '..', 'node_modules', '.bin', 'electron'), args: ['.'], env: { - NODE_APP_INSTANCE: env, - NODE_ENV: 'production', + NODE_ENV: env, USE_STUBBED_NETWORK: true, ELECTRON_ENABLE_LOGGING: true, ELECTRON_ENABLE_STACK_DUMPING: true, diff --git a/main.js b/main.js index c32457be9..092fd52a4 100644 --- a/main.js +++ b/main.js @@ -899,7 +899,7 @@ app.on('window-all-closed', () => { config.environment === 'test' || config.environment === 'test-lib' || config.environment === 'test-loki' || - config.environmen.includes('test-integration') + config.environment.includes('test-integration') ) { app.quit(); } @@ -950,11 +950,10 @@ ipc.on('add-setup-menu-items', () => { }); ipc.on('draw-attention', () => { - if (process.platform === 'darwin') { - app.dock.bounce(); - } else if (process.platform === 'win32') { - mainWindow.flashFrame(true); - } else if (process.platform === 'linux') { + if (!mainWindow) { + return; + } + if (process.platform === 'win32' || process.platform === 'linux') { mainWindow.flashFrame(true); } }); diff --git a/package.json b/package.json index 6cc5f7249..ae9fe41d0 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "test-lib-view": "NODE_ENV=test-lib yarn run start", "test-loki-view": "NODE_ENV=test-loki yarn run start", "test-electron": "yarn grunt test", - "test-integration-session": "ELECTRON_DISABLE_SANDBOX=1 mocha --exit --timeout 5000 integration_test/integration_test.js", + "test-integration": "ELECTRON_DISABLE_SANDBOX=1 mocha --exit --timeout 5000 integration_test/integration_test.js", "test-node": "mocha --recursive --exit test/app test/modules ts/test libloki/test/node", "eslint": "eslint --cache .", "eslint-fix": "eslint --fix .", diff --git a/preload.js b/preload.js index 6232c2cd5..c61462fc0 100644 --- a/preload.js +++ b/preload.js @@ -52,8 +52,8 @@ window.getDefaultFileServer = () => config.defaultFileServer; window.initialisedAPI = false; if ( - typeof process.env.NODE_APP_INSTANCE === 'string' && - process.env.NODE_APP_INSTANCE.includes('test-integration') + typeof process.env.NODE_ENV === 'string' && + process.env.NODE_ENV.includes('test-integration') ) { window.electronRequire = require; } From 555db5e83b7dcde58805b53fcdf969a3966d4198 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Fri, 27 Mar 2020 09:06:30 +1100 Subject: [PATCH 07/10] Update documentation --- CONTRIBUTING.md | 58 ++++++++++++++++++++----------------------------- package.json | 1 + 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 61cd4f4d6..9e01cf225 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -82,38 +82,43 @@ while you make changes: yarn grunt dev # runs until you stop it, re-generating built assets on file changes ``` -## Additional storage profiles +## Multiple instances Since there is no registration for Session, you can create as many accounts as you -can public keys. To test the P2P functionality on the same machine, however, requries -that each client binds their message server to a different port. +can public keys. Each client however has a dedicated storage profile which is determined by the environment and instance variables. -You can use the following command to start a client bound to a different port. +This profile will change [userData](https://electron.atom.io/docs/all/#appgetpathname) +directory from `%appData%/Session` to `%appData%/Session-{environment}-{instance}`. +There are a few scripts which you can use: ``` -yarn start-multi +yarn start - Start development +yarn start-multi - Start second instance of development +yarn start-prod - Start production but in development mode +yarn start-prod-multi - Start another instance of production ``` -For more than 2 clients, you can setup additional storage profiles and switch -between them using the `NODE_APP_INSTANCE` environment variable. +For more than 2 clients, you may run the above command with `NODE_APP_INSTANCE` set before them. +For example, running: +``` +NODE_APP_INSTANCE=alice yarn start +``` +Will run the development environment with the `alice` instance and thus create a seperate storage profile. + +If a fixed profile is needed (in the case of tests), you can specify it using `storageProfile` in the config file. If the change is local then put it in `local-{instance}.json` otherwise put it in `default-{instance}.json` or `{env}-{instance}.json`. + +Local config files will be ignored by default in git. -For example, to create an 'alice' profile, put a file called `local-alice.json` in the +For example, to create an 'alice' profile locally, put a file called `local-alice.json` in the `config` directory: ``` { - "storageProfile": "aliceProfile", + "storageProfile": "alice-profile", } ``` -Then you can start up the application a little differently to load the profile: - -``` -NODE_APP_INSTANCE=alice yarn run start -``` - -This changes the [userData](https://electron.atom.io/docs/all/#appgetpathname) -directory from `%appData%/Session` to `%appData%/Session-aliceProfile`. +This will then set the `userData` directory to `%appData%/Session-alice-profile` when running the `alice` instance. # Making changes @@ -185,26 +190,11 @@ Above all, spend some time with the repository. Follow the pull request template your pull request description automatically. Take a look at recent approved pull requests, see how they did things. -## Testing Production Builds +## Production Builds -To test changes to the build system, build a release using +You can build a production binary by running the following: ``` yarn generate yarn build-release ``` - -Then, run the tests using `grunt test-release:osx --dir=release`, replacing `osx` with `linux` or `win` depending on your platform. - - diff --git a/package.json b/package.json index ae9fe41d0..7df33965b 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "grunt": "grunt", "icon-gen": "electron-icon-maker --input=images/icon_1024.png --output=./build", "generate": "yarn icon-gen && yarn grunt", + "build-release": "cross-env SIGNAL_ENV=production npm run build -- --config.directories.output=release", "build-module-protobuf": "pbjs --target static-module --wrap commonjs --out ts/protobuf/compiled.js protos/*.proto && pbts --out ts/protobuf/compiled.d.ts ts/protobuf/compiled.js", "clean-module-protobuf": "rm -f ts/protobuf/compiled.d.ts ts/protobuf/compiled.js", "build-protobuf": "yarn build-module-protobuf", From 5c36b757238224cf2800b402409086f5eaea86a7 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Fri, 27 Mar 2020 09:29:29 +1100 Subject: [PATCH 08/10] More integration test cleanup --- .../default-test-integration-session-2.json | 4 --- ...ion-session.json => test-integration.json} | 1 - integration_test/common.js | 27 +++++++++++++------ 3 files changed, 19 insertions(+), 13 deletions(-) delete mode 100644 config/default-test-integration-session-2.json rename config/{default-test-integration-session.json => test-integration.json} (53%) diff --git a/config/default-test-integration-session-2.json b/config/default-test-integration-session-2.json deleted file mode 100644 index a8a83dedc..000000000 --- a/config/default-test-integration-session-2.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "storageProfile": "test-integration-session-2", - "localServerPort": "8082" -} diff --git a/config/default-test-integration-session.json b/config/test-integration.json similarity index 53% rename from config/default-test-integration-session.json rename to config/test-integration.json index 2feee3707..d2b1f6973 100644 --- a/config/default-test-integration-session.json +++ b/config/test-integration.json @@ -1,5 +1,4 @@ { - "storageProfile": "test-integration-session", "openDevTools": false, "updatesEnabled": false } diff --git a/integration_test/common.js b/integration_test/common.js index 53f3aef25..83565e361 100644 --- a/integration_test/common.js +++ b/integration_test/common.js @@ -50,17 +50,28 @@ module.exports = { return new Promise(resolve => setTimeout(resolve, ms)); }, - async startApp(env = 'test-integration-session') { + async startApp(environment = 'test-integration-session') { + const env = { + NODE_ENV: environment, + USE_STUBBED_NETWORK: true, + ELECTRON_ENABLE_LOGGING: true, + ELECTRON_ENABLE_STACK_DUMPING: true, + ELECTRON_DISABLE_SANDBOX: 1, + }; + + // If it's specifically integration environment then we should extract the instance from it. + // This will still allow its storage to be found in Session-{environment} + // It just makes it easier to manage the config file + if (environment.includes('test-integration-')) { + const instance = environment.replace('test-integration-', ''); + env.NODE_ENV = 'test-integration'; + env.NODE_APP_INSTANCE = instance; + } + const app1 = new Application({ path: path.join(__dirname, '..', 'node_modules', '.bin', 'electron'), args: ['.'], - env: { - NODE_ENV: env, - USE_STUBBED_NETWORK: true, - ELECTRON_ENABLE_LOGGING: true, - ELECTRON_ENABLE_STACK_DUMPING: true, - ELECTRON_DISABLE_SANDBOX: 1, - }, + env, startTimeout: 10000, requireName: 'electronRequire', // chromeDriverLogPath: '../chromedriverlog.txt', From fa387b5dfa6bf3edc68f6b7169251aeb007b9376 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Fri, 27 Mar 2020 09:48:37 +1100 Subject: [PATCH 09/10] Linting and review fix --- CONTRIBUTING.md | 3 +++ app/config.js | 13 +++++-------- app/user_config.js | 10 +++++++--- integration_test/common.js | 34 +++++++++++++--------------------- 4 files changed, 28 insertions(+), 32 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9e01cf225..7a13f984f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -91,6 +91,7 @@ This profile will change [userData](https://electron.atom.io/docs/all/#appgetpat directory from `%appData%/Session` to `%appData%/Session-{environment}-{instance}`. There are a few scripts which you can use: + ``` yarn start - Start development yarn start-multi - Start second instance of development @@ -100,9 +101,11 @@ yarn start-prod-multi - Start another instance of production For more than 2 clients, you may run the above command with `NODE_APP_INSTANCE` set before them. For example, running: + ``` NODE_APP_INSTANCE=alice yarn start ``` + Will run the development environment with the `alice` instance and thus create a seperate storage profile. If a fixed profile is needed (in the case of tests), you can specify it using `storageProfile` in the config file. If the change is local then put it in `local-{instance}.json` otherwise put it in `default-{instance}.json` or `{env}-{instance}.json`. diff --git a/app/config.js b/app/config.js index 6156d7f41..5ae3c9f8e 100644 --- a/app/config.js +++ b/app/config.js @@ -38,13 +38,10 @@ const config = require('config'); config.environment = environment; // Log resulting env vars in use by config -[ - 'NODE_ENV', - 'NODE_APP_INSTANCE', - 'NODE_CONFIG_DIR', - 'NODE_CONFIG', -].forEach(s => { - console.log(`${s} ${config.util.getEnv(s)}`); -}); +['NODE_ENV', 'NODE_APP_INSTANCE', 'NODE_CONFIG_DIR', 'NODE_CONFIG'].forEach( + s => { + console.log(`${s} ${config.util.getEnv(s)}`); + } +); module.exports = config; diff --git a/app/user_config.js b/app/user_config.js index 20b5b70c3..2324c8008 100644 --- a/app/user_config.js +++ b/app/user_config.js @@ -7,8 +7,12 @@ const { start } = require('./base_config'); const config = require('./config'); let storageProfile; -const { NODE_ENV: environment, NODE_APP_INSTANCE:instance } = process.env; -const isValidInstance = instance && instance.length > 0; + +// Node makes sure all environment variables are strings +const { NODE_ENV: environment, NODE_APP_INSTANCE: instance } = process.env; + +// We need to make sure instance is not empty +const isValidInstance = instance === 'string' && instance.length > 0; const isProduction = environment === 'production' && !isValidInstance; // Use seperate data directories for each different environment and app instances @@ -18,7 +22,7 @@ if (config.has(storageProfile)) { } else if (!isProduction) { storageProfile = environment; if (isValidInstance) { - storageProfile = storageProfile.concat(`-${instance}`) + storageProfile = storageProfile.concat(`-${instance}`); } } diff --git a/integration_test/common.js b/integration_test/common.js index 83565e361..0a2daca5b 100644 --- a/integration_test/common.js +++ b/integration_test/common.js @@ -51,27 +51,22 @@ module.exports = { }, async startApp(environment = 'test-integration-session') { - const env = { - NODE_ENV: environment, - USE_STUBBED_NETWORK: true, - ELECTRON_ENABLE_LOGGING: true, - ELECTRON_ENABLE_STACK_DUMPING: true, - ELECTRON_DISABLE_SANDBOX: 1, - }; - - // If it's specifically integration environment then we should extract the instance from it. - // This will still allow its storage to be found in Session-{environment} - // It just makes it easier to manage the config file - if (environment.includes('test-integration-')) { - const instance = environment.replace('test-integration-', ''); - env.NODE_ENV = 'test-integration'; - env.NODE_APP_INSTANCE = instance; - } + const env = environment.startsWith('test-integration') + ? 'test-integration' + : environment; + const instance = environment.replace('test-integration-', ''); const app1 = new Application({ path: path.join(__dirname, '..', 'node_modules', '.bin', 'electron'), args: ['.'], - env, + env: { + NODE_ENV: env, + NODE_APP_INSTANCE: instance, + USE_STUBBED_NETWORK: true, + ELECTRON_ENABLE_LOGGING: true, + ELECTRON_ENABLE_STACK_DUMPING: true, + ELECTRON_DISABLE_SANDBOX: 1, + }, startTimeout: 10000, requireName: 'electronRequire', // chromeDriverLogPath: '../chromedriverlog.txt', @@ -131,10 +126,7 @@ module.exports = { }, async startAndAssureCleanedApp(env = 'test-integration-session') { - const userData = path.join( - this.USER_DATA_ROOT_FOLDER, - `Session-${env}` - ); + const userData = path.join(this.USER_DATA_ROOT_FOLDER, `Session-${env}`); await this.rmFolder(userData); From 9f585792430ba3a89e023818761b2d16fd883609 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Fri, 27 Mar 2020 09:54:36 +1100 Subject: [PATCH 10/10] Minor fix --- app/config.js | 1 - app/user_config.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/config.js b/app/config.js index 5ae3c9f8e..760f20e33 100644 --- a/app/config.js +++ b/app/config.js @@ -6,7 +6,6 @@ let environment; // In production mode, NODE_ENV cannot be customized by the user if (isDevelopment) { - console.log('development'); environment = process.env.NODE_ENV || 'development'; process.env.LOKI_DEV = 1; } else { diff --git a/app/user_config.js b/app/user_config.js index 2324c8008..cb434935c 100644 --- a/app/user_config.js +++ b/app/user_config.js @@ -12,7 +12,7 @@ let storageProfile; const { NODE_ENV: environment, NODE_APP_INSTANCE: instance } = process.env; // We need to make sure instance is not empty -const isValidInstance = instance === 'string' && instance.length > 0; +const isValidInstance = typeof instance === 'string' && instance.length > 0; const isProduction = environment === 'production' && !isValidInstance; // Use seperate data directories for each different environment and app instances