From 7fdd0af34d5f6df8858b725b7a8fa0acc22d22ce Mon Sep 17 00:00:00 2001 From: ejolly Date: Mon, 5 Oct 2020 21:51:10 -0400 Subject: [PATCH] Fixed a nasty bug that still booted the app when AWS credentials were missing. Also apparently the download release dep's uzip dep can't unzip tar archives. Need to manually compress the packaged app for now. --- main/main.js | 65 +++++++++++++++++++++++++++------------------------- package.json | 4 ++-- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/main/main.js b/main/main.js index f6a42ae..a751404 100644 --- a/main/main.js +++ b/main/main.js @@ -66,11 +66,41 @@ const mainLog = log.scope('main'); let mainWindow; // try to load aws credentials -let awsCredentials = { - accessKeyId: process.env.AWS_SECRET_ACCESS_KEY, - secretAccessKey: process.env.AWS_ACCESS_KEY_ID, +let awsCredentials; + +// LOAD AWS CREDENTIALS +const loadAWS = () => { + awsCredentials = { + accessKeyId: process.env.AWS_SECRET_ACCESS_KEY, + secretAccessKey: process.env.AWS_ACCESS_KEY_ID, + }; + if (awsCredentials.accessKeyId && awsCredentials.secretAccessKey) { + mainLog.info('AWS credentials loaded from environment variables.'); + } else { + fs.readFile(`${app.getPath('home')}/.awscredentials.json`, (err, data) => { + if (err) { + mainLog.error('AWS credentials not configured'); + dialog + .showMessageBox({ + type: 'error', + title: 'No AWS Credentials', + message: + "Hmm I can't seem to find your AWS credentials. Are you sure you configured them? See the directions: https://eshinjolly.com/svelteturk/#/aws-credentials", + }) + .then(() => { + mainLog.info('Exiting...'); + app.exit(0); + process.abort(); + }); + } else { + awsCredentials = JSON.parse(data); + mainLog.info('AWS credentials loaded from file'); + } + }); + } }; + // Settings file location const settingsFile = path.join(svelteturkPath, '.svelteturkrc'); // Default settings only applied if settings file doesn't exist @@ -211,34 +241,6 @@ const checkForLatestVersion = async () => { return updateAvailable; }; -// LOAD AWS CREDENTIALS -if (awsCredentials.accessKeyId && awsCredentials.secretAccessKey) { - mainLog.info('AWS credentials loaded from environment variables.'); -} else { - fs.readFile(`${app.getPath('home')}/.awscredentials.json`, (err, data) => { - if (err) { - if (err.code === 'ENOENT') { - dialog - .showMessageBox({ - type: 'error', - title: 'File not found', - message: - 'No environment variables or config file were found for your AWS Credentials! Please configure them and restart the app', - }) - .then(() => { - mainLog.error('No AWS environment variables or config file found. Exiting...'); - app.exit(0); - process.abort(); - }); - } else { - throw err; - } - } else { - awsCredentials = JSON.parse(data); - mainLog.info('AWS credentials loaded from file'); - } - }); -} // Create the browser window. const createWindow = () => { mainWindow = new BrowserWindow({ @@ -279,6 +281,7 @@ app.on('activate', () => { // Send aws credentials and user settings ipcMain.handle('initialize', async (ev) => { mainLog.info('<--API: intialize'); + loadAWS(); let updateAvailable; let userWantsToUpdate = false; try { diff --git a/package.json b/package.json index 2e9a121..3624d4f 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,12 @@ { "name": "SvelteTurk", "productName": "SvelteTurk", - "version": "0.1.1", + "version": "0.1.2", "description": "Control mturk via a simple gui app", "main": "main/main.js", "scripts": { "start": "ls main/main.js | entr -r concurrently \"npm:svelte-dev\" \"electron-forge start\"", - "package": "rollup -c && electron-forge package && tar -zcf out/SvelteTurk-darwin-x64.zip out/SvelteTurk-darwin-x64", + "package": "rollup -c && electron-forge package && rm out/*.zip", "prep-release": "./makerelease.sh", "release": "npm run package && npm run prep-release", "make": "electron-forge make",