From e146a95620d02a3d2035c8b3b1d0206f7c58f45c Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Thu, 13 Jul 2017 01:27:21 +0530 Subject: [PATCH] Electron-77 - Implemented method to update user config --- installer/mac/postinstall.sh | 1 + js/main.js | 52 +++++++++++++++++++++++++++++++++--- package.json | 3 ++- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/installer/mac/postinstall.sh b/installer/mac/postinstall.sh index 08beeefc..9317ff3c 100755 --- a/installer/mac/postinstall.sh +++ b/installer/mac/postinstall.sh @@ -46,6 +46,7 @@ rm -f $tempFilePath ## For launching symphony with sandbox enabled, create a shell script that is used as the launch point for the app EXEC_PATH=$installPath/Symphony.app/Contents/MacOS +exec $EXEC_PATH/Symphony --install $newPath mv $EXEC_PATH/Symphony $EXEC_PATH/Symphony-bin cat > $EXEC_PATH/Symphony << EOT #!/bin/sh diff --git a/js/main.js b/js/main.js index 0d74cd86..31cccc92 100644 --- a/js/main.js +++ b/js/main.js @@ -9,7 +9,11 @@ const urlParser = require('url'); const { getConfigField } = require('./config.js'); const { isMac, isDevEnv } = require('./utils/misc.js'); const protocolHandler = require('./protocolHandler'); -const getCmdLineArg = require('./utils/getCmdLineArg.js') +const getCmdLineArg = require('./utils/getCmdLineArg.js'); +const childProcess = require('child_process'); +const path = require('path'); +const AppDirectory = require('appdirectory'); +const dirs = new AppDirectory('Symphony'); require('electron-dl')(); @@ -94,9 +98,18 @@ function setupThenOpenMainWindow() { let hasInstallFlag = getCmdLineArg(process.argv, '--install', true); if (!isMac && hasInstallFlag) { getConfigField('launchOnStartup') - .then(setStartup) - .then(app.quit) - .catch(app.quit); + .then(setStartup) + .then(updateUserConfigWin) + .then(app.quit) + .catch(app.quit); + return; + } + + // allows mac installer to overwrite user config + if (isMac && hasInstallFlag) { + updateUserConfigMac() + .then(app.quit) + .catch(app.quit); return; } @@ -118,6 +131,37 @@ function setStartup(lStartup){ }); } +// Method to overwrite user config on mac installer +function updateUserConfigMac() { + return new Promise((resolve, reject) => { + let userConfigPath = process.env.HOME + '/Library/Application Support/Symphony/'; + let globalConfigPath = process.argv[2]; + let userName = process.env.USER; + + childProcess.exec(`rsync -r "${globalConfigPath}" "${userConfigPath}" && chown -R "${userName}" "${userConfigPath}"`, (error, stdout) => { + if (error) { + reject(error); + } + resolve(); + }); + }); +} + +// Method to overwrite user config on windows installer +function updateUserConfigWin() { + return new Promise((resolve, reject) => { + let userConfigPath = app.getPath('userData'); + let globalConfigPath = path.join(__dirname, '..', '..', '..', 'config/Symphony.config'); + + childProcess.exec(`echo D|xcopy /y /e /s /c "${globalConfigPath}" "${userConfigPath}"`, (err) => { + if (err) { + reject(err); + } + resolve(); + }); + }); +} + function getUrlAndCreateMainWindow() { // for dev env allow passing url argument if (isDevEnv) { diff --git a/package.json b/package.json index 2f40012d..8bdfa2c4 100644 --- a/package.json +++ b/package.json @@ -92,7 +92,8 @@ "keymirror": "0.1.1", "winreg": "^1.2.3", "electron-dl": "^1.9.0", - "filesize": "^3.5.10" + "filesize": "^3.5.10", + "appdirectory": "^0.1.0" }, "optionalDependencies": { "screen-snippet": "git+https://github.com/symphonyoss/ScreenSnippet.git#v1.0.1"